1

I need to keep the values ​​from the quote in the custom attributes of the customer object. This is necessary for the user to be able to add additional fields on the checkout.

I added 2 custom attributes for the customer_address entity, added them to the extension attributes. Also hung plugin before on method SaveAddressInformation in order to add the values ​​of my attributes to the quote, pre-expanded quote table. Also, thanks to the observer, I saved these values ​​from the quote in the order.

And now, in order for a registered user to save this data in the address, I need to somehow transfer and save the values ​​from the quote to the customer_address_entity table

I just can not understand at what point I can do it.

public function beforeSaveAddressInformation(
    \Magento\Checkout\Api\ShippingInformationManagementInterface $subject,
    $cartId,
    \Magento\Checkout\Api\Data\ShippingInformationInterface $addressInformation
) {
    $extensionAttributes = $addressInformation->getShippingAddress()->getExtensionAttributes();

    if ($extensionAttributes) {
        $cityId = $extensionAttributes->getCityId();
        $warehouseId = $extensionAttributes->getWarehouseId();

        $quote = $this->quoteRepository->getActive($cartId);
        $quote->setCityId($cityId);
        $quote->setWarehouseId($warehouseId);
    }
}

Observer: $order = $observer->getEvent()->getOrder();

    $quote = $this->quoteRepository->get($order->getQuoteId());
    $order->setCityId($quote->getCityId());
    $order->setWarehouseId($quote->getWarehouseId());

    return $this;
}
RoyFace
  • 11
  • 3

0 Answers0