关闭

magento随机关联同分类下upsell产品

1210人阅读 评论(0) 收藏 举报
分类:
<?php //if(count($this->getItemCollection()->getItems())): ?>
<?php 
	$_product = $this->getProduct();
	$categories = $_product->getCategoryIds();
	
	
	$_currentCatId = $categories[array_rand($categories,1)];
	$_currentCategory = Mage::getModel('catalog/category')->load($_currentCatId);
	
	$visibility = array(
		Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
		Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
	);
	$products = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($_currentCategory)->addAttributeToSelect(array('name', 'price'), 'inner')-> addAttributeToFilter('visibility', $visibility);
	foreach ($products as $product) {
		$result[] = $product->getId();
	}
	if(count($result) >= 5){
		$ourneed = array_rand($result,5);
	}else{
		$ourneed = array_keys($result);
	}
?>
<div class="box-collateral box-up-sell">
    <h5 class="upsell-product-h5"><?php echo $this->__('You may also be interested in the following product(s)') ?></h5>
    <table class="mini-products-grid" id="upsell-product-table">
    <?php // $this->setColumnCount(5);  ?>
    <?php //$this->resetItemsIterator() ?>
    <?php //for($_i=0;$_i<$row;$_i++): ?>
        <tr>
        <?php
			foreach($ourneed as $cc):
			$_product = Mage::getModel('catalog/product')->load($result[$cc]);
		?>
            <td>
                <a href="<?php echo Mage::getBaseUrl('web').$_product->getUrlKey().'.html' ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(171) ?>" width="171" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" /></a>
                <div class="moreinformation">
                    <h3 class="product-name"><a href="<?php echo Mage::getBaseUrl('web').$_product->getUrlKey().'.html' ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></h3>
                    <?php echo $this->getPriceHtml($_product, true, '-upsell') ?>
                </div>
            </td>
        <?php endforeach; ?>
        </tr>
    <?php //endfor; ?>
    </table>
    <script type="text/javascript">decorateTable('upsell-product-table')</script>
</div>
<?php //endif ?>

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:160343次
    • 积分:1830
    • 等级:
    • 排名:千里之外
    • 原创:19篇
    • 转载:65篇
    • 译文:1篇
    • 评论:17条
    博主推荐
    文章分类
    最新评论