dominicwatts / addtocart
Magento 2 Add to cart helper - just drop in and go - avoid template block inheritance issues
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 0
Open Issues: 0
Type:magento2-module
Requires
- php: >=7.1.0
- magento/framework: *
- magento/module-catalog: *
- magento/module-checkout: *
This package is auto-updated.
Last update: 2024-11-10 16:20:35 UTC
README
Shortcurt to build add to cart parameters without having worry about template block inheritence
Install instructions
composer require dominicwatts/addtocart
php bin/magento setup:upgrade
php bin/magento setup:di:compile
Usage instructions
$xigenHelper = $this->helper(Xigen\AddToCart\Helper\AddToCart::class);
$postParams = $xigenHelper->getAddToCartPostParams($_item);
Then pthml as normal e.g.
<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>