magento网址无法正常呈现

时间:2012-09-13 21:29:02

标签: url magento

我已经构建了一个magento模板模块,可以在此网站上的人员的帮助下生成单个类别的产品列表,以及来自Christian Young @ http://workingmagento.blogspot.ca/

的精彩文章

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

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>

1 个答案:

答案 0 :(得分: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()方法的第二个参数。