`
kirenenko04
  • 浏览: 145947 次
  • 性别: Icon_minigender_2
  • 来自: 上海
社区版块
存档分类
最新评论

Magento random display same category product

阅读更多
	public function get_random_same_cate_products() {
		$_product = $this->getProduct();
		$categoryIds = $_product->getCategoryIds();
		if(count($categoryIds) ){
			foreach ($categoryIds as $cid) {
				$_category = Mage::getModel('catalog/category')->load($cid);
				if ($_category->getLevel() == 3) {
					
					$_productCollection = Mage::getModel('catalog/product')
					->getCollection()
					->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
					->addAttributeToSelect('*')
					
					->addAttributeToFilter('category_id', array(
							array('finset' => $cid),
							)
					)
					->addAttributeToFilter('type_id','configurable')
					->addAttributeToFilter('sku',array('neq'=>$_product->getSku()));
					
					$_productCollection->getSelect()->order(new Zend_Db_Expr('RAND()'));
					$_productCollection->setPage(1, 4);
					
					return $_productCollection;
				}
			}
			
		}
	}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics