Hi, all.
I have very stupid question:
How to add and use new column in exist db table (for example customer_address_entity).
I added some column in db table, but can't set data using $obj->setData('custom_field',$custom_value), i need to custom field in DB, not EAV, custom addribute, extension attribute and another bull**bleep** in Service Contract.
I don't need stupid extension attribute or custom attribute or something else attribute. I need to add this field directly on db. I found solution but is very very bad.
I'm developer and i need direct access to DB field, but is magento Service Contract is too many not compatible interfaces.
For example if i use Collection to get data form model, that return all field in DB, but if i use Repository, that return random field.
Second if i need to set data to db directly for example i make many to many relationship whit extra field, i need to create custom query to add that data, but this is very big problem when i use loop to add multiple records.
I need for KISS solution for that. May be like ($object->setData('db_field',$value) to add value.
Please help.
I dont have an idea without extension attribute.
For example, in my case i want to add custom field i order table. If I want to pass through the data and needs to be stored after placing order it must needs be saved in quote. so I followed extension attribute it works fine. In the observer file I get the quote value by
public function beforeSaveAddressInformation(
\Magento\Checkout\Model\ShippingInformationManagement $subject,
$cartId,
\Magento\Checkout\Api\Data\ShippingInformationInterface $addressInformation
) {
if (!$extAttributes = $addressInformation->getExtensionAttributes()) {
return;
}
$quote = $this->quoteRepository->getActive($cartId);
$quote->setCustomFieldName($extAttributes->getCustomFieldName());
}
Reference : https://oyenetwork.com/articles/magento2-devliery-date-module-creation-from-scratch/
Thanks for reply, but i need something easy.
I added three fields in customer_address_entity and need to work whit him.
If i use extension attribute, i can't search whit SearchCriteria. If i added in table i can't set value.
"I dont have an idea without extension attribute." - because i can't search whit search criteria.
can you try it with eav attribute,which saves the values as you asked for.