Création d'un module LivraisonForfaitaire pour pouvoir choisir les frais de livraisons sur les commandes passées depuis le backOffice

This commit is contained in:
2021-07-04 13:09:18 +02:00
parent 8992cbee62
commit ebb1376015
12 changed files with 245 additions and 23 deletions

View File

@@ -0,0 +1,55 @@
<?php
namespace LivraisonForfaitaire;
use Thelia\Model\Country;
use Thelia\Module\AbstractDeliveryModule;
class LivraisonForfaitaire extends AbstractDeliveryModule
{
/** @var string */
const DOMAIN_NAME = 'livraisonforfaitaire';
/**
* calculate and return delivery price
*
* @param Country $country
* @throws \Exception
*
* @return mixed
*/
public function getPostage(Country $country)
{
if (null !== $area = $this->getAreaForCountry($country)) {
$select = $this->getRequest()->get('select-forfait');
if ($select !== null && $select !== "")
$postage = $select;
else
$postage = $area->getPostage();
} else {
throw new \InvalidArgumentException("Country or Area should not be null");
}
return $postage === null ? 0 : $postage;
}
/**
* This method is called by the Delivery loop, to check if the current module has to be displayed to the customer.
* Override it to implements your delivery rules/
*
* If you return true, the delivery method will de displayed to the customer
* If you return false, the delivery method will not be displayed
*
* @param Country $country the country to deliver to.
*
* @return boolean
*/
public function isValidDelivery(Country $country)
{
// We should find an area for the country.
return null !== $this->getAreaForCountry($country);
}
}