1

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();
  }

1 Answer 1

2

Try below code, Its tested and working.

$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();
}
8
  • Warning: Missing argument 2 for Mage_Checkout_Model_Type_Onepage::saveBilling() Commented Mar 30, 2017 at 16:19
  • This workd if I turn off developer mode and error reporting which I can't really do, any ideas on how to get this working cleanly? Commented Mar 30, 2017 at 16:21
  • Updated code. For shipping method error Make sure you have free shipping method enabled Commented Mar 30, 2017 at 16:23
  • Yes I have free shipping enabled, with dev off and reporting off it goes in as an order and sets the correct shipping but why? Commented Mar 30, 2017 at 16:25
  • Let me try with developer mode on Commented Mar 30, 2017 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.