Guest User

Untitled

a guest
Mar 23rd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. $connection->addColumn(
  2. $installer->getTable('quote_address'),
  3. 'mob_type',
  4. [
  5. 'type' => MagentoFrameworkDBDdlTable ::TYPE_TEXT,
  6. 'nullable' => true,
  7. 'default' => NULL,
  8. 'length' => 255,
  9. 'comment' => 'Mob Type'
  10. ]
  11. );
  12. $connection->addColumn(
  13. $installer->getTable('sales_order_address'),
  14. 'mob_type',
  15. [
  16. 'type' => MagentoFrameworkDBDdlTable ::TYPE_TEXT,
  17. 'nullable' => true,
  18. 'default' => NULL,
  19. 'length' => 255,
  20. 'comment' => 'Mob Type'
  21. ]
  22. );
  23. $installer->endSetup();
  24.  
  25. use MagentoCheckoutBlockCheckoutLayoutProcessor;
  26.  
  27. class MobPlugin
  28. {
  29. public function afterProcess(LayoutProcessor $subject, $jsLayout) {
  30. $customAttributeCode = 'mob_type';
  31. $customField = [
  32. 'component' => 'Magento_Ui/js/form/element/select',
  33. 'config' => [
  34. 'customScope' => 'shippingAddress.custom_attributes',
  35. 'template' => 'ui/form/field',
  36. 'elementTmpl' => 'ui/form/element/select',
  37. 'id' => 'drop-down',
  38. ],
  39. 'dataScope' => 'shippingAddress.custom_attributes.mob_type',
  40. 'label' => 'Mob Type',
  41. 'provider' => 'checkoutProvider',
  42. 'visible' => true,
  43. 'validation' => ['required-entry' => true],
  44. 'sortOrder' => 150,
  45. 'id' => 'drop-down',
  46. 'options' => [
  47. [
  48. 'value' => 'local',
  49. 'label' => 'Local',
  50. ],
  51. [
  52. 'value' => 'vip',
  53. 'label' => 'VIP',
  54. ]
  55. ]
  56. ];
  57.  
  58. $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']['shippingAddress']['children']['shipping-address-fieldset']['children'][$customAttributeCode] = $customField;
  59.  
  60. return $jsLayout;
  61. }
  62. }
  63.  
  64. <?xml version="1.0"?>
  65. <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
  66. <type name="MagentoCheckoutModelShippingInformationManagement">
  67. <plugin name="save_custom_field" type="NamespaceCustomModulePluginCheckoutSaveAddressInformation" />
  68. </type>
  69.  
  70. </config>
  71.  
  72. class SaveAddressInformation
  73. {
  74. protected $quoteRepository;
  75. public function __construct(
  76. MagentoQuoteModelQuoteRepository $quoteRepository
  77. ) {
  78. $this->quoteRepository = $quoteRepository;
  79. }
  80. /**
  81. * @param MagentoCheckoutModelShippingInformationManagement $subject
  82. * @param $cartId
  83. * @param MagentoCheckoutApiDataShippingInformationInterface $addressInformation
  84. */
  85. public function beforeSaveAddressInformation(
  86. MagentoCheckoutModelShippingInformationManagement $subject,
  87. $cartId,
  88. MagentoCheckoutApiDataShippingInformationInterface $addressInformation
  89. ) {
  90. $shippingAddress = $addressInformation->getShippingAddress();
  91. $shippingAddressExtensionAttributes = $shippingAddress->getExtensionAttributes();
  92. if ($shippingAddressExtensionAttributes) {
  93. $customField = $shippingAddressExtensionAttributes->getMobType();
  94. $shippingAddress->setMobType($customField);
  95. }
  96.  
  97. }
  98. }
Add Comment
Please, Sign In to add comment