Magento: Adding category attributes

Here, I will be showing you how you can add attributes for your categories in Magento. From the admin panel, you can only add attributes to product. To add attributes to category, you need to write sql query in your phpmyadmin or a better way would be creating a new custom module and adding attributes … Read more

Magento: Set Random Order in Collection using RAND()

Scenario: You have created a custom module. You have entered certain data in your database. You need to show the data randomly. Solution: In MySQL the rand() function helps the select query to fetch data randomly. In Magento, you can select random rows from MySQL table using Zend_Db_Expr(‘RAND()’). You have to create a new function … Read more

Magento: Very Useful Collection Functions

There are different important functions that you can implement in your Collection object. The functions are present in Varien_Data_Collection_Db class. The class file is present in lib/Varien/Data/Collection/Db.php Here are some of the functions that you can use in your collection object:- /** * Get Zend_Db_Select instance */ $collection->getSelect(); /** * Get collection size */ $collection->getSelect()->getSize(); … Read more

Magento 1.4: No products displayed in category listing

Scenario: I have a fresh installation of Magento 1.4. I already have installed the sample data for Magento. Now, when I go to the category listing page, no products are displayed. It says “There are no products matching the selection.“. By category listing page, I mean the product listing page displayed when any category is … Read more

Magento: How to change Currency symbol by Model Override ?

In my previous article, I had written about how you can change the currency symbol by making some change in the Zend (lib/Zend/Locale/Data/en.xml) file. It’s easy way but the main drawback of this method is that all your changes will vanish once you upgrade Magento. A better way will be overriding Magento model classes that … Read more

Magento: How to get all associated children product of a configurable product?

A configurable product can have multiple other products associated to it. This article shows how to fetch all the children products that are associated with a configurable product. Here is the code: /** * Load product by product id */ $product = Mage::getModel('catalog/product') ->load(YOUR_PRODUCT_ID); /** * Get child products id (only ids) */ $childIds = … Read more

Magento: How to change Currency symbol ?

I had to change the currency symbol of Nepalese Rupee (from Nrs to Rs). By default, the currency symbol for Nepalese Rupee is Nrs. For this, you need to edit lib/Zend/Locale/Data/en.xml Well, the xml file to edit depends upon your locale settings. My locale is set to English (United States). So, I will have to … Read more

Magento: How to get Currency Rates?

You can see the currency Rates from Magento Admin System -> Manage Currency Rates You can change base currency and allowed currencies from System -> Configuration -> GENERAL -> Currency Setup -> Currency Options Now, here I will show you how you can get currency rates values for any given currency code. Here, I will … Read more

Magento: How to change order status programmatically?

This article shows how to change your order status programmatically in Magento. First, you need to load your order. You can load order by either order_id or order_increment_id. Load order by “order id” $orderId = YOUR_ORDER_ID; $order = Mage::getModel('sales/order')->load($orderId); Load order by “order increment id” $orderIncrementId = YOUR_ORDER_INCREMENT_ID; $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId); Change order status to … Read more