Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $connection->addColumn(
- $installer->getTable('quote_address'),
- 'mob_type',
- [
- 'type' => MagentoFrameworkDBDdlTable ::TYPE_TEXT,
- 'nullable' => true,
- 'default' => NULL,
- 'length' => 255,
- 'comment' => 'Mob Type'
- ]
- );
- $connection->addColumn(
- $installer->getTable('sales_order_address'),
- 'mob_type',
- [
- 'type' => MagentoFrameworkDBDdlTable ::TYPE_TEXT,
- 'nullable' => true,
- 'default' => NULL,
- 'length' => 255,
- 'comment' => 'Mob Type'
- ]
- );
- $installer->endSetup();
- use MagentoCheckoutBlockCheckoutLayoutProcessor;
- class MobPlugin
- {
- public function afterProcess(LayoutProcessor $subject, $jsLayout) {
- $customAttributeCode = 'mob_type';
- $customField = [
- 'component' => 'Magento_Ui/js/form/element/select',
- 'config' => [
- 'customScope' => 'shippingAddress.custom_attributes',
- 'template' => 'ui/form/field',
- 'elementTmpl' => 'ui/form/element/select',
- 'id' => 'drop-down',
- ],
- 'dataScope' => 'shippingAddress.custom_attributes.mob_type',
- 'label' => 'Mob Type',
- 'provider' => 'checkoutProvider',
- 'visible' => true,
- 'validation' => ['required-entry' => true],
- 'sortOrder' => 150,
- 'id' => 'drop-down',
- 'options' => [
- [
- 'value' => 'local',
- 'label' => 'Local',
- ],
- [
- 'value' => 'vip',
- 'label' => 'VIP',
- ]
- ]
- ];
- $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']['shippingAddress']['children']['shipping-address-fieldset']['children'][$customAttributeCode] = $customField;
- return $jsLayout;
- }
- }
- <?xml version="1.0"?>
- <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
- <type name="MagentoCheckoutModelShippingInformationManagement">
- <plugin name="save_custom_field" type="NamespaceCustomModulePluginCheckoutSaveAddressInformation" />
- </type>
- </config>
- class SaveAddressInformation
- {
- protected $quoteRepository;
- public function __construct(
- MagentoQuoteModelQuoteRepository $quoteRepository
- ) {
- $this->quoteRepository = $quoteRepository;
- }
- /**
- * @param MagentoCheckoutModelShippingInformationManagement $subject
- * @param $cartId
- * @param MagentoCheckoutApiDataShippingInformationInterface $addressInformation
- */
- public function beforeSaveAddressInformation(
- MagentoCheckoutModelShippingInformationManagement $subject,
- $cartId,
- MagentoCheckoutApiDataShippingInformationInterface $addressInformation
- ) {
- $shippingAddress = $addressInformation->getShippingAddress();
- $shippingAddressExtensionAttributes = $shippingAddress->getExtensionAttributes();
- if ($shippingAddressExtensionAttributes) {
- $customField = $shippingAddressExtensionAttributes->getMobType();
- $shippingAddress->setMobType($customField);
- }
- }
- }
Add Comment
Please, Sign In to add comment