Hi guys,
I have created a custom attribute called 'part number' and I want to use this attribute instead of SKU.
In the customer dashboard view order page, the default SKU is working properly. I mean for simple products it shows the Sku and for the configurable ones, it shows the SKU of the SELECTED CHILD ITEM which is correct.
When I want to replace the SKU with the custom attribute part number, for simple products it is OK, but for configurable products, it displays the custom attribute of the PARENT ITEM NOT THE SELECTED CHILD ITEM!
For View Cart page I could write the code to check if the item is configurable, get the selected child in the cart and show its part number. But this code does not work for customer view order page!
The issue is I cannot get the child item of the ordered item if it's configurable.
Here is the code I used for view cart in template/checkout/cart/item/default.phtml and is working fine:
<td class="a-center"> <?php if ($isVisibleProduct): if ($_item->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) { //Return first item of the array, in the case of 'configurable', it will be a one item array. $_simpleItem = reset($_item->getChildren()); $_product2= Mage::getModel('catalog/product')->load($_simpleItem->getProductId()); echo $_product2->getResource()->getAttribute('part_number2')->getFrontend()->getValue($_product2); }else{ $_product= Mage::getModel('catalog/product')->load($_item->getProductId()); echo $_product->getResource()->getAttribute('part_number2')->getFrontend()->getValue($_product); } endif ?> </td>
And below is the code I used in customer view order page in template/sales/order/items/renderer/default.phtml which I cannot get the custom attribute of the selected item of configurable product:
<td> <?php //if item is configurable if($_options = $this->getItemOptions()){ // I want to get the selected child item and show its part number here }else{ $_product= Mage::getModel('catalog/product')->load($_item->getProductId()); echo $_product->getResource()->getAttribute('part_number2')->getFrontend()->getValue($_product); } ?> </td>
Any solution?!
Thanks
Solved! Go to Solution.
Found a solution. Not very proper, but solved my problem. In the frontend template/sales/order/items/renderer/default.phtml I wrote the below code to get child custom attribute instead of their parent if parent is configurable:
//Add Part Number in view order if($_options = $this->getItemOptions()){ // if product is configurable $simpleProduct=Mage::getModel('catalog/product')->loadByAttribute('sku', $_item->getSku()); echo $simpleProduct->getResource()->getAttribute('part_number2')->getFrontend()->getValue($simpleProduct); }else{ $_product= Mage::getModel('catalog/product')->load($_item->getProductId()); echo $_product->getResource()->getAttribute('part_number2')->getFrontend()->getValue($_product); }
Hi @Armita,
Maybe this question could sound silly but... did you enabled the template path hints (with blocks too) to see which template and block is renderind that section?
[duplicate answer]
Dear Damian,
Thanks for your reply. I know I am in the right template. Thanks again for the hint.
Found a solution. Not very proper, but solved my problem. In the frontend template/sales/order/items/renderer/default.phtml I wrote the below code to get child custom attribute instead of their parent if parent is configurable:
//Add Part Number in view order if($_options = $this->getItemOptions()){ // if product is configurable $simpleProduct=Mage::getModel('catalog/product')->loadByAttribute('sku', $_item->getSku()); echo $simpleProduct->getResource()->getAttribute('part_number2')->getFrontend()->getValue($simpleProduct); }else{ $_product= Mage::getModel('catalog/product')->load($_item->getProductId()); echo $_product->getResource()->getAttribute('part_number2')->getFrontend()->getValue($_product); }