From 329e02d8f01bfe3d82450f69a0c717d6996a2345 Mon Sep 17 00:00:00 2001 From: Gytautas Zumaras <96050852+GytisZum@users.noreply.github.com> Date: Fri, 2 Aug 2024 10:13:35 +0300 Subject: [PATCH] Release v3.2.20 beta (#89) (#90) * initial opc compatibility * opc compatibility improvements * opc improvements and added some styles * Adding auto indexes * Automatic license addition applying * styling and layout for checkout * Automatic license addition applying * onepagecheckout ps module compatibility fixes * comment edited * fixed onepagecheckout ps dropdown * Automatic license addition applying * changed hardcoded value * css changes to change input order * version bump and changelog added --------- Co-authored-by: GytisZum Co-authored-by: Justas Vaitkus Co-authored-by: justelis22 Co-authored-by: justelis22 <103486043+justelis22@users.noreply.github.com> --- CHANGELOG.md | 5 +- config/service.yml | 1 + config/validator.yml | 3 + dpdbaltics.php | 33 +++++++-- src/Config/Config.php | 3 + src/Service/CarrierPhoneService.php | 10 ++- .../OpcModuleCompatibilityValidator.php | 44 ++++++++++++ src/Validate/Compatibility/index.php | 30 ++++++++ views/css/front/onepagecheckout.css | 69 +++++++++++++++++++ views/css/front/order-input.css | 11 +-- views/css/front/pudo-shipment.css | 6 +- views/js/front/order-opc.js | 36 ++++++++++ views/js/front/pudo.js | 2 +- .../hook/front/carrier-delivery-time.tpl | 4 +- .../hook/front/carrier-phone-number.tpl | 8 +-- .../hook/front/partials/pudo-search-block.tpl | 6 +- 16 files changed, 248 insertions(+), 23 deletions(-) create mode 100644 src/Validate/Compatibility/OpcModuleCompatibilityValidator.php create mode 100644 src/Validate/Compatibility/index.php create mode 100644 views/css/front/onepagecheckout.css diff --git a/CHANGELOG.md b/CHANGELOG.md index a1aeae13..d821b8e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -164,4 +164,7 @@ - Carrier availability in country - Phone input selections sorted by active countries in shop - Work hours pop up fix -- Numeric post code improvements \ No newline at end of file +- Numeric post code improvements + +## [3.2.20] +- One page checkout compatibility improvements \ No newline at end of file diff --git a/config/service.yml b/config/service.yml index e7a9c2ee..1271387d 100644 --- a/config/service.yml +++ b/config/service.yml @@ -18,6 +18,7 @@ services: - '@invertus.dpdbaltics.orm.entity_manager' - '@invertus.dpdbaltics.repository.phone_prefix_repository' - '@invertus.dpdbaltics.repository.order_repository' + - '@invertus.dpdbaltics.validator.opc_module_compatibility_validator' invertus.dpdbaltics.service.carrier.update_carrier_service: class: 'Invertus\dpdBaltics\Service\Carrier\UpdateCarrierService' diff --git a/config/validator.yml b/config/validator.yml index a254ce24..190c529f 100644 --- a/config/validator.yml +++ b/config/validator.yml @@ -41,3 +41,6 @@ services: arguments: - '@dpdbaltics' - '@invertus.dpdbaltics.repository.phone_repository' + + invertus.dpdbaltics.validator.opc_module_compatibility_validator: + class: 'Invertus\dpdBaltics\Validate\Compatibility\OpcModuleCompatibilityValidator' diff --git a/dpdbaltics.php b/dpdbaltics.php index 9043978f..812579f8 100644 --- a/dpdbaltics.php +++ b/dpdbaltics.php @@ -18,7 +18,6 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 */ - use Invertus\dpdBaltics\Grid\Row\PrintAccessibilityChecker; use Invertus\dpdBaltics\Builder\Template\Front\CarrierOptionsBuilder; use Invertus\dpdBaltics\Config\Config; @@ -92,7 +91,7 @@ public function __construct() $this->author = 'Invertus'; $this->tab = 'shipping_logistics'; $this->description = 'DPD Baltics shipping integration'; - $this->version = '3.2.19'; + $this->version = '3.2.20'; $this->ps_versions_compliancy = ['min' => '1.7.1.0', 'max' => _PS_VERSION_]; $this->need_instance = 0; parent::__construct(); @@ -168,7 +167,7 @@ public function getModuleContainer($id = false) public function hookActionFrontControllerSetMedia() { //TODO fillup this array when more modules are compatible with OPC - $onePageCheckoutControllers = ['supercheckout']; + $onePageCheckoutControllers = ['supercheckout', 'onepagecheckoutps', 'thecheckout']; $applicableControlelrs = ['order', 'order-opc', 'ShipmentReturn', 'supercheckout']; $currentController = !empty($this->context->controller->php_self) ? $this->context->controller->php_self : Tools::getValue('controller'); @@ -183,7 +182,10 @@ public function hookActionFrontControllerSetMedia() ); } - if (in_array($currentController, $onePageCheckoutControllers, true)) { + /** @var \Invertus\dpdBaltics\Validate\Compatibility\OpcModuleCompatibilityValidator $opcModuleCompatibilityValidator */ + $opcModuleCompatibilityValidator = $this->getModuleContainer('invertus.dpdbaltics.validator.opc_module_compatibility_validator'); + + if (in_array($currentController, $onePageCheckoutControllers, true) || $opcModuleCompatibilityValidator->isOpcModuleInUse()) { $this->context->controller->addJqueryPlugin('chosen'); $this->context->controller->registerJavascript( @@ -198,11 +200,26 @@ public function hookActionFrontControllerSetMedia() $this->context->controller->registerJavascript( 'dpdbaltics-supercheckout', 'modules/' . $this->name . '/views/js/front/modules/supercheckout.js', + [ + 'position' => 'bottom', + 'priority' => 130 + ] + ); + + $this->context->controller->registerStylesheet( + 'dpdbaltics-opc', + 'modules/' . $this->name . '/views/css/front/onepagecheckout.css', [ 'position' => 'bottom', 'priority' => 130 ] ); + + Media::addJsDef([ + 'dpdbaltics' => [ + 'isOnePageCheckout' => $opcModuleCompatibilityValidator->isOpcModuleInUse() + ] + ]); } /** @var \Invertus\dpdBaltics\Provider\CurrentCountryProvider $currentCountryProvider */ @@ -261,7 +278,7 @@ public function hookActionFrontControllerSetMedia() 'dpdLockerMarkerPath' => $this->getPathUri() . 'views/img/locker.png', 'dpdHookAjaxUrl' => $this->context->link->getModuleLink($this->name, 'Ajax'), 'pudoSelectSuccess' => $this->l('Pick-up point selected'), - 'dpd_carrier_ids' => $carrierIds + 'dpd_carrier_ids' => $carrierIds, ]); $this->context->controller->registerStylesheet( @@ -348,6 +365,12 @@ public function hookActionValidateStepComplete(&$params) return; } } + + //NOTE: thecheckout triggers this hook without phone parameters the phone is saved with ajax request + if (Tools::getValue('module') === 'thecheckout') { + return; + } + if (!Tools::getValue('dpd-phone')) { $this->context->controller->errors[] = $this->l('In order to use DPD Carrier you need to enter phone number'); diff --git a/src/Config/Config.php b/src/Config/Config.php index fe9a188a..c50f5c1d 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -257,6 +257,9 @@ class Config const COUNTRY_ISO_CODES_WITH_MIXED_CHARACTERS = ['IE', 'GB', 'NL']; + // NOTE: Add OPC module tech name if payment option is compatible + public const DPD_OPC_MODULE_LIST = ['onepagecheckoutps', 'supercheckout', 'thecheckout']; + const PRODUCT_NAME_B2B = [ 'LT' => 'Pristatymas privatiems asmenims', 'EE' => 'DPD kuller', diff --git a/src/Service/CarrierPhoneService.php b/src/Service/CarrierPhoneService.php index b14a4f9a..5febbb9b 100644 --- a/src/Service/CarrierPhoneService.php +++ b/src/Service/CarrierPhoneService.php @@ -22,6 +22,7 @@ use Invertus\dpdBaltics\Repository\PhonePrefixRepository; use Invertus\dpdBaltics\Config\Config; use DPDOrderPhone; +use Invertus\dpdBaltics\Validate\Compatibility\OpcModuleCompatibilityValidator; class CarrierPhoneService { @@ -45,19 +46,25 @@ class CarrierPhoneService * @var OrderRepository */ private $orderRepository; + /** + * @var OpcModuleCompatibilityValidator + */ + private $opcModuleCompatibilityValidator; public function __construct( DPDBaltics $module, Context $context, EntityManager $entityManager, PhonePrefixRepository $phonePrefixRepository, - OrderRepository $orderRepository + OrderRepository $orderRepository, + OpcModuleCompatibilityValidator $opcModuleCompatibilityValidator ) { $this->module = $module; $this->context = $context; $this->entityManager = $entityManager; $this->phonePrefixRepository = $phonePrefixRepository; $this->orderRepository = $orderRepository; + $this->opcModuleCompatibilityValidator = $opcModuleCompatibilityValidator; } public function getCarrierPhoneTemplate($cartId, $carrierReference) @@ -94,6 +101,7 @@ public function getCarrierPhoneTemplate($cartId, $carrierReference) 'dpdPhoneArea' => $phoneData['mobile_phone_code_list'], 'contextPrefix' => Config::PHONE_CODE_PREFIX . $phonePrefix, 'isAbove177' => Config::isPrestashopVersionAbove177(), + 'isOpcCheckout' => $this->opcModuleCompatibilityValidator->isOpcModuleInUse(), ] ); diff --git a/src/Validate/Compatibility/OpcModuleCompatibilityValidator.php b/src/Validate/Compatibility/OpcModuleCompatibilityValidator.php new file mode 100644 index 00000000..dbf3d191 --- /dev/null +++ b/src/Validate/Compatibility/OpcModuleCompatibilityValidator.php @@ -0,0 +1,44 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ + + +namespace Invertus\dpdBaltics\Validate\Compatibility; + +use DPDBaltics; +use Invertus\dpdBaltics\Config\Config; +use Invertus\dpdBaltics\Exception\DpdCarrierException; +use Invertus\dpdBaltics\Repository\PhoneRepository; +use Invertus\dpdBaltics\Util\NumberUtility; +use Invertus\dpdBaltics\Util\StringUtility; +use Module; + +class OpcModuleCompatibilityValidator +{ + public function isOpcModuleInUse(): bool + { + foreach (Config::DPD_OPC_MODULE_LIST as $opcModule){ + if (Module::isInstalled($opcModule) && Module::isEnabled($opcModule)) { + return true; + } + } + + return false; + } +} \ No newline at end of file diff --git a/src/Validate/Compatibility/index.php b/src/Validate/Compatibility/index.php new file mode 100644 index 00000000..74851d77 --- /dev/null +++ b/src/Validate/Compatibility/index.php @@ -0,0 +1,30 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ + + +header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); +header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); + +header("Cache-Control: no-store, no-cache, must-revalidate"); +header("Cache-Control: post-check=0, pre-check=0", false); +header("Pragma: no-cache"); + +header("Location: ../"); +exit; diff --git a/views/css/front/onepagecheckout.css b/views/css/front/onepagecheckout.css new file mode 100644 index 00000000..5de29d0c --- /dev/null +++ b/views/css/front/onepagecheckout.css @@ -0,0 +1,69 @@ +/** + * Copyright since 2007 PrestaShop SA and Contributors + * PrestaShop is an International Registered Trademark & Property of PrestaShop SA + * + * NOTICE OF LICENSE + * + * This source file is subject to the Academic Free License version 3.0 + * that is bundled with this package in the file LICENSE.md. + * It is also available through the world-wide-web at this URL: + * https://opensource.org/licenses/AFL-3.0 + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@prestashop.com so we can send you a copy immediately. + * + * @author PrestaShop SA and Contributors + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ +#phone-block-wrapper { + display: flex; + flex-direction: column; +} + +.points-container .list-inline .row { + margin-left: 15px; + margin-right: 15px; +} + +.panel-body .points-container .dpd-services-block { + width: 100%; +} + +.panel-body .points-container { + width: 340px; + margin-left: 18px; +} + +.dpd-services-block .list-inline-item { + min-width: 370px; +} + +.carrier-extra-content { + display: flex; + flex-direction: column; + padding: 10px 5px; +} + +.dpd-phone-block { + padding-bottom: 0; +} + +.chosen-container { + width: 100% !important; + max-width: 290px; +} + +.carrier-extra-content .chosen-select { + min-height: 49px; + height: 100%; +} + +.dpd-checkout-delivery-time--container { + width: 100%; +} + +.search-block-container { + padding-left: 15px; + padding-right: 15px; +} \ No newline at end of file diff --git a/views/css/front/order-input.css b/views/css/front/order-input.css index 9cc1ef45..3e4d9902 100644 --- a/views/css/front/order-input.css +++ b/views/css/front/order-input.css @@ -19,7 +19,7 @@ This file is generated by `grunt build`, do not edit it by hand. -moz-user-select: none; -ms-user-select: none; user-select: none; - width: 100% !important; + width: 100%; max-width: 100%; } @@ -84,7 +84,7 @@ This file is generated by `grunt build`, do not edit it by hand. margin: 1px 0; padding: 4px 20px 4px 5px; width: 100%; - height: auto; + height: 49px; outline: 0; border: 1px solid #aaa; background: url("../../img/dpd-chosen-front.png") no-repeat 100% -20px; @@ -178,11 +178,12 @@ This file is generated by `grunt build`, do not edit it by hand. margin-right: 20px; text-overflow: ellipsis; white-space: nowrap; - padding: 13px 0; + padding: 16px 0; } .chosen-container-single a.chosen-single { - height: auto; + min-height: 49px; + height: 100%; } .chosen-container-single .chosen-single div { @@ -203,7 +204,7 @@ div.form-control-chosen:focus-within { .css-dpd-phone-prefix .chosen-single:before { content: '+'; position: absolute; - transform: translate(-12px, 12px); + transform: translate(-12px, 16px); } .dpd-input-wrapper .form-control, diff --git a/views/css/front/pudo-shipment.css b/views/css/front/pudo-shipment.css index 30d25df0..be2c6e7e 100644 --- a/views/css/front/pudo-shipment.css +++ b/views/css/front/pudo-shipment.css @@ -123,7 +123,7 @@ .phone-block-hr, .delivery-time-hr { - padding-bottom: 2rem; + padding-bottom: 0; } @@ -244,3 +244,7 @@ a.chosen-single:hover { width: 100%; } +.dpd-delivery-time-block { + margin-top: 1rem; +} + diff --git a/views/js/front/order-opc.js b/views/js/front/order-opc.js index 33065923..5589e21c 100644 --- a/views/js/front/order-opc.js +++ b/views/js/front/order-opc.js @@ -17,6 +17,11 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 */ var isPudoPointSelected = false; +var phoneQuerySelectors = [ + '#checkout #delivery-address [name="phone"]', + '.address-fields input[name="phone"]', + '#checkout [name="delivery_phone_mobile"]' +]; $(document).ready(function (){ @@ -24,6 +29,17 @@ $(document).ready(function (){ handlePhoneNumber($(this)); }); + $('body').on('click', '#confirm_order', function(e) { + e.preventDefault(); + + if ($('.dpd-phone-block') !== undefined) { + if(!handlePhoneNumber($('.dpd-phone-block'))) { + return; + } + } + + }); + $(document).on('click','.payment_module a', function (e){ e.preventDefault(); @@ -41,9 +57,19 @@ function handlePhoneNumber(selector) if (!$('.dpd-phone-block')) { return true; } + var phone = selector.find('input[name="dpd-phone"]').val(); var phoneArea = selector.find('select[name="dpd-phone-area"] option:selected').val(); + // if empty then take it from opc phone field + if (phone === '') { + phoneQuerySelectors.forEach(function (phoneSelector) { + if ($(phoneSelector).val()) { + phone = $(phoneSelector).val(); + } + }); + } + if (currentController === 'supercheckout') { saveSelectedPhoneNumberSuperCheckout(phone, phoneArea) } else { @@ -82,3 +108,13 @@ function DPDdisplayMessageOpc(parent, template) { var $messageContainer = parent.find('.dpd-message-container'); $messageContainer.html(template); } + +// Module "onepagecheckoutps" compatibility +$(document).on('opc-load-review:completed', function() { + handlePhoneNumber($('.dpd-phone-block')); +}); + +// Then address is being modified +$(document).on('thecheckout_Address_Modified', function () { + handlePhoneNumber($('.dpd-phone-block')); +}); diff --git a/views/js/front/pudo.js b/views/js/front/pudo.js index e1137f44..b7d0debf 100644 --- a/views/js/front/pudo.js +++ b/views/js/front/pudo.js @@ -108,7 +108,7 @@ $(document).ready(function () { } //Js to open extra content failed from theme, doing it manually. - if (params.deliveryOption.length > 0 && !$(params.deliveryOption).next('.carrier-extra-content').is(':visible')) { + if (params.deliveryOption.length > 0 && !$(params.deliveryOption).next('.carrier-extra-content').is(':visible') && !dpdbaltics.isOnePageCheckout) { $('.carrier-extra-content').hide(); $(params.deliveryOption).next('.carrier-extra-content').slideDown(); } diff --git a/views/templates/hook/front/carrier-delivery-time.tpl b/views/templates/hook/front/carrier-delivery-time.tpl index f166f8dd..ed02d79a 100644 --- a/views/templates/hook/front/carrier-delivery-time.tpl +++ b/views/templates/hook/front/carrier-delivery-time.tpl @@ -18,9 +18,9 @@ *}
-
+

{l s='Desirable delivery time' mod='dpdbaltics'}

-
+
{html_options options=$dpdPhoneArea selected=$contextPrefix} @@ -37,7 +37,7 @@
-
+
{l s='Phone' mod='dpdbaltics'}
diff --git a/views/templates/hook/front/partials/pudo-search-block.tpl b/views/templates/hook/front/partials/pudo-search-block.tpl index c230e3dc..3ada10d1 100644 --- a/views/templates/hook/front/partials/pudo-search-block.tpl +++ b/views/templates/hook/front/partials/pudo-search-block.tpl @@ -19,10 +19,10 @@
{if count($city_list) > 1} -
+
{/if} {if !empty($city_list)} @@ -40,7 +40,7 @@
-
+
{include file='module:dpdbaltics/views/templates/hook/front/partials/pudo-search-street.tpl'}