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
$trackings=Mage::getResourceModel('sales/order_shipment_track_collection')->addAttributeToSelect('*')->addAttributeToFilter('parent_id',$shipment->getId()); | |
$allTrackingIds = $trackings->getAllIds(); | |
//Mage::log($allTrackingIds); |
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
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!
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 »
Magento: Linking multiple shipments with their invoices
In Magento, it’s a feature to create multiple invoices and shipments. But you can’t find the link between invoice with their respective shipment if you have more than one invoice and shipment. It’s because if you have forced invoice and shipment enabled (Invoice and Ship button combined in Manage Orders view page), it saves both invoice and shipment object together and hence can’t give the invoice id to shipment and hence fails in building the link between them.
So what we need to do here is:
1. Add a column to sales_flat_shipment which will store invoice increment id (say invoice_id)
2. Before invoice and shipment are saved, get the invoice’s latest increment id and increment it by 1 (to get next invoice increment id)
3. Give that invoice increment id to shipment object, so it will get saved along with other shipment columns
Here we go technically,
Continue reading »
Magento: Adding column to sales_flat_order_item, sales_flat_invoice_item and sales_flat_shipment_item
Suppose you want to add column to some table before it gets save in Magento. Example, Magento doesn’t save regular price of product when an order is placed, it only saves the selling price. So if your product have some special price in it, then Magento only saves it’s special price when an order is placed, so there is no track of regular price of that product in order item table. Same it goes to invoice item and shipment item. When creating invoice and shipment, Magento doesn’t have any track on the regular price of invoiced item’s and shipment item’s regular price.
So here I show you how you will add a column “product_mrp” in each of 3 tables and update the information without firing any query!
First of all, make an installer script in your module that will alter these three tables and add column “product_mrp” or any of your choice.
Continue reading »
Welcome to my Blog
Certifications
Honor
Recognition
Contributions
Categories
- Apache (2)
- ChatGPT (1)
- Domain name (2)
- eCommerce (2)
- htaccess (1)
- Humor (3)
- Instagram API (1)
- jQuery (4)
- JSON (1)
- Linux (10)
- Magento (142)
- Magento admin (58)
- Magento Certification (5)
- Magento error (13)
- Magento frontend (68)
- Magento Imagine (2)
- Magento Interview (5)
- Magento Master (2)
- Magento2 (10)
- Mobile (1)
- MySQL (7)
- OpenAI (1)
- OroCRM (2)
- Performance (2)
- PHP (8)
- Prototype JS (3)
- Security (4)
- Wordpress (3)
- XML (2)