Magento 1 how to get custom option values in cart or order page from quote

By | April 26, 2019
Spread the love

When customer select custom option from product and click add to cart then magento save these values in quote object. So you can get easily from quote object by loading anywhere in application.

If you are on cart or checkout page on frontend then  you can get cart object from session.

Mage::helper("checkout/session")->getCart()->getQuote();

If you want to get cart items by order id then

$order = Mage::getModel("sales/order")->load($id);
$items = $order->getAllItems();

To get product custom option values from quote object, use the following code.

$items = Mage::helper('checkout/cart')->getCart()->getQuote()->getAllItems();

/* cart item loop */
foreach($items as $item) {

    /* This will get custom option value of cart item */
    $_customOptions = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());

    /* Each custom option loop */
    foreach($_customOptions['options'] as $_option){
        echo $_option['label'] .'=>'. $_option['value']."<br/>";
        // Do your further logic here
    }
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *

fifteen − eight =