0

I need to assign data to quote, how can I do this?

1 Answer 1

0

You can use below sample code to add data in quote and you can modify according to your requirement

    $product = Mage::getModel('catalog/product')->load('product_id');

    $customer = Mage::getSingleton('customer/session')->getCustomer();
    $store = Mage::app()->getStore();

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

    $quote->setStore($store);
    $billingAddressData = array(
    'firstname' => 'Test',
    'lastname' => 'Test',
    'street' => 'Wall Street 10',
    'city' => 'Somewhere',
    'postcode' => '123456',
    'telephone' => '123456',
    'country_id' => 'US',
    'region_id' => 12, // id from directory_country_region table
    ); // billing address
    $shippingAddressData = array(
    'firstname' => 'Test',
    'lastname' => 'Test',
    'street' => 'Sample Street 10',
    'city' => 'Somewhere',
    'postcode' => '123456',
    'telephone' => '123456',
    'country_id' => 'US',
    'region_id' => 12, // id from directory_country_region table
    );// shipping address
    $billingAddress = $quote->getBillingAddress()->addData($billingAddressData);
    $shippingAddress = $quote->getShippingAddress()->addData($shippingAddressData);
    $shippingAddress->setCollectShippingRates(true)->collectShippingRates()
    ->setShippingMethod('flatrate_flatrate')
    ->setPaymentMethod('checkmo');
    $quote->getPayment()->importData(array('method' => 'checkmo'));
    $quote->collectTotals()->save();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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