1 Comment

load more then one category id

Estimate Shipping and Tax removed (show transport costs)
Multi-Store Rewrites and htaccess (index.php)

How to load more then one category id

$categoryIds = array(957);
  $collection = Mage::getModel('catalog/category')->load($categoryIds)
->getProductCollection()
->addAttributeToSelect('*');
$collection->joinField(
                        'is_in_stock',
                        'cataloginventory/stock_item',
                        'is_in_stock',
                        'product_id=entity_id',
                        '{{table}}.stock_id=1',
                        'left'
                )
                ->addAttributeToFilter('is_in_stock', array('eq' => 0));
//->addAttributeToFilter('status',array('eq' => Mage_Catalog_Model_Product_Status::STATUS_DISABLED))

Related Posts

  • Load custom collection with multiple category ids (1)
    I am using magento 1.9 version. I am having custom collection which consists category ids. I tried to get the collection based on the category ids. I followed this link. I tried with this code too. $collection->addAttributeToFilter('category_id', array('in' => array('finset' […]
  • display product present only in both category 1 and category 2 (1)
    I am trying to display only those products which are present in both category 1 and category 2 or in other words only those products which are present in both parent category and its sub category I tried this: $collection = Mage::getModel('catalog/product') […]
  • Magento 2 category page collection not affect the left navigation (0)
    vendormagentomodule-catalogModelLayer.php public function getProductCollection() { if (isset($this->_productCollections[$this->getCurrentCategory()->getId()])) { $collection = $this->_productCollections[$this->getCurrentCategory()->getId()]; } else […]
  • get product collection for specific ids in magento 1.9.2? (4)
    I've got a list of product ids and I want to load a product collection for the list: $getdata[$a]=Array ( [0] => 166 [1] => 166 [2] => 164 ); $_productCollection =Mage::getModel('catalog/product')->getCollection() […]
  • Unclear on loading the product collection from entity id magento2 (0)
    Im not getting a clear answer still on how to get or load the product collection based on its entity id and then save the entity id only if it is not there in the custom table. I have used as follows: protected function _saveProducts() { $tagmodel = […]
  • How can I load the product collection without some products? (3)
    Actually, I want to load the product collection except for some products. I have the product ids that I don't want in the collection. For example, the product ids that I don't want in the product collection is like $productIds = array(10,20,30); How can I do this?
  • Can retrieve product category ID but category name is always null (2)
    I need to be able to get the Category name and ID from a product and I am able to retrieve the ID doing the following: $categoryID = $product->getCategoryCollection()->getFirstItem()->getId(); However If I try to get the name, It always returns null. $categoryName = […]
  • Magento load subcategory based on dropdown option value (2)
    How to load 2nd dropdown based on 1st dropdown <!-- Get Parent Category Id Based on Root Category --> <?php $children = Mage::getModel('catalog/category')->getCategories(2);?> <select> <?php foreach ($children as $category) {?> […]
  • magento 2.1 getParentCategories for category id (2)
    i try to get getParentCategories for category id // 4 is product id $product = $this->_productFactory->load(4); $cats = $product->getCategoryIds(); $category = $this->categoryFactory->create(); $collection = $category->getResourceCollection(); […]
  • Get product IDs of current category page (1)
    I would like to get all the product IDs from the current category page. I don't want to load the whole collection, I just need to get the product IDs from the products currently displayed. E.g.: Customer goes on category, order is set to price descending, number of displayed […]
Estimate Shipping and Tax removed (show transport costs)
Multi-Store Rewrites and htaccess (index.php)

1 Comment on this article

  • User November 12, 2016

    I would try a different approach. Rather than loading a lot of categories, you could load the product collection and then filter by categories

    $products = Mage::getModel('catalog/product')->getCollection();
    $products->joinField(
        'qty',
        'cataloginventory/stock_item',
        'qty',
        'product_id=entity_id',
        '{{table}}.stock_id=1',
        'left'
    );
    
    $products->joinField('category_id',
        'catalog/category_product',
        'category_id',
        'product_id=entity_id',
        null,
        'left'
    );
    
    $products->addAttributeToFilter('category_id', array('in' => array(32,5)));
    
    foreach ($products as $product) {
    
    }
    

    Reply

Add a comment

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax