Allow admin orders to add child variations in 2.0

Created on 6 January 2022, over 2 years ago
Updated 14 August 2023, 11 months ago

Problem/Motivation

I recently upgraded from the 8-1.0-rc3 branch to 2.0.0-beta1. When I did so, I no longer get the add-on variations added to my orders when the parent product is added via the admin order interface. This worked great in the previous version and is a huge requirement for our project. I double checked that the front-end cart is working, just not the admin cart.

Steps to reproduce

Add a parent product variation to an order in the admin ui (/admin/commerce/order/{order_id}/edit) -> Save. Notice no children are added.

Proposed resolution

This functionality worked in the previous version, and in my mind is a regression. The old version seemed to do most of the work in OrderEvents::ORDER_PRESAVE, the new version seems to do most of the work in CartEvents::CART_ENTITY_ADD. I am not sure how this structure could be used to support admin orders where there is no cart.

✨ Feature request
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States scottsawyer Atlanta

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.0.7 + Environment: PHP 7.3 & MySQL 5.7
    last update about 1 year ago
    Composer error. Unable to continue.
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update about 1 year ago
    13 pass
  • Might need to look into how programmatic creation of children should be handled. With this patch applied, the children can attempt to be created.

  • Seeing this error in migrations, due to $parent_variation not being set:
    TypeError: Drupal\commerce_vado\EventSubscriber\VadoEventSubscriber::createChildren(): Argument #1 ($parent_variation) must be of type Drupal\commerce_product\Entity\ProductVariationInterface, null given, called in /var/www/html/web/modules/contrib/commerce_vado/src/EventSubscriber/VadoEventSubscriber.php on line 310 in /var/www/html/web/modules/contrib/commerce_vado/src/EventSubscriber/VadoEventSubscriber.php on line 103 #0 /var/www/html/web/modules/contrib/commerce_vado/src/EventSubscriber/VadoEventSubscriber.php(310):

    I think something like this might be better:

          if ($order->get('cart')->getValue()[0]['value'] == FALSE) {
            $parent_variation = $order_item->getPurchasedEntity();
            // Create children for non-cart orders only.
            if (!$parent_variation) {
              return;
            }
            $children = $this->createChildren($parent_variation, $order_item, $order);
            return $children;
          }
Production build 0.69.0 2024