Skip to content

Commit d25adf4

Browse files
authored
Merge pull request #4071 from craftcms/nathaniel/pt-2840-5x-twig-runtimeerror-couponhiddeninputs-called-when-editing
[5.x] Fix #4069 edit discounts PHP error
2 parents 49f157b + 4ad748e commit d25adf4

3 files changed

Lines changed: 6 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Fixed a PHP error that could occur when viewing variant indexes and using Craft CMS 5.6.17 or earlier. ([#4060](https://github.com/craftcms/commerce/issues/4060))
77
- Fixed a bug where currency based order condition rules incorrectly showed up as custom fields.
88
- Fixed a bug where Subscription and Transfer elements’ field layouts were not deleted when Commerce was uninstalled.
9+
- Fixed a PHP error that could occur when editing discounts. ([#4069](https://github.com/craftcms/commerce/issues/4069))
910

1011
## 5.4.0 - 2025-06-23
1112

src/controllers/DiscountsController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ public function actionEdit(int $id = null, Discount $discount = null, string $st
227227
$variables['percentSymbol'] = Craft::$app->getFormattingLocale()->getNumberSymbol(Locale::SYMBOL_PERCENT);
228228
$this->getView()->registerAssetBundle(CouponsAsset::class);
229229

230+
$variables['coupons'] = collect($variables['discount']->getCoupons())
231+
->map(fn(Coupon $coupon) => $coupon->toArray())
232+
->all();
233+
230234
return $this->renderTemplate('commerce/store-management/discounts/_edit', $variables);
231235
}
232236

src/templates/store-management/discounts/_edit.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@
269269
id: 'commerce-coupons-table',
270270
name: couponsTable.name,
271271
cols: couponsTable.cols,
272-
rows: discount.coupons,
272+
rows: coupons,
273273
addRowLabel: 'Add a coupon'|t('commerce'),
274274
allowAdd: true,
275275
allowDelete: true,

0 commit comments

Comments
 (0)