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

@@ -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;
}
/**