Magento - 添加到购物车,并在追加销售产品上添加数量字段

标签 magento

我正在尝试让我的追加销售产品(我使用该产品而不是 view.phtml 上的相关产品)来使用“添加到购物车”按钮前面的“数量”字段。我还使用 AheadWorks Ajax AddToCart Pro 2.5 扩展。

现在,我正在使用以下代码段添加没有数量字段的产品:

<form action="<?php echo $this->getAddToCartUrl($_link) ?>" method="post" id="view_addtocart_form_<?php echo $_link->getId(); ?>"><button onclick="setLocation('<?php echo $this->getAddToCartUrl($_link) ?>')" class="greenbutton" title="Add to Cart" type="button"><span><span>Add to Cart</span></span></button></form>

这很好用,但由于缺少数量字段,我无法更改数量。然后我尝试从我的 list.phtml 中使用它,它在类别 View 中工作正常:

<script type="text/javascript">
                    function setQty(id, url) {
                        var qty = document.getElementById('qty_' + id).value;
                        document.getElementById('cart_button_' + id).innerHTML = '<button type="button" class="greenbutton-small" onclick="setLocation(\'' + url + 'qty/' + qty + '/\')"><span><span>Læg i kurv</span></span></button>';   
                    }
                </script>
                <label for="qty"><?php echo $this->__('Qty:') ?></label>
                <input type="text" name="qty_<?php echo $_product->getId(); ?>" id="qty_<?php echo $_product->getId(); ?>" maxlength="12" value="1" onkeyup="setQty(<?php echo $_product->getId(); ?>, '<?php echo $this->getAddToCartUrl($_product) ?>');" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
                <span id="cart_button_<?php echo $_product->getId(); ?>">
                <button type="button" class="greenbutton-small" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></span>    

现在,有趣的是,如果我尝试在 upsell.phtml 中使用它,这不起作用,但我不明白为什么?这与 AW 的 Ajax Cart Pro 在类别 View 中完美配合。

最佳答案

upsell.phtml 中,产品对象称为 $_link,代码如下:

<?php if($_link=$this->getIterableItem()): ?>

如果您尝试将代码包含在 upsell.phtml 中,则必须将 $_product 更改为 $_link像这样:

<label for="qty"><?php echo $this->__('Qty:') ?></label>
            <input type="text" name="qty_<?php echo $_link->getId(); ?>" id="qty_<?php echo $_link->getId(); ?>" maxlength="12" value="1" onkeyup="setQty(<?php echo $_link->getId(); ?>, '<?php echo $this->getAddToCartUrl($_link) ?>');" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
            <span id="cart_button_<?php echo $_link->getId(); ?>">
            <button type="button" class="greenbutton-small" onclick="setLocation('<?php echo $this->getAddToCartUrl($_link) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></span>

它应该位于以下行之后:

<?php if($_link=$this->getIterableItem()): ?>

关于Magento - 添加到购物车,并在追加销售产品上添加数量字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15640036/

相关文章:

mysql - 定制的客户网格导致 MySQL 表扫描和文件排序也就是性能下降

php - 登录成功后magento 404

php - Magento 事件调度/观察/修改调度对象

magento - 将自定义类别属性添加到前端。

php - Magento 数据库平面表

php - 如何在 Magento 的低库存系列中只获取已启用的产品

php - 回显没有分配 magento 类别的产品列表

php - 以编程方式创建显示缺货的可下载产品

Magento 商店 - 不要发送时事通讯成功电子邮件

magento - Magento 联系人页面 URL 的更改