Magento

  • Magento

    How to override a controller in Magento

    How to override a controller in Magento In several time ,we need to override a controlller.How to override a controller in Magento. There are two process available: 1.Basic Old process. 2.Upgrade Process from Magento CE 1.5.0. First have describe second process. It available from Magento CE 1.5.0.Where, i have Overriding controllers magento core controller .I have using before tag for use to override controller of a module-   Here ,step to override a controllers: a)First check which module ,i want to override. Ex1: Suppose have override magento Magento Core Module Mage_Contacts and want override IndexController.php Write below code <frontend> <routers> <contacts> <args> <modules> <customcontacts before="Mage_Contacts">Amit_Customcontacts</customcontacts> </modules> </args> </contacts> </routers> </frontend>…

  • Magento

    Programmatically create Shipment of a new order in magento

    Programmatically create Shipment of a new order in magento Programmatically create Shipment of a new order in magento For some time need to create Shipment of an order.I have write code for how to create Shipment of an order pragmatically here First of all load an order by order id, Check all item of an order are already creating Shipment. if ,invoice is not created then create Shipment of all items Step1 ::load order by order id $order=Mage::getModel(‘sales/order’)->load($orderId); Or $order = Mage::getModel(‘sales/order’)->loadByIncrementId($orderIncrementId); Step2: check a item is available for shipment and set quantity for shipment $qty=array(); $Itemqty = $eachOrderItem->getQtyOrdered() – $eachOrderItem->getQtyShipped() – $eachOrderItem->getQtyRefunded() – $eachOrderItem->getQtyCanceled(); $qty[$eachOrderItem->getId()]=$Itemqty; Step3:create a shipment and…

  • Magento

    How to change page layout in Magento

    In this post,you can change page layout in Magento also set a Magento page template layout How to change page layout in Magento There are in few steps,you can page pay layouts. For change the page layout,you need to change root block  template(<reference name=”root”>) using setsetTemplate() method  ,So use <action method=”setTemplate”><template>YourPageLayoutLocation/YourLayput.phtml</template></action> and apply this template by  <action method=”setIsHandle”><applied>1</applied></action>   <?xml version="1.0"?> <layout version="0.1.0"> ....... <HandlerName> <reference name="root"> <action method="setTemplate"><template>YourPageLayoutLocation/YourLayput.phtml</template></action> <action method="setIsHandle"><applied>1</applied></action> </reference> </HandlerName> [...] </layout>   Suppose i am changing template   in checkout cart page <checkout_cart_index translate="label"> <reference name="root"> <action method="setTemplate"><template>page/2columns-left.phtml</template></action> <!-- Mark root page block that template is applied --> <action method="setIsHandle"><applied>1</applied></action> </reference> </checkout_cart_index>  

  • Magento

    Create an magento extension with custom database table

    Create an magento extension with custom database table For,a newcomer magento developer,it is not easy to create an magento extension with custom database. There are few steps to create an extension. First of all create module control file Module name as Amit_Custommodule.xml at app/etc/modules/. Which is enabling and disabling that custom module.First of all define CodePool of extension. There are two type of codePool one local another community. Suppose i am using community.Then the code of Amit_Custommodule.xml are: <?xml version="1.0"?> <config> <modules> <Amit_Custommodule> <codePool>community</codePool> <active>true</active> </Amit_Custommodule> </modules> </config> Create a config.xml ,where we are declared table,model,blocks,layouts file , controllers,In a word we can say configuration file that extension. Path Of…

  • Magento

    Programmatically create invoice of an order in magento

    Programmatically create invoice of an order in magento and create partial invoice of an order For some time need to create invoice of  an order.I have write code for  how to create invoice of an order pragmatically here. First of   load an order by order id/order increment id, Check which items of  that order are available for create invoice. if ,invoice is not created then create invoice of those items #this code is suite if order does have any invoice $order=Mage::getModel('sales/order')->load($orderID); #checkout order capable to create invoice if($order->canInvoice() and $order->getIncrementId()) { $items = array(); foreach ($order->getAllItems() as $item) { $items[$item->getId()] = $item->getQtyOrdered(); } $invoiceId=Mage::getModel('sales/order_invoice_api')->create($order->getIncrementId(),$items,null,false,true); #capture the invoice Mage::getModel('sales/order_invoice_api')->capture($invoiceId);    …

  • Magento

    Magento custom collection filter and sort

    Magento custom collection filter and sort   We have already know how to filter magento product ,customer,wishlist,order  collection  fields filters. But whenever we are working on  non-exiting model collection, then we facing problem.Here i have put some tricks how you can filter a custom collection by a field.In post,i have working on a writing how a custom collection is filter by a filed and how the collection will filter. Suppose a custom collection is #Mage::getModel('[ModulePrefix/Entities]')->getCollection(); $collection=Mage::getModel('[custommodule/customemodule]')->getCollection(); For add addFieldToSelect('*') at that Collection for retrieves all field value for a module is Then want to filter that collection by a field name ‘age’ then use $collection->addFieldToSelect('age'); For add for sort by a…