1
我想獲得至少有一個類別的產品集合。其實我想忽略那些不屬於任何類別的產品。誰能幫助嗎? 我的代碼如下:Magento:獲得至少有一個類別的產品集合
protected function _prepareCollection()
{
$store = $this->_getStore();
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('sku')
->addAttributeToSelect('name')
->addAttributeToSelect('attribute_set_id')
->addAttributeToSelect('type_id')
->joinField('qty',
'cataloginventory/stock_item',
'qty',
'product_id=entity_id',
'{{table}}.stock_id=1',
'left');
if ($store->getId()) {
//$collection->setStoreId($store->getId());
$adminStore = Mage_Core_Model_App::ADMIN_STORE_ID;
$collection->addStoreFilter($store);
$collection->joinAttribute('name', 'catalog_product/name', 'entity_id', null, 'inner', $adminStore);
$collection->joinAttribute('custom_name', 'catalog_product/name', 'entity_id', null, 'inner', $store->getId());
$collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner', $store->getId());
$collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner', $store->getId());
$collection->joinAttribute('price', 'catalog_product/price', 'entity_id', null, 'left', $store->getId());
}
else {
$collection->addAttributeToSelect('price');
$collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner');
$collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner');
}
$this->setCollection($collection);
parent::_prepareCollection();
$this->getCollection()->addWebsiteNamesToResult();
return $this;
}
感謝,
傑克,捆綁。我想在產品網格上添加此過濾器。但是當我在網格集合代碼上應用您的代碼片段時,出現錯誤(重複的ID錯誤)。 :( – Adeel
請在您的第一個消息代碼片段中加載您的收藏夾,我的代碼加載了所有具有任何類別的產品 –
我編輯了這個問題,在這裏我想添加此檢查 – Adeel