13 | = $block->getDeliveryComment() ?> 14 |
├── README.md
└── SR
└── DeliveryDate
├── Block
└── Adminhtml
│ └── DeliveryDate.php
├── Model
├── Config.php
├── Config
│ └── Source
│ │ └── Disabled.php
├── DeliveryDateConfigProvider.php
└── Validator.php
├── Observer
├── AddHtmlToOrderShippingBlock.php
├── AddHtmlToOrderShippingView.php
├── AdminhtmlSalesOrderCreateProcessData.php
└── SalesModelServiceQuoteSubmitBefore.php
├── Plugin
└── Checkout
│ ├── Block
│ └── LayoutProcessor.php
│ └── Model
│ └── ShippingInformationManagement.php
├── Setup
└── InstallSchema.php
├── composer.json
├── etc
├── adminhtml
│ ├── events.xml
│ └── system.xml
├── config.xml
├── di.xml
├── events.xml
├── extension_attributes.xml
├── frontend
│ ├── di.xml
│ └── events.xml
└── module.xml
├── registration.php
└── view
├── adminhtml
├── layout
│ ├── sales_order_create_index.xml
│ └── sales_order_create_load_block_shipping_method.xml
├── templates
│ ├── order
│ │ └── create
│ │ │ └── delivery_date.phtml
│ └── order_info_shipping_info.phtml
└── ui_component
│ └── sales_order_grid.xml
└── frontend
├── requirejs-config.js
├── templates
└── order_info_shipping_info.phtml
└── web
├── js
├── mixin
│ └── shipping-mixin.js
├── model
│ └── shipping-save-processor
│ │ └── default.js
└── view
│ ├── delivery-date-block.js
│ └── delivery-date.js
└── template
├── delivery-date-block.html
└── fields
└── delivery-date.html
/README.md:
--------------------------------------------------------------------------------
1 | The Order Delivery Date Extension gives your customers possibility to choose the date on which they want the products purchased from your store to be delivered.
2 |
3 | Features
4 |
5 | 1. Allows users to provide expected shipping arrival date
6 | 2. Users can also write comments while placing an order from your online shop
7 | 3. Option to display shipping arrival date and comment in order view page
8 | 4. Previous date selection is not possible
9 | 5. Disable week off days (like Saturday and Sunday) [Stores -> Configuration -> Sales -> Order Delivery Date Settings]
10 |
11 |
12 | Setup Step:
13 |
14 | 1. copy SR folder inside app/code
15 | 2. var folder permission should be 777
16 | 3. run following command 'php bin/magento setup:upgrade'
17 |
18 | Install Using Composer
19 |
--------------------------------------------------------------------------------
/SR/DeliveryDate/Block/Adminhtml/DeliveryDate.php:
--------------------------------------------------------------------------------
1 | config = $config;
36 | $this->json = $json;
37 | parent::__construct($context, $data);
38 | }
39 |
40 | /**
41 | * @return string
42 | */
43 | public function getConfig()
44 | {
45 | return $this->json->serialize($this->config->getConfig());
46 | }
47 |
48 | /**
49 | * @return mixed
50 | */
51 | public function getRequiredDeliveryDate()
52 | {
53 | return $this->config->getRequiredDeliveryDate();
54 | }
55 | }
--------------------------------------------------------------------------------
/SR/DeliveryDate/Model/Config.php:
--------------------------------------------------------------------------------
1 | storeManager = $storeManager;
58 | $this->scopeConfig = $scopeConfig;
59 | $this->appState = $appState;
60 | $this->adminOrderCreate = $adminOrderCreate;
61 | }
62 |
63 | /**
64 | * @return mixed
65 | */
66 | public function getFormat()
67 | {
68 | $store = $this->getStoreId();
69 |
70 | return $this->scopeConfig->getValue(self::XPATH_FORMAT, ScopeInterface::SCOPE_STORE, $store);
71 | }
72 |
73 | /**
74 | * @return mixed
75 | */
76 | public function getDisabled()
77 | {
78 | $store = $this->getStoreId();
79 | return $this->scopeConfig->getValue(self::XPATH_DISABLED, ScopeInterface::SCOPE_STORE, $store);
80 | }
81 |
82 | /**
83 | * @return mixed
84 | */
85 | public function getHourMin()
86 | {
87 | $store = $this->getStoreId();
88 | return $this->scopeConfig->getValue(self::XPATH_HOURMIN, ScopeInterface::SCOPE_STORE, $store);
89 | }
90 |
91 | /**
92 | * @return mixed
93 | */
94 | public function getHourMax()
95 | {
96 | $store = $this->getStoreId();
97 | return $this->scopeConfig->getValue(self::XPATH_HOURMAX, ScopeInterface::SCOPE_STORE, $store);
98 | }
99 |
100 | /**
101 | * @return mixed
102 | */
103 | public function getRequiredDeliveryDate()
104 | {
105 | $store = $this->getStoreId();
106 | return (bool) $this->scopeConfig->getValue(self::XPATH_REQUIRED_DELIVERY_DATE, ScopeInterface::SCOPE_STORE, $store);
107 | }
108 |
109 | /**
110 | * @return int
111 | */
112 | public function getStoreId()
113 | {
114 | if (!$this->storeId) {
115 | if ($this->appState->getAreaCode() == 'adminhtml') {
116 | $this->storeId = $this->adminOrderCreate->getQuote()->getStoreId();
117 | } else {
118 | $this->storeId = $this->storeManager->getStore()->getStoreId();
119 | }
120 | }
121 |
122 | return $this->storeId;
123 | }
124 |
125 | /**
126 | * {@inheritdoc}
127 | */
128 | public function getConfig()
129 | {
130 | $disabled = $this->getDisabled();
131 | $hourMin = $this->getHourMin();
132 | $hourMax = $this->getHourMax();
133 | $format = $this->getFormat();
134 |
135 | $noday = 0;
136 | if($disabled == -1) {
137 | $noday = 1;
138 | }
139 |
140 | $config = [
141 | 'shipping' => [
142 | 'delivery_date' => [
143 | 'format' => $format,
144 | 'disabled' => $disabled,
145 | 'noday' => $noday,
146 | 'hourMin' => $hourMin,
147 | 'hourMax' => $hourMax
148 | ]
149 | ]
150 | ];
151 |
152 | return $config;
153 | }
154 | }
--------------------------------------------------------------------------------
/SR/DeliveryDate/Model/Config/Source/Disabled.php:
--------------------------------------------------------------------------------
1 | localeLists = $localeLists;
22 | }
23 |
24 | /**
25 | * @return array
26 | */
27 | public function toOptionArray()
28 | {
29 | $options = $this->localeLists->getOptionWeekdays();
30 | array_unshift($options, [
31 | 'label' => __('No Day'),
32 | 'value' => -1
33 | ]);
34 | return $options;
35 | }
36 | }
--------------------------------------------------------------------------------
/SR/DeliveryDate/Model/DeliveryDateConfigProvider.php:
--------------------------------------------------------------------------------
1 | config = $config;
22 | }
23 |
24 | /**
25 | * {@inheritdoc}
26 | */
27 | public function getConfig()
28 | {
29 | return $this->config->getConfig();
30 | }
31 | }
--------------------------------------------------------------------------------
/SR/DeliveryDate/Model/Validator.php:
--------------------------------------------------------------------------------
1 | dateTime = $dateTime;
22 | }
23 |
24 | /**
25 | * @param string $deliveryDate
26 | * @return bool
27 | */
28 | public function validate($deliveryDate)
29 | {
30 | if ($deliveryDate) {
31 | $deliveryDate = $this->dateTime->date('Y-m-d H:i:s', $deliveryDate);
32 | $now = $this->dateTime->date('Y-m-d H:i:s');
33 | if ($now > $deliveryDate) {
34 | return false;
35 | }
36 | }
37 |
38 | return true;
39 | }
40 | }
--------------------------------------------------------------------------------
/SR/DeliveryDate/Observer/AddHtmlToOrderShippingBlock.php:
--------------------------------------------------------------------------------
1 | templateFactory = $templateFactory;
33 | $this->timezone = $timezone;
34 | }
35 |
36 | /**
37 | * @param EventObserver $observer
38 | * @return $this
39 | */
40 | public function execute(EventObserver $observer)
41 | {
42 | if($observer->getElementName() == 'sales.order.info') {
43 | $orderShippingViewBlock = $observer->getLayout()->getBlock($observer->getElementName());
44 | $order = $orderShippingViewBlock->getOrder();
45 | if($order->getDeliveryDate() != '0000-00-00 00:00:00') {
46 | $formattedDate = $this->timezone->formatDateTime(
47 | $order->getDeliveryDate(),
48 | \IntlDateFormatter::MEDIUM,
49 | \IntlDateFormatter::MEDIUM,
50 | null,
51 | $this->timezone->getConfigTimezone(
52 | ScopeInterface::SCOPE_STORE,
53 | $order->getStore()->getCode()
54 | )
55 | );
56 | } else {
57 | $formattedDate = __('N/A');
58 | }
59 |
60 | /** @var \Magento\Framework\View\Element\Template $deliveryDateBlock */
61 | $deliveryDateBlock = $this->templateFactory->create();
62 | $deliveryDateBlock->setDeliveryDate($formattedDate);
63 | $deliveryDateBlock->setDeliveryComment($order->getDeliveryComment());
64 | $deliveryDateBlock->setTemplate('SR_DeliveryDate::order_info_shipping_info.phtml');
65 | $html = $observer->getTransport()->getOutput() . $deliveryDateBlock->toHtml();
66 | $observer->getTransport()->setOutput($html);
67 | }
68 |
69 | return $this;
70 | }
71 | }
--------------------------------------------------------------------------------
/SR/DeliveryDate/Observer/AddHtmlToOrderShippingView.php:
--------------------------------------------------------------------------------
1 | templateFactory = $templateFactory;
33 | $this->timezone = $timezone;
34 | }
35 |
36 | /**
37 | * @param EventObserver $observer
38 | * @return $this
39 | */
40 | public function execute(EventObserver $observer)
41 | {
42 | if($observer->getElementName() == 'order_shipping_view') {
43 | $orderShippingViewBlock = $observer->getLayout()->getBlock($observer->getElementName());
44 | $order = $orderShippingViewBlock->getOrder();
45 | if($order->getDeliveryDate() != '0000-00-00 00:00:00') {
46 | $formattedDate = $this->timezone->formatDateTime(
47 | $order->getDeliveryDate(),
48 | \IntlDateFormatter::MEDIUM,
49 | \IntlDateFormatter::MEDIUM,
50 | null,
51 | $this->timezone->getConfigTimezone(
52 | ScopeInterface::SCOPE_STORE,
53 | $order->getStore()->getCode()
54 | )
55 | );
56 | } else {
57 | $formattedDate = __('N/A');
58 | }
59 |
60 | /** @var \Magento\Framework\View\Element\Template $deliveryDateBlock */
61 | $deliveryDateBlock = $this->templateFactory->create();
62 | $deliveryDateBlock->setDeliveryDate($formattedDate);
63 | $deliveryDateBlock->setDeliveryComment($order->getDeliveryComment());
64 | $deliveryDateBlock->setTemplate('SR_DeliveryDate::order_info_shipping_info.phtml');
65 | $html = $observer->getTransport()->getOutput() . $deliveryDateBlock->toHtml();
66 | $observer->getTransport()->setOutput($html);
67 | }
68 |
69 | return $this;
70 | }
71 | }
--------------------------------------------------------------------------------
/SR/DeliveryDate/Observer/AdminhtmlSalesOrderCreateProcessData.php:
--------------------------------------------------------------------------------
1 | getRequest();
16 | $deliveryDate = isset($requestData['delivery_date']) ? $requestData['delivery_date'] : null;
17 | $deliveryComment = isset($requestData['delivery_comment']) ? $requestData['delivery_comment'] : null;
18 |
19 | /** @var \Magento\Sales\Model\AdminOrder\Create $orderCreateModel */
20 | $orderCreateModel = $observer->getOrderCreateModel();
21 | $quote = $orderCreateModel->getQuote();
22 | $quote->setDeliveryDate($deliveryDate);
23 | $quote->setDeliveryComment($deliveryComment);
24 |
25 | return $this;
26 | }
27 | }
--------------------------------------------------------------------------------
/SR/DeliveryDate/Observer/SalesModelServiceQuoteSubmitBefore.php:
--------------------------------------------------------------------------------
1 | quoteRepository = $quoteRepository;
32 | $this->validator = $validator;
33 | }
34 |
35 | /**
36 | * @param EventObserver $observer
37 | * @return $this
38 | * @throws \Exception
39 | */
40 | public function execute(EventObserver $observer)
41 | {
42 | $order = $observer->getOrder();
43 | /** @var \Magento\Quote\Model\Quote $quote */
44 | $quote = $this->quoteRepository->get($order->getQuoteId());
45 | if (!$this->validator->validate($quote->getDeliveryDate())) {
46 | throw new \Exception(__('Invalid Delevery Date'));
47 | }
48 | $order->setDeliveryDate($quote->getDeliveryDate());
49 | $order->setDeliveryComment($quote->getDeliveryComment());
50 |
51 | return $this;
52 | }
53 | }
--------------------------------------------------------------------------------
/SR/DeliveryDate/Plugin/Checkout/Block/LayoutProcessor.php:
--------------------------------------------------------------------------------
1 | config = $config;
22 | }
23 |
24 | /**
25 | * @param \Magento\Checkout\Block\Checkout\LayoutProcessor $subject
26 | * @param array $jsLayout
27 | * @return array
28 | */
29 | public function afterProcess(
30 | \Magento\Checkout\Block\Checkout\LayoutProcessor $subject,
31 | array $jsLayout
32 | ) {
33 |
34 | $requiredDeliveryDate = $this->config->getRequiredDeliveryDate()?: false;
35 | $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
36 | ['shippingAddress']['children']['shippingAdditional'] = [
37 | 'component' => 'uiComponent',
38 | 'displayArea' => 'shippingAdditional',
39 | 'children' => [
40 | 'delivery_date' => [
41 | 'component' => 'SR_DeliveryDate/js/view/delivery-date-block',
42 | 'displayArea' => 'delivery-date-block',
43 | 'deps' => 'checkoutProvider',
44 | 'dataScopePrefix' => 'delivery_date',
45 | 'children' => [
46 | 'form-fields' => [
47 | 'component' => 'uiComponent',
48 | 'displayArea' => 'delivery-date-block',
49 | 'children' => [
50 | 'delivery_date' => [
51 | 'component' => 'SR_DeliveryDate/js/view/delivery-date',
52 | 'config' => [
53 | 'customScope' => 'delivery_date',
54 | 'template' => 'ui/form/field',
55 | 'elementTmpl' => 'SR_DeliveryDate/fields/delivery-date',
56 | 'options' => [],
57 | 'id' => 'delivery_date',
58 | 'data-bind' => ['datetimepicker' => true]
59 | ],
60 | 'dataScope' => 'delivery_date.delivery_date',
61 | 'label' => 'Delivery Date',
62 | 'provider' => 'checkoutProvider',
63 | 'visible' => true,
64 | 'validation' => [
65 | 'required-entry' => $requiredDeliveryDate
66 | ],
67 | 'sortOrder' => 10,
68 | 'id' => 'delivery_date'
69 | ],
70 | 'delivery_comment' => [
71 | 'component' => 'Magento_Ui/js/form/element/textarea',
72 | 'config' => [
73 | 'customScope' => 'delivery_date',
74 | 'template' => 'ui/form/field',
75 | 'elementTmpl' => 'ui/form/element/textarea',
76 | 'options' => [],
77 | 'id' => 'delivery_comment'
78 | ],
79 | 'dataScope' => 'delivery_date.delivery_comment',
80 | 'label' => 'Comment',
81 | 'provider' => 'checkoutProvider',
82 | 'visible' => true,
83 | 'validation' => [],
84 | 'sortOrder' => 20,
85 | 'id' => 'delivery_comment'
86 | ]
87 | ],
88 | ],
89 | ]
90 | ]
91 | ]
92 | ];
93 |
94 | return $jsLayout;
95 | }
96 | }
--------------------------------------------------------------------------------
/SR/DeliveryDate/Plugin/Checkout/Model/ShippingInformationManagement.php:
--------------------------------------------------------------------------------
1 | quoteRepository = $quoteRepository;
23 | }
24 |
25 | /**
26 | * @param \Magento\Checkout\Model\ShippingInformationManagement $subject
27 | * @param $cartId
28 | * @param ShippingInformationInterface $addressInformation
29 | */
30 | public function beforeSaveAddressInformation(
31 | \Magento\Checkout\Model\ShippingInformationManagement $subject,
32 | $cartId,
33 | ShippingInformationInterface $addressInformation
34 | ) {
35 | $extAttributes = $addressInformation->getExtensionAttributes();
36 | $deliveryDate = $extAttributes->getDeliveryDate();
37 | $deliveryComment = $extAttributes->getDeliveryComment();
38 | $quote = $this->quoteRepository->getActive($cartId);
39 | $quote->setDeliveryDate($deliveryDate);
40 | $quote->setDeliveryComment($deliveryComment);
41 | }
42 | }
--------------------------------------------------------------------------------
/SR/DeliveryDate/Setup/InstallSchema.php:
--------------------------------------------------------------------------------
1 | startSetup();
22 |
23 | $installer->getConnection()->addColumn(
24 | $installer->getTable('quote'),
25 | 'delivery_date',
26 | [
27 | 'type' => 'datetime',
28 | 'nullable' => false,
29 | 'comment' => 'Delivery Date',
30 | ]
31 | );
32 |
33 | $installer->getConnection()->addColumn(
34 | $installer->getTable('quote'),
35 | 'delivery_comment',
36 | [
37 | 'type' => 'text',
38 | 'nullable' => false,
39 | 'comment' => 'Delivery Comment',
40 | ]
41 | );
42 |
43 | $installer->getConnection()->addColumn(
44 | $installer->getTable('sales_order'),
45 | 'delivery_date',
46 | [
47 | 'type' => 'datetime',
48 | 'nullable' => false,
49 | 'comment' => 'Delivery Date',
50 | ]
51 | );
52 |
53 | $installer->getConnection()->addColumn(
54 | $installer->getTable('sales_order'),
55 | 'delivery_comment',
56 | [
57 | 'type' => 'text',
58 | 'nullable' => false,
59 | 'comment' => 'Delivery Comment',
60 | ]
61 | );
62 |
63 | $installer->getConnection()->addColumn(
64 | $installer->getTable('sales_order_grid'),
65 | 'delivery_date',
66 | [
67 | 'type' => 'datetime',
68 | 'nullable' => false,
69 | 'comment' => 'Delivery Date',
70 | ]
71 | );
72 |
73 | $setup->endSetup();
74 | }
75 | }
--------------------------------------------------------------------------------
/SR/DeliveryDate/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "sr/module-delivery-date",
3 | "description": "Order Delivery date extension will allow customer to choose preferable delivery date for order.",
4 | "require": {
5 | "php": "~7.1.3||~7.2.0",
6 | "magento/module-config": "101.1.*",
7 | "magento/module-store": "101.0.*",
8 | "magento/module-backend": "101.0.*",
9 | "magento/module-checkout": "100.3.*",
10 | "magento/module-sales": "102.0.*"
11 | },
12 | "type": "magento2-module",
13 | "version": "2.0.2",
14 | "license": [
15 | "OSL-3.0",
16 | "AFL-3.0"
17 | ],
18 | "autoload": {
19 | "files": [
20 | "registration.php"
21 | ],
22 | "psr-4": {
23 | "SR\\DeliveryDate\\": ""
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/SR/DeliveryDate/etc/adminhtml/events.xml:
--------------------------------------------------------------------------------
1 |
2 |