[英]Get price and Add to cart button Magento
I create a block where I display all the products from a category by its ID. 我创建一个块,在其中按类别显示其类别中的所有产品。 At this moment I can see the title of the product and its image, but i need the (ADD TO CART) and the (PRICE).
此时,我可以看到产品的标题及其图像,但是我需要(添加到购物车)和(价格)。 My code is:
我的代码是:
<div class="freeProducts voucher code">
<?php
$categoryid = 64;
$category = new Mage_Catalog_Model_Category();
$category->load($categoryid);
$collection = $category->getProductCollection();
$collection->addAttributeToSelect('*');
foreach ($collection as $_product) { ?>
<a href="<?php echo $_product->getProductUrl() ?>"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(200); ?>" width="200" height="200" alt="" /></a> <a href="<?php echo $_product->getProductUrl(); ?>"><?php echo $_product->getName(); ?></a>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_item) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
<?php echo $this->getPriceHtml($_item, true) ?>
<?php } ?>
</div>
Updated button code: 更新的按钮代码:
Remove: 去掉:
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_item) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
Add: 加:
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo Mage::getUrl('checkout/cart/add/')?>product/<?php echo $_product->getId() ?>/')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
$this->getAddToCartUrl($_item)
will not work in custom code. $this->getAddToCartUrl($_item)
在自定义代码中不起作用。 This is used in product detail page where helper is called. 这在调用帮助程序的产品详细信息页面中使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.