75 lines
2.5 KiB
PHP
75 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace LivraisonParSecteurs\Hook;
|
|
|
|
use LivraisonParSecteurs\LivraisonParSecteurs;
|
|
use LivraisonParSecteurs\Model\LpsAreaCityQuery;
|
|
use Propel\Runtime\Exception\PropelException as PropelException;
|
|
use Propel\Runtime\Propel;
|
|
use Thelia\Core\Event\Hook\HookRenderEvent;
|
|
use Thelia\Core\Hook\BaseHook;
|
|
use Thelia\Core\Translation\Translator;
|
|
use Thelia\Exception\TheliaProcessException;
|
|
use Thelia\Model\AddressQuery;
|
|
use Thelia\Module\Exception\DeliveryException;
|
|
|
|
class FrontHook extends BaseHook
|
|
{
|
|
|
|
public function onOrderDeliveryExtra(HookRenderEvent $event)
|
|
{
|
|
$con = Propel::getConnection();
|
|
|
|
$addressId = $this->getRequest()->getSession()->getOrder()->getChoosenDeliveryAddress();
|
|
$zipcode = AddressQuery::create()->filterById($addressId)->findOne($con)->getZipcode();
|
|
try {
|
|
$areaId = LpsAreaCityQuery::create()->findOneByZipcode($zipcode)->getIdArea();
|
|
}
|
|
catch (PropelException $e) {
|
|
throw new DeliveryException(
|
|
Translator::getInstance()->trans("This module cannot be used on the current cart."));
|
|
}
|
|
|
|
$event->add(
|
|
$this->render(
|
|
'order-delivery-extra.html',
|
|
[
|
|
'module_id' => LivraisonParSecteurs::getModuleId(),
|
|
'address_id' => $addressId,
|
|
'area_id' => $areaId
|
|
]
|
|
)
|
|
);
|
|
}
|
|
|
|
|
|
public function displayDeliveryDate(HookRenderEvent $event)
|
|
{
|
|
$order = $this->getSession()->getOrder();
|
|
if ((null !== $order) && $order->getDeliveryModuleId() == LivraisonParSecteurs::getModuleId())
|
|
{
|
|
$sessionData = $this->getSession()->get('lpsData');
|
|
$selectedDay = $sessionData->getDeliveryDate();
|
|
$beginTime = $sessionData->getDeliveryStartTime();
|
|
$endTime = $sessionData->getDeliveryEndTime();
|
|
|
|
if ( (null !== $selectedDay) && (null !== $beginTime) && (null !== $endTime) )
|
|
{
|
|
$event->add(
|
|
$this->render(
|
|
'delivery-address.html', [
|
|
'day' => $selectedDay,
|
|
'begin_time' => $beginTime,
|
|
'end_time' => $endTime
|
|
])
|
|
);
|
|
}
|
|
else
|
|
throw new TheliaProcessException("LivraisonParSecteurs : Impossible de récupérer les données de session LpsData");
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|