Files
sterivein/local/modules/LivraisonForfaitaire/LivraisonForfaitaire.php

56 lines
1.5 KiB
PHP

<?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);
}
}