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:
55
local/modules/LivraisonForfaitaire/LivraisonForfaitaire.php
Normal file
55
local/modules/LivraisonForfaitaire/LivraisonForfaitaire.php
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user