Magento: Get Product Collection by Type

Products can be of different types in Magento. The different product types are Simple Product, Configurable Product, Bundle Product, Grouped Product, Downloadable Product, and Virtual Product. For example: Chair can be a Simple Product. Shoes can be of different color and size. So, shoes falls under Configurable product. A downloadable mp3 music file will fall … Read more

Magento: Get manufacturer name and id from product

Suppose, you have the product data, i.e. you have a loaded product information stored in a variable named ‘$_product‘. Now, when you type $_product->getManufacturer() , you will get the manufacturer ID. To get the manufacturer name, you have to use the following: $_product->getAttributeText(‘manufacturer’). Below is the complete code: Get Manufacturer Name and ID from Product … Read more

Magento: How to filter product collection using 2 or more category filters?

Suppose, you have a product collection and you want to filter it by category. Suppose, you want to filter it by more than one category. You can use addCategoryFilter if you have only one category. But, what if you want to filter by more than one category? Category ids are stored for product in a … Read more

Magento: Get sub categories and product count

This article shows how to get sub categories of a particular category and the number of products (product count) present in the sub categories. Suppose, you have a category named Furniture. The sub categories under Furniture are Living Room and Bedroom. Now, you want to show the sub categories under Funiture and the products associated … Read more

Magento: How to enable backorders?

Difference between backorder and pre-order A backorder is for an item that was in stock previously but is temporarily out of stock. A pre-order is for an item that has not been released yet. Scenario for backorder: For example, a customer orders 3 items. One item is not in stock. Shouldn’t I be able to … Read more

Magento: Product Edit Warning: Invalid argument supplied for foreach()

Scenario: While editing product programatically from frontend. I was trying to change the status of the product with the following code. I was trying to disable the product. Status value 2 = Disabled. // Trying to disable the product // $product->getId() = PRODUCT ID Mage::getModel('catalog/product')->load($product->getId())->setStatus(2)->save(); Problem: Product could not be edited programatically from frontend. The … Read more

Magento: Get all categories name and url of a product

This article shows how you can fetch all the categories related/associated with a particular product. $product->getCategoryIds() function gives array of category ids with which the product is associated to. We can loop through this array and load each category to get the category name and url. // Load product $productId = 1; // YOUR PRODUCT … Read more

Magento: Load store specific product

Different stores can be set in Magento. A product can be made visible in selected stores. /** * get store id */ $storeId = Mage::app()->getStore()->getId(); /** * call the Magento catalog/product model * set the current store ID * load the product */ $product = Mage::getModel('catalog/product') ->setStoreId($storeId) ->load($key); Hope it helps. Thanks.

Magento: Get parent id of simple product associated to configurable product

Scenario: A simple product is associated with a configurable product. You have the id of the simple product. Now, you need the id of the configurable product with which the simple product is associated. Get parent product id, i.e. get id of configurable product from a simple product. Note: This method is deprecated after 1.4.2.0 … Read more