我将迷你购物车添加到标题中,现在我有了一个不错的弹出窗口,显示了我的购物车中的物品列表。我可以看到我的购物车上有多少个项目,但我希望用户能够更改该数量。实现这一目标的最佳方法是什么?

这是获得迷你购物车内容的部分:

<?php $_items = $this->getRecentItems() ?>
    <?php if(count($_items)): ?>

            <div id="header-items">
                <!--div class="block-subtitle">
                    <span><?php echo $this->__('Recently added item(s)') ?></span> 
                    <div class="clear"></div>
                </div>-->

                <ol id="cart-sidebar" class="mini-products-list">
                <?php foreach($_items as $_item): ?>
                    <?php echo $this->getItemHtml($_item) ?>
                <?php endforeach; ?>
                </ol>
                <a class="view_all" href="<?php echo $this->getUrl('checkout/cart')?>"><?php echo ($_cartQty > 3) ? $this->__('View All Items'): $this->__('View Cart');?></a>                                             
                <button type="button" title="<?php echo $this->__('Checkout') ?>" class="button checkout" onclick="window.location='<?php echo $this->getUrl('checkout/onepage')?>';"><span><span><?php echo $this->__('Checkout') ?></span></span></button>                                
                <div class="clear"></div>
            </div>
        <script type="text/javascript">decorateList('cart-sidebar', 'none-recursive')</script>

    <?php else: ?>
        <div id="header-items">
            <p class="empty"><?php echo $this->__('You have no items in your shopping cart.') ?></p>
        </div>
    <?php endif ?>

在PHP文件上,我有此(除其他功能):

public function getRecentItems($count = null)
    {
        if ($count === null) {
            $count = $this->getItemCount();
        }

        $items = array();
        if (!$this->getSummaryCount()) {
            return $items;
        }

        $i = 0;
        $allItems = array_reverse($this->getItems());
        foreach ($allItems as $item) {
            /* @var $item Mage_Sales_Model_Quote_Item */
            if (!$item->getProduct()->isVisibleInSiteVisibility()) {
                $productId = $item->getProduct()->getId();
                $products  = Mage::getResourceSingleton('catalog/url')
                    ->getRewriteByProductStore(array($productId => $item->getStoreId()));
                if (!isset($products[$productId])) {
                    continue;
                }
                $urlDataObject = new Varien_Object($products[$productId]);
                $item->getProduct()->setUrlDataObject($urlDataObject);
            }

            $items[] = $item;
            if (++$i == $count) {
                break;
            }
        }

        return $items;
    }

现在,这给了我这一点:项目-QTY-删除按钮 - 编辑按钮,我想用输入替换编辑按钮以更改项目的数量

有帮助吗?

解决方案

您在说什么购物车都没关系。您需要的是更改产品数量的URL,这些URL是:

\Mage_Checkout_CartController::updatePostAction()

因此,URL是:

$this->getUrl('checkout/cart/updatePost');

然后您只需要添加 $qouteIitem->getId() 和新的 $qty 以一种形式。以格式发送表格 array(cart => array($quoteItemId => $qty)) 为此URL,数量已更新。

许可以下: CC-BY-SA归因
scroll top