dominicwatts/addtocart

Magento 2 添加到购物车助手 - 直接使用 - 避免模板块继承问题

安装: 0

依赖项: 0

建议者: 0

安全性: 0

星标: 2

关注者: 3

分支: 0

开放问题: 0

类型:magento2-module

1.0.0 2021-09-10 09:44 UTC

This package is auto-updated.

Last update: 2024-09-10 15:56:51 UTC


README

构建添加到购物车参数的快捷方式,无需担心模板块继承问题

phpcs

PHPCompatibility

PHPStan

php-cs-fixer

安装说明

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>