Quelques corrections + init du module ClickAndCollect
This commit is contained in:
62
local/modules/ClickAndCollect/ClickAndCollect.php
Normal file
62
local/modules/ClickAndCollect/ClickAndCollect.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace ClickAndCollect;
|
||||
|
||||
use PointRetrait\Model\PdrPlacesQuery;
|
||||
use PointRetrait\Model\PdrScheduleQuery;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Model\Country;
|
||||
use Thelia\Model\OrderPostage;
|
||||
use Thelia\Module\AbstractDeliveryModule;
|
||||
use Thelia\Module\Exception\DeliveryException;
|
||||
|
||||
class ClickAndCollect extends AbstractDeliveryModule
|
||||
{
|
||||
/** @var string */
|
||||
const DOMAIN_NAME = 'clickandcollect';
|
||||
const MODULE_URL = '/admin/module/ClickAndCollect';
|
||||
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate and return delivery price in the shop's default currency
|
||||
*
|
||||
* @param Country $country the country to deliver to.
|
||||
*
|
||||
* @return OrderPostage|float the delivery price
|
||||
* @throws DeliveryException if the postage price cannot be calculated.
|
||||
*/
|
||||
public function getPostage(Country $country)
|
||||
{
|
||||
if (! $this->isValidDelivery($country)) {
|
||||
throw new DeliveryException(
|
||||
Translator::getInstance()->trans("This module cannot be used on the current cart.")
|
||||
);
|
||||
}
|
||||
|
||||
$price = 0;
|
||||
if (null !== $chosenPlace = $this->getRequest()->get(('cnc-choosen-place'))) {
|
||||
$placeId = PdrScheduleQuery::create()->findOneById($chosenPlace)->getIdPlace();
|
||||
$price = PdrPlacesQuery::create()->findOneById($placeId)->getPrice();
|
||||
}
|
||||
|
||||
return $price;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user