Currently browsing

September 3, 2018

Magento: Get list of all manufacturers

Here is the code to list all the manufacturers. $_product = $this->getProduct(); $attributes = Mage::getResourceModel(‘eav/entity_attribute_collection’) ->setEntityTypeFilter($_product->getResource()->getTypeId()) ->addFieldToFilter(‘attribute_code’, ‘manufacturer’); $attribute = $attributes->getFirstItem()->setEntity($_product->getResource()); $manufacturers = $attribute->getSource()->getAllOptions(false); echo “<pre>”; print_r($manufacturers); echo “</pre>”; Looking for improvement for your Magento Store? Facebook Connector Extension Product related article extension Magento Offer popup on exit extension Unlimited …

Magento: Get current and parent category

You can get current category from the following code: $currentCategory = Mage::registry(‘current_category’); You can get the parent category from the following code: /** * You want the parent category of a sub-category * Let the sub-category be $subCategory */ $parentCategory = Mage::getModel(‘catalog/category’)->load($subCategory->getParentId()); Looking for improvement for your Magento Store? Facebook …

Magento: Get sub categories and product count

Here, I will be showing you the code to get sub categories of a particular category and the number of products (product count) present in the sub categories. Looking for improvement for your Magento Store? Facebook Connector Extension Product related article extension Magento Offer popup on exit extension Unlimited Slideshow …

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. …

Magento: Get country and region collection

If you have country code(e.g. NP, EN, NL) then you can get country name from the following code: $countryName = Mage::getModel(‘directory/country’)->load($countryCode)->getName(); Get the collection of all the countries. /** * Get country collection * @return array */ public function getCountryCollection() { $countryCollection = Mage::getModel(‘directory/country_api’)->items(); return $countryCollection; } Looking for improvement …

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: Mage::getModel(‘catalog/product’)->load($product->getId())->setStatus(2)->save(); Problem: Product could not be edited programatically from frontend. The following error message is shown: Warning: Invalid argument supplied for foreach() in /var/www/magento/app/code/core/Mage/Eav/Model/Entity/Abstract.php on line 937 Solution: It …