Magento 2:在购物车页面上更新产品列表页面中的数量

时间:2017-07-25 20:45:29

标签: magento magento2

我在产品列表中添加了qty输入(list.phtml)是否可以通过购物车页面或minicart实现更新数量的解决方案?不只是添加到购物车,而是更新产品列表中的数量。

关心马特

2 个答案:

答案 0 :(得分:0)

您可以使用以下内容:

<?php $postParams = $block->getAddToCartPostParams($_product); ?>

<form data-role="tocart-form" onsubmit="return false;" action="<?php /* @escapeNotVerified */ echo $postParams['action']; ?>" method="post">
    <?php echo $block->getBlockHtml('formkey')?>
    <input type="hidden" name="product" value="<?php /* @escapeNotVerified */ echo $postParams['data']['product']; ?>">
    <input type="hidden" name="<?php /* @escapeNotVerified */ echo Action::PARAM_NAME_URL_ENCODED; ?>" value="<?php /* @escapeNotVerified */ echo $postParams['data'][Action::PARAM_NAME_URL_ENCODED]; ?>">
    <input type="text" name="qty" id="qty" class="qty" value="1"/>
    <button type="submit"
            title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>"
            class="action tocart primary"
            <span class="label">
                <?php /* @escapeNotVerified */ echo __('Add to Cart') ?>
            </span>
    </button>                                                
</form>  

但这只适用于简单的产品。

答案 1 :(得分:0)

mincart.phtml中的以下代码替换为deply:

<?php
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

/** @var $block \Magento\Checkout\Block\Cart\Sidebar */
?>

<div data-block="minicart" class="minicart-wrapper">
    <a class="action showcart" href="<?php /* @escapeNotVerified */ echo $block->getShoppingCartUrl(); ?>"
       data-bind="scope: 'minicart_content'">
        <span class="text"><?php /* @escapeNotVerified */ echo __('Warenkorb'); ?></span>
        <span class="counter qty empty"
              data-bind="css: { empty: !!getCartParam('summary_count') == false }, blockLoader: isLoading">
            <span class="counter-number"><!-- ko text: getCartParam('summary_count') --><!-- /ko --></span>
            <span class="counter-label">
            <!-- ko if: getCartParam('summary_count') -->
                <!-- ko text: getCartParam('summary_count') --><!-- /ko -->
                <!-- ko i18n: 'items' --><!-- /ko -->
            <!-- /ko -->
            </span>
        </span>
    </a>
    <?php if ($block->getIsNeedToDisplaySideBar()): ?>
        <div class="block block-minicart empty"
             data-role="dropdownDialog"
             data-mage-init='{"dropdownDialog":{
                "appendTo":"[data-block=minicart]",
                "triggerTarget":".showcart",
                "timeout": "2000",
                "closeOnMouseLeave": false,
                "closeOnEscape": true,
                "triggerClass":"active",
                "parentClass":"active",
                "buttons":[]}}'>
                <div class="menu-main-title-mobile min-cart-mob">
                            <a href="#" class="close-mega-menu"><?php echo __('< Zurück') ?></a>
                            <h4><span><?php echo __('Warenkorb') ?></span></h4>                     
                        </div>
            <div id="minicart-content-wrapper" data-bind="scope: 'minicart_content'">
            <?php   /* <div class="menu-main-title">
                    <h3>Ihr EGLO Warenkorb</h3>
                    <span><a href="#"> Liste hochladen</a></span>
                    <a href="#" class="close-mega-menu">Schliessen   x</a>
                </div> */ ?>
                <!-- ko template: getTemplate() --><!-- /ko -->

            </div>
            <?php //echo $block->getChildHtml('minicart.addons'); ?>
        </div>
    <?php endif ?>
    <script>
        window.checkout = <?php /* @escapeNotVerified */ echo \Zend_Json::encode($block->getConfig()); ?>;
    </script>
    <script type="text/x-magento-init">
    {
        "[data-block='minicart']": {
            "Magento_Ui/js/core/app": <?php /* @escapeNotVerified */ echo $block->getJsLayout();?>
        },
        "*": {
            "Magento_Ui/js/block-loader": "<?php /* @escapeNotVerified */ echo $block->getViewFileUrl('images/loader-1.gif'); ?>"
        }
    }
    </script>
</div>
<script>

/* Minicart Plus Minus Script */
function cartplus(elementId) {
    var qty = document.getElementById('cart-item-'+elementId+'-qty').value; 
    qty = parseInt(qty) + 1;
    document.getElementById('cart-item-'+elementId+'-qty').value = qty;
    document.getElementById('update-cart-item-'+elementId).style.display = "block";

    }

function cartminus(elementId){
     var qty = document.getElementById('cart-item-'+elementId+'-qty').value;    
    qty = parseInt(qty) - 1;
    if (qty < 0)
       qty = 0;
    document.getElementById('cart-item-'+elementId+'-qty').value = qty;
    document.getElementById('update-cart-item-'+elementId).style.display = "block";
    }

/* Minicart Plus Minus Script End */

</script>