0

I'm currently creating a checkout page in Magento based on "One Page Checkout" - or well, I emptied onepage.phtml and started from scratch.

The order gets placed and everything, but the user is never coming to the third-party payment page; some payment methods return a blank page while other returns the error code "Error in Klarna::setConfig: Missing config field(s): secret".

I suspect that some missing JavaScript is involved, so my final question is: Is it possible to make the checkout work without JavaScript and, in that case, how?

If relevant, here is the PHP code I use to create the order (placed in the top of onepage.phtml).

<?php
    $checkout = Mage::getSingleton('checkout/type_onepage');

    //STEP(1)
    $checkout->saveCheckoutMethod('guest');

    //STEP(2)
    $checkout->saveBilling($_POST['billing'], false);

    //STEP(3)
    $checkout->saveShipping($_POST, false);

    //STEP(4)
    $checkout->saveShippingMethod('flatrate_flatrate');

    //STEP(5)
    $checkout->savePayment($_POST['payment']);

    //STEP(6)
    $checkout->saveOrder();
?>

Thank you in advance!

2
  • 1
    It isn't possible easily. The Magento checkout is almost completely based in prototype, you would need to write your own methods to replace the steps in which they do in JavaScript to remove it. Commented Apr 5, 2012 at 15:31
  • Okay. But exactly what is done in JavaScript during the checkout process? Commented Apr 6, 2012 at 8:17

1 Answer 1

1

Yes you can place order without any JS. For supporting payment methods with some redirect url after savePayment method you must add this lines:

$redirectUrl = $checkout->getQuote()
   ->getPayment()
   ->getCheckoutRedirectUrl();
if ($redirectUrl) {
    return $this->getResponse()->setRedirect($redirectUrl);
}

and after saveOrder add this:

$redirectUrl = $checkout->getRedirectUrl();
if ($redirectUrl) {
    $this->_redirect($redirectUrl);
}

Also you must use try {...} catch () { ...} block for error handling:

try {
   $checkout = Mage::getSingleton('checkout/type_onepage');

    //STEP(1)
    $checkout->saveCheckoutMethod('guest');

    //STEP(2)
    $checkout->saveBilling($_POST['billing'], false);

    //STEP(3)
    $checkout->saveShipping($_POST, false);

    //STEP(4)
    $checkout->saveShippingMethod('flatrate_flatrate');

    //STEP(5)
    $checkout->savePayment($_POST['payment']);

    //STEP(6)
    $checkout->saveOrder();
} catch (Mage_Core_Exception $e) {
    Mage::getSingleton('checkout/session')->addError($e->getMessage());
} catch (Exception $e) {
    Mage::logException($e);
    Mage::getSingleton('checkout/session')->addError(Mage::helper('checkout')->__('Unable to process your order. Please try again later'));
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.