I am trying to create an order for guest checkout programmatically. I have gone through a lot of articles. Finally, I got one stackExchange link for creating order. But In that code, they are not showing how to get cart product list and assign to guest checkout.
This is code for reference.
$checkout = Mage::getSingleton('checkout/type_onepage');
$checkout->initCheckout();
$checkout->saveCheckoutMethod('guest');
$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$emailaddress = $_POST["email"];
$confirmemailaddress = $_POST["cemail"];
if(isset($_POST['tel'])):
$telephone = $_POST['tel'];
else:
$telephone = "Not Applicable";
endif;
if(isset($_POST['postcode'])):
$postcode = $_POST['postcode'];
else:
$postcode = "Not Applicable";
endif;
if(isset($_POST['addr1'])):
$street1 = $_POST['addr1'];
else:
$street1 = "Not Applicable";
endif;
if(isset($_POST['addr2'])):
$street2 = $_POST['addr2'];
else:
$street2 = "Not Applicable";
endif;
if(isset($_POST['city'])):
$city = $_POST['city'];
else:
$city = "Not Applicable";
endif;
$billingAddress = array (
'firstname' => $firstname,
'lastname' => $lastname,
'email' => $emailaddress,
'street' => Array(
'0' => $street1,
'1' => $street2
),
'city' => $city,
'postcode' => $postcode,
'country_id' => 'GB',
'telephone' => $telephone,
);
$shippingAddress = array (
'firstname' => $firstname,
'lastname' => $lastname,
'email' => $emailaddress,
'street' => Array(
'0' => $street1,
'1' => $street2
),
'city' => $city,
'postcode' => $postcode,
'country_id' => 'GB',
'telephone' => $telephone,
);
$checkout->saveBilling($billingAddress,null);
$checkout->saveShipping($shippingAddress,null);
$checkout->getQuote()->getShippingAddress()->setShippingMethod('freeshipping_freeshipping')->collectTotals();
$checkout->savePayment(array('method'=>'free'));
$checkout->saveOrder();
foreach( Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item ){
Mage::getSingleton('checkout/cart')->removeItem( $item->getId() )->save();
}
Please help to get code Asap. Thanks.