Closed (fixed)
Project:
Commerce Core
Version:
8.x-2.x-dev
Component:
Promotions
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
9 Jun 2017 at 07:34 UTC
Updated:
23 Jun 2017 at 09:59 UTC
Jump to comment: Most recent
When creating a new promotion, the Add new Coupon button fails.
The log gives:
TypeError: Argument 1 passed to Drupal\commerce_promotion\PromotionUsage::getUsage() must implement interface Drupal\commerce_promotion\Entity\PromotionInterface, null given, called in /Applications/MAMP/htdocs/uctd8/web/modules/contrib/commerce/modules/promotion/src/Plugin/Field/FieldWidget/UsageLimitWidget.php on line 82
It looks like the newly created Coupon entity has no Promotion ID set yet, when getUsage is called.
A solution would be to test for this before calling getUsage in UsageLimitWidget.php:
if ($promotion = $entity->getPromotion()) {
$usage = $this->usage->getUsage($promotion, $entity);
}
else {
$usage = 0;
}
Comments
Comment #2
finneGithub: https://github.com/drupalcommerce/commerce/pull/746
Comment #3
finneComment #4
finneComment #5
bojanz commentedAh yes, my code works only if the promotion was saved before creating the coupon.
Comment #6
finneOn my install this never worked, neither new nor previously saved promotions...
Comment #7
bojanz commentedCause it's the same bug. Retitling. We're obviously missing test coverage.
Comment #9
bojanz commentedPushed a fix. Thanks!