1

I'm using Magento2.2.6.

When trying to checkout as a guest and filling manually the shipping address, everything works fine. When trying to checkout as logged user it gives and error like this: error

When I try to checkout as logged user but filling in manually a new address, it also works fine.

It is only throwing the error when it takes the saved addresses from my profile.

I use a custom courier module for shipping cost estimation.

Here is a link to the file:

https://drive.google.com/open?id=1-6wyyjXN-Cp16wuVTY7TSUZ1v80b5v25

Can somebody help?

The error is from here:

$judet_dest = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $detalii_dest["region"]);

Where:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cart = $objectManager->get('\Magento\Checkout\Model\Cart'); 
$shippingAddress = $cart->getQuote()->getShippingAddress();
$detalii_dest = $shippingAddress->getData();
  • Error occurs when the customer has two or more address – magefms Mar 25 at 8:23
  • because the $detalii_dest["region"] returns an array on that case – magefms Mar 25 at 8:24
  • so the best solution would be to use reset() or current() array function, in that case it will get only the value of the first or current array – magefms Mar 25 at 8:25
  • I added:$judet_dest = iconv("UTF-8", "ISO-8859-1//TRANSLIT", next($detalii_dest["region"])); in line 290. It works fine for the existing saved addressed – Cristi Daniliuc Mar 25 at 9:06
  • 1
    if (is_array($detalii_dest["region"])){ $judet_dest = iconv("UTF-8", "ISO-8859-1//TRANSLIT", next($detalii_dest["region"])); }else{ $judet_dest = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $detalii_dest["region"]); } – Cristi Daniliuc Mar 25 at 9:42
1

Error occurs when the current logged in customer has two or more addresses. Because what happens is, your code tries to load all the region or city that was registered or associated with the user.

Try this, replace your iconv lines with these:

$city = current($detalii_dest["city"]);
$region= current($detalii_dest["region"]);
$localitate_dest = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $city);
$judet_dest = iconv("UTF-8", "ISO-8859-1//TRANSLIT",  $region);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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