Created
May 24, 2012 12:56
-
-
Save brankoajzele/2781404 to your computer and use it in GitHub Desktop.
Programatically create Magento order with tablerate shipping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'app/Mage.php'; | |
Mage::app(); | |
$quote = Mage::getModel('sales/quote') | |
->setStoreId(Mage::app()->getStore('default')->getId()); | |
$product = Mage::getModel('catalog/product')->load(6); /* 6 => Some product ID */ | |
$buyInfo = array('qty' => 1); | |
$quote->addProduct($product, new Varien_Object($buyInfo)); | |
$billingAddress = array( | |
'firstname' => 'Branko', | |
'lastname' => 'Ajzele', | |
'company' => 'Inchoo', | |
'email' => '[email protected]', | |
'street' => array( | |
'Sample Street Line_1', | |
'Sample Street Line_2' | |
), | |
'city' => 'City', | |
'region_id' => '', | |
'region' => 'State/Province', | |
'postcode' => '12345', | |
'country_id' => 'NL', | |
'telephone' => '1234567890', | |
'fax' => '123456987', | |
'customer_password' => '', | |
'confirm_password' => '', | |
'save_in_address_book' => '0', | |
'use_for_shipping' => '1', | |
); | |
$quote->getBillingAddress() | |
->addData($billingAddress); | |
$quote->getShippingAddress() | |
->addData($billingAddress) | |
->setShippingMethod('tablerate_bestway') | |
->setPaymentMethod('checkmo') | |
->setCollectShippingRates(true) | |
->collectTotals(); | |
$quote->setCheckoutMethod('guest') | |
->setCustomerId(null) | |
->setCustomerEmail($quote->getBillingAddress()->getEmail()) | |
->setCustomerIsGuest(true) | |
->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID); | |
$quote->getPayment()->importData( array('method' => 'checkmo')); | |
$quote->save(); | |
$service = Mage::getModel('sales/service_quote', $quote); | |
$service->submitAll(); | |
//$order = $service->getOrder(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
setWebsiteId(Mage::app()->getStore()->getWebsiteId())->load($customerId); // echo 'Not working for me. Facing error {"status":false,"data":"Please specify a shipping method.","msg":"Request unsuccessfull"} for table rate shipping method.