Получить все товары только определенной категории - без товаров ее дочерних категорий
Я хочу получить коллекцию продуктов определенной категории, а не включать в нее продукт дочерней категории.
Ниже приведен код, который я пробовал.
$category = Mage::getModel('catalog/category')->load(5);
$getCollections = $category->getProductCollection()
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addAttributeToFilter('visibility', 4)
->addAttributeToSelect('*');
Может ли кто-нибудь, пожалуйста, помочь мне?
3
2 answers
Попробуйте это:
$category = Mage::getModel('catalog/category')->load(5);
$isAnchorFlag = $category->getIsAnchor();
$category->setIsAnchor(false);
$getCollections = $category->getProductCollection()
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addAttributeToFilter('visibility', 4)
->addAttributeToSelect('*');
$category->setIsAnchor($isAnchorFlag);
7
Author: Marius, 2017-06-26 06:06:57
Я сделаю это, немного изменив ваш код.
$category = Mage::getModel('catalog/category')->load(5);
/* Load all child categories */
$child_cats = $category->getChildren();
$getCollections = $category->getProductCollection()
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addAttributeToFilter('visibility', 4)
->addAttributeToSelect('*')
->addAttributeToFilter('entity_id', array('neq' => $child_cats));
Ссылка: https://stackoverflow.com/questions/15600354/product-collection-exclude-products-from-a-certain-category https://stackoverflow.com/questions/18525419/get-child-categories-magento
0
Author: PY Yick, 2017-06-26 06:07:12