2

I have did all the steps from this tutorial and it works well for updating custom fields in quote table.

In my case, I need to add custom fields to quote_address and (later) in customer_address_entity tables.

I've created a plugin for: <type name="Magento\Checkout\Model\ShippingInformationManagement">.

What I've got so far:

#Vendor/module/Plugin/Checkout/Model/Checkout/ShippingInformationManagementPlugin.php


public function beforeSaveAddressInformation(
    ShippingInformationManagement $subject,
    $cartId,
    ShippingInformationInterface $addressInformation
) {
    $this->logger->log(\Psr\Log\LogLevel::DEBUG, 'INDEXIS');

    $extAttributes = $addressInformation->getExtensionAttributes();

    $number = $extAttributes->getNumber();
    $complement = $extAttributes->getComplement();
    $district = $extAttributes->getDistrict();
    $area_code = $extAttributes->getAreaCode();
    $this->logger->log(\Psr\Log\LogLevel::DEBUG, "number: " . $number);
    $this->logger->log(\Psr\Log\LogLevel::DEBUG, "complement: " . $complement);
    $this->logger->log(\Psr\Log\LogLevel::DEBUG, "district:" . $district);
    $this->logger->log(\Psr\Log\LogLevel::DEBUG, "area_code:" . $area_code);


    $quote = $this->quoteRepository->getActive($cartId);

    $quote->setNumber($number);
    $quote->setComplement($complement);
    $quote->setDistrict($district);
    $quote->setAreaCode($area_code);
}

It logs the values in debug.log file but won't update the fields in my database.

I know that my mistake is trying to set my custom fields in $this->quoteRepository. So my question is: What object should I use to set my custom fields in quote_address table?

There will more questions related to this topic, but only after this one is solved.

5

For address save, you need to assign value into address object. Here is an example:

Here delivery_date is a new custom column of quote_address table

$billingAddress = $addressInformation->getBillingAddress();
$billingAddress->setDeliveryDate('2016-09-30 12:22:00');

If you need to assign shipping address too, then you need to do it the same way. Basically magento uses two rows for addresses, in quote/order; One address for billing and one for shipping.

$shippingAddress = $addressInformation->getShippingAddress();
$shippingAddress->setDeliveryDate('2016-09-30 12:22:00');
3
  • Awesome. I've set both addresses. Now, how can I show my custom data in payment screen? And how can I use the same form in payment screen (when the user unchecks "My billing and shipping address are the same") Sep 30 '16 at 15:18
  • It is saving in quote_address table but not showing in checkout shipping address Jun 27 '19 at 11:55
  • sadly, you almost need to make modification in every spot Jun 7 '20 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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