It's becoming very annoying to load a coupon when we only know the code.

    $coupon = $couponStorage->loadByProperties(['code' => $coupon_code]);
    $coupon = reset($coupon);

Would be must easier if the storage could do this for us.

CommentFileSizeAuthor
#2 add_custom_coupon-2855815-2.patch1.92 KBmitrpaka
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mglaman created an issue. See original summary.

mitrpaka’s picture

mglaman’s picture

Status: Needs review » Needs work
+++ b/modules/promotion/src/CouponStorage.php
@@ -0,0 +1,21 @@
+  public function loadByCode($coupon_code) {
+    $coupons = $this->loadByProperties(['code' => $coupon_code]);

+++ b/modules/promotion/src/CouponStorageInterface.php
@@ -0,0 +1,23 @@
+  public function loadByCode($coupon_code);

As stated on PR, let's just make it $code

Also, lets whip up a quick Kernel test to verify it works.

mglaman’s picture

Status: Needs work » Needs review

  • mglaman committed 7ca6964 on 8.x-2.x authored by mitrpaka
    Issue #2855815: Add custom coupon storage, provide loadByCode method.
    
    
mglaman’s picture

Status: Needs review » Fixed

Committed, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.