Kategorilere göre Magento ürünleri

0 Cevap php

Bu kod ile productsCollection almaya çalışın:

    $collection = Mage::getModel('catalog/category')->getCollection();
/* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */
$collection->addAttributeToSelect('url_key')
    ->addAttributeToSelect('name')
    ->addAttributeToSelect('is_anchor')
    ->addAttributeToFilter('is_active', 1)
    ->addIdFilter(array(4,5))//$_categories)
    ->setOrder('position', 'ASC')
    ->joinUrlRewrite()
    ->load();

$productCollection = Mage::getResourceModel('catalog/product_collection');
$layer             = Mage::getSingleton('catalog/layer');
$layer->prepareProductCollection($productCollection);
$productCollection->addCountToCategories($collection);
foreach($productCollection as $product){
    print_r($product->getCategoryIds());
}

Ama çizgi addIdFilter (array (4,5)) çalışmaz, ve ben tüm ürün görmek, hatta bazı Kategorileri yok.

Yanlış olan nedir?

0 Cevap