magento列表页调用自定义尺码这个功能在一些小额交易客户不用仔细查看商品说明时很关键也很重要,但是如果直接copy自定义尺码代码就会发现这样并不能实现magento分类页调用自定义尺码.
在list页面 ($_productCollection as $_product)后面增加
<?php
$productSku = $_product->getSku();
$product = Mage::getModel('catalog/product');
$productId = $product->getIdBySku( $productSku );
$product = Mage::getModel("catalog/product")->load($productId);
$attVal = $product->getOptions();//外贸建站
$optStr = "";//www.zuimoban.com
?>
然后把
<div class="actions">
<?php if($_product->isSaleable()):?>
<form action="<?php echo $this->helper('checkout/cart')->getAddUrl($_product)?>" method="post" id= "product_addtocart_form" <?php if($_product->getOptions()):?> enctype="multipart/form-data"<?php endif;?>>
<?php foreach($attVal as $optionKey => $optionVal)
{
$optStr.= "<select style='display:block; clear:both;' name='options[".$optionVal->getId()."]'>"; foreach($optionVal->getValues() as $valuesKey => $valuesVal)
{
$optStr.= "<option value='".$valuesVal->getId()."'>".$valuesVal->getTitle()."</option>";
}
$optStr.= "</select>";
}
echo($optStr );?>
<!--Replace "buttonImage.png" with any button image in your skin images -->.
<input type="image" src="<?php echo $this->getSkinUrl('img/buttonImage.png')?>" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product)?>')">
<?php else:?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock')?></span></p>
<?php endif;?>
<ul class="add-to-links">
<?php if ($this->helper('wishlist')->isAllow()) :? >
<li>
<a href="<?php echo $this->helper('wishlist')->getAddUrl($_product)?>" class="link-wishlist">
<?php echo $this->__('Add to Wishlist')?>
</a>
</li>
<?php endif;?>
<?php if($_compareUrl=$this->getAddToCompareUrl($_product)):?>
<li>
<span class="separator">|</span>
<a href="<?php echo $_compareUrl?>" class="link-compare"><?php echo $this->__('Add to Compare')?>
</a>
</li>
<?php endif;?>
</ul>
</form>
</div>
加到对应位置就可以实现在magento分类页调用尺码并直接选择购买了
(责任编辑:最模板) |