Skip to main content

magento Magento resource model catalog product filter with attributes and category id

I am trying to develop custom filter navigation. Below is the code for product collection by category id

$category = Mage::getModel ('catalog/category')->load($category_id);
    $products = Mage::getResourceModel('catalog/product_collection')
                  // ->addAttributeToSelect('*')
                  ->AddAttributeToSelect('name')
                  ->addAttributeToSelect('price')
                  ->addFinalPrice()
                  ->addAttributeToSelect('small_image')
                  ->addAttributeToSelect('image')
                  ->addAttributeToSelect('thumbnail')
                  ->addAttributeToSelect('short_description')
                  ->addUrlRewrite()
                  ->AddCategoryFilter($category);


    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
    
    //$products->addAttributeToFilter('color', array('eq' => '27')); /* here color attribute */

Product collection by category id is working as expected. But when i tried with single color attribute, it always comes asreturns an empty array.Same Same color 27 attribute gives one product as result when i check on default navigation.

AnyWhat is the best way to achieve multiple attribute code filter with resource model catalog product collection. Please advice?

magento resource model catalog product filter with attributes and category id

I am trying to develop custom filter navigation. Below is the code for product collection by category id

$category = Mage::getModel ('catalog/category')->load($category_id);
    $products = Mage::getResourceModel('catalog/product_collection')
                  // ->addAttributeToSelect('*')
                  ->AddAttributeToSelect('name')
                  ->addAttributeToSelect('price')
                  ->addFinalPrice()
                  ->addAttributeToSelect('small_image')
                  ->addAttributeToSelect('image')
                  ->addAttributeToSelect('thumbnail')
                  ->addAttributeToSelect('short_description')
                  ->addUrlRewrite()
                  ->AddCategoryFilter($category);


    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
    
    //$products->addAttributeToFilter('color', array('eq' => '27')); /* here color attribute */

Product collection by category id is working as expected. But when i tried with single color attribute, it always comes as empty array.Same color 27 attribute gives one product as result when i check on default navigation.

Any best way to achieve multiple attribute code filter with resource model catalog product collection. Please advice

Magento resource model catalog product filter with attributes and category id

I am trying to develop custom filter navigation. Below is the code for product collection by category id

$category = Mage::getModel ('catalog/category')->load($category_id);
    $products = Mage::getResourceModel('catalog/product_collection')
                  // ->addAttributeToSelect('*')
                  ->AddAttributeToSelect('name')
                  ->addAttributeToSelect('price')
                  ->addFinalPrice()
                  ->addAttributeToSelect('small_image')
                  ->addAttributeToSelect('image')
                  ->addAttributeToSelect('thumbnail')
                  ->addAttributeToSelect('short_description')
                  ->addUrlRewrite()
                  ->AddCategoryFilter($category);


    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
    
    //$products->addAttributeToFilter('color', array('eq' => '27')); /* here color attribute */

Product collection by category id is working as expected. But when i tried with single color attribute, it always returns an empty array. Same color 27 attribute gives one product as result when i check on default navigation.

What is the best way to achieve multiple attribute code filter with resource model catalog product collection?

added 7 characters in body
Source Link
mymotherland
  • 275
  • 1
  • 5
  • 21

I am trying to develop custom filter navigation. Below is the code for product collection by category id

$category = Mage::getModel ('catalog/category')->load($category_id);
    $products = Mage::getResourceModel('catalog/product_collection')
                  // ->addAttributeToSelect('*')
                  ->AddAttributeToSelect('name')
                  ->addAttributeToSelect('price')
                  ->addFinalPrice()
                  ->addAttributeToSelect('small_image')
                  ->addAttributeToSelect('image')
                  ->addAttributeToSelect('thumbnail')
                  ->addAttributeToSelect('short_description')
                  ->addUrlRewrite()
                  ->AddCategoryFilter($category);


    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
    
    //$products->addAttributeToFilter('color', array('eq' => '27')); /* here color attribute */

Product collection by category id is working as expected. But when i tried with single color attribute, it always comes as empty array.Same color 27 attribute gives one product as result when i check on default navigation.

Any best way to achieve multiple attribute code filter with resource model catalog product collection. Please advice

I am trying to develop custom navigation. Below is the code for product collection by category id

$category = Mage::getModel ('catalog/category')->load($category_id);
    $products = Mage::getResourceModel('catalog/product_collection')
                  // ->addAttributeToSelect('*')
                  ->AddAttributeToSelect('name')
                  ->addAttributeToSelect('price')
                  ->addFinalPrice()
                  ->addAttributeToSelect('small_image')
                  ->addAttributeToSelect('image')
                  ->addAttributeToSelect('thumbnail')
                  ->addAttributeToSelect('short_description')
                  ->addUrlRewrite()
                  ->AddCategoryFilter($category);


    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
    
    //$products->addAttributeToFilter('color', array('eq' => '27')); /* here color attribute */

Product collection by category id is working as expected. But when i tried with single color attribute, it always comes as empty array.Same color 27 attribute gives one product as result when i check on default navigation.

Any best way to achieve multiple attribute code filter with resource model catalog product collection. Please advice

I am trying to develop custom filter navigation. Below is the code for product collection by category id

$category = Mage::getModel ('catalog/category')->load($category_id);
    $products = Mage::getResourceModel('catalog/product_collection')
                  // ->addAttributeToSelect('*')
                  ->AddAttributeToSelect('name')
                  ->addAttributeToSelect('price')
                  ->addFinalPrice()
                  ->addAttributeToSelect('small_image')
                  ->addAttributeToSelect('image')
                  ->addAttributeToSelect('thumbnail')
                  ->addAttributeToSelect('short_description')
                  ->addUrlRewrite()
                  ->AddCategoryFilter($category);


    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
    
    //$products->addAttributeToFilter('color', array('eq' => '27')); /* here color attribute */

Product collection by category id is working as expected. But when i tried with single color attribute, it always comes as empty array.Same color 27 attribute gives one product as result when i check on default navigation.

Any best way to achieve multiple attribute code filter with resource model catalog product collection. Please advice

Source Link
mymotherland
  • 275
  • 1
  • 5
  • 21

magento resource model catalog product filter with attributes and category id

I am trying to develop custom navigation. Below is the code for product collection by category id

$category = Mage::getModel ('catalog/category')->load($category_id);
    $products = Mage::getResourceModel('catalog/product_collection')
                  // ->addAttributeToSelect('*')
                  ->AddAttributeToSelect('name')
                  ->addAttributeToSelect('price')
                  ->addFinalPrice()
                  ->addAttributeToSelect('small_image')
                  ->addAttributeToSelect('image')
                  ->addAttributeToSelect('thumbnail')
                  ->addAttributeToSelect('short_description')
                  ->addUrlRewrite()
                  ->AddCategoryFilter($category);


    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
    
    //$products->addAttributeToFilter('color', array('eq' => '27')); /* here color attribute */

Product collection by category id is working as expected. But when i tried with single color attribute, it always comes as empty array.Same color 27 attribute gives one product as result when i check on default navigation.

Any best way to achieve multiple attribute code filter with resource model catalog product collection. Please advice