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: Upgrading mysql setup of a module

Suppose, you have a module called MyModule. Its version is 0.1.0. Now, you want to do some database changes for the module. You have the mysql setup file (mysql install file) mysql4-install-0.1.0.php in MyModule/sql/mymodule_setup folder of your module. You don’t need to make direct changes to database. You can upgrade your module to make your … 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: Get store information

Magento allows to maintain multiple websites from single backend admin. Furthermore, each website can have multiple stores. Below is the code to get Magento store information like store id, store code, store name, etc. All of these functions can be found in class Mage_Core_Model_Store. Get store data array // Get all store data in an … Read more

Magento: Get height and width of Product Image

The following functions can be used to get product’s image height and width. Image functions are defined in Mage_Catalog_Helper_Image class. getOriginalWidth gives width of image. getOriginalHeigh or getOriginalHeight gives height of image. getOriginalSizeArray gives the height and width of an image in array. $_product = $this->getProduct(); $imageWidth = $this->helper('catalog/image')->init($_product, 'image')->getOriginalWidth(); if($imageWidth > 600) { $lightboxImage … Read more

Magento: How to call static block from template (.phtml) file?

You can easily call any static block from template (phtml) file. At first, you have to create a static block. Let us suppose, you created a static block with the identifier cool_items. Now, you can call the static block from any phtml file with the help of following code: echo $this->getLayout() ->createBlock('cms/block') ->setBlockId('cool_items') ->toHTML(); Thanks.

Magento: How to call block directly from phtml file without defining in layout?

You can call your block directly from a phtml file with the following code. You can keep this code and call the block from any phtml file. I have assumed my module name as Newmodule and my block name as Newblock.php. The phtml file for the block is assumed to be newmodule/newblock.phtml echo $this->getLayout() ->createBlock('newmodule/newblock') … Read more