├── 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 | 3 | 4 | 6 | 7 | 8 | 10 | 11 | -------------------------------------------------------------------------------- /SR/DeliveryDate/etc/adminhtml/system.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | 6 | sales 7 | SR_DeliveryDate::deliverydate 8 | 9 | 10 | 11 | 12 | yy-mm-dd 13 | 14 | 15 | 16 | SR\DeliveryDate\Model\Config\Source\Disabled 17 | 18 | 19 | 20 | Should be 8=>8AM, 9=>9AM 21 | 22 | 23 | 24 | Should be 22=>7PM, 23=>8PM because Minutes cover 1hr 25 | 26 | 27 | 28 | Magento\Config\Model\Config\Source\Yesno 29 | 30 | 31 |
32 |
33 |
34 | -------------------------------------------------------------------------------- /SR/DeliveryDate/etc/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | yy-mm-dd 7 | -1 8 | 8 9 | 22 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /SR/DeliveryDate/etc/di.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | sales_order.delivery_date 10 | 11 | 12 | 13 | 14 | 16 | 17 | -------------------------------------------------------------------------------- /SR/DeliveryDate/etc/events.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /SR/DeliveryDate/etc/extension_attributes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /SR/DeliveryDate/etc/frontend/di.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | SR\DeliveryDate\Model\DeliveryDateConfigProvider 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /SR/DeliveryDate/etc/frontend/events.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /SR/DeliveryDate/etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /SR/DeliveryDate/registration.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /SR/DeliveryDate/view/adminhtml/layout/sales_order_create_load_block_shipping_method.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /SR/DeliveryDate/view/adminhtml/templates/order/create/delivery_date.phtml: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 |
5 | 7 |
8 |
9 |
10 | 11 |
12 | 16 |
17 |
18 | -------------------------------------------------------------------------------- /SR/DeliveryDate/view/adminhtml/templates/order_info_shipping_info.phtml: -------------------------------------------------------------------------------- 1 |
2 |
3 | escapeHtml(__('Delivery Date Information')) ?> 4 |
5 |
6 |
7 | 8 | getDeliveryDate() ?> 9 |
10 |
11 | : 12 |
13 | getDeliveryComment() ?> 14 |
15 |
16 |
17 | -------------------------------------------------------------------------------- /SR/DeliveryDate/view/adminhtml/ui_component/sales_order_grid.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Magento_Ui/js/grid/columns/column 8 | 9 | 10 | true 11 | text 12 | left 13 | Delivery Date 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /SR/DeliveryDate/view/frontend/requirejs-config.js: -------------------------------------------------------------------------------- 1 | var config = { 2 | "map": { 3 | "*": { 4 | 'Magento_Checkout/js/model/shipping-save-processor/default': 'SR_DeliveryDate/js/model/shipping-save-processor/default' 5 | } 6 | }, 7 | config: { 8 | mixins: { 9 | 'Magento_Checkout/js/view/shipping': { 10 | 'SR_DeliveryDate/js/mixin/shipping-mixin': true 11 | }, 12 | 'Amazon_Payment/js/view/shipping': { 13 | 'SR_DeliveryDate/js/mixin/shipping-mixin': true 14 | } 15 | } 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /SR/DeliveryDate/view/frontend/templates/order_info_shipping_info.phtml: -------------------------------------------------------------------------------- 1 |
2 | 3 | getDeliveryDate() ?> 4 |
5 |
6 | : 7 |
8 | getDeliveryComment() ?> 9 |
10 | -------------------------------------------------------------------------------- /SR/DeliveryDate/view/frontend/web/js/mixin/shipping-mixin.js: -------------------------------------------------------------------------------- 1 | define( 2 | [ 3 | 'jquery', 4 | 'ko' 5 | ], function ( 6 | $, 7 | ko 8 | ) { 9 | 'use strict'; 10 | 11 | return function (target) { 12 | return target.extend({ 13 | setShippingInformation: function () { 14 | if (this.validateDeliveryDate()) { 15 | this._super(); 16 | } 17 | }, 18 | validateDeliveryDate: function() { 19 | this.source.set('params.invalid', false); 20 | this.source.trigger('delivery_date.data.validate'); 21 | 22 | if (this.source.get('params.invalid')) { 23 | return false; 24 | } 25 | 26 | return true; 27 | } 28 | }); 29 | } 30 | } 31 | ); -------------------------------------------------------------------------------- /SR/DeliveryDate/view/frontend/web/js/model/shipping-save-processor/default.js: -------------------------------------------------------------------------------- 1 | /*global define,alert*/ 2 | define( 3 | [ 4 | 'jquery', 5 | 'ko', 6 | 'Magento_Checkout/js/model/quote', 7 | 'Magento_Checkout/js/model/resource-url-manager', 8 | 'mage/storage', 9 | 'Magento_Checkout/js/model/payment-service', 10 | 'Magento_Checkout/js/model/payment/method-converter', 11 | 'Magento_Checkout/js/model/error-processor', 12 | 'Magento_Checkout/js/model/full-screen-loader', 13 | 'Magento_Checkout/js/action/select-billing-address' 14 | ], 15 | function ( 16 | $, 17 | ko, 18 | quote, 19 | resourceUrlManager, 20 | storage, 21 | paymentService, 22 | methodConverter, 23 | errorProcessor, 24 | fullScreenLoader, 25 | selectBillingAddressAction 26 | ) { 27 | 'use strict'; 28 | 29 | return { 30 | saveShippingInformation: function () { 31 | var payload; 32 | 33 | if (!quote.billingAddress()) { 34 | selectBillingAddressAction(quote.shippingAddress()); 35 | } 36 | 37 | payload = { 38 | addressInformation: { 39 | shipping_address: quote.shippingAddress(), 40 | billing_address: quote.billingAddress(), 41 | shipping_method_code: quote.shippingMethod().method_code, 42 | shipping_carrier_code: quote.shippingMethod().carrier_code, 43 | extension_attributes:{ 44 | delivery_date: $('[name="delivery_date"]').val(), 45 | delivery_comment: $('[name="delivery_comment"]').val() 46 | } 47 | } 48 | }; 49 | 50 | fullScreenLoader.startLoader(); 51 | 52 | return storage.post( 53 | resourceUrlManager.getUrlForSetShippingInformation(quote), 54 | JSON.stringify(payload) 55 | ).done( 56 | function (response) { 57 | quote.setTotals(response.totals); 58 | paymentService.setPaymentMethods(methodConverter(response.payment_methods)); 59 | fullScreenLoader.stopLoader(); 60 | } 61 | ).fail( 62 | function (response) { 63 | errorProcessor.process(response); 64 | fullScreenLoader.stopLoader(); 65 | } 66 | ); 67 | } 68 | }; 69 | } 70 | ); 71 | -------------------------------------------------------------------------------- /SR/DeliveryDate/view/frontend/web/js/view/delivery-date-block.js: -------------------------------------------------------------------------------- 1 | define([ 2 | 'jquery', 3 | 'ko', 4 | 'Magento_Ui/js/form/form' 5 | ], function ($, ko, Component) { 6 | 'use strict'; 7 | 8 | return Component.extend({ 9 | defaults: { 10 | template: 'SR_DeliveryDate/delivery-date-block' 11 | } 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /SR/DeliveryDate/view/frontend/web/js/view/delivery-date.js: -------------------------------------------------------------------------------- 1 | define([ 2 | 'jquery', 3 | 'ko', 4 | 'Magento_Ui/js/form/element/abstract' 5 | ], function ($, ko, Component) { 6 | 'use strict'; 7 | 8 | return Component.extend({ 9 | initialize: function () { 10 | this._super(); 11 | var disabled = window.checkoutConfig.shipping.delivery_date.disabled; 12 | var noday = window.checkoutConfig.shipping.delivery_date.noday; 13 | var hourMin = parseInt(window.checkoutConfig.shipping.delivery_date.hourMin); 14 | var hourMax = parseInt(window.checkoutConfig.shipping.delivery_date.hourMax); 15 | var format = window.checkoutConfig.shipping.delivery_date.format; 16 | if(!format) { 17 | format = 'yy-mm-dd'; 18 | } 19 | var disabledDay = disabled.split(",").map(function(item) { 20 | return parseInt(item, 10); 21 | }); 22 | 23 | ko.bindingHandlers.datetimepicker = { 24 | init: function (element, valueAccessor, allBindingsAccessor) { 25 | var $el = $(element); 26 | //initialize datetimepicker 27 | if(noday) { 28 | var options = { 29 | minDate: 0, 30 | dateFormat:format, 31 | hourMin: hourMin, 32 | hourMax: hourMax 33 | }; 34 | } else { 35 | var options = { 36 | minDate: 0, 37 | dateFormat:format, 38 | hourMin: hourMin, 39 | hourMax: hourMax, 40 | beforeShowDay: function(date) { 41 | var day = date.getDay(); 42 | if(disabledDay.indexOf(day) > -1) { 43 | return [false]; 44 | } else { 45 | return [true]; 46 | } 47 | } 48 | }; 49 | } 50 | 51 | $el.datetimepicker(options); 52 | 53 | var writable = valueAccessor(); 54 | if (!ko.isObservable(writable)) { 55 | var propWriters = allBindingsAccessor()._ko_property_writers; 56 | if (propWriters && propWriters.datetimepicker) { 57 | writable = propWriters.datetimepicker; 58 | } else { 59 | return; 60 | } 61 | } 62 | writable($(element).datetimepicker("getDate")); 63 | }, 64 | update: function (element, valueAccessor) { 65 | var widget = $(element).data("DateTimePicker"); 66 | //when the view model is updated, update the widget 67 | if (widget) { 68 | var date = ko.utils.unwrapObservable(valueAccessor()); 69 | widget.date(date); 70 | } 71 | } 72 | }; 73 | 74 | return this; 75 | } 76 | }); 77 | }); -------------------------------------------------------------------------------- /SR/DeliveryDate/view/frontend/web/template/delivery-date-block.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /SR/DeliveryDate/view/frontend/web/template/fields/delivery-date.html: -------------------------------------------------------------------------------- 1 | --------------------------------------------------------------------------------