Magento: Quick way to create order invoice programmatically

Here is a quick and easy way to create order invoice programmatically. Suppose, $_order contains your order. Here goes the code to create invoice:- if($_order->canInvoice()) { /** * Create invoice * The invoice will be in 'Pending' state */ $invoiceId = Mage::getModel('sales/order_invoice_api') ->create($_order->getIncrementId(), array()); $invoice = Mage::getModel('sales/order_invoice') ->loadByIncrementId($invoiceId); /** * Pay invoice * i.e. the … Read more

Magento: Downloadable products not displayed in Associated Products tab in Grouped Product

Scenario: – I created downloadable products. – Then I created a grouped product. – But, when I go to the ‘Associated Products’ tab in product add/edit page for Grouped product, I don’t see the downloadable products that I created before in the list. Cause/Solution: – Edit downloadable product – Go to Downloadable Information tab (the … Read more

Magento: Authorize.net not displayed in Payment Information section while Checkout

Scenario: I have enabled Authorize.net payment method but it is not displayed in Payment Information section while Checkout. Problem: In the class Mage_Paygate_Model_Authorizenet, you will find the following variable:- protected $_allowCurrencyCode = array('USD'); It means, the allowed currency for Authorize.net is only US Dollar (USD). You have to add the currency code to the above … Read more

Magento: Enable Cookies Problem

Problem: When I try to add products to shopping cart, I get redirected to enable-cookies CMS page. Similarly, when I try to login as customer from customer account login, I get redirected to the same (enable-cookies) page. The enable-cookies page asks me to enable cookies in my browser. The message says: Please enable cookies in … Read more

Magento: How to get most viewed products?

Here, I will show you the code to get the most viewed products in Magento. The function addViewsCount() filters the products with their views count. Here is the code:- Get overall Most viewed products public function getMostViewedProducts() { /** * Number of products to display * You may change it to your desired value */ … Read more

Magento: Get Product Collection by Type

Products can be of different types in Magento. The different product types are Simple Product, Configurable Product, Bundle Product, Grouped Product, Downloadable Product, and Virtual Product. For example: Chair can be a Simple Product. Shoes can be of different color and size. So, shoes falls under Configurable product. A downloadable mp3 music file will fall … Read more

Magento: Setup multiple currency shop

You can easily setup a multiple currency shop in Magento. By multiple currency shop, I mean giving the user to browse products in different currencies. Magento will provide a currency dropdown in category and product listing page. When you select your desired currency, the entire products price will be changed to your selected currency. Here … Read more

Magento: Crop image

Here is a quick tip to crop image to any degree of your choice in Magento. The crop function of Varien_Image does the magic :) Here goes the code: $mainImage = Mage::getBaseDir('media') . DS . 'test' . DS . 'image.jpg'; $image = new Varien_Image($mainImage); // crop image // crop($top=0, $left=0, $right=0, $bottom=0) $image->crop(10, 10, 10, … Read more