【问题标题】:Add to cart button not adding product in cart添加到购物车按钮未在购物车中添加产品
【发布时间】:2016-09-08 17:06:46
【问题描述】:

我在目录/产品中创建了一个 new1.phtml 文件,内容如下

<?php
        //getting new product collection

        $product=Mage::getModel("catalog/product")->getCollection();
        $filtered_prodduct=$product->addAttributeToSelect("*")
                                    ->setOrder("created_at","desc")
                                    ->addPriceData();
        echo "<ul>
                <li>";
                $i=0;
                $row=3;
        foreach($filtered_prodduct as $prod){ 
            $i++;
            if($i>$row*3){
                break;
            }
            ?>
        <div class="prod_box">
            <div class="center_prod_box">
                <div class="product_title">
                    <a href="<?php echo $prod->getProductUrl()?>">
                        <?php echo $prod->getName() ?>
                    </a>
                </div>
                <div class="product_img">
                    <a href="<?php echo $prod->getproductUrl()?>">
                        <img src="<?php echo $prod->getImageUrl()?>" alt=""          border="0" height="100" width="100"> 

                    </a>
                </div>
                <div class="prod_price">
                    <span class="reduce"><?php echo $prod->getSpecialPrice()?></span>
                    <span class="price"><?php echo $prod->getPrice()?></span><br/>
                </div>
            </div>
            <div class="prod_details_tab">

                <?php if($prod->isSaleable()): ?>
                        <a href="<?php echo $this->getUrl()?>checkout/cart/add? product=<?php echo $prod->getId(); ?>&qty=1" class="prod_buy">
                            <?php echo $this->__('Add') ?>
                        </a>

                    <?php else: ?>
                         <p class="availability out-of-stock"><span>
                 <?php echo   $this->__('Out of stock') ?></span></p>
                    <?php endif; ?>
                <a href="<?php echo $prod->getProductUrl()?>" class="prod_details">
                    Details
                </a>
            </div>
        </div>
        <?php } 
      ?>

一切正常,但“添加”按钮(表示添加到购物车)不起作用。它只是打开结帐/购物车。

我已经在主页的布局 xml 中添加了这个 phtml 文件。代码有什么问题?

【问题讨论】:

  • 没有。它是 add?product=

标签: magento


【解决方案1】:

你可以使用下面的代码,which generated add to cart url来做到这一点。

Mage::helper('checkout/cart')->getAddUrl(($prod);

如果产品type is configurable and group or if product type is simple and it have customoption,那么它没有选择任何选项直接购物车

【讨论】:

    【解决方案2】:

    控制器的操作验证请求,因此您应该发送 formKey

    public function addAction() { if (!$this->_validateFormKey()) { $this->_goBack(); return; } ... {

    【讨论】:

      【解决方案3】:
      Mage::helper('checkout/cart')->getAddUrl(($prod);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-12-19
        • 2023-03-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多