I have a script to create order programmatically in magento 1.
Everything works fine except the fact that my created order doesn't have this field (Purchased From(store)) like in the picture bellow
My code looks like this:
foreach($product as $key => $value){
$sku_qty = implode(" ",$value);
$sqk_qty_array = explode(";",$sku_qty);
$sku = ($sqk_qty_array[1]);
$sku_array = explode(".", $sku);
$products[] = $sku_array[0]."-".$sku_array[0].".".$sku_array[1]."-".$sku_array[2]." ".$sqk_qty_array[2];
}
//take products id by sku
$products_id = array();
foreach($products as $key=> $value){
//take the sku from array without qty
$sku_no_qty = explode(" ",$value);
$sku = $sku_no_qty[0];
$item = Mage::getModel('catalog/product');
$id = Mage::getModel('catalog/product')->getResource()->getIdBySku($sku);
$product_id_qty[] = $id."-".$sku_no_qty[1];
$products_id []=$id;
}
//add order by script
$email = "[email protected]";
$productids = $products_id;
$websiteId = Mage::app()->getWebsite()->getId();
$store = Mage::app()->getStore();
// Start New Sales Order Quote
$quote = Mage::getModel('sales/quote')->setStoreId($store->getId());
//products count
$prod_num = count($products_id);
// Set Sales Order Quote Currency
$quote->setCurrency($order->AdjustmentAmount->currencyID);
$customer = Mage::getModel('customer/customer')
->setWebsiteId($websiteId)
->loadByEmail($email);
if ($customer->getId() == "") {
$customer = Mage::getModel('customer/customer');
$customer->setWebsiteId($websiteId)
->setStore($store)
->setFirstname('Client')
->setLastname('Jolidon')
->setEmail($email)
->setPassword("password");
$customer->save();
}
// Assign Customer To Sales Order Quote
$quote->assignCustomer($customer);
// Configure Notification
$quote->setSendCconfirmation(1);
foreach ($product_id_qty as $id)
{ $split = explode("-", $id);
$id=$split[0];
$qty =$split[1];
$product = Mage::getModel('catalog/product')->load($id);
$quote->addProduct($product, new Varien_Object(array('qty' => $qty)));
}
// Set Sales Order Billing Address
$billingAddress = $quote->getBillingAddress()->addData(array(
'customer_address_id' => '',
'prefix' => '',
'firstname' => 'Client',
'middlename' => 'Client',
'lastname' => 'Client',
'suffix' => '',
'company' => '',
'street' => array(
'0' => '',
'1' => 'Client64'
),
'city' => 'Client',
'country_id' => 'Client',
'region' => 'Client',
'postcode' => 'Client',
'telephone' => 'Client',
'fax' => 'Client',
'vat_id' => '',
'save_in_address_book' => 1
));
// Set Sales Order Shipping Address
$shippingAddress = $quote->getShippingAddress()->addData(array(
'customer_address_id' => '',
'prefix' => '',
'firstname' => 'Client',
'middlename' => 'Unic',
'lastname' => 'Client',
'suffix' => '',
'company' => '',
'street' => array(
'0' => 'Client',
'1' => '45'
),
'city' => 'Client',
'country_id' => 'Client',
'region' => 'Client',
'postcode' => 'Client',
'telephone' => 'Client',
'fax' => 'Client',
'vat_id' => '',
'save_in_address_book' => 1
));
if ($shipprice == 0) {
$shipmethod = 'freeshipping_freeshipping';
}
// Collect Rates and Set Shipping & Payment Method
$shippingAddress->setCollectShippingRates(true)
->collectShippingRates()
->setShippingMethod('flatrate_flatrate')
->setPaymentMethod('checkmo');
// Set Sales Order Payment
$quote->getPayment()->importData(array('method' => 'checkmo'));
// Collect Totals & Save Quote
$quote->collectTotals()->save();
try {
// Create Order From Quote
$service = Mage::getModel('sales/service_quote', $quote);
$service->submitAll();
$increment_id = $service->getOrder()->getRealOrderId();
}
catch (Exception $ex) {
echo $ex->getMessage();
}
catch (Mage_Core_Exception $e) {
echo $e->getMessage();
}
// Resource Clean-Up
$quote = $customer = $service = null;
// Finished
return $this->_redirectUrl
How can i add this missing filed in my order?