Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email

Magento Forum

How to set product attributes while creating order programmatically
Jr. Member
Total Posts:  29
Joined:  2009-08-27

I am using magento, I have a script which places order with product,customer info. The order is created successfully, but I am facing a problem to set product attribute while running this script to create order. I am posting my second function which sets information however my first function sets customer, product and billing/shipping address.

public function createOrder($quoteId
= array();
$quoteObj Mage::getModel('sales/quote')->load($quoteId);
$items $quoteObj->getAllItems();
$convertQuoteObj Mage::getSingleton('sales/convert_quote');
$orderObj $convertQuoteObj->addressToOrder($quoteObj->getShippingAddress());        
        foreach (
$items as $item{
$orderItem $convertQuoteObj->itemToOrderItem($item);
$options = array();

$orderItem->setProductOptions(new Varien_Object(
'product' => $item->getProduct(),
//'code' => 'shoe_size',
'code' => '502',
'value' => '41' // Option id goes here. If more options, then comma separate 
        if (
$productOptions $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct())) {
if ($addOptions $item->getOptionByCode('additional_options')) {
if ($options{
if ($item->getParentItem()) {
catch (Exception $e){        
$last_insert_order_id $orderObj->getRealOrderId();
I am testing this after installing magento sample data, where men’s shoes[id=93], its attribute is size/8.
I will be very thankful any kind of help.
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top