3

I load quote by quote id and adding items to quote_item table.

I need to know how to add product options i.e. info_buyrequest options to quote item from controller only. I tried below code.

    $quote = Mage::getModel('sales/quote')->load('1125');
    $quote = $quote->setUpdatedAt(now());

    $product = Mage::getModel('catalog/product')->load($product_id);
    $quoteItem = Mage::getModel('sales/quote_item')->setProduct($product)->setQty(1);
    $quote->addItem($quoteItem);

    $additionalOptions = array(
            'label' => 'shop_data',
            'value' => 1
        );

     /* Here the modification is needed */
    foreach($quote->getAllVisibleItems() as $row){
        if($row->getProductId() == 95 ){
            $row->getProduct()->addCustomOption('info_buyRequest', serialize($additionalOptions));
        }
    }

    try{
        $quote->save();
    }catch(Exception $e){
        echo $e->getMessage();
    }
2

please try belo

<?php 
    $quote = Mage::getModel('sales/quote')->load('1125');
    $quote = $quote->setUpdatedAt(now());

    $product = Mage::getModel('catalog/product')->load($product_id);
    $quoteItem = Mage::getModel('sales/quote_item')->setProduct($product)->setQty(1);
    $quote->addItem($quoteItem);

    $additionalOptions = array(
            'label' => 'shop_data',
            'value' => 1
        );

     /* Here the modification is needed */
    foreach($quote->getAllVisibleItems() as $row){
        if($row->getProductId() == 95 ){
            $row->addOption(array(
                'code' => 'info_buyRequest',
                'value' => serialize($additionalOptions)
            ));
        }
    }

    try{
        $quote->save();
    }catch(Exception $e){
        echo $e->getMessage();
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.