Currently my product belong to many Categories, I want to get Category Name, from which product was ordered.
-
where you want the category name on sales->order grid of admin or somewhere else please specify.– Ashish Madankar M2 ProfessionaCommented May 6, 2016 at 13:08
-
Yes, I have created my custom grid from order items, I want it there– Abdul GhaffarCommented May 6, 2016 at 13:10
-
have you ever made use of renderer ?– Ashish Madankar M2 ProfessionaCommented May 6, 2016 at 13:27
-
Did you find any best way>– GemCommented Aug 23, 2018 at 11:08
2 Answers
Abdul Ghaffar,magento does not save category details at sales model.So it not possible to get Category Name, from which product was ordered.
Magento save order only product id,sku at sales module.
If you want to then you need do customization,first you need to add a field to at sales_quote_item & sales_flat_order_item.
During cart,you need to add category id to sales_quote_item table.
During order place, convert that field value to sales_flat_order_table
try below code:
$product = Mage::getModel('catalog/product')->load($_item['product_id']);
$cats = $product->getCategoryIds();
foreach ($cats as $category_id) {
$_cat = Mage::getModel('catalog/category')->load($category_id);
if (in_array($category_id, $elements)) {
echo $_cat->getName();
}
}