/** * @param CartInterface $quote * @param AddressInterface $address * @param string $method * @return CartInterface */ private function prepareShippingAssignment(CartInterface $quote, AddressInterface $address, $method) { $cartExtension = $quote->getExtensionAttributes(); if ($cartExtension === null) { $cartExtension = $this->getCartExtensionFactory()->create(); } $shippingAssignment = $cartExtension->getShippingAssignments()[0]; if ($cartExtension->getShippingAssignments() === null) { $shippingAssignment = $this->getShippingAssignmentFactory()->create(); } $shipping = $shippingAssignment->getShipping(); if ($shipping === null) { $shipping = $this->getShippingFactory()->create(); } $shipping->setAddress($address); $shipping->setMethod($method); $shippingAssignment->setShipping($shipping); $cartExtension->setShippingAssignments([$shippingAssignment]); return $quote->setExtensionAttributes($cartExtension); }