0
我在我的主類別頁面上有一個自定義登錄頁面,我想要使用集合顯示9個產品的隨機選擇。當我有我的類別設置如下圖所示與主類別錨是和子類別不,它工作正常,並顯示隨機的9個產品Magento - 如果類別錨設置爲否,則爲空集合
Main category A - anchor Yes
- sub category 1 - anchor No
- sub category 2 - anchor No
- sub category 3 - anchor No
但我現在需要圍繞切換這一點,並有主目錄爲NO和子類別爲錨是沒有被顯示,並集合爲空
Main category A - anchor No
- sub category 1 - anchor Yes
- sub category 2 - anchor Yes
- sub category 3 - anchor Yes
我的代碼是:
$_category = $this->getCurrentCategory();
$collection = $_category->getProductCollection();
Mage::getModel('catalog/layer')->prepareProductCollection($collection);
$collection->getSelect()->order('rand()');
$collection->addStoreFilter();
$numProducts = 9;
$collection->setPage(1, $numProducts)->load();
foreach($collection as $product) {
// display...
是否有一個原因,收集代碼不會以這種方式工作?
做的var_dump($ _分類 - >的getId()),並分享結果 – Pankaj