experius / Magento-2-Module-Experius-ExtraCheckoutAddressFields

Add Extra Address Attributes to the Magento 2 Checkout
GNU General Public License v3.0
41 stars 25 forks source link

Exception when process checkout through API without passing an address #12

Open emastyle opened 5 years ago

emastyle commented 5 years ago

When try to process an order via API during checkout, if no address is set an exception error occurred:

PHP message: PHP Fatal error: Uncaught TypeError: Argument 4 passed to Experius\ExtraCheckoutAddressFields\Plugin\Magento\Checkout\Model\PaymentInformationManagement::beforeSavePaymentInformation() must implement interface Magento\Quote\Api\Data\AddressInterface, null given ...

This happen because no default null value is set of fourth parameter, and also check if address is null.

The code method beforeSavePaymentInformation in Experius\ExtraCheckoutAddressFields\Plugin\Magento\Checkout\Model\PaymentInformationManagement should be modified as:

public function beforeSavePaymentInformation(
        \Magento\Checkout\Model\PaymentInformationManagement $subject,
        $cartId,
        \Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
        \Magento\Quote\Api\Data\AddressInterface $address = null
    ) {

if (is_null($address))
            return;
        $extAttributes = $address->getExtensionAttributes();
        if (!empty($extAttributes)) {
            $this->helper->transportFieldsFromExtensionAttributesToObject(
                $extAttributes,
                $address,
                'extra_checkout_billing_address_fields'
            );
        }
    }