diff --git a/local/modules/DHL/Config/config.xml b/local/modules/DHL/Config/config.xml index 0793ca7c..b392015d 100644 --- a/local/modules/DHL/Config/config.xml +++ b/local/modules/DHL/Config/config.xml @@ -20,10 +20,8 @@ - - - + diff --git a/local/modules/DHL/Config/drop.sql b/local/modules/DHL/Config/drop.sql index 91471a4e..e94d695b 100644 --- a/local/modules/DHL/Config/drop.sql +++ b/local/modules/DHL/Config/drop.sql @@ -1,5 +1,17 @@ SET FOREIGN_KEY_CHECKS = 0; +-- Suppression de la table des tarfis DROP TABLE IF EXISTS `dhl_delivery_price`; +-- Suppression du mail +SET @var := 0; +SELECT @var := `id` FROM `message` WHERE name="mail_dhl"; +DELETE FROM `message` WHERE `id`=@var; +DELETE FROM `message_i18n` WHERE `id`=@var; + +-- Suppression des zones dédiées DHL +DELETE FROM `country_area` WHERE `area_id` IN (SELECT `id` FROM `area` WHERE name LIKE 'DHL - Delivery Zone%'); +DELETE FROM `area_delivery_module` WHERE `area_id` IN (SELECT `id` FROM `area` WHERE name LIKE 'DHL - Delivery Zone%'); +DELETE FROM `area` WHERE name LIKE 'DHL - Delivery Zone%'; + SET FOREIGN_KEY_CHECKS = 1; diff --git a/local/modules/DHL/DHL.php b/local/modules/DHL/DHL.php index 3c2a5599..731745e5 100644 --- a/local/modules/DHL/DHL.php +++ b/local/modules/DHL/DHL.php @@ -17,8 +17,11 @@ use Thelia\Model\CountryArea; use Thelia\Model\CountryQuery; use Thelia\Model\MessageQuery; use Thelia\Model\ModuleConfigQuery; +use Thelia\Model\OrderPostage; +use Thelia\Model\TaxRuleQuery; use Thelia\Module\AbstractDeliveryModule; use Thelia\Module\Exception\DeliveryException; +use Thelia\TaxEngine\Calculator; /** * Class DHL @@ -33,9 +36,8 @@ class DHL extends AbstractDeliveryModule private static $prices = null; const DOMAIN_NAME = 'dhl'; - const JSON_PRICE_RESOURCE = "/Config/prices.json"; + const JSON_PRICE_RESOURCE = '/Config/prices.json'; const WEBSERVICE_URL = 'tracking_url'; - const TRACKING_MESSAGE_NAME = 'mail_dhl'; @@ -49,6 +51,7 @@ class DHL extends AbstractDeliveryModule return self::$prices; } + public function postActivation(ConnectionInterface $con = null) { self::setConfigValue(self::WEBSERVICE_URL, "https://www.dhl.com/fr-fr/home/suivi.html?tracking-id="); @@ -58,7 +61,7 @@ class DHL extends AbstractDeliveryModule // Create DHL shipping zones for home delivery $moduleId = self::getModuleId(); - $moduleConfiguration = json_decode(file_get_contents(__DIR__. '/Config/prices.json')); + $moduleConfiguration = json_decode(file_get_contents(__DIR__. DHL::JSON_PRICE_RESOURCE)); if (false === $moduleConfiguration) { throw new TheliaProcessException("Invalid JSON configuration for DHL module"); } @@ -99,6 +102,7 @@ class DHL extends AbstractDeliveryModule } } + public function isValidDelivery(Country $country) { if (null !== $area = $this->getAreaForCountry($country)) { @@ -120,7 +124,6 @@ class DHL extends AbstractDeliveryModule } } } - return false; } @@ -190,7 +193,20 @@ class DHL extends AbstractDeliveryModule $cartWeight ); - return $postage; + $orderPostage = new OrderPostage(); + $taxRule = TaxRuleQuery::create()->findOneByIsDefault(true); + + $tax = (new Calculator()) + ->loadTaxRuleWithoutProduct($taxRule, $country) + ->getTaxAmountFromTaxedPrice($postage); + + $orderPostage->setAmount($postage); + $orderPostage->setAmountTax($tax); + $orderPostage->setTaxRuleTitle( + $taxRule->setLocale($this->getRequest()->getSession()->getLang()->getLocale())->getTitle() + ); + + return $orderPostage; } /** diff --git a/local/modules/DHL/Form/Configuration.php b/local/modules/DHL/Form/Configuration.php index 642d6647..2c9a97f6 100644 --- a/local/modules/DHL/Form/Configuration.php +++ b/local/modules/DHL/Form/Configuration.php @@ -3,6 +3,7 @@ namespace DHL\Form; use DHL\DHL; +use Symfony\Component\Validator\Constraints\NotBlank; use Thelia\Form\BaseForm; /** @@ -19,6 +20,7 @@ class Configuration extends BaseForm DHL::WEBSERVICE_URL, 'text', [ + 'constraints' => [new NotBlank()], 'label' => $this->translator->trans('DHL tracking URL', [], DHL::DOMAIN_NAME), 'label_attr' => [ 'help' => $this->translator->trans('This is the URL of the DHL tracking service.', [], DHL::DOMAIN_NAME) diff --git a/local/modules/DHL/EventListener/AreaDeletedListener.php b/local/modules/DHL/Listener/AreaDeletedListener.php similarity index 97% rename from local/modules/DHL/EventListener/AreaDeletedListener.php rename to local/modules/DHL/Listener/AreaDeletedListener.php index c9c7c42a..7a50bcf4 100644 --- a/local/modules/DHL/EventListener/AreaDeletedListener.php +++ b/local/modules/DHL/Listener/AreaDeletedListener.php @@ -1,6 +1,6 @@