Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
3.0 kB
4
Indexable
Never
<?php

/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/**
 * @var \Magento\Framework\View\Element\AbstractBlock $block
 */

// We should use strlen function because coupon code could be "0", converted to bool will lead to false
$hasCouponCode = $block->getCouponCode() !== null && strlen($block->getCouponCode()) > 0;
?>
<div class="block discount" id="block-discount" data-mage-init='{"collapsible":{"active": <?= $hasCouponCode ? 'true' : 'false' ?>, "openedState": "active", "saveState": false}}'>
    <div class="title" data-role="title">
        <strong id="block-discount-heading" role="heading" aria-level="2"><?= $block->escapeHtml(__('Apply Discount Code')) ?></strong>
    </div>
    <div class="content" data-role="content" aria-labelledby="block-discount-heading">
        <form id="discount-coupon-form" action="<?= $block->escapeUrl($block->getUrl('checkout/cart/couponPost')) ?>" method="post" data-mage-init='{"discountCode":{"couponCodeSelector": "#coupon_code",
                                               "removeCouponSelector": "#remove-coupon",
                                               "applyButton": "button.action.apply",
                                               "cancelButton": "button.action.cancel"}}'>
            <div class="fieldset coupon<?= $hasCouponCode ? ' applied' : '' ?>">
                <input type="hidden" name="remove" id="remove-coupon" value="0" />
                <div class="field">
                    <label for="coupon_code" class="label"><span><?= $block->escapeHtml(__('Coupon:')) ?></span></label>
                    <div class="control">
                        <input type="text" class="input-text" id="coupon_code" name="coupon_code" value="<?= $block->escapeHtmlAttr($block->getCouponCode()) ?>" placeholder="<?= $block->escapeHtmlAttr(__('Coupon code')) ?>" <?php if ($hasCouponCode) : ?> disabled="disabled" <?php endif; ?> />
                    </div>
                </div>
                <div class="actions-toolbar">
                    <?php if (!$hasCouponCode) : ?>
                        <div class="primary">
                            <button class="action apply primary" type="button" value="<?= $block->escapeHtmlAttr(__('Apply Coupon')) ?>">
                                <span><?= $block->escapeHtml(__('Apply Coupon')) ?></span>
                            </button>
                        </div>
                    <?php else : ?>
                        <div class="primary">
                            <button type="button" class="action cancel primary" value="<?= $block->escapeHtmlAttr(__('Cancel')) ?>"><span><?= $block->escapeHtml(__('Cancel')) ?></span></button>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
            <?php if (!$hasCouponCode) : ?>
                <?= /* @noEscape */ $block->getChildHtml('captcha') ?>
            <?php endif; ?>
        </form>
    </div>
</div>
Leave a Comment