From 0fb8dc500c809ab8f7432ff2ec4d789fdaa6b4ca Mon Sep 17 00:00:00 2001 From: PhoenixDev - JJ Date: Tue, 16 Jan 2018 12:19:12 +0100 Subject: [PATCH] Fix exception when no extension attributes have been loaded yet --- Model/CashOnDelivery.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Model/CashOnDelivery.php b/Model/CashOnDelivery.php index b97c561..8ea93d1 100644 --- a/Model/CashOnDelivery.php +++ b/Model/CashOnDelivery.php @@ -54,14 +54,17 @@ public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null) return $available; } - $shippingMethods = $quote->getExtensionAttributes()->getShippingAssignments(); - - $disallowedShippingMethods = $this->getDisallowedShippingMethods(); - foreach ($shippingMethods as $shippingMethod) { - if (in_array($shippingMethod->getShipping()->getMethod(), $disallowedShippingMethods)) { - $available = false; + $extensionAttributes = $quote->getExtensionAttributes(); + if ($extensionAttributes !== null) { + $shippingMethods = $extensionAttributes->getShippingAssignments(); + + $disallowedShippingMethods = $this->getDisallowedShippingMethods(); + foreach ($shippingMethods as $shippingMethod) { + if (in_array($shippingMethod->getShipping()->getMethod(), $disallowedShippingMethods)) { + $available = false; + } + $shippingMethod->getShipping()->getMethod(); } - $shippingMethod->getShipping()->getMethod(); } return $available;