search
top

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

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

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

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

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

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

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

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

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

« Previous Entries

top