An open API service indexing awesome lists of open source software.

https://github.com/bdcrops/module-ordernotes

OrderNotes for Magento 2 extensions
https://github.com/bdcrops/module-ordernotes

magento-2-extensions ordernotes-for-magento-2-extensions ordernotes-magento-2

Last synced: 11 months ago
JSON representation

OrderNotes for Magento 2 extensions

Awesome Lists containing this project

README

          

# Magento2x OrderNotes

This module is used as a OrderNotes for Magento 2 extensions.
we have built a small, but functional, order notes module. This allowed us to
familiarize ourselves with an important aspect of customizing the checkout experience. The gist
of this lies in understanding the checkout_index_index layout handle, the JavaScript
window.checkoutConfig object, and the uiComponent.

## Goal

- Customizing & Passing data Checkout Experiences
- Adding order notes to the checkout
- Learn Magento 2 Certified Professional Developer exam topics "Customizing the Checkout Process 13%"

## 1. Install & upgrade OrderNotes

#### 1.1 Copy and paste

If you don't want to install via composer, you can use this way.

- Download [the latest version here](https://github.com/bdcrops/module-ordernotes/archive/master.zip)
- Extract `master.zip` file to `app/code/BDC/OrderNotes` ; You should create a folder path `app/code/BDC/OrderNotes` if not exist.
- Go to Magento root folder and run upgrade command line to install `BDC_OrderNotes`:

```
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
```

#### 1.2 Install via composer

We recommend you to install BDC_OrderNotes module via composer. It is easy to install, update and maintaince.Run the following command in Magento 2 root folder.

```
composer config repositories.module-ordernotes git
https://github.com/bdcrops/module-ordernotes.git

composer require bdcrops/module-ordernotes:~1.0.0
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
```

#### 1.3 Upgrade

```
composer update bdcrops/module-ordernotes
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
```

Run compile if your store in Product mode:

```
php bin/magento setup:di:compile
```

## 2. Magento 2 Module "OrderNotes" Step By Step Tutorial

- Create app/code/BDC/OrderNotes/registration.php
```

```
- Create app/code/BDC/OrderNotes/Setup/InstallSchema.php
```
getConnection();
$connection->addColumn(
$setup->getTable('quote'),
'order_notes', [
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'nullable' => true,
'comment' => 'Order Notes'
]
);

$connection->addColumn(
$setup->getTable('sales_order'),
'order_notes', [
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'nullable' => true,
'comment' => 'Order Notes'
]
);
}
}

```
- Create app/code/BDC/OrderNotes/etc/frontend/routes.xml
```





```
- Create app/code/BDC/OrderNotes/Controller/Index.php
```
checkoutSession = $checkoutSession;
$this->logger = $logger;
parent::__construct($context);
}
public function execute() {
try {
if ($notes = $this->getRequest()->getParam('order_notes', null)) {
$quote = $this->checkoutSession->getQuote();
$quote->setOrderNotes($notes);
$quote->save();
}
$result = ['time' => (new \DateTime('now'))->format('Y-m-d H:i:s'), ];
} catch (\Exception $e) {
$this->logger->critical($e);
$result = [
'error' => __('Something went wrong.'),
'errorcode' => $e->getCode(),
];
}
$resultJson = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_JSON);
$resultJson->setData($result);
return $resultJson;
}
}

```

- Create app/code/BDC/OrderNotes/etc/frontend/di.xml
```




BDC\OrderNotes\Model\ConfigProvider


```
- Create app/code/BDC/OrderNotes/Model/ConfigProvider.php
```
[
'title' => __('Order Notes'),
'header' => __('Header content.'),
'footer' => __('Footer content.'),
'options' => [
[ 'code' => 'ring', 'value' => __('Ring longer') ],
[ 'code' => 'backyard', 'value' => __('Try backyard') ],
[ 'code' => 'neighbour', 'value' => __('Ping neighbour') ],
[ 'code' => 'other', 'value' => __('Other') ],
],
'time' => (new \DateTime('now'))->format('Y-m-d H:i:s')
]
];
}
}

```
- Create app/code/BDC/OrderNotes/etc/webapi_rest/events.xml
```



```
- Create app/code/BDC/OrderNotes/Observer/SaveOrderNotesToOrder.php
```
getEvent();
if ($notes = $event->getQuote()->getOrderNotes()) {
$event->getOrder()->setOrderNotes($notes)
->addStatusHistoryComment('Customer note: ' . $notes);
}
return $this;
}
}

```
- Create app/code/BDC/OrderNotes/view/frontend/layout/checkout_index_index.xml
```











BDC_OrderNotes/js/view/order-notes
2









```
- Create app/code/BDC/OrderNotes/view/frontend/web/js/view/order-notes.js
```
define( ['ko',
'uiComponent',
'underscore',
'Magento_Checkout/js/model/step-navigator',
'jquery',
'mage/translate',
'mage/url'],
function (
ko,
Component,
_,
stepNavigator,
$,
$t,
url ) {
'use strict';
let checkoutConfigOrderNotes = window.checkoutConfig.orderNotes;
return Component.extend({
defaults: { template: 'BDC_OrderNotes/order/notes' },
isVisible: ko.observable(true),
initialize: function () {
this._super();
stepNavigator.registerStep('order_notes', null, $t('Order Notes'), this.isVisible, _.bind(this.navigate, this), 15);
return this;
},

getTitle: function () { return checkoutConfigOrderNotes.title; },
getHeader: function () { return checkoutConfigOrderNotes.header; },
getFooter: function () { return checkoutConfigOrderNotes.footer; },
getNotesOptions: function () { return checkoutConfigOrderNotes.options; },
getCheckoutConfigOrderNotesTime: function ()
{ return checkoutConfigOrderNotes.time;},
setOrderNotes: function (valObj, event) {
if (valObj.code == 'other') {
$('[name="order_notes"]').val('');
} else {
$('[name="order_notes"]').val(valObj.value);
}
return true;
},

navigate: function () {
// Code to trigger when landing on our step
},

navigateToNextStep: function () {
if ($(arguments[0]).is('form')) {
$.ajax({
type: 'POST',
url: url.build('ordernotes/index/process'),
data: $(arguments[0]).serialize(),
showLoader: true,
complete: function (response) {
stepNavigator.next();
}
});
}
}
});
}
);

```
- Create app/code/BDC/OrderNotes/view/frontend/web/template/order/notes.html
```























  • ```
    - OrderNotes Checkout

    ![](docs/OrderNotesCheckout.png)

    - Order Notes Order Details
    ![](docs/OrderNotesOrderDetails.png)

    - Order Notes Order Comment
    ![](docs/OrderNotesOrderComent.png)

    ## 3. FAQ

    ## Ref