I want to show values from Custom option text field in product view page if customer already ordered the product. I don't have fixed options attribute they may change like custom size, sleeve size, etc. I am trying following code and fetch last order. I don't know how to get product custom options (text field) attribute dynamically.
if(Mage::getSingleton('customer/session')->isLoggedIn()){
$customer = Mage::getSingleton('customer/session')->getCustomer();
$email= $customer->getEmail();
$_customer = Mage::getModel('customer/customer');
// get order id
$orders1 = Mage::getResourceModel('sales/order_collection')
->addFieldToSelect('*')
->addFilter('customer_email', $email)
->addAttributeToSort('created_at', 'DESC')
->setPageSize(1);
$id= $orders1->getFirstItem()->getId();
$order = Mage::getModel('sales/order')->load($id);
//get all items
$items = $order->getAllItems();
$itemcount= count($items);
$data = array();
$i=0;
//loop for all order items
foreach ($items as $itemId => $item)
{
$data[$i]['name'] = $item->getName();
$data[$i]['attr'] = $item->getAttributeName();
}
1 Answer 1
If I understand well you have configurable products. Therefore, with the product id or sku, you can retrieve the different data you need to display on the product view.
If you want to stock the attribute in the quote and in the order item, you can also read this article : http://www.atwix.com/magento/custom-product-attribute-quote-order-item/
Additionnaly, I would better stock the attribute with the customer if it is customer relative data. It would help if one day you want to have preselected sleeves length or belt size on any product.
-
yes i just want all the custom option value to be displayed if user want to order the product againParas Arora– Paras Arora2015年10月23日 07:07:19 +00:00Commented Oct 23, 2015 at 7:07
-
you can retrieve this custom options from the configurable product that you can load with the product id of the item.Christophe Ferreboeuf– Christophe Ferreboeuf2015年10月23日 07:21:25 +00:00Commented Oct 23, 2015 at 7:21