0

我已经构建了一个 magento 模板模块,该模块生成一个单一类别的产品列表,在这个网站上的人们的帮助下,以及 Christian Young @ http://workingmagento.blogspot.ca/的一篇好文章

唯一的问题是 href Url 无法正确呈现。

网址如下所示:

 <button class="button btn-cart" onclick="setLocation('http://shop.com/en/checkout/cart/add?product=&qty=1')" type="button">

网址应如下所示:

 <button class="button btn-cart" type="button" onclick="setLocation('http://mshop.com/en/checkout/cart/add/uenc/aHR0cDovL3Nob3Btc2N0ZXN0LmNvbS9lbi9tb2JpbGU4MjAwLmh0bWw,/product/12/')">

这是代码:

$productCollection = Mage::getModel('catalog/category')->load(4)
    ->getProductCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('status', 1)
    ->addAttributeToFilter('visibility', 4)
    ->setOrder('price', 'ASC');
?>

<div class='block block-list'> 
<div class='block-title'><strong><span><?php echo $this->__('SPECIALS') ?></span></strong></div>
    <div class='block-content'> 
        <ul>
            <h2><?php echo $this->__( $this->getLabel() ); ?></h2>
            <?php foreach ($productCollection as $product): ?>
                <div class="item">
                    <a class="product-image" href="<?php echo $product->getProductUrl() ?>">
                        <img src="<?php echo $this->helper('catalog/image')->init($product, 'small_image')->resize(150); ?>" alt="<?php echo $this->htmlEscape($this->getImageLabel($product, 'small_image')) ?>" />
                    </a>
                    <a class="product-name" href="<?php echo $product->getProductUrl() ?>"><?php echo $this->htmlEscape($product->getName()) ?></a>                     
                   <?php echo $this->getPriceHtml($product, true) ?>                       
                </div>

                <div class="cms-price-box" style=" text-align:center;"></div>
                <div class="button-row" style="text-align:center;">                 
                    <button class="button btn-cart" type="button" onclick="setLocation('<?php echo $this->getUrl('')."checkout/cart/add?product=".$this->getId()."&qty=1"  ?>')" class="button"><span><?php echo $this->__('Add to Cart') ?></span></button>
                </div>
                <br/><br/>
            <?php endforeach ?>
        </ul>
     </div>
</div>
4

1 回答 1

0

试试下面的代码:

<?php
    /** @var $cartHelper Mage_Checkout_Helper_Cart */
    $cartHelper = Mage::helper('checkout/cart');
?>
<button class="button btn-cart" type="button" onclick="setLocation('<?php echo $cartHelper->getAddUrl($product); ?>')" class="button">

您还可以添加其他选项作为 Mage_Checkout_Helper_Cart::getAddUrl() 方法的第二个参数。

于 2012-09-13T21:42:55.983 回答