i need to create an order programatically without using customer or ordering as guest, is there a way to do this?
1 Answer
Create a file in root dir CreateOrder.php
require_once 'app/Mage.php'; ini_set('display_startup_errors',1); //error_reporting(1); umask(0); Mage::app('default'); $quote = Mage::getModel('sales/quote') ->setStoreId(Mage::app()->getStore('default')->getId()); $product = Mage::getModel('catalog/product')->load(231); /* your product ID */ $buyInfo = array('qty' => 1); $quote->addProduct($product, new Varien_Object($buyInfo)); // adding billing address $billingAddress = array( 'firstname' => 'Mohan', 'lastname' => 'Raj', 'company' => 'Webstocks', '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); //set shippingaddress, shipping method, payment method $quote->getShippingAddress() ->addData($billingAddress) ->setShippingMethod('flatrate_flatrate') ->setPaymentMethod('cashondelivery') ->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' => 'cashondelivery')); $quote->save(); $service = Mage::getModel('sales/service_quote', $quote); $service->submitAll();
Finding payment method code
$allPaymentMethods = Mage::getModel('payment/config')->getAllMethods(); foreach($allPaymentMethods as $paymentMethod) { echo $paymentMethod->getCode(); }
It working me
-
i always got this error 'The requested Payment Method is not available.' Commented Nov 3, 2017 at 4:35
-
make sure your payment method enable or not , here i use cashondelovery . which payment method you using ?– mohanCommented Nov 3, 2017 at 4:55
-
-
maybe it will using some diffent code name. i add code to my answer finding payment code try you get all possible payment method, then add than payment– mohanCommented Nov 3, 2017 at 7:59