Magento: Get Sales Quote & Order in both Frontend and Admin

Here is a code snippet to get sales quote and order data in both admin and frontend in Magento. Get Sales Quote in Frontend Mage::getSingleton('checkout/session')->getQuote(); Get Sales Quote in Admin $quote = Mage::getSingleton('adminhtml/session_quote')->getQuote(); Get Latest Order in Frontend $orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId(); $order = Mage::getModel('sales/order')->loadByIncrementId($orderId); Get Latest Order in Admin $order = Mage::getModel('sales/order')->getCollection() ->setOrder('created_at','DESC') ->setPageSize(1) ->setCurPage(1) … Read more

Magento: Add jQuery tabs in CMS page

You can add tabs in a CMS page in Magento. I have used jQueryUI tabs for this purpose. You can view the examples and source code of the tabs feature here: http://jqueryui.com/tabs/ Here is the step-by-step guide to create tabs on Magento CMS page:- 1. Create a CMS page (CMS -> Pages -> Add New … Read more

Magento: Get Product by SKU

Here is a quick code to get / load product by its SKU in Magento. Generally we load product by its ID. Assuming product id to be ‘166’. $_productId = '166'; $_product = Mage::getModel('catalog/product')->load($_productId); But, we can also load product by its attributes, like SKU. Assuming product sku to be ‘logitechcord’. $_sku = 'logitechcord'; $_product … Read more

Magento: Get Add to Cart URL of any Product

Here is a quick code to get add to cart url of any product. Suppose that we are fetching add to cart url of a product with id ‘166’. $_productId = '166'; $_product = Mage::getModel('catalog/product')->load($_productId); $_url = Mage::helper('checkout/cart')->getAddUrl($_product); Hope it helps. Thanks.

Linux: Convert Video to Audio using FFmpeg

You can convert any video file to audio format (extract audio from video) with the help of FFmpeg tool. FFmpeg is a complete, cross-platform solution to record, convert and stream audio and video. It includes libavcodec – the leading audio/video codec library. Installing FFmpeg on Ubuntu Linux sudo apt-get install ffmpeg libavcodec-extra-53 Note that you … Read more

Magento: Avoid Module/Extension Rewrite/Override Class Conflict

While developing Magento modules/extensions, we often come up with a case where our module and some other module are rewriting/overriding the same core class. Hence, we get a conflict here and either our module or the other module will not function as expected. There are some ways to avoid such conflicts. I will explain about … Read more

Magento: Use MySQL functions with addExpressionAttributeToSelect

Function addExpressionAttributeToSelect as defined in Mage_Eav_Model_Entity_Collection_Abstract (/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php) allows us to use MySQL functions in Magento collection. Here is an example of using MySQL function CONCAT in Magento customer collection to concat customer’s firstname and lastname: $collection = Mage::getResourceModel('customer/customer_collection') ->addExpressionAttributeToSelect('fullname', 'CONCAT({{firstname}}, " ", {{lastname}})', array('firstname','lastname')); Here is another example which uses MySQL function MONTH which fetches … Read more

Xubuntu iBus: Unable to type in local language / No input method listed

Problem: I am using Xubuntu (lightweight version of Ubuntu) and I am unable to type in local language using iBus (an input method (IM) framework for multilingual input in Unix-like operating systems). iBus is already installed. When I go to its ‘Preferences‘ and then click the ‘Input Method‘ tab, I could only see ‘Chinese‘ language … Read more