Premiers écrans sur module PointRetrait

This commit is contained in:
2021-02-26 21:10:10 +01:00
parent 86d849a059
commit 1276d9bf3d
34 changed files with 1200 additions and 100 deletions

View File

@@ -1,28 +1,98 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace PointRetrait;
use Thelia\Module\BaseModule;
use Propel\Runtime\Connection\ConnectionInterface;
use Propel\Runtime\Propel;
use Thelia\Core\Translation\Translator;
use Thelia\Install\Database;
use Thelia\Model\Country;
use Thelia\Model\OrderPostage;
use Thelia\Module\AbstractDeliveryModule;
use Thelia\Module\Exception\DeliveryException;
class PointRetrait extends BaseModule
class PointRetrait extends AbstractDeliveryModule
{
/** @var string */
const DOMAIN_NAME = 'pointretrait';
const MESSAGE_DOMAIN = 'pointretrait';
/*
* You may now override BaseModuleInterface methods, such as:
* install, destroy, preActivation, postActivation, preDeactivation, postDeactivation
*
* Have fun !
/**
* @param ConnectionInterface|null $con
*/
public function postActivation(ConnectionInterface $con = null)
{
$database = new Database($con->getWrappedConnection());
$database->insertSql(null, array(__DIR__ . '/Config/thelia.sql'));
}
/**
* 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;
$con = Propel::getConnection();
// $currentAddressId = $this->getRequest()->getSession()->getOrder()->getChoosenDeliveryAddress();
// if (!empty($currentAddressId)) {
// $zipcode = AddressQuery::create()->filterById($currentAddressId)->findOne($con)->getZipcode();
// $areaId = LpsAreaCityQuery::create()->findOneByZipcode($zipcode)->getIdArea();
// $price = LpsAreaQuery::create()->findOneById($areaId)->getPrice();
// }
return $price;
}
static public function getDayLabel($int)
{
$translator = Translator::getInstance();
$days = [
$translator->trans("Monday", [], PointRetrait::MESSAGE_DOMAIN),
$translator->trans("Tuesday", [], PointRetrait::MESSAGE_DOMAIN),
$translator->trans("Wednesday", [], PointRetrait::MESSAGE_DOMAIN),
$translator->trans("Thursday", [], PointRetrait::MESSAGE_DOMAIN),
$translator->trans("Friday", [], PointRetrait::MESSAGE_DOMAIN),
$translator->trans("Saturday", [], PointRetrait::MESSAGE_DOMAIN),
$translator->trans("Sunday", [], PointRetrait::MESSAGE_DOMAIN)
];
if ($int === null)
return $days;
else
return $days[$int];
}
}