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.