문제

Hi i have this code:

                //shop the look product code
                $products = Mage::getResourceModel('catalog/product_collection');
                // Select which fields to load into the product
                // * will load all fields but it is possible to pass an array of
                // select fields to load
                $products->addCategoryFilter(Mage::getModel('catalog/category')->load($this->getCatId()));
                $products->addAttributeToSelect('*');
                $products->addAttributeToFilter('type_id', array('eq' => 'configurable'));
                // Ensure the product is visible
                $products->addAttributeToFilter('visibility', array('neq' => 1));
                // Ensure the product is enabled
                $products->addAttributeToFilter('status', 1);
                $products->addAttributeToFilter('featured_products', 'si');
                $products->getSelect()->limit(1);
                // Load the collection
                $products->load();

it will take all products from the passed catedory id with a filter on featured_products. it works fine but only with simple products, it don’t load configurable products from the category!!

it’s a magento bug i think, there is a solution to retrive configurable products too?

도움이 되었습니까?

해결책

Take a look at catalog_product_entity. Essentially you are interested in the type_id column. Now because it is located in the base table for the entity you should use addFieldToFilter instead of addAttributeToFilter http://www.creare.co.uk/magento-product-collection-bible

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top