Hi I have a form posting information to a page which will then place an order as a guest with what is in the current sessions basket but I am having some issues.
I get the error:
Please check shipping address information. Please enter the first name. Please enter the last name. Please enter the street. Please enter the city. Please enter the telephone number. Please enter the zip/postal code. Please enter the country.
I have done a var_dump of the shipping and billing addresses and they look fine my POST is passing the info correctly. Can anyone spot what might be wrong?
$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, true);
$checkout->saveShipping($shippingAddress, true);
$checkout->saveShippingMethod('freeshipping_freeshipping');
$checkout->savePayment(array('method'=>'free'));
$checkout->saveOrder();
foreach( Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item ){
Mage::getSingleton('checkout/cart')->removeItem( $item->getId() )->save();
}