From 21d39218fbb9b73766c6ac6a0d6951f6b23fc43c Mon Sep 17 00:00:00 2001 From: Gytautas Zumaras <96050852+GytisZum@users.noreply.github.com> Date: Thu, 21 Dec 2023 14:24:36 +0200 Subject: [PATCH 01/10] 3.2.18 (#76) * hide print label button in orders listing page * fix: translation domain added * fix: moved dev dependency from production ones * added additional filtration for the price rules which includes check of the country * version increased and changelog updated * feat: upgrade method created to define value * price rule and country fix --- CHANGELOG.md | 5 + composer.json | 8 +- composer.lock | 469 +++++++++--------- .../AdminDPDBalticsSettingsController.php | 17 + dpdbaltics.php | 10 +- src/Config/Config.php | 1 + src/Install/Installer.php | 1 + src/Repository/PriceRuleRepository.php | 24 +- .../ShippingPriceCalculationService.php | 3 +- upgrade/Upgrade-3.2.18.php | 29 ++ 10 files changed, 331 insertions(+), 236 deletions(-) create mode 100644 upgrade/Upgrade-3.2.18.php diff --git a/CHANGELOG.md b/CHANGELOG.md index b3168040..548b7aed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -154,3 +154,8 @@ ## [3.2.17] - Label printing after changing shipment product bug fix + +## [3.2.18] +- Ability to hide label print feature in orders list page +- Vulnerability fix with development dependencies +- Price rule bug fix to add additional filtration by country diff --git a/composer.json b/composer.json index 8fdb63d6..7be6b9e6 100644 --- a/composer.json +++ b/composer.json @@ -36,16 +36,16 @@ "invertus/dpdbaltics-api": "dev-developer", "invertus/psmoduletabs": "dev-develop", "symfony/console": "^3.4", - "prestashop/decimal": "^1.4", - "prestashop/autoindex": "1.0.0", - "prestashop/header-stamp": "1.7" + "prestashop/decimal": "^1.4" }, "require-dev": { "phpunit/phpunit": "*", "facebook/webdriver": "dev-master", "squizlabs/php_codesniffer": "*", "vlucas/phpdotenv": "^3.6", - "friendsofphp/php-cs-fixer": "^2.19" + "prestashop/autoindex": "1.0.0", + "friendsofphp/php-cs-fixer": "^2.19", + "prestashop/header-stamp": "1.7" }, "author": "PrestaShop", "license": "AFL-3.0" diff --git a/composer.lock b/composer.lock index fc7e496f..67c4085f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9ff3d00c8c0f2f99a7cf13791049d534", + "content-hash": "d0adbb8ef686f675841e9929585eae6d", "packages": [ { "name": "apimatic/jsonmapper", @@ -271,61 +271,6 @@ ], "time": "2022-06-09T08:53:42+00:00" }, - { - "name": "nikic/php-parser", - "version": "v3.1.5", - "source": { - "type": "git", - "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "bb87e28e7d7b8d9a7fda231d37457c9210faf6ce" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/bb87e28e7d7b8d9a7fda231d37457c9210faf6ce", - "reference": "bb87e28e7d7b8d9a7fda231d37457c9210faf6ce", - "shasum": "" - }, - "require": { - "ext-tokenizer": "*", - "php": ">=5.5" - }, - "require-dev": { - "phpunit/phpunit": "~4.0|~5.0" - }, - "bin": [ - "bin/php-parse" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0-dev" - } - }, - "autoload": { - "psr-4": { - "PhpParser\\": "lib/PhpParser" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Nikita Popov" - } - ], - "description": "A PHP parser written in PHP", - "keywords": [ - "parser", - "php" - ], - "support": { - "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v3.1.5" - }, - "time": "2018-02-28T20:30:58+00:00" - }, { "name": "paragonie/random_compat", "version": "v2.0.21", @@ -607,52 +552,6 @@ ], "time": "2020-07-20T17:29:33+00:00" }, - { - "name": "prestashop/autoindex", - "version": "v1.0.0", - "source": { - "type": "git", - "url": "https://github.com/PrestaShopCorp/autoindex.git", - "reference": "92e10242f94a99163dece280f6bd7b7c2b79c158" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/PrestaShopCorp/autoindex/zipball/92e10242f94a99163dece280f6bd7b7c2b79c158", - "reference": "92e10242f94a99163dece280f6bd7b7c2b79c158", - "shasum": "" - }, - "require": { - "nikic/php-parser": "^3.1", - "php": ">=5.6", - "symfony/console": "^3.4", - "symfony/finder": "^3.4" - }, - "bin": [ - "bin/autoindex" - ], - "type": "library", - "autoload": { - "psr-4": { - "PrestaShop\\AutoIndex\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "AFL-3.0" - ], - "authors": [ - { - "name": "PrestaShop SA", - "email": "contact@prestashop.com" - } - ], - "description": "Automatically add an 'index.php' in all the current or specified directories and all sub-directories.", - "homepage": "https://github.com/PrestaShopCorp/autoindex", - "support": { - "source": "https://github.com/PrestaShopCorp/autoindex/tree/v1.0.0" - }, - "time": "2020-03-11T13:37:03+00:00" - }, { "name": "prestashop/decimal", "version": "1.4.0", @@ -709,56 +608,6 @@ }, "time": "2020-10-08T07:14:07+00:00" }, - { - "name": "prestashop/header-stamp", - "version": "v1.7", - "source": { - "type": "git", - "url": "https://github.com/PrestaShopCorp/header-stamp.git", - "reference": "d77ce6d0a7f066670a4774be88f05e5f07b4b6fc" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/PrestaShopCorp/header-stamp/zipball/d77ce6d0a7f066670a4774be88f05e5f07b4b6fc", - "reference": "d77ce6d0a7f066670a4774be88f05e5f07b4b6fc", - "shasum": "" - }, - "require": { - "nikic/php-parser": "^3.1", - "php": ">=5.6", - "symfony/console": "^3.4 || ~4.0 || ~5.0", - "symfony/finder": "^3.4 || ~4.0 || ~5.0" - }, - "require-dev": { - "prestashop/php-dev-tools": "1.*" - }, - "bin": [ - "bin/header-stamp" - ], - "type": "library", - "autoload": { - "psr-4": { - "PrestaShop\\HeaderStamp\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "AFL-3.0" - ], - "authors": [ - { - "name": "PrestaShop SA", - "email": "contact@prestashop.com" - } - ], - "description": "Rewrite your file headers to add the license or to make them up-to-date", - "homepage": "https://github.com/PrestaShopCorp/header-stamp", - "support": { - "issues": "https://github.com/PrestaShopCorp/header-stamp/issues", - "source": "https://github.com/PrestaShopCorp/header-stamp/tree/v1.7" - }, - "time": "2020-12-09T16:40:38+00:00" - }, { "name": "psr/log", "version": "1.1.4", @@ -962,67 +811,6 @@ "abandoned": "symfony/error-handler", "time": "2020-10-24T10:57:07+00:00" }, - { - "name": "symfony/finder", - "version": "v3.4.47", - "source": { - "type": "git", - "url": "https://github.com/symfony/finder.git", - "reference": "b6b6ad3db3edb1b4b1c1896b1975fb684994de6e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/b6b6ad3db3edb1b4b1c1896b1975fb684994de6e", - "reference": "b6b6ad3db3edb1b4b1c1896b1975fb684994de6e", - "shasum": "" - }, - "require": { - "php": "^5.5.9|>=7.0.8" - }, - "type": "library", - "autoload": { - "psr-4": { - "Symfony\\Component\\Finder\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Finder Component", - "homepage": "https://symfony.com", - "support": { - "source": "https://github.com/symfony/finder/tree/v3.4.47" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2020-11-16T17:02:08+00:00" - }, { "name": "symfony/inflector", "version": "v3.4.47", @@ -1797,16 +1585,16 @@ }, { "name": "composer/semver", - "version": "3.3.2", + "version": "3.4.0", "source": { "type": "git", "url": "https://github.com/composer/semver.git", - "reference": "3953f23262f2bff1919fc82183ad9acb13ff62c9" + "reference": "35e8d0af4486141bc745f23a29cc2091eb624a32" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/semver/zipball/3953f23262f2bff1919fc82183ad9acb13ff62c9", - "reference": "3953f23262f2bff1919fc82183ad9acb13ff62c9", + "url": "https://api.github.com/repos/composer/semver/zipball/35e8d0af4486141bc745f23a29cc2091eb624a32", + "reference": "35e8d0af4486141bc745f23a29cc2091eb624a32", "shasum": "" }, "require": { @@ -1856,9 +1644,9 @@ "versioning" ], "support": { - "irc": "irc://irc.freenode.org/composer", + "irc": "ircs://irc.libera.chat:6697/composer", "issues": "https://github.com/composer/semver/issues", - "source": "https://github.com/composer/semver/tree/3.3.2" + "source": "https://github.com/composer/semver/tree/3.4.0" }, "funding": [ { @@ -1874,7 +1662,7 @@ "type": "tidelift" } ], - "time": "2022-04-01T19:23:25+00:00" + "time": "2023-08-31T09:50:34+00:00" }, { "name": "composer/xdebug-handler", @@ -2068,8 +1856,22 @@ ], "support": { "issues": "https://github.com/doctrine/instantiator/issues", - "source": "https://github.com/doctrine/instantiator/tree/master" + "source": "https://github.com/doctrine/instantiator/tree/1.0.5" }, + "funding": [ + { + "url": "https://www.doctrine-project.org/sponsorship.html", + "type": "custom" + }, + { + "url": "https://www.patreon.com/phpdoctrine", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/doctrine%2Finstantiator", + "type": "tidelift" + } + ], "time": "2015-06-14T21:17:01+00:00" }, { @@ -2341,6 +2143,61 @@ }, "time": "2017-10-19T19:58:43+00:00" }, + { + "name": "nikic/php-parser", + "version": "v3.1.5", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "bb87e28e7d7b8d9a7fda231d37457c9210faf6ce" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/bb87e28e7d7b8d9a7fda231d37457c9210faf6ce", + "reference": "bb87e28e7d7b8d9a7fda231d37457c9210faf6ce", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "~4.0|~5.0" + }, + "bin": [ + "bin/php-parse" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "PhpParser\\": "lib/PhpParser" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "support": { + "issues": "https://github.com/nikic/PHP-Parser/issues", + "source": "https://github.com/nikic/PHP-Parser/tree/v3.1.5" + }, + "time": "2018-02-28T20:30:58+00:00" + }, { "name": "php-cs-fixer/diff", "version": "v1.3.1", @@ -2887,6 +2744,102 @@ "abandoned": true, "time": "2017-06-30T09:13:00+00:00" }, + { + "name": "prestashop/autoindex", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/PrestaShopCorp/autoindex.git", + "reference": "92e10242f94a99163dece280f6bd7b7c2b79c158" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PrestaShopCorp/autoindex/zipball/92e10242f94a99163dece280f6bd7b7c2b79c158", + "reference": "92e10242f94a99163dece280f6bd7b7c2b79c158", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^3.1", + "php": ">=5.6", + "symfony/console": "^3.4", + "symfony/finder": "^3.4" + }, + "bin": [ + "bin/autoindex" + ], + "type": "library", + "autoload": { + "psr-4": { + "PrestaShop\\AutoIndex\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "AFL-3.0" + ], + "authors": [ + { + "name": "PrestaShop SA", + "email": "contact@prestashop.com" + } + ], + "description": "Automatically add an 'index.php' in all the current or specified directories and all sub-directories.", + "homepage": "https://github.com/PrestaShopCorp/autoindex", + "support": { + "source": "https://github.com/PrestaShopCorp/autoindex/tree/v1.0.0" + }, + "time": "2020-03-11T13:37:03+00:00" + }, + { + "name": "prestashop/header-stamp", + "version": "v1.7", + "source": { + "type": "git", + "url": "https://github.com/PrestaShopCorp/header-stamp.git", + "reference": "d77ce6d0a7f066670a4774be88f05e5f07b4b6fc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PrestaShopCorp/header-stamp/zipball/d77ce6d0a7f066670a4774be88f05e5f07b4b6fc", + "reference": "d77ce6d0a7f066670a4774be88f05e5f07b4b6fc", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^3.1", + "php": ">=5.6", + "symfony/console": "^3.4 || ~4.0 || ~5.0", + "symfony/finder": "^3.4 || ~4.0 || ~5.0" + }, + "require-dev": { + "prestashop/php-dev-tools": "1.*" + }, + "bin": [ + "bin/header-stamp" + ], + "type": "library", + "autoload": { + "psr-4": { + "PrestaShop\\HeaderStamp\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "AFL-3.0" + ], + "authors": [ + { + "name": "PrestaShop SA", + "email": "contact@prestashop.com" + } + ], + "description": "Rewrite your file headers to add the license or to make them up-to-date", + "homepage": "https://github.com/PrestaShopCorp/header-stamp", + "support": { + "issues": "https://github.com/PrestaShopCorp/header-stamp/issues", + "source": "https://github.com/PrestaShopCorp/header-stamp/tree/v1.7" + }, + "time": "2020-12-09T16:40:38+00:00" + }, { "name": "sebastian/code-unit-reverse-lookup", "version": "1.0.2", @@ -3448,16 +3401,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "3.7.1", + "version": "3.7.2", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "1359e176e9307e906dc3d890bcc9603ff6d90619" + "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/1359e176e9307e906dc3d890bcc9603ff6d90619", - "reference": "1359e176e9307e906dc3d890bcc9603ff6d90619", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ed8e00df0a83aa96acf703f8c2979ff33341f879", + "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879", "shasum": "" }, "require": { @@ -3493,14 +3446,15 @@ "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", "keywords": [ "phpcs", - "standards" + "standards", + "static analysis" ], "support": { "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", "source": "https://github.com/squizlabs/PHP_CodeSniffer", "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" }, - "time": "2022-06-18T07:21:10+00:00" + "time": "2023-02-22T23:07:41+00:00" }, { "name": "symfony/event-dispatcher", @@ -3640,6 +3594,67 @@ ], "time": "2020-10-24T10:57:07+00:00" }, + { + "name": "symfony/finder", + "version": "v3.4.47", + "source": { + "type": "git", + "url": "https://github.com/symfony/finder.git", + "reference": "b6b6ad3db3edb1b4b1c1896b1975fb684994de6e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/finder/zipball/b6b6ad3db3edb1b4b1c1896b1975fb684994de6e", + "reference": "b6b6ad3db3edb1b4b1c1896b1975fb684994de6e", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Finder\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Finder Component", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/finder/tree/v3.4.47" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-11-16T17:02:08+00:00" + }, { "name": "symfony/options-resolver", "version": "v3.4.47", diff --git a/controllers/admin/AdminDPDBalticsSettingsController.php b/controllers/admin/AdminDPDBalticsSettingsController.php index be47f2bd..820795ec 100644 --- a/controllers/admin/AdminDPDBalticsSettingsController.php +++ b/controllers/admin/AdminDPDBalticsSettingsController.php @@ -39,6 +39,8 @@ class AdminDPDBalticsSettingsController extends AbstractAdminController { + private const FILE_NAME = 'AdminDPDBalticsSettingsController'; + public function init() { $parentReturn = parent::init(); @@ -114,6 +116,21 @@ protected function initOptions() 'title' => $this->l('Save'), ], ], + 'orders_page_configuration' => [ + 'title' => $this->l('Orders listing page configuration', self::FILE_NAME), + 'icon' => 'dpd-icon-settings', + 'fields' => [ + Config::HIDE_ORDERS_LABEL_PRINT_BUTTON => [ + 'title' => $this->l('Hide print button in admin orders listing page'), + 'type' => 'bool', + 'validation' => 'isBool', + 'cast' => 'intval' + ], + ], + 'submit' => [ + 'title' => $this->l('Save'), + ], + ], 'log_configuration' => [ 'title' => $this->l('Log configuration'), 'icon' => 'dpd-icon-settings', diff --git a/dpdbaltics.php b/dpdbaltics.php index cb11ea4f..86f43c38 100644 --- a/dpdbaltics.php +++ b/dpdbaltics.php @@ -92,7 +92,7 @@ public function __construct() $this->author = 'Invertus'; $this->tab = 'shipping_logistics'; $this->description = 'DPD Baltics shipping integration'; - $this->version = '3.2.17'; + $this->version = '3.2.18'; $this->ps_versions_compliancy = ['min' => '1.7.1.0', 'max' => _PS_VERSION_]; $this->need_instance = 0; parent::__construct(); @@ -1207,12 +1207,18 @@ public function hookDisplayOrderDetail($params) public function hookActionAdminOrdersListingFieldsModifier($params) { + if ((bool) Configuration::get(Config::HIDE_ORDERS_LABEL_PRINT_BUTTON)) { + return false; + } + if (isset($params['select'])) { $params['select'] .= ' ,ds.`id_order` AS id_order_shipment '; } + if (isset($params['join'])) { $params['join'] .= ' LEFT JOIN `' . _DB_PREFIX_ . 'dpd_shipment` ds ON ds.`id_order` = a.`id_order` '; } + $params['fields']['id_order_shipment'] = [ 'title' => $this->l('DPD Label'), 'align' => 'text-center', @@ -1267,6 +1273,7 @@ public function hookActionOrderGridDefinitionModifier(array $params) $definition = $params['definition']; + if (!(bool) Configuration::get(Config::HIDE_ORDERS_LABEL_PRINT_BUTTON)) { $definition->getColumns() ->addAfter( 'date_add', @@ -1276,6 +1283,7 @@ public function hookActionOrderGridDefinitionModifier(array $params) 'actions' => $this->getGridAction() ]) ); + } $definition->getBulkActions() ->add( diff --git a/src/Config/Config.php b/src/Config/Config.php index 0e633611..fe9a188a 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -115,6 +115,7 @@ class Config const DEFAULT_LABEL_POSITION = 'DPD_DEFAULT_LABEL_POSITION'; const SEND_EMAIL_ON_PARCEL_CREATION = 'DPD_SEND_EMAIL_TO_CUSTOMER'; const MULTIPLE_LABEL_NAME_MAX_SIZE = 44; + const HIDE_ORDERS_LABEL_PRINT_BUTTON = 'DPD_HIDE_ORDERS_LABEL_PRINT_BUTTON'; const PHONE_CODE_PREFIX = '+'; diff --git a/src/Install/Installer.php b/src/Install/Installer.php index 7943125b..2e806e4c 100644 --- a/src/Install/Installer.php +++ b/src/Install/Installer.php @@ -220,6 +220,7 @@ public function getDefaultConfiguration() Config::IMPORT_LINES_SKIP => 1, Config::IMPORT_FIELD_SEPARATOR => ';', Config::IMPORT_DELETE_OLD_DATA => 0, + Config::HIDE_ORDERS_LABEL_PRINT_BUTTON => 0, /** On-board */ Config::ON_BOARD_TURNED_ON => 1, diff --git a/src/Repository/PriceRuleRepository.php b/src/Repository/PriceRuleRepository.php index ce71fdae..c9572803 100644 --- a/src/Repository/PriceRuleRepository.php +++ b/src/Repository/PriceRuleRepository.php @@ -73,12 +73,14 @@ public function getAllFlag($tableName, $idPriceRule) * * @param Address $deliveryAddress * @param int $carrierReferenceId + * @param bool $includeCountryCheck * @return array price rules IDs * @throws PrestaShopDatabaseException */ public function getByCarrierReference( Address $deliveryAddress, - $carrierReference + $carrierReference, + bool $includeCountryCheck = false ) { $query = new DbQuery(); $query->select('prc.`id_dpd_price_rule`'); @@ -89,11 +91,27 @@ public function getByCarrierReference( 'prs', 'prs.`id_dpd_price_rule` = prc.`id_dpd_price_rule`' ); - $query->where('prc.`id_reference`="' . (int)$carrierReference . '" OR prc.`all_carriers`="1"'); + + /* param needed to filter out by countries to get specific price rules for that country address */ + if ($includeCountryCheck && $deliveryAddress->id_country) { + $query->innerJoin( + 'dpd_price_rule_zone', + 'prz', + 'prc.`id_dpd_price_rule` = prz.`id_dpd_price_rule`' + ); + $query->innerJoin( + 'dpd_zone_range', + 'zr', + 'prz.`id_dpd_zone` = zr.`id_dpd_zone`' + ); + + $query->where('zr.`id_country`= ' . (int) $deliveryAddress->id_country); + } + + $query->where('prc.`id_reference`="' . (int) $carrierReference . '" OR prc.`all_carriers`="1"'); $query->where('pr.active = 1'); $query->orderBy('pr.position ASC'); - if (Validate::isLoadedObject($deliveryAddress)) { if ($deliveryAddress->company) { $query->where( diff --git a/src/Service/ShippingPriceCalculationService.php b/src/Service/ShippingPriceCalculationService.php index 2e696558..1bbc8e3f 100644 --- a/src/Service/ShippingPriceCalculationService.php +++ b/src/Service/ShippingPriceCalculationService.php @@ -56,7 +56,8 @@ public function calculate(Cart $cart, \Carrier $carrier, Address $deliveryAddres $priceRulesIds = $this->priceRuleRepository->getByCarrierReference( $deliveryAddress, - $carrier->id_reference + $carrier->id_reference, + true ); $shippingCosts += $this->priceRuleService->applyPriceRuleForCarrier( diff --git a/upgrade/Upgrade-3.2.18.php b/upgrade/Upgrade-3.2.18.php new file mode 100644 index 00000000..8b111167 --- /dev/null +++ b/upgrade/Upgrade-3.2.18.php @@ -0,0 +1,29 @@ + + * @copyright Copyright (c) permanent, INVERTUS, UAB + * @license Addons PrestaShop license limitation + * @see /LICENSE + * + * International Registered Trademark & Property of INVERTUS, UAB + */ + +use Invertus\dpdBaltics\Config\Config; + +if (!defined('_PS_VERSION_')) { + exit; +} + +/** + * @return bool + * + * @throws PrestaShopDatabaseException + * @throws PrestaShopException + */ +function upgrade_module_3_2_18(DPDBaltics $module) +{ + return Configuration::updateValue(Config::HIDE_ORDERS_LABEL_PRINT_BUTTON, 0); +} + From ede5164043893163e2302488d93438b9af82a701 Mon Sep 17 00:00:00 2001 From: Gytautas Date: Fri, 19 Jan 2024 14:32:01 +0200 Subject: [PATCH 02/10] added additional filtration to filter active countries only --- src/Repository/PhonePrefixRepository.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Repository/PhonePrefixRepository.php b/src/Repository/PhonePrefixRepository.php index 2bec758f..097f511b 100644 --- a/src/Repository/PhonePrefixRepository.php +++ b/src/Repository/PhonePrefixRepository.php @@ -57,6 +57,8 @@ public function getCallPrefixesFrontOffice() $query = new DbQuery(); $query->select('c.`call_prefix`'); $query->from('country', 'c'); + $query->where('active=1'); + $resource = Db::getInstance()->query($query); $result = []; while ($row = Db::getInstance()->nextRow($resource)) { From c595738ef9b9e4d607890cac8e745181827efac6 Mon Sep 17 00:00:00 2001 From: Gytautas Date: Fri, 19 Jan 2024 14:45:02 +0200 Subject: [PATCH 03/10] modal fix for more information --- views/js/front/pudo-search.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/js/front/pudo-search.js b/views/js/front/pudo-search.js index ba3dc8be..ee43983b 100644 --- a/views/js/front/pudo-search.js +++ b/views/js/front/pudo-search.js @@ -137,7 +137,7 @@ function saveSelectedStreet(city, street) { var coordinates = response.coordinates; var $idReference = $parent.data('id'); $('.points-container').empty().append(response.template); - + reselectDataPopover(); initMap(coordinates, true, response.selectedPudoId, false, $idReference); isPudoPointSelected = true; } From 6dca1fbc885d65944299db211f8a111ad18e8fed Mon Sep 17 00:00:00 2001 From: Gytautas Date: Thu, 29 Feb 2024 16:20:16 +0200 Subject: [PATCH 04/10] fix: fixed post codes to check only numeric one --- src/Adapter/AddressAdapter.php | 7 ++++--- src/Repository/ZoneRepository.php | 7 +++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Adapter/AddressAdapter.php b/src/Adapter/AddressAdapter.php index 6c8f47ea..27aec1d9 100644 --- a/src/Adapter/AddressAdapter.php +++ b/src/Adapter/AddressAdapter.php @@ -85,9 +85,10 @@ private function getFormattedZipCode(Country $country, $postCode) $postCode = preg_replace("/[^a-zA-Z0-9]+/", "", $postCode); // If C doesn't exist in zip code format - don't modify the zip code - if (false === $countryCodePosition) { - return $postCode; - } + //todo this check prevents from saving zip code to numeric not sure why c has to be checked +// if (false === $countryCodePosition) { +// return $postCode; +// } $countryCodeLength = Tools::strlen($country->iso_code); $countryCode = Tools::substr($postCode, $countryCodePosition, $countryCodeLength); diff --git a/src/Repository/ZoneRepository.php b/src/Repository/ZoneRepository.php index a26f3d77..c1cd4102 100644 --- a/src/Repository/ZoneRepository.php +++ b/src/Repository/ZoneRepository.php @@ -24,6 +24,7 @@ use Address; use Country; use DbQuery; +use Invertus\dpdBaltics\Adapter\AddressAdapter; use PrestaShopDatabaseException; class ZoneRepository extends AbstractEntityRepository @@ -101,14 +102,16 @@ public function addProductZonesFromArray(array $zones) public function findZoneInRangeByAddress(Address $address) { $idCountry = $address->id_country ?: (int)\Configuration::get('PS_COUNTRY_DEFAULT'); - $zipCode = $address->postcode; + $addressAdapter = new AddressAdapter(); + + $zipCode = $addressAdapter->getZipCodeByCountry($idCountry, $address->postcode); $query = new DbQuery(); $query->select('dz.id_dpd_zone'); $query->from('dpd_zone', 'dz'); $query->leftJoin('dpd_zone_range', 'dzr', 'dzr.id_dpd_zone = dz.id_dpd_zone'); $query->where('dzr.id_country = ' . (int)$idCountry); - $query->where('dzr.include_all_zip_codes = 1 OR (dzr.zip_code_from <= \'' . pSQL($zipCode) . '\' AND dzr.zip_code_to >= \'' . pSQL($zipCode) . '\')'); + $query->where('dzr.include_all_zip_codes = 1 OR (dzr.zip_code_from_numeric <= \'' . pSQL($zipCode) . '\' AND dzr.zip_code_to_numeric >= \'' . pSQL($zipCode) . '\')'); $result = $this->db->executeS($query); From 0f7f5b73dd7ee6a36588f70815184541f4f65046 Mon Sep 17 00:00:00 2001 From: Gytautas Date: Thu, 29 Feb 2024 17:20:01 +0200 Subject: [PATCH 05/10] restore country code check --- src/Adapter/AddressAdapter.php | 7 +++---- src/Repository/ZoneRepository.php | 5 ++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Adapter/AddressAdapter.php b/src/Adapter/AddressAdapter.php index 27aec1d9..6c8f47ea 100644 --- a/src/Adapter/AddressAdapter.php +++ b/src/Adapter/AddressAdapter.php @@ -85,10 +85,9 @@ private function getFormattedZipCode(Country $country, $postCode) $postCode = preg_replace("/[^a-zA-Z0-9]+/", "", $postCode); // If C doesn't exist in zip code format - don't modify the zip code - //todo this check prevents from saving zip code to numeric not sure why c has to be checked -// if (false === $countryCodePosition) { -// return $postCode; -// } + if (false === $countryCodePosition) { + return $postCode; + } $countryCodeLength = Tools::strlen($country->iso_code); $countryCode = Tools::substr($postCode, $countryCodePosition, $countryCodeLength); diff --git a/src/Repository/ZoneRepository.php b/src/Repository/ZoneRepository.php index c1cd4102..b19169a2 100644 --- a/src/Repository/ZoneRepository.php +++ b/src/Repository/ZoneRepository.php @@ -25,6 +25,7 @@ use Country; use DbQuery; use Invertus\dpdBaltics\Adapter\AddressAdapter; +use Invertus\dpdBaltics\Validate\Zone\ZoneRangeValidate; use PrestaShopDatabaseException; class ZoneRepository extends AbstractEntityRepository @@ -102,9 +103,7 @@ public function addProductZonesFromArray(array $zones) public function findZoneInRangeByAddress(Address $address) { $idCountry = $address->id_country ?: (int)\Configuration::get('PS_COUNTRY_DEFAULT'); - $addressAdapter = new AddressAdapter(); - - $zipCode = $addressAdapter->getZipCodeByCountry($idCountry, $address->postcode); + $zipCode = ZoneRangeValidate::getNumericZipCode($address->postcode, $idCountry); $query = new DbQuery(); $query->select('dz.id_dpd_zone'); From 9f88532fa3e298db700a3433c0a1b9ff112f914e Mon Sep 17 00:00:00 2001 From: Gytautas Date: Thu, 14 Mar 2024 10:57:36 +0200 Subject: [PATCH 06/10] unused use statement deleted --- src/Repository/ZoneRepository.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Repository/ZoneRepository.php b/src/Repository/ZoneRepository.php index b19169a2..d0620df8 100644 --- a/src/Repository/ZoneRepository.php +++ b/src/Repository/ZoneRepository.php @@ -24,7 +24,6 @@ use Address; use Country; use DbQuery; -use Invertus\dpdBaltics\Adapter\AddressAdapter; use Invertus\dpdBaltics\Validate\Zone\ZoneRangeValidate; use PrestaShopDatabaseException; From 0be83918adcdb0ba8bf7eee9ffbc4d5ff0cdbb85 Mon Sep 17 00:00:00 2001 From: Gytautas Date: Thu, 14 Mar 2024 16:45:20 +0200 Subject: [PATCH 07/10] version bump and changelogs added --- CHANGELOG.md | 6 ++++++ dpdbaltics.php | 11 +++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 548b7aed..a1aeae13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -159,3 +159,9 @@ - Ability to hide label print feature in orders list page - Vulnerability fix with development dependencies - Price rule bug fix to add additional filtration by country + +## [3.2.19] +- 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 diff --git a/dpdbaltics.php b/dpdbaltics.php index e22b3855..9043978f 100644 --- a/dpdbaltics.php +++ b/dpdbaltics.php @@ -92,7 +92,7 @@ public function __construct() $this->author = 'Invertus'; $this->tab = 'shipping_logistics'; $this->description = 'DPD Baltics shipping integration'; - $this->version = '3.2.18'; + $this->version = '3.2.19'; $this->ps_versions_compliancy = ['min' => '1.7.1.0', 'max' => _PS_VERSION_]; $this->need_instance = 0; parent::__construct(); @@ -203,7 +203,6 @@ public function hookActionFrontControllerSetMedia() 'priority' => 130 ] ); - } /** @var \Invertus\dpdBaltics\Provider\CurrentCountryProvider $currentCountryProvider */ @@ -278,7 +277,8 @@ public function hookActionFrontControllerSetMedia() $googleApiService = $this->getModuleContainer('invertus.dpdbaltics.service.google_api_service'); $this->context->controller->registerJavascript( 'dpdbaltics-google-api', - $googleApiService->getFormattedGoogleMapsUrl(), [ + $googleApiService->getFormattedGoogleMapsUrl(), + [ 'server' => 'remote' ] ); @@ -507,7 +507,7 @@ public function getOrderShippingCostExternal($cart) $parcelDistribution = \Configuration::get(Config::PARCEL_DISTRIBUTION); $maxAllowedWeight = Config::getDefaultServiceWeights($countryCode, $serviceCarrier['product_reference']); - if (!$cartWeightValidator->validate($cart, $parcelDistribution ,$maxAllowedWeight)) { + if (!$cartWeightValidator->validate($cart, $parcelDistribution, $maxAllowedWeight)) { return false; } @@ -1150,7 +1150,6 @@ private function updateOrderCarrier($shipmentId) public function hookDisplayOrderDetail($params) { - $isReturnServiceEnabled = Configuration::get(Config::PARCEL_RETURN); if (!$isReturnServiceEnabled) { return; @@ -1279,7 +1278,7 @@ public function hookActionOrderGridDefinitionModifier(array $params) $definition = $params['definition']; if (!(bool) Configuration::get(Config::HIDE_ORDERS_LABEL_PRINT_BUTTON)) { - $definition->getColumns() + $definition->getColumns() ->addAfter( 'date_add', (new ActionColumn('dpd_print_label')) From defb608341370984f21b17d56a7018efc3d9c765 Mon Sep 17 00:00:00 2001 From: Gytautas Zumaras <96050852+GytisZum@users.noreply.github.com> Date: Thu, 18 Apr 2024 11:56:39 +0300 Subject: [PATCH 08/10] Release v3.2.19 (#82) (#83) * hide print label button in orders listing page * fix: translation domain added * fix: moved dev dependency from production ones * added additional filtration for the price rules which includes check of the country * version increased and changelog updated * feat: upgrade method created to define value * price rule and country fix * carrier availability in country fox * not needed use statement removed * fix: fixed to check all countries too * added additional filtration to filter active countries only * modal fix for more information * fix: fixed post codes to check only numeric one * restore country code check * unused use statement deleted * version bump and changelogs added --- CHANGELOG.md | 6 ++++ dpdbaltics.php | 16 ++++++---- src/Repository/PhonePrefixRepository.php | 2 ++ src/Repository/ProductRepository.php | 38 ++++++++++++++++++++++++ src/Repository/ZoneRepository.php | 5 ++-- views/js/front/pudo-search.js | 2 +- 6 files changed, 60 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 548b7aed..a1aeae13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -159,3 +159,9 @@ - Ability to hide label print feature in orders list page - Vulnerability fix with development dependencies - Price rule bug fix to add additional filtration by country + +## [3.2.19] +- 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 diff --git a/dpdbaltics.php b/dpdbaltics.php index 86f43c38..9043978f 100644 --- a/dpdbaltics.php +++ b/dpdbaltics.php @@ -92,7 +92,7 @@ public function __construct() $this->author = 'Invertus'; $this->tab = 'shipping_logistics'; $this->description = 'DPD Baltics shipping integration'; - $this->version = '3.2.18'; + $this->version = '3.2.19'; $this->ps_versions_compliancy = ['min' => '1.7.1.0', 'max' => _PS_VERSION_]; $this->need_instance = 0; parent::__construct(); @@ -203,7 +203,6 @@ public function hookActionFrontControllerSetMedia() 'priority' => 130 ] ); - } /** @var \Invertus\dpdBaltics\Provider\CurrentCountryProvider $currentCountryProvider */ @@ -278,7 +277,8 @@ public function hookActionFrontControllerSetMedia() $googleApiService = $this->getModuleContainer('invertus.dpdbaltics.service.google_api_service'); $this->context->controller->registerJavascript( 'dpdbaltics-google-api', - $googleApiService->getFormattedGoogleMapsUrl(), [ + $googleApiService->getFormattedGoogleMapsUrl(), + [ 'server' => 'remote' ] ); @@ -475,6 +475,11 @@ public function getOrderShippingCostExternal($cart) return false; } + if (!$productRepo->checkIfCarrierIsAvailableInCountry((int) $carrier->id_reference, (int) $deliveryAddress->id_country) + ) { + return false; + } + try { $isCarrierAvailableInShop = $productRepo->checkIfCarrierIsAvailableInShop($carrier->id_reference, $this->context->shop->id); if (empty($isCarrierAvailableInShop)) { @@ -502,7 +507,7 @@ public function getOrderShippingCostExternal($cart) $parcelDistribution = \Configuration::get(Config::PARCEL_DISTRIBUTION); $maxAllowedWeight = Config::getDefaultServiceWeights($countryCode, $serviceCarrier['product_reference']); - if (!$cartWeightValidator->validate($cart, $parcelDistribution ,$maxAllowedWeight)) { + if (!$cartWeightValidator->validate($cart, $parcelDistribution, $maxAllowedWeight)) { return false; } @@ -1145,7 +1150,6 @@ private function updateOrderCarrier($shipmentId) public function hookDisplayOrderDetail($params) { - $isReturnServiceEnabled = Configuration::get(Config::PARCEL_RETURN); if (!$isReturnServiceEnabled) { return; @@ -1274,7 +1278,7 @@ public function hookActionOrderGridDefinitionModifier(array $params) $definition = $params['definition']; if (!(bool) Configuration::get(Config::HIDE_ORDERS_LABEL_PRINT_BUTTON)) { - $definition->getColumns() + $definition->getColumns() ->addAfter( 'date_add', (new ActionColumn('dpd_print_label')) diff --git a/src/Repository/PhonePrefixRepository.php b/src/Repository/PhonePrefixRepository.php index 2bec758f..097f511b 100644 --- a/src/Repository/PhonePrefixRepository.php +++ b/src/Repository/PhonePrefixRepository.php @@ -57,6 +57,8 @@ public function getCallPrefixesFrontOffice() $query = new DbQuery(); $query->select('c.`call_prefix`'); $query->from('country', 'c'); + $query->where('active=1'); + $resource = Db::getInstance()->query($query); $result = []; while ($row = Db::getInstance()->nextRow($resource)) { diff --git a/src/Repository/ProductRepository.php b/src/Repository/ProductRepository.php index 611e1a82..35954d16 100644 --- a/src/Repository/ProductRepository.php +++ b/src/Repository/ProductRepository.php @@ -252,4 +252,42 @@ public function findProductByProductReference($carrierReference) return $this->db->getRow($query) ?: null; } + + /** + * @param int $carrierReference + * @param int $countryId + * + * @return array|bool|mysqli_result|PDOStatement|resource|null + * @throws PrestaShopDatabaseException + */ + public function checkIfCarrierIsAvailableInCountry(int $carrierReference, int $countryId) + { + $productId = $this->getProductIdByCarrierReference($carrierReference); + $product = new DPDProduct($productId); + + if ($product->all_zones) { + return ['id_dpd_product' => $productId]; + } + + $query = new DbQuery(); + $query->select('dp.id_dpd_product'); + $query->from('dpd_product', 'dp'); + + $query->leftJoin( + 'dpd_product_zone', + 'dpz', + 'dp.`id_dpd_product` = dpz.`id_dpd_product`' + ); + + $query->leftJoin( + 'dpd_zone_range', + 'dzr', + 'dzr.`id_dpd_zone` = dpz.`id_dpd_zone`' + ); + + $query->where('dp.id_reference= '.(int) $product->id_reference); + $query->where('dzr.id_country = '.(int) $countryId); + + return $this->db->executeS($query); + } } diff --git a/src/Repository/ZoneRepository.php b/src/Repository/ZoneRepository.php index a26f3d77..d0620df8 100644 --- a/src/Repository/ZoneRepository.php +++ b/src/Repository/ZoneRepository.php @@ -24,6 +24,7 @@ use Address; use Country; use DbQuery; +use Invertus\dpdBaltics\Validate\Zone\ZoneRangeValidate; use PrestaShopDatabaseException; class ZoneRepository extends AbstractEntityRepository @@ -101,14 +102,14 @@ public function addProductZonesFromArray(array $zones) public function findZoneInRangeByAddress(Address $address) { $idCountry = $address->id_country ?: (int)\Configuration::get('PS_COUNTRY_DEFAULT'); - $zipCode = $address->postcode; + $zipCode = ZoneRangeValidate::getNumericZipCode($address->postcode, $idCountry); $query = new DbQuery(); $query->select('dz.id_dpd_zone'); $query->from('dpd_zone', 'dz'); $query->leftJoin('dpd_zone_range', 'dzr', 'dzr.id_dpd_zone = dz.id_dpd_zone'); $query->where('dzr.id_country = ' . (int)$idCountry); - $query->where('dzr.include_all_zip_codes = 1 OR (dzr.zip_code_from <= \'' . pSQL($zipCode) . '\' AND dzr.zip_code_to >= \'' . pSQL($zipCode) . '\')'); + $query->where('dzr.include_all_zip_codes = 1 OR (dzr.zip_code_from_numeric <= \'' . pSQL($zipCode) . '\' AND dzr.zip_code_to_numeric >= \'' . pSQL($zipCode) . '\')'); $result = $this->db->executeS($query); diff --git a/views/js/front/pudo-search.js b/views/js/front/pudo-search.js index ba3dc8be..ee43983b 100644 --- a/views/js/front/pudo-search.js +++ b/views/js/front/pudo-search.js @@ -137,7 +137,7 @@ function saveSelectedStreet(city, street) { var coordinates = response.coordinates; var $idReference = $parent.data('id'); $('.points-container').empty().append(response.template); - + reselectDataPopover(); initMap(coordinates, true, response.selectedPudoId, false, $idReference); isPudoPointSelected = true; } From 48439b3a1ce2dae36c191299a9282711e79ce463 Mon Sep 17 00:00:00 2001 From: Gytautas Date: Thu, 18 Apr 2024 13:19:57 +0300 Subject: [PATCH 09/10] compatibility fix --- src/Repository/ProductRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Repository/ProductRepository.php b/src/Repository/ProductRepository.php index 35954d16..e09e6ca2 100644 --- a/src/Repository/ProductRepository.php +++ b/src/Repository/ProductRepository.php @@ -260,7 +260,7 @@ public function findProductByProductReference($carrierReference) * @return array|bool|mysqli_result|PDOStatement|resource|null * @throws PrestaShopDatabaseException */ - public function checkIfCarrierIsAvailableInCountry(int $carrierReference, int $countryId) + public function checkIfCarrierIsAvailableInCountry($carrierReference, $countryId) { $productId = $this->getProductIdByCarrierReference($carrierReference); $product = new DPDProduct($productId); From 0a2c7449ca3906ae9d3d6ccf62e696a400ba987f Mon Sep 17 00:00:00 2001 From: Gytautas Zumaras <96050852+GytisZum@users.noreply.github.com> Date: Thu, 18 Apr 2024 13:30:20 +0300 Subject: [PATCH 10/10] Update ProductRepository.php --- src/Repository/ProductRepository.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Repository/ProductRepository.php b/src/Repository/ProductRepository.php index cb83b9b0..e09e6ca2 100644 --- a/src/Repository/ProductRepository.php +++ b/src/Repository/ProductRepository.php @@ -260,7 +260,6 @@ public function findProductByProductReference($carrierReference) * @return array|bool|mysqli_result|PDOStatement|resource|null * @throws PrestaShopDatabaseException */ - public function checkIfCarrierIsAvailableInCountry($carrierReference, $countryId) { $productId = $this->getProductIdByCarrierReference($carrierReference);