search
top

Get customer order count in Magento

Hello All, I am writing here a script snippet for getting the orders count for given customer < ?php $customer_id = 5; $_orders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('customer_id',$customer_id); $_orderCnt = $_orders->count(); //orders count echo 'Customer with ID '.$customer_id.' has '.$_orderCnt.' orders'; ?>
read more

Product Quantities Ordered in Magento

I am explaining here the way to display the total quantities ordered in the Product view page. I have used Magento version 1.7.0.2 1) Block file Create a file app/code/local/Mage/Catalog/Block/Product/View/Quantity.php (note the codepool is ‘local’ ) Copy this code in the file and save the file. class Mage_Catalog_Block_Product_View_Quantity extends Mage_Catalog_Block_Product_View_Abstract { ...
read more

Directory paths in Magento

Hello All, I am writing here the code to get various base directory paths, which might be useful. Assuming the directory is named ‘magento’ where your site is present and its the root directory of the filesystem. echo Mage::getBaseDir('base'); magento echo Mage::getBaseDir('app'); magento/app echo Mage::getBaseDir('code'); magento/app/code echo Mage::getModel('core/config')->getOptions()->getCodeDir(); magento/app/code echo...
read more

Order State and Status in Magento

Many of you might have come across the requirement, where they needed to change the order status dynamically. Difference between order state and status State is used by Magento to tell if the order is new, processing, complete, holded, closed, canceled etc.; while Statuses are the one that YOU would be defining at the back-end in System -> Order Statuses. Magento displays order STATUSES and not STATES...
read more

First and Last collection item in Magento

We the Magento developers work mostly with data collections. For accessing the data we use ‘foreach’ to iterate over collection. $product_collection = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToSelect('*'); foreach ($product_collection as $k => $v) { echo $v->getName(); echo '<br/>'; } What if we need only...
read more

Get database connection details in Magento

I am writing here an important code snippet for getting the database connection details used in Magento $config = Mage::getConfig()->getResourceConnectionConfig("default_setup"); $_host = $config->host; $_uname = $config->username; $_pass = $config->password; $_dbname = $config->dbname; echo $_host; ///likewise
read more

Get table prefix in Magento

Hello All, I am writing here an important code snippet for getting the table prefix (if any defined) in Magento. $prefix = Mage::getConfig()->getTablePrefix(); echo $prefix;
read more

Add attachment to order email in Magento

Many times there arise the need to attach files to the order mail. I am giving here a brief explanation for this: I have used Magento ver. 1.7.0.0 ( In previous version there was no mailer class). 1) Rewrite Sales Class Copy the file found at app\code\core\Mage\Sales\Model\Order.php to app\code\local\Mage\Sales\Model\Order.php Overwrite the `sendNewOrderEmail()’ method found. Here you need to...
read more

Limit results collection in Magento

Many times need arises to limit collection for say pagination or for any customization. I am listing here an example which shows how to limit the collection. I have used the Product Model below. <?php $limit = 5; $starting_from = 2; $product_collection = Mage::getModel('catalog/product')->getCollection()->setOrder('name', 'asc'); //getting the product collection, results are ordered by...
read more

Optgroup in Magento

For a module I was working on in one of my project, I needed to display a select box, with optgroup, Magento has inbuilt function for this. Kindly go through this post Select Box in Magento of mine for understanding how to generate select box before reading forward. For option group you need to pass the ‘value’ also as an array. Suppose your Category name is ‘Furniture’ and...
read more

« Previous Entries Next Entries »

top