按类别筛选
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了按类别筛选相关的知识,希望对你有一定的参考价值。
filter out by category ID in Magento
//get the current category $_currentCategory = Mage::getModel('catalog/category')->load(Mage::registry('current_category')->getId()); //spit out the collection filtered by store then by category $_productCollection = Mage::getResourceModel('catalog/product_collection') ->addStoreFilter() ->addCategoryFilter($_currentCategory); //get all categories $categories = Mage::getModel('catalog/category')->load($parent_category_id)->getAllChildren(); foreach ($categories as $_category) { $cur_category = Mage::getModel(���¢�¯�¿�½�¯�¿�½catalog/category���¢�¯�¿�½�¯�¿�½)->load($_category->getId()); //get all products associated with the current category $products = Mage::getResourceModel(���¢�¯�¿�½�¯�¿�½catalog/product_collection���¢�¯�¿�½�¯�¿�½) ->addCategoryFilter($_category) ->addAttributeToSelect(���¢�¯�¿�½�¯�¿�½some_attributes���¢�¯�¿�½�¯�¿�½); foreach ( $products as $productModel ) { $_product = Mage::getModel(���¢�¯�¿�½�¯�¿�½catalog/product���¢�¯�¿�½�¯�¿�½)->load($productModel->getId()); //do something useful with this $_product object //$_product->getName(), $_product->getId() etc. } }
以上是关于按类别筛选的主要内容,如果未能解决你的问题,请参考以下文章
用于 WordPress 的 PHP 片段,用于获取所有产品子类别