Browsing articles in "Magento"
Jan 24, 2013
kalpesh

Magento: Add additional product/item attributes in order and invoice emails

Recently I was working with a German client, who wanted to show additional product attribute options in the order and invoice emails due to stricter law for e-commerce in their country. Magento provides basic information in the default email templates, but each store has their unique requirement to show additional information.

I will show you how to add extra product attribute values, along with order item options and custom options in order emails and invoice emails.

Here is the code that should work for order and invoice emails to get additional PRODUCT ATTRIBUTES displayed:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$productId = $_item->getProduct()->getId(); //for order emails
//$productId = $_item->getProductId(); //for invoice emails
$product = Mage::getModel('catalog/product')->load($productId);
$attributes = $product->getAttributes();

//Get a list of all PRODUCT ATTRIBUTES you want to show in this array...
$dispAttribs = array('hardrive', 'memory', 'processor'); 

foreach ($attributes as $attribute) {    
        $attributeCode = $attribute->getAttributeCode();
        if(!in_array($attributeCode, $dispAttribs)) continue;
        $label = $attribute->getFrontend()->getLabel($product);
        $value = $attribute->getFrontend()->getValue($product); 
        echo "<br /><strong>" . $label . ":</strong> " . $value;
}

Continue reading »

Jan 4, 2013
kalpesh

Magento Certification Preparation / Interview Questions Answers

Hi guys, here is the stuff I collected and created from myriad number of websites/blogs/forums/ magento source codebase during my Magento certification preparation. I have put all the things I found and studied during my preparation in one place, so that other developers who are preparing for the exam can benefit from it.

Credits to all who have contributed these things over the web from where I copied for study purpose. Few credits to me as well as I also have contributed many things in it 🙂 This may contain errors and wrong information and I don’t guarantee it to be completely correct. But this should be a good resource if you want a heads up! Please be aware that you need to go through the study guide and fundamental videos yourself in order to pass this exam.

If you are here to prepare for Interview, then I would recommend you to also go through these links:
Magento Interview questions and answers
Magento Advanced Interview questions/

The below stuff alone will definitely not going to help you much in passing the exam. Not to mention, these resource can also be used for Magento interview preparation.

Continue reading »

Dec 27, 2012
kalpesh

Magento Certified Developer Exam

Yesterday I gave my Magento Certified Developer exam and passed with a decent score. After sharing my score and success in the exam, most of my friends asked me how to prepare for this exam. So, here I share with you guys what I studied/prepared for this exam.

For passing or getting good score in this exam, you must have very decent experience in Magento. Good amount of projects with both frontend and backend hands-on is highly recommended before taking this test.

I prepared for 2 months, along with my work. Thanks to my wife who allowed me to study for the exam without disturbing or complaining 🙂 In the last 15 days before my test, I thank my Boss who allowed me to also prepare for the exam in the work hours.

First of all, I went through the videos available Free (On-Demand, 40 Hours, Fundamentals of Magento) on Magento website. You can even purchase more videos if you are interested.
http://www.magentocommerce.com/training/on-demand

Then, most of the time I spent on Study Guide PDF. It’s very important because for each question it asks you, you have to dig the Magento source code to find the answer. That also helps you in improving your understanding of Magento architecture.
http://www.magentocommerce.com/certification/ (under Resources Tab)

Once you think that you are now prepared with all the items listed in the Study Guide PDF, you can cross-check it with the Magento Self-Assessment Checklist PDF.
https://www.magentocommerce.com/services/certification

Go through all the articles by Alan Storm in the Knowledge Base section of Magentocommerce website. (Actually, that is the first step I took when starting my Magento career)
Magestore.com has an dedicated blog category for Certification, go through all the topics:
http://blog.magestore.com/category/magento-tutorials/magento-certificate-material/

(If you still have time, I would recommend you to go through the stack overflow answers, related to Magento, given by Alan Storm, Vinai Kopp, …)
http://stackoverflow.com/users/485589/vinai
http://stackoverflow.com/users/4668/alan-storm
http://stackoverflow.com/users/465971/ivan-chepurnyi
Stack Overflow top Magento answerers
You can find many more Magento gurus on StackOverflow.

Considering you have completed all the above mentioned preparation guides, there is no way you can fail in Magento Certified Developer exam!

Best luck.

Oct 22, 2012
kalpesh

Magento: Add products to placed order programatically

Ever wondered how to attach products to order programatically? It may require if you want to surprise your customer by giving them some special items along with their ordered products. Magento doesn’t allow you to do this, you need to write it through calling observer for event sales_order_place_after.

Copy this in the observer file which observes order place after event.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $skuToAdd); //your product SKU to add 
$qty = 1;
$rowTotal = $product->getPrice();
$orderItem = Mage::getModel('sales/order_item')
        ->setStoreId($order->getStore()->getStoreId())
        ->setQuoteItemId(NULL)
        ->setQuoteParentItemId(NULL)
        ->setProductId($product->getId())
        ->setProductType($product->getTypeId())
        ->setQtyBackordered(NULL)
        ->setTotalQtyOrdered($qty)
        ->setQtyOrdered($qty)
        ->setName($product->getName())
        ->setSku($product->getSku())
        ->setPrice($product->getPrice())
        ->setBasePrice($product->getPrice())
        ->setOriginalPrice($product->getPrice())
        ->setRowTotal($rowTotal)
        ->setBaseRowTotal($rowTotal)
        ->setOrder($order);
$orderItem->save();

Please note that you may also need to add the entry in sales_flat_quote_item table to be 100% sure it’s going to work for reorder also. If you’re not worried about reordering, the above code is fine.

Oct 18, 2012
kalpesh

Magento Get most popular products in a category

Magento get most popular products in any specified category using below code, you can show them in the sidebar of product detail page to let your visitors know the popularity of the products for that category.

1
2
3
4
5
6
$category = Mage::getModel('catalog/category')->load($categoryId); 
$products = Mage::getResourceModel('reports/product_collection') 
    ->addOrderedQty() //total number of quantities ordered
    ->addAttributeToSelect('*') //get all attributes
    ->setOrder('ordered_qty', 'desc') //most ordered quantity products first
    ->addCategoryFilter($category);
Pages:«1...16171819202122...29»

Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!

Certifications

Honor

Recognition

Magento top 50 contributors

Magento top 50 contributors

Contributions