繁体   English   中英

Magento:$ this-> getAddToCartUrl($ product)当我试图在主页上展示最畅销的产品时无法正常工作

[英]Magento: $this->getAddToCartUrl($product) not working when I try to display the best selling products on homepage

我是Magento的新手,所以我被困在不同的情况下。 我找到了一个关于如何在主页上展示畅销产品的指南,实现它并且一切正常,除了$ this-> getAddToCartUrl($ product)。 单击“添加到购物车”后,产品不会添加到购物车中。 这是我的代码:

$totalPerPage = ($this->show_total) ? $this->show_total : 4;
$counter = 1;
$visibility = array(
                      Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
                      Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
                  );

$storeId = Mage::app()->getStore()->getId();
$productCollection = Mage::getResourceModel('reports/product_collection')
                              ->addAttributeToSelect('*')
                              ->addOrderedQty()
                              ->addAttributeToFilter('visibility', $visibility)
                              ->setOrder('ordered_qty', 'desc');

<div class="main_content">
    <div class="container">
        <div class="products_list">
            <div class="best_deals">
                <div class="recommended_products best_deals_products">
                    <ul>
            <?php foreach($productCollection as $product): ?>

            <?php
                    $categories = null;
                    foreach (explode(",", $product->category_ids) as $catId){

                      //Mage_Catalog_Model_Category
                      $cat = Mage::getModel('catalog/category')
                                    ->setStoreId(Mage::app()->getStore()->getId())
                                    ->load($catId);
                      $catName = $cat->getName();

                      $catLink = $cat->getUrlPath();
                      $categories .= '<a href="'.$catLink.'" title="'.$catName.'">'.$catName.'</a>&nbsp;&nbsp;';
                    }

            ?>

            <?php if($counter <= $totalPerPage): ?>

            <?php $productUrl =  $product->getProductUrl() ?> 
                        <li>
            <div class="img_bottle">
            <a href="<?php echo $productUrl ?>" title="View <?php echo $product->name ?>">
            <img src="<?php echo $this->helper('catalog/image')->init($product, 'image')->resize(107, 339); ?>" alt="Product image"  />
            </a>
            </div>
            <div class="product_desc">            
            <span><?php echo $product->name ?></span>            
            <span>Our price: $<?php echo number_format($product->getPrice(), 2); ?></span>
            <?php if($product['country_of_manufacture']): ?>
            <span>Country: <i><?php echo strtoupper($product->getAttributeText('country_of_manufacture')); ?></i></span>
            <?php endif; ?>
            <?php if($product['region']): ?>
            <span>Region: <i><?php echo strtoupper($product['region']); ?></i></span>
            <?php endif; ?>                            
                <?php if($product->isSaleable()): ?>
                    <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart buy_now_button" onclick="setLocation('<?php echo $this->getAddToCartUrl($product) ?>')">Add to Cart</button>
                <?php else: ?>
                    <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                <?php endif; ?>
            </div>
                            </li>
            <?php endif; $counter++; ?>

            <?php endforeach; ?>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>

提前谢谢,我希望我的问题能在这里得到解决。

按照以下更改按钮。

<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart buy_now_button" onclick="setLocation('<?php echo $this->helper('checkout/cart')->getAddUrl($product)?>')">Add to Cart</button>

我找到了解决方案。 问题出在管理员面板上。

我遇到的问题不是代码......当我进入管理产品和单个产品时,我看到我想要添加到购物车的产品只有1个数量,所以我已将它们添加到购物车所以我再也不能了。

我改变了数量超过1的数量。它有效。

对不起,谢谢你的时间,一切顺利

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM