2

I am a newbie in magento2 and getting a problem when the user placing the order It is returning me 500(Internal server error) I am using one step checkout extension of the mega plaza I am unable to understand what's wrong in my code. Also when I checked error in chrome network console error is in the checkout-information file.

You can check and place an order by this Url. Please help me to resolve this error thanks in advanced.

This is the error I am getting

jquery.js:10254 POST

https://magento2.petpanic.gr/rest/default/V1/carts/mine/checkout-information 500 (Internal Server Error)

8
  • 1
    Go to your app/bootstrap.php file and uncomment line ini_set('display_errors', 1); it will display you error details. Then you can add those details in your question to have more details to debug. May 4, 2019 at 10:24
  • @JaiminSutariya already uncomment May 4, 2019 at 10:34
  • Have you tried to purchase a product from the link I shared @magefms May 4, 2019 at 11:52
  • yeah and it is an error with observer in Temand Shipping
    – fmsthird
    May 4, 2019 at 11:57
  • Uncaught TypeError: Argument 1 passed to Temando\Shipping\Model\Checkout\Address::setServiceSelection() must be of the type array, null given
    – fmsthird
    May 4, 2019 at 11:58

1 Answer 1

1

The error was from Temando Shipping SaveCheckoutFieldsObserver.
You can try fixing this by overriding Temando's SaveCheckoutFieldsObserver

In your di.xml file, add this:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Temando\Shipping\Observer\SaveCheckoutFieldsObserver" type="Vendor\Module\Observer\Temando\SaveCheckoutFieldsObserver" />
</config>

Then create observer file at:

app/code/Vendor/Module/Observer/Temando/SaveCheckoutFieldObserver

<?php

namespace Vendor\Module\Observer\Temando;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Temando\Shipping\Api\Data\Checkout\AddressInterface;
use Temando\Shipping\Api\Data\Checkout\AddressInterfaceFactory;
use Temando\Shipping\Model\ResourceModel\Repository\AddressRepositoryInterface;

 /**
 * Save checkout fields with quote shipping address.
 *
 */
class SaveCheckoutFieldsObserver extends \Temando\Shipping\Observer\SaveCheckoutFieldsObserver 
{
    /**
     * @var AddressRepositoryInterface
     */
    private $addressRepository;
    /**
     * @var AddressInterfaceFactory
     */
    private $addressFactory;
    /**
     * SaveCheckoutFieldsObserver constructor.
     * @param AddressRepositoryInterface $addressRepository
     * @param AddressInterfaceFactory $addressFactory
     */
    public function __construct(
        AddressRepositoryInterface $addressRepository,
        AddressInterfaceFactory $addressFactory
    ) {
        $this->addressRepository = $addressRepository;
        $this->addressFactory = $addressFactory;
    }
    /**
     * @param Observer $observer
     * @return void
     */
    public function execute(Observer $observer)
    {
        /** @var \Magento\Quote\Api\Data\AddressInterface|\Magento\Quote\Model\Quote\Address $quoteAddress */
        $quoteAddress = $observer->getData('quote_address');
        if ($quoteAddress->getAddressType() !== \Magento\Quote\Model\Quote\Address::ADDRESS_TYPE_SHIPPING) {
            return;
        }
        if (!$quoteAddress->getExtensionAttributes()) {
            return;
        }
        // persist checkout fields
        try {
            $checkoutAddress = $this->addressRepository->getByQuoteAddressId($quoteAddress->getId());
        } catch (NoSuchEntityException $e) {
            $checkoutAddress = $this->addressFactory->create(['data' => [
                AddressInterface::SHIPPING_ADDRESS_ID => $quoteAddress->getId(),
            ]]);
        }
        $extensionAttributes = $quoteAddress->getExtensionAttributes();
        if(!is_array($extensionAttributes)){
            $checkoutAddress->setServiceSelection(array());
        }else{
            $checkoutAddress->setServiceSelection($extensionAttributes->getCheckoutFields());
        }

        $this->addressRepository->save($checkoutAddress);
    }
}
1
  • 1
    let me try and back to you May 4, 2019 at 12:51

Your Answer

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

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