Skip to content

Instantly share code, notes, and snippets.

@gastonsoto
Created September 2, 2013 20:49
Show Gist options
  • Save gastonsoto/6417165 to your computer and use it in GitHub Desktop.
Save gastonsoto/6417165 to your computer and use it in GitHub Desktop.
<?php
$data = array(
'payment' => 'bankdeposit',
'customer'=> array(
'email' => '[email protected]',
'name' => 'Guest Customer',
'address' => 'Address 123',
'phone' => '123456',
'city' => 'City',
'state' => 'State',
'country' => 'US',
'zip' => '123'
)
)
$quote = Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore('default')->getId());
$quote->setCustomerEmail($data['customer']['email']);
$prods = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
foreach($prods as $product){
$buyInfo = array(
'qty' => $product->getQty()
);
$productx = Mage::getModel('catalog/product')->load($product->getProduct()->getId());
$quote->addProduct($productx, new Varien_Object($buyInfo));
}
$regionModel = Mage::getModel('directory/region')->loadByName($data['customer']['state'], $data['customer']['country']);
$regionId = $regionModel->getId();
$addressData = array(
'firstname' => 'Guest',
'lastname' => 'Customer',
'street' => $data['customer']['address'],
'city' => $data['customer']['city'],
'state' => $data['customer']['state'],
'postcode' => $data['customer']['zip'],
'telephone' => $data['customer']['phone'],
'country_id' => $data['customer']['country'],
'region_id' => $regionId
);
$billingAddress = $quote->getBillingAddress()->addData($addressData);
$shippingAddress = $quote->getShippingAddress()->addData($addressData);
$shippingAddress->setCollectShippingRates(true)->collectShippingRates()
->setShippingMethod('fedex')
->setPaymentMethod($data['payment']);
$quote->getPayment()->importData(array('method' => $data['payment']));
$quote->collectTotals();
$quote->save();
$service = Mage::getModel('sales/service_quote', $quote);
$service->submitAll();
$order = $service->getOrder();
return $order->getIncrementId();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment