7

The goal is to get the shipping address (in fact only the country) currently selected by the customer in the onepage checkout process.

I'm aware that quote-related data can be accessed by using

Mage::getModel('checkout/session')->getQuote()

and in particular

Mage::getModel('checkout/session')->getQuote()->getShippingAddress()->getData().

This also works when already existing customer shipping data is selected from the address book, but not when

1) new customers try to order, i.e. not logged in 2) the "new address" option is selected (logged in or not logged in does not matter)

The question is: Why do we not get customer shipping data for logged out users and/or new addresses entered in the OPC process using Mage::getModel('checkout/session')->getQuote()->getShippingAddress()->getData()?

Here is the corresponding code for reference:

$quote = Mage::getModel('checkout/session')->getQuote();

if ($quote) {
  if ($quote->getShippingAddress()) {
    // check customer shipping address country
    $shippingData = $quote->getShippingAddress()->getData();
if ($shippingData['country_id'] === 'DE') {
  $inlandCost = floatval($inlandCost) - 8.0;
} else if ($shippingData['country_id'] === 'AT') {
  if (floatval($quote->getGrandTotal()) < 70) {
     $inlandCost = floatval($inlandCost) - 5.0;
  }
}


}
}

For reference: This is the code we ended up using (working):

    $quote = Mage::getModel('checkout/session')->getQuote();
  if ($quote) {
    if ($quote->getShippingAddress()) {
      // check customer shipping address country
      $shippingData = $quote->getShippingAddress()->getData();

      if (isset($shippingData['country_id'])) {
        if ($shippingData['country_id'] === 'DE') {
          $baseCost; // do some calculation here
        } else if ($shippingData['country_id'] === 'AT') {
          if (floatval($quote->getGrandTotal()) < 70) {
            $baseCost = // do some calculation here
          }
        }
      }
    }
  }

closed as off-topic by Rajeev K Tomy, brentwpeterson, Keyul Shah, Marius Feb 3 '17 at 22:10

  • This question does not appear to be about the Magento e-Commerce platform within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • As it turns out this problem was related to a specific extension. Thus, please consider this issue closed. – mkerstner Aug 24 '15 at 6:22
  • Hm, I'm facing the same problem - would you mind sharing what you found was causing it on your side? Thanks! – Leo Apr 10 '16 at 23:50
  • 1
    Hey, I've updated the question to include the final code version. – mkerstner Apr 12 '16 at 10:07
  • 1
    Thanks a lot @mrkestner! Just for heads up, we found a problem with "getModel('checkout/session')" - we call it on "collectRates" in our carrier model, and it gets us the old address if you return to shipping address step of the checkout process and change the data in the form - if you call "getSingleton('checkout/session')", however, you get fresh data. Maybe it can help. – Leo Apr 12 '16 at 11:09
  • 3
    I'm voting to close this question as off-topic because this issue was related to third party extension as OP points out in comment section. – Rajeev K Tomy Feb 3 '17 at 4:19