May 19, 2012
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
Apr 21, 2012
Event and Observer in Magento
There is an Event-Observer methodology used in Magento, Magento has been programmed to raise events in crucial areas of the flow.
We can use these events for our requirement.
I am describing here a way to use it. An example would be the event ‘checkout_onepage_controller_success_action’ (this has been use by me at many instances) which will be raised by Magento immediately after an order...
read more
Mar 30, 2012
Adminhtml Frontname in Magento
I am writing here a code snipet for fetching the name (alias) used to access admin end, which is set to ‘admin’ by default
<?php
echo Mage::getConfig()->getNode('admin/routers/adminhtml/args/frontName');
?>
Below code for creating an admin URL
<?php
$hlpr = Mage::helper("adminhtml");
$params = array('v'=>1,'pv'=>2);
echo $url = $hlpr->getUrl('*/sales_order/',$params);
?>
read more
Feb 28, 2012
Category and Product SOAP API in Magento
In one of my post I explained the basics of SOAP API, please refer Magento SOAP API before proceeding further
I am listing here the methods to create Categories and Products using SOAP API
1) Category
a) Category Creation
<?php
$category_name = 'Test Category';
//create new category
//start
$category = array(
2,
array('name'=>$category_name,
'display_mode' => PRODUCTS_AND_PAGE,
'is_anchor'...
read more
Feb 20, 2012
Payment Methods in Magento
These days I am working on Payment Module.
I am writing here the code which is useful and related to Payment module
1) To fetch the existing Payment Methods
There is a payment module helper file existing in default Magento, which is really very helpful.
Path – app/code/core/Mage/Payment/Helper/Data.php
<?php
$payment_helper = Mage::helper('payment');
$method_list = $payment_helper->getPaymentMethodList();
echo...
read more
Feb 10, 2012
Get Table Name in Magento
I am writing here a small but useful snippet of code, for getting the table name of any module (whose table name are defined in config file).
This is very useful when using joins in query.
Suppose my module is ‘vendor’.
<?php
$resource = Mage::getSingleton('core/resource');
$tableName = $resource->getTableName('vendor/vendor');
?>
read more
Jan 6, 2012
Website ID from Store Group ID in Magento
Hello All,
I am posting here code for fetching website information from Store Group Id.
Also useful code showing relations between Stores, Groups and Websites.
< ?php
$store_id = 1; //your required store Id will go here
$store_model = Mage::getModel('core/store'); //store model
$store_group_model = Mage::getModel('core/store_group'); //store group model
$website_model = Mage::getModel('core/website');...
read more
Nov 28, 2011
Root Category in Magento
In Magento, products are assigned to Website, though we can disable the product in independent store, but this is very lengthy procedure as you need to edit each and every products.
So I came up with the solution to restrict the display of categories and products, though if you assign different Root Catalog to different store, Magento will display the categories as per the stores but not products as...
read more
Nov 11, 2011
Order Profit column in Magento
I am explaining here the way to add a Profit column in Order grid seen in admin-end
This column will show the profit gained per order (i.e, the difference between Cost and Selling Price)
1) Copy the app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php file to app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php, by maintaining the directory structure
2) There is a protected function _prepareColumns,...
read more
Oct 13, 2011
Empty Cart in Magento
In one of my project, I needed to explicity delete the items from cart after order placed.
You can also use this script for making a functionlity for giving an option for empting the cart at once from cart page.
Here is the script for the same. Place it in function ‘successAction’ in app\code\local\Mage\Checkout\controllers\OnepageController.php (copy this file from app\code\core\Mage\Checkout\controllers\OnepageController.php)
/**
...
read more
