Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Currently we can enter two coupons with the same names. And the code just gets first one from entity query made for coupons and apply it.
/**
* {@inheritdoc}
*/
public function loadByCode($code) {
$coupons = $this->loadByProperties(['code' => $code, 'status' => TRUE]);
return reset($coupons);
}
Comments
Comment #2
bojanz CreditAttribution: bojanz at Centarro commentedThe CouponCodeConstraint checks that the code is unique when a coupon is validated.
Maybe we're running into an Inline Entity Form bug that's causing it to be skipped?
Comment #3
sumanthkumarc CreditAttribution: sumanthkumarc at Azri Solutions commented@bojanz sorry i didn't specify the case, i am trying to create a coupon programmatically and add it to promotion.
it doesn't throw any exceptions or errors in this case.
Comment #4
bojanz CreditAttribution: bojanz at Centarro commentedYou need to run $violations = $coupon->validate(); and then check that. Drupal doesn't run validation on save (which is silly, I know)
Comment #5
sumanthkumarc CreditAttribution: sumanthkumarc at Azri Solutions commentedjust changing the title, incase someone gets into similar condition.