Skip to content

Commit

Permalink
Merge pull request #4 from mageworx/update_comp
Browse files Browse the repository at this point in the history
Update compatibility: add support of new version of the main module
  • Loading branch information
SiarheyUchukhlebau committed Nov 29, 2022
2 parents f73d5af + 8b765ba commit 1a3fbfd
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 40 deletions.
9 changes: 3 additions & 6 deletions Observer/CheckoutLayoutModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,15 @@ public function execute(Observer $observer)
unset($originalElement['children']['comment_container']);

// Update Date component
$originalElement['children']['datetime_container']['children']['delivery_day']['config']['template'] =
$originalElement['children']['datetime_container']['childTemplates']['delivery_day']['config']['template'] =
'MageWorx_DeliveryDateCheckout/form/field';
if ($originalElement['children']['datetime_container']['children']['delivery_day']['config']['elementTmpl'] ===
if (isset($originalElement['children']['datetime_container']['children']['delivery_day']['config']['elementTmpl'])
&& $originalElement['children']['datetime_container']['children']['delivery_day']['config']['elementTmpl'] ===
'MageWorx_DeliveryDate/checkout/form/element/date/calendar') {
$originalElement['children']['datetime_container']['children']['delivery_day']['config']['elementTmpl'] =
$this->getDeliveryDayInputTemplate();
}

// Update Time component
$originalElement['children']['datetime_container']['children']['delivery_time']['config']['template'] =
'MageWorx_DeliveryDateCheckout/form/field';

$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
['shippingMethods']['children']['shipping_method_additional_data']['children'][$nameInLayout] =
$originalElement;
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"description": "Delivery Date and MageWorx Checkout Compatibility Extension",
"require": {
"magento/module-ui" : ">=100.1.0 < 102",
"mageworx/module-checkout" : ">=1.0.0",
"mageworx/module-deliverydate" : ">=1.8.6 < 1.14"
"mageworx/module-checkout" : ">=1.0.15",
"mageworx/module-deliverydate" : ">=1.17.1"
},
"type": "magento2-module",
"version": "1.0.3",
"version": "1.1.0",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
4 changes: 2 additions & 2 deletions view/frontend/requirejs-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
var config = {
config: {
mixins: {
'MageWorx_DeliveryDate/js/checkout/time_range': {
'MageWorx_DeliveryDateCheckout/js/mixin/time-range-mixin': true
'Magento_Checkout/js/model/shipping-save-processor/payload-extender': {
'MageWorx_DeliveryDateCheckout/js/mixin/payload-extender-mixin': true
}
}
}
Expand Down
42 changes: 42 additions & 0 deletions view/frontend/web/js/mixin/payload-extender-mixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*jshint browser:true jquery:true*/
/*global alert*/
define([
'mage/utils/wrapper',
'uiRegistry',
'underscore'
], function (wrapper, registry, _) {
'use strict';

return function (originalPayloadExtender) {

return wrapper.wrap(originalPayloadExtender, function (originalAction) {
if (!_.isEmpty(mwDeliveryDateConfig) && mwDeliveryDateConfig.enabled) {
let payload = originalAction(),
shippingAddress = payload.addressInformation.shipping_address,
deliveryDateSource = registry.get('deliveryDateProvider'),
deliveryDateData = deliveryDateSource.delivery_date || {};

if (shippingAddress['extensionAttributes'] === undefined) {
shippingAddress['extensionAttributes'] = {};
}

shippingAddress['extensionAttributes']['delivery_comment'] = deliveryDateData['delivery_comment'];
shippingAddress['extensionAttributes']['delivery_day'] = deliveryDateData['delivery_day'];
shippingAddress['extensionAttributes']['delivery_option_id'] = deliveryDateData['delivery_option_id'];
shippingAddress['extensionAttributes']['delivery_time'] = deliveryDateData['delivery_time'];

// Validate custom attributes and
// pass execution to original action ('Magento_Checkout/js/action/set-shipping-information')
deliveryDateSource.set('params.invalid', false);
deliveryDateSource.trigger('delivery_date.data.validate');

if (deliveryDateSource.get('params.invalid')) {
console.log('DELIVERY DATE ERROR!!!');
} else {
return payload;
}
}
});

}
});
19 changes: 0 additions & 19 deletions view/frontend/web/js/mixin/time-range-mixin.js

This file was deleted.

2 changes: 1 addition & 1 deletion view/frontend/web/template/container.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
-->
<div data-bind="visible: isVisible" id="delivery-date-container" class="delivery-date-container-checkout">
<each args="data: elems, as: 'element'">
<render if="hasTemplate()"/>
<render if="hasTemplate()"></render>
</each>
</div>
18 changes: 9 additions & 9 deletions view/frontend/web/template/form/field.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@
visible="$data.labelVisible"
></label>

<render args="elementTmpl" ifnot="hasAddons()"/>
<render args="elementTmpl" ifnot="hasAddons()"></render>

<div class="admin__control-addon" if="hasAddons()">
<render args="elementTmpl"/>
<render args="elementTmpl"></render>

<label class="admin__addon-prefix" if="$data.addbefore" attr="for: uid">
<span text="addbefore"/>
<span text="addbefore"></span>
</label>
<label class="admin__addon-suffix" if="$data.addafter" attr="for: uid">
<span text="addafter"/>
<span text="addafter"></span>
</label>
</div>

<render args="tooltipTpl" if="$data.tooltip"/>
<render args="tooltipTpl" if="$data.tooltip"></render>

<render args="fallbackResetTpl" if="$data.showFallbackReset && $data.isDifferedFromDefault"/>
<render args="fallbackResetTpl" if="$data.showFallbackReset && $data.isDifferedFromDefault"></render>

<label class="admin__field-error" if="error" attr="for: uid" text="error"/>
<label class="admin__field-error" if="error" attr="for: uid" text="error"></label>

<div class="admin__field-note" if="$data.notice" attr="id: noticeId">
<span translate="notice"/>
<span translate="notice"></span>
</div>

<div class="admin__additional-info" if="$data.additionalInfo" html="$data.additionalInfo"></div>

<render args="$data.service.template" if="$data.hasService()"/>
<render args="$data.service.template" if="$data.hasService()"></render>
</div>
</div>

0 comments on commit 1a3fbfd

Please sign in to comment.