Files
aux-bieaux-legumes/local/modules/LivraisonParSecteurs/Hook/FrontHook.php

47 lines
1.4 KiB
PHP

<?php
namespace LivraisonParSecteurs\Hook;
use LivraisonParSecteurs\LivraisonParSecteurs;
use LivraisonParSecteurs\Model\Base\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\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
]
)
);
}
}