Encore des modifs sur module DHL

This commit is contained in:
2020-12-09 08:53:27 +01:00
parent 92dae7030b
commit bd13055424
5 changed files with 37 additions and 9 deletions

View File

@@ -20,10 +20,8 @@
<argument type="service" id="mailer"/> <argument type="service" id="mailer"/>
<tag name="kernel.event_subscriber"/> <tag name="kernel.event_subscriber"/>
</service> </service>
</services>
<services> <service id="area.deleted.listener" class="DHL\Listener\AreaDeletedListener" scope="request">
<service id="area.deleted.listener" class="DHL\EventListener\AreaDeletedListener" scope="request">
<tag name="kernel.event_subscriber"/> <tag name="kernel.event_subscriber"/>
<argument type="service" id="request" /> <argument type="service" id="request" />
</service> </service>

View File

@@ -1,5 +1,17 @@
SET FOREIGN_KEY_CHECKS = 0; SET FOREIGN_KEY_CHECKS = 0;
-- Suppression de la table des tarfis
DROP TABLE IF EXISTS `dhl_delivery_price`; 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; SET FOREIGN_KEY_CHECKS = 1;

View File

@@ -17,8 +17,11 @@ use Thelia\Model\CountryArea;
use Thelia\Model\CountryQuery; use Thelia\Model\CountryQuery;
use Thelia\Model\MessageQuery; use Thelia\Model\MessageQuery;
use Thelia\Model\ModuleConfigQuery; use Thelia\Model\ModuleConfigQuery;
use Thelia\Model\OrderPostage;
use Thelia\Model\TaxRuleQuery;
use Thelia\Module\AbstractDeliveryModule; use Thelia\Module\AbstractDeliveryModule;
use Thelia\Module\Exception\DeliveryException; use Thelia\Module\Exception\DeliveryException;
use Thelia\TaxEngine\Calculator;
/** /**
* Class DHL * Class DHL
@@ -33,9 +36,8 @@ class DHL extends AbstractDeliveryModule
private static $prices = null; private static $prices = null;
const DOMAIN_NAME = 'dhl'; const DOMAIN_NAME = 'dhl';
const JSON_PRICE_RESOURCE = "/Config/prices.json"; const JSON_PRICE_RESOURCE = '/Config/prices.json';
const WEBSERVICE_URL = 'tracking_url'; const WEBSERVICE_URL = 'tracking_url';
const TRACKING_MESSAGE_NAME = 'mail_dhl'; const TRACKING_MESSAGE_NAME = 'mail_dhl';
@@ -49,6 +51,7 @@ class DHL extends AbstractDeliveryModule
return self::$prices; return self::$prices;
} }
public function postActivation(ConnectionInterface $con = null) public function postActivation(ConnectionInterface $con = null)
{ {
self::setConfigValue(self::WEBSERVICE_URL, "https://www.dhl.com/fr-fr/home/suivi.html?tracking-id="); 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 // Create DHL shipping zones for home delivery
$moduleId = self::getModuleId(); $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) { if (false === $moduleConfiguration) {
throw new TheliaProcessException("Invalid JSON configuration for DHL module"); throw new TheliaProcessException("Invalid JSON configuration for DHL module");
} }
@@ -99,6 +102,7 @@ class DHL extends AbstractDeliveryModule
} }
} }
public function isValidDelivery(Country $country) public function isValidDelivery(Country $country)
{ {
if (null !== $area = $this->getAreaForCountry($country)) { if (null !== $area = $this->getAreaForCountry($country)) {
@@ -120,7 +124,6 @@ class DHL extends AbstractDeliveryModule
} }
} }
} }
return false; return false;
} }
@@ -190,7 +193,20 @@ class DHL extends AbstractDeliveryModule
$cartWeight $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;
} }
/** /**

View File

@@ -3,6 +3,7 @@
namespace DHL\Form; namespace DHL\Form;
use DHL\DHL; use DHL\DHL;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Form\BaseForm; use Thelia\Form\BaseForm;
/** /**
@@ -19,6 +20,7 @@ class Configuration extends BaseForm
DHL::WEBSERVICE_URL, DHL::WEBSERVICE_URL,
'text', 'text',
[ [
'constraints' => [new NotBlank()],
'label' => $this->translator->trans('DHL tracking URL', [], DHL::DOMAIN_NAME), 'label' => $this->translator->trans('DHL tracking URL', [], DHL::DOMAIN_NAME),
'label_attr' => [ 'label_attr' => [
'help' => $this->translator->trans('This is the URL of the DHL tracking service.', [], DHL::DOMAIN_NAME) 'help' => $this->translator->trans('This is the URL of the DHL tracking service.', [], DHL::DOMAIN_NAME)

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace DHL\EventListener; namespace DHL\Listener;
use DHL\DHL; use DHL\DHL;
use DHL\Model\Config\DHLConfigValue; use DHL\Model\Config\DHLConfigValue;