Feb 12, 2012
kalpesh

Magento: Show “track your order” in frontend – My Orders

It is always required for the customer to track their order. The shipping carriers can be anything: Aramex, Bluedart, DHL, First Flight, Federal Express, etc.. Navigate to My Account and place a button in My Orders section there “Track Order”. Paste the code below to link it to tracking popup that you can also see in backend Shipments area.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
if($_order->hasShipments()) {
    $show = true;
    foreach($_order->getTracksCollection() as $k=>$v) {                            
        if($v['carrier_code'] == 'custom' || $v['carrier_code'] == '')
            $show = false;
    }
    if($show) {?>
        <span class="separator2">&nbsp;</span>

        <a class="askTrackBtn" href="javascript:;" onclick="popWin('<?php echo Mage::helper('shipping/data')->getTrackingPopUpUrlByOrderId($_order->getId()) ?>', 'tracking the order', 'scrollbars=yes,width=800,height=600,resizable=yes');return false;"><span><?php echo $this->__('Track Order') ?></span></a>
       <?php 
    }
}?>
Feb 12, 2012
kalpesh

Magento: Get all/latest tracking number of any shipment

In magento, if you have more than one tracking number assigned for any particular shipment, we need to show the latest track number with details to the customer.

Here I will show you how to get all tracking numbers as well as only the latest tracking number for any shipment.

Get all tracking numbers for shipment

1
2
3
$trackings=Mage::getResourceModel('sales/order_shipment_track_collection')->addAttributeToSelect('*')->addAttributeToFilter('parent_id',$shipment->getId());
$allTrackingIds = $trackings->getAllIds();
//Mage::log($allTrackingIds);

Continue reading »

Feb 12, 2012
kalpesh

Magento/PHP: Convert your XML Object to Array

While developing shipment tracking using SimpleXML in magento, I came accross the requirement where I have to get all the XML tags as keys and all the data inside XML tags as values in array. Means I wanted to convert XML to an Array where I can display all the information in some decorative format.

So here is how I converted XML to Array without any kind of hardcoding.

PHP class method to convert xml to array

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
public function convertXmlObjToArr($obj, &$arr){
            $children = $obj->children();
            $executed = false;
            foreach ($children as $elementName => $node){
                if($arr[$elementName]!=null){
                    if($arr[$elementName][0]!==null){
                        $i = count($arr[$elementName]);
                            $this->convertXmlObjToArr($node, $arr[$elementName][$i]);
                    }else{
                        $tmp = $arr[$elementName];
                        $arr[$elementName] = array();
                        $arr[$elementName][0] = $tmp;
                        $i = count($arr[$elementName]);
                            $this->convertXmlObjToArr($node, $arr[$elementName][$i]);
                    }
                }else{
                                $arr[$elementName] = array();
                                $this->convertXmlObjToArr($node, $arr[$elementName]);
                }
                $executed = true;
            }
            if(!$executed&&$children->getName()==""){
                $arr = (String)$obj;
            }
            return;
        }

Hope this helps!

Jan 29, 2012
kalpesh

Magento Interview Questions

Here is a list of Magento advanced interview questions that I can think off now.
EDIT: There are also Expert interview questions that I added lately.

1. Explain Magento’s MVC architecture
2. How Magento’s ORM work?
3. What is EAV in Magento?
4. Difference between Mage::getSingleton() and Mage::getModel()
5. What are the steps to change the theme of Magento
6. If you want to add/modify core functionality, how will you do it?
7. How will you create a new module in Magento?
8. How will you call a CMS page in your module’s PHTML file?
9. What is codePool in Magento?
10. Explain handles in Magento’s layout Continue reading »

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