Currently browsing

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 usingZend_Db_Expr(‘RAND()’). You have to …

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 Looking for improvement for your Magento Store? Facebook Connector Extension Product related article extension Magento Offer popup on exit extension Unlimited Slideshow Magento …

Magento: Get Product Collection by Type

Here, I will be showing how you can get product collection from product type i.e. simple, configurable, bundle, grouped, and virtual. Here is the code:- $collectionSimple = Mage::getResourceModel(‘catalog/product_collection’) ->addAttributeToFilter(‘type_id’, array(‘eq’ => ‘simple’)); $collectionConfigurable = Mage::getResourceModel(‘catalog/product_collection’) ->addAttributeToFilter(‘type_id’, array(‘eq’ => ‘configurable’)); $collectionBundle = Mage::getResourceModel(‘catalog/product_collection’) ->addAttributeToFilter(‘type_id’, array(‘eq’ => ‘bundle’)); $collectionGrouped = Mage::getResourceModel(‘catalog/product_collection’) ->addAttributeToFilter(‘type_id’, …

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 …