dominicwatts / addtocart
Magento 2 添加到购物车助手 - 直接使用 - 避免模板块继承问题
1.0.0
2021-09-10 09:44 UTC
Requires
- php: >=7.1.0
- magento/framework: *
- magento/module-catalog: *
- magento/module-checkout: *
This package is auto-updated.
Last update: 2024-09-10 15:56:51 UTC
README
构建添加到购物车参数的快捷方式,无需担心模板块继承问题
安装说明
composer require dominicwatts/addtocart
php bin/magento setup:upgrade
php bin/magento setup:di:compile
使用说明
$xigenHelper = $this->helper(Xigen\AddToCart\Helper\AddToCart::class);
$postParams = $xigenHelper->getAddToCartPostParams($_item);
然后像通常一样使用 pthml,例如。
<form data-role="tocart-form"
data-product-sku="<?= $_item->getSku() ?>"
action="<?= /* @noEscape */ $postParams['action'] ?>"
method="post">
<input type="hidden"
name="product"
value="<?= /* @noEscape */ $postParams['data']['product'] ?>">
<?= $block->getBlockHtml('formkey') ?>
<input type="number"
name="qty"
id="qty-<?= $_item->getSku() ?>"
maxlength="12"
value="1"
title="<?php /* @escapeNotVerified */ echo __('Qty') ?>"
class="input-text qty form-control" />
<button type="submit"
title="<?= /* @noEscape */ __('Add to Basket') ?>"
class="action tocart primary btn btn-primary">
<span class="d-none d-lg-inline"><?= /* @noEscape */ __('Add to Basket') ?></span>
<span class="d-lg-none"><?= /* @noEscape */ __('Add') ?></span>
</button>
</form>