Steps to reproduce:
1. Install Drupal 8.5.3 && Drupal Commerce 8.x-2.6
2. Goto /admin/commerce/orders/add
3. Specify all required details
4. Add the Adjustment:
Type - Promotion
Label - any label
Amount - any amount
5. Save changes and try to place the order. You will get:
TypeError: Argument 2 passed to Drupal\commerce_promotion\PromotionUsage::register() must implement interface Drupal\commerce_promotion\Entity\PromotionInterface, null given, called in /path/modules/contrib/commerce/modules/promotion/src/EventSubscriber/OrderEventSubscriber.php on line 85 in Drupal\commerce_promotion\PromotionUsage->register() (line 33 of /path/modules/contrib/commerce/modules/promotion/src/PromotionUsage.php)
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | commerce-custom-promotion-error-on-order-backend-placing-2980255-5.patch | 875 bytes | max-kuzomko |
Comments
Comment #2
bojanz commentedOrderEventSubscriber::registerUsage():
We need to check that $promotion is an object (and not FALSE) before passing it to $this->usage->register().
Comment #3
max-kuzomko commentedComment #4
max-kuzomko commentedThanks, @bojanz for really quick response!
Attaching the patch.
Comment #5
max-kuzomko commentedWrong patch
Comment #7
max-kuzomko commentedComment #8
mglamanLooks good, to me. Ideally we'd have a test showing that this crash won't occur again.
Comment #10
bojanz commentedCrediting archnode, who posted a duplicate patch in another issue (#2992825: Don't require a promotion adjustment source_id to match an entity).
Comment #12
bojanz commentedCommitted. Thanks, everyone.