Used to add comments to the website and remember the user's Disqus login credentials across websites that use said service. These cookies ensure basic functionalities and security features of the website, anonymously. Necessary cookies are absolutely essential for the website to function properly. Vendor/magento/module-sales/view/frontend/templates/order/info.phtmlĪnd get the note: getData('simple_note') ?>Īs you can see the process of adding additional fields to the checkout needs a lot of effort, but it allows to have additional functionality and additional opportunity to interact with a customer. 'Atwix_SimpleNote/js/action/save-order-simple-note',įunction ($, ko, Component, saveOrderSimpleNote, quote) ) īefore we added the possibility to save the data in the order grid table, now we can show the note in the order view grid:Īpp/code/Atwix/SimpleNote/view/adminhtml/ui_component/sales_order_grid.xml Īlso, you can display the note in the different places, the note is available from an order, you only need to overwrite necessary template and print the data.įor example for showing the note in the customer order view page you need to overwrite: So, now we can add the simple note to the checkout and show the field on the payment step:Īpp/code/Atwix/SimpleNote/view/frontend/layout/checkout_index_index.xml Ītwix_SimpleNote/js/view/order-simple-noteĪpp/code/Atwix/SimpleNote/view/frontend/web/js/view/order-simple-note.js define( For it, we need to add virtual type in the di.xml We also need to save the data in the order grid table, but it is not required if you do not want to display the data in the admin order grid. $order->setData(SchemaInformation::ATTRIBUTE_SIMPLE_NOTE, $simpleNote) $simpleNote = $quote->getData(SchemaInformation::ATTRIBUTE_SIMPLE_NOTE) $quote = $observer->getEvent()->getQuote() Adding the observer and declared the event:Īpp/code/Atwix/SimpleNote/etc/events.xml Īpp/code/Atwix/SimpleNote/Observer/AddSimpleNoteToOrderObserver.php getEvent()->getOrder() Now we need to save the data from quote to the order. Throw new CouldNotSaveException(_('The simple note # number could not be saved')) $quote->setData(SchemaInformation::ATTRIBUTE_SIMPLE_NOTE, strip_tags($sn)) Throw new NoSuchEntityException(_('Cart %1 doesn\'t contain products', $cartId)) $quote = $this->quoteRepository->getActive($cartId) Return $this->setData(SchemaInformation::ATTRIBUTE_SIMPLE_NOTE, $simpleNote) Īpp/code/Atwix/SimpleNote/Model/SimpleNoteManagement.php quoteRepository = $quoteRepository $dataSetup->getTable('sales_order_grid'),Īdding Magento API classes to save the data:Īpp/code/Atwix/SimpleNote/Api/Data/SimpleNoteInterface.php Īpp/code/Atwix/SimpleNote/Model/Data/SimpleNote.php _get(SchemaInformation::ATTRIBUTE_SIMPLE_NOTE) Protected function addAttributeToOrderGrid($attributeCode, $attributeAttr, $dataSetup) $salesSetup->addAttribute('order', $attributeCode, $attributeAttr) $salesSetup = $this->salesSetupFactory->create( Protected function addAttributeToOrder($attributeCode, $attributeAttr, $dataSetup) $quoteSetup->addAttribute('quote', $attributeCode, $attributeAttr) $quoteSetup = $this->quoteSetupFactory->create( Protected function addAttributeToQuote($attributeCode, $attributeAttr, $dataSetup) SchemaInformation::ATTRIBUTE_SIMPLE_NOTE, Public function execute(ModuleDataSetupInterface $dataSetup) $this->salesSetupFactory = $salesSetupFactory $this->addSimpleNoteFieldToQuoteAndOrderService->execute($setup) Īpp/code/Atwix/SimpleNote/Setup/SetupService/AddSimpleNoteFieldToQuoteAndOrderService.php quoteSetupFactory = $quoteSetupFactory Public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) Also, to have an ability to see it on the order’s grid, we need to add the column in the sales_order_grid table.Īdding a setup script classes for adding the attribute to the tables:Īpp/code/Atwix/SimpleNote/Setup/SchemaInformation.php addSimpleNoteFieldToQuoteAndOrderService = $addSimpleNoteFieldToQuoteAndOrderService We need to add the attributes to the quote and order entities. In our case, we will create Atwix_SimpleNote module.Īpp/code/Atwix/SimpleNote/registration.php So, in the post, we will add a simple note field on the checkout, it can be a different element of form but we think the text field is more in demand.įirst, we need to create our custom module. Unfortunately, Magento 2 does not provide any additional forms on the Magento one page checkout steps by default. It can be an additional choice or message from a customer. Sometimes the additional info in the order is very useful.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |