|
7 | 7 | /**
|
8 | 8 | * @var \Magento\Framework\View\Element\AbstractBlock $block
|
9 | 9 | */
|
| 10 | + |
| 11 | +// We should use strlen function because coupon code could be "0", converted to bool will lead to false |
| 12 | +$hasCouponCode = (bool) strlen($block->getCouponCode()); |
10 | 13 | ?>
|
11 | 14 | <div class="block discount"
|
12 | 15 | id="block-discount"
|
13 |
| - data-mage-init='{"collapsible":{"openedState": "active", "saveState": false}}' |
| 16 | + data-mage-init='{"collapsible":{"active": <?= $hasCouponCode ? 'true' : 'false' ?>, "openedState": "active", "saveState": false}}' |
14 | 17 | >
|
15 | 18 | <div class="title" data-role="title">
|
16 | 19 | <strong id="block-discount-heading" role="heading" aria-level="2"><?= $block->escapeHtml(__('Apply Discount Code')) ?></strong>
|
|
23 | 26 | "removeCouponSelector": "#remove-coupon",
|
24 | 27 | "applyButton": "button.action.apply",
|
25 | 28 | "cancelButton": "button.action.cancel"}}'>
|
26 |
| - <div class="fieldset coupon<?= strlen($block->getCouponCode()) ? ' applied' : '' ?>"> |
| 29 | + <div class="fieldset coupon<?= $hasCouponCode ? ' applied' : '' ?>"> |
27 | 30 | <input type="hidden" name="remove" id="remove-coupon" value="0" />
|
28 | 31 | <div class="field">
|
29 | 32 | <label for="coupon_code" class="label"><span><?= $block->escapeHtml(__('Enter discount code')) ?></span></label>
|
|
34 | 37 | name="coupon_code"
|
35 | 38 | value="<?= $block->escapeHtmlAttr($block->getCouponCode()) ?>"
|
36 | 39 | placeholder="<?= $block->escapeHtmlAttr(__('Enter discount code')) ?>"
|
37 |
| - <?php if (strlen($block->getCouponCode())) :?> |
| 40 | + <?php if ($hasCouponCode) :?> |
38 | 41 | disabled="disabled"
|
39 | 42 | <?php endif; ?>
|
40 | 43 | />
|
41 | 44 | </div>
|
42 | 45 | </div>
|
43 | 46 | <div class="actions-toolbar">
|
44 |
| - <?php if (!strlen($block->getCouponCode())) :?> |
| 47 | + <?php if (!$hasCouponCode) :?> |
45 | 48 | <div class="primary">
|
46 | 49 | <button class="action apply primary" type="button" value="<?= $block->escapeHtmlAttr(__('Apply Discount')) ?>">
|
47 | 50 | <span><?= $block->escapeHtml(__('Apply Discount')) ?></span>
|
|
54 | 57 | <?php endif; ?>
|
55 | 58 | </div>
|
56 | 59 | </div>
|
57 |
| - <?php if (!strlen($block->getCouponCode())) : ?> |
| 60 | + <?php if (!$hasCouponCode) : ?> |
58 | 61 | <?= /* @noEscape */ $block->getChildHtml('captcha') ?>
|
59 | 62 | <?php endif; ?>
|
60 | 63 | </form>
|
|
0 commit comments