LivraisonParSecteurs : rajout de quelques infos dans le template front
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
</hook>
|
||||
<hook id="lps.front.hookmanager" class="LivraisonParSecteurs\Hook\FrontHook">
|
||||
<tag name="hook.event_listener" event="order-delivery.extra" type="front" method="onOrderDeliveryExtra" />
|
||||
<tag name="hook.event_listener" event="order-invoice.delivery-address" type="front" method="displayDeliveryDate" />
|
||||
</hook>
|
||||
</hooks>
|
||||
|
||||
|
||||
@@ -41,6 +41,29 @@ class FrontHook extends BaseHook
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function displayDeliveryDate(HookRenderEvent $event)
|
||||
{
|
||||
if ((null !== $order = $this->getSession()->getOrder()) && $order->getDeliveryModuleId() == LivraisonParSecteurs::getModuleId())
|
||||
{
|
||||
$selectedDay = $this->getSession()->get(LivraisonParSecteurs::LPS_DELIVERY_DATE);
|
||||
$beginTime = $this->getSession()->get(LivraisonParSecteurs::LPS_DELIVERY_BEGIN_TIME);
|
||||
$endTime = $this->getSession()->get(LivraisonParSecteurs::LPS_DELIVERY_END_TIME);
|
||||
|
||||
if ( (null !== $selectedDay) && (null !== $beginTime) && (null !== $endTime) )
|
||||
{
|
||||
$event->add(
|
||||
$this->render(
|
||||
'delivery-address.html', [
|
||||
'day' => $selectedDay,
|
||||
'begin_time' => $beginTime,
|
||||
'end_time' => $endTime
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -21,9 +21,13 @@ class LivraisonParSecteurs extends AbstractDeliveryModule
|
||||
{
|
||||
/** @var string */
|
||||
const DOMAIN_NAME = 'livraisonparsecteurs';
|
||||
const MESSAGE_DOMAIN = "livraisonparsecteurs";
|
||||
const MESSAGE_DOMAIN = 'livraisonparsecteurs';
|
||||
const VARIABLE_MINIMUM_DELAY = 'minimum_delay_before_order';
|
||||
|
||||
const LPS_AREA_SCHEDULE_ID = 'lps_area_schedule_id';
|
||||
const LPS_CHOSEN_ADDRESS = 'lps_chosen_delivery_address';
|
||||
const LPS_DELIVERY_DATE = 'lps_delivery_date';
|
||||
const LPS_DELIVERY_BEGIN_TIME = 'lps_begin_time';
|
||||
const LPS_DELIVERY_END_TIME = 'lps_end_time';
|
||||
|
||||
/**
|
||||
* @param ConnectionInterface|null $con
|
||||
@@ -117,6 +121,7 @@ class LivraisonParSecteurs extends AbstractDeliveryModule
|
||||
$date = new \DateTime();
|
||||
$date->add(new DateInterval('P'. $minimumDelayBeforeOrder . 'D'));
|
||||
|
||||
$nextPossibleDay = '';
|
||||
switch ($baseDay) {
|
||||
case 0 :
|
||||
$nextPossibleDay = $date->modify('next monday');
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace LivraisonParSecteurs\Loop;
|
||||
|
||||
use LivraisonParSecteurs\LivraisonParSecteurs;
|
||||
use LivraisonParSecteurs\Model\LpsAreaSchedule;
|
||||
use LivraisonParSecteurs\Model\LpsAreaScheduleQuery;
|
||||
use Thelia\Core\Template\Element\BaseLoop;
|
||||
use Thelia\Core\Template\Element\LoopResult;
|
||||
use Thelia\Core\Template\Element\LoopResultRow;
|
||||
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Model\OrderQuery;
|
||||
|
||||
/**
|
||||
* @package LivraisonParSecteurs\Loop
|
||||
*/
|
||||
class SelectedDeliveryDate extends BaseLoop implements PropelSearchLoopInterface
|
||||
{
|
||||
protected function getArgDefinitions()
|
||||
{
|
||||
return new ArgumentCollection(
|
||||
Argument::createIntTypeArgument('order_id')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function buildModelCriteria()
|
||||
{
|
||||
if (null !== $orderId = $this->getOrderId())
|
||||
{
|
||||
|
||||
if (null !== $order = OrderQuery::create()->findPk($orderId))
|
||||
{
|
||||
return MondialRelayPickupAddressQuery::create()
|
||||
->filterByOrderAddressId($order->getDeliveryOrderAddressId());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function parseResults(LoopResult $loopResult)
|
||||
{
|
||||
foreach ($loopResult->getResultDataCollection() as $item) {
|
||||
$loopResultRow = new LoopResultRow($item);
|
||||
$loopResultRow
|
||||
->set("ID", $relayData['id'])
|
||||
->set("LATITUDE", $relayData['latitude'])
|
||||
->set("LONGITUDE", $relayData['longitude'])
|
||||
->set("ZIPCODE", $relayData['zipcode'])
|
||||
->set("CITY", $relayData['city'])
|
||||
->set("COUNTRY", $relayData['country'])
|
||||
->set("NAME", $relayData['name'])
|
||||
->set("ADDRESS", $relayData['address'])
|
||||
->set("DISTANCE", $relayData['distance'])
|
||||
->set("OPENINGS", $relayData['openings'])
|
||||
;
|
||||
|
||||
$loopResult->addRow($loopResultRow);
|
||||
}
|
||||
|
||||
return $loopResult;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
{strip}
|
||||
|
||||
<div class="panel panel-default col-sm-6">
|
||||
{loop type="address" name="delivery-address" id={order attr="delivery_address"}}
|
||||
<div class="panel-heading">{intl l="Delivery address"}</div>
|
||||
<div class="panel-body">
|
||||
<span class="fn">{loop type="title" name="customer.title.info" id=$TITLE}{$SHORT}{/loop} {$LASTNAME|upper} {$FIRSTNAME|ucwords}</span>
|
||||
<span class="org">{$COMPANY}</span>
|
||||
<address class="adr">
|
||||
<span class="street-address">{$ADDRESS1}</span><br>
|
||||
{if $ADDRESS2 != ""}
|
||||
<span class="street-address">{$ADDRESS2}</span><br>
|
||||
{/if}
|
||||
{if $ADDRESS3 != ""}
|
||||
<span class="street-address">{$ADDRESS3}</span><br>
|
||||
{/if}
|
||||
<span class="postal-code">{$ZIPCODE} </span>
|
||||
<span class="locality">{$CITY}
|
||||
</address>
|
||||
</div>
|
||||
{/loop}
|
||||
|
||||
<div class="panel-heading">{intl l="Delivery day" d="livraisonparsecteurs"}</div>
|
||||
<div class="panel-body">
|
||||
<span>{$day} entre {format_date date=$begin_time format="H:i"} et {format_date date=$end_time format="H:i"}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/strip}
|
||||
@@ -1,8 +1,6 @@
|
||||
<script type="text/html" id="lps_ui">
|
||||
|
||||
|
||||
<td colspan="3">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-4">
|
||||
{form name="thelia.order.delivery"}
|
||||
|
||||
@@ -39,7 +39,7 @@ class DeliveryListener extends BaseAction implements EventSubscriberInterface
|
||||
* @param OrderEvent $event
|
||||
* @throws \Propel\Runtime\Exception\PropelException
|
||||
*/
|
||||
public function updateCurrentDeliveryAddress(OrderEvent $event, $eventName, EventDispatcherInterface $dispatcher)
|
||||
public function recordCurrentDeliveryAddress(OrderEvent $event, $eventName, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
/** @var Request $request */
|
||||
$request = $this->requestStack->getCurrentRequest();
|
||||
@@ -48,39 +48,74 @@ class DeliveryListener extends BaseAction implements EventSubscriberInterface
|
||||
$session = $request->getSession();
|
||||
|
||||
if ($event->getDeliveryModule() == LivraisonParSecteurs::getModuleId()) {
|
||||
|
||||
$con = Propel::getConnection();
|
||||
$con->beginTransaction();
|
||||
$query = new OrderDeliverySchedule();
|
||||
|
||||
if (null !== $scheduleId = $request->get('lps-choosen-day', null)) {
|
||||
try {
|
||||
$query->setScheduleId($scheduleId);
|
||||
$session->set(LivraisonParSecteurs::LPS_AREA_SCHEDULE_ID, $scheduleId);
|
||||
$session->set(LivraisonParSecteurs::LPS_CHOSEN_ADDRESS, $session->getOrder()->getChoosenDeliveryAddress());
|
||||
|
||||
$query->setDeliveryAddressId($request->getSession()->getOrder()->getChoosenDeliveryAddress());
|
||||
$schedule = LpsAreaScheduleQuery::create()->findOneById($scheduleId);
|
||||
$chosenDate = LivraisonParSecteurs::calculateRelativeDate($schedule->getDay());
|
||||
$scheduleId = $session->get(LivraisonParSecteurs::LPS_AREA_SCHEDULE_ID);
|
||||
$schedule = LpsAreaScheduleQuery::create()->findOneById($scheduleId);
|
||||
|
||||
$format = 'Y-m-d H:i:s';
|
||||
$startDate = DateTime::createFromFormat($format, $chosenDate->format('Y-m-d ') . $schedule->getBeginTime()->format('H:i:s'));
|
||||
$query->setDueDeliveryTimeStart($startDate);
|
||||
$endDate = DateTime::createFromFormat($format, $chosenDate->format('Y-m-d ') . $schedule->getEndTime()->format('H:i:s'));
|
||||
$query->setDueDeliveryTimeEnd($endDate);
|
||||
$chosenDate = LivraisonParSecteurs::calculateRelativeDate($schedule->getDay());
|
||||
|
||||
$query->save($con);
|
||||
$con->commit();
|
||||
}
|
||||
catch (ProcessFileException $e) {
|
||||
throw new TheliaProcessException("PlanificationLivraison : Impossible to record this schedule");
|
||||
}
|
||||
// On sauvegarde la date de livraison choisie avec les heures, pour affichage ultérieur.
|
||||
$completeDay = LivraisonParSecteurs::getDayLabel($schedule->getDay());
|
||||
$completeDay .= " " . $chosenDate->format("d/m");
|
||||
$session->set(LivraisonParSecteurs::LPS_DELIVERY_DATE, $completeDay);
|
||||
$session->set(LivraisonParSecteurs::LPS_DELIVERY_BEGIN_TIME, $schedule->getBeginTime());
|
||||
$session->set(LivraisonParSecteurs::LPS_DELIVERY_END_TIME, $schedule->getEndTime());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OrderEvent $event
|
||||
* @throws \Propel\Runtime\Exception\PropelException
|
||||
*/
|
||||
public function updateCurrentDeliveryAddress(OrderEvent $event)
|
||||
{
|
||||
/** @var Session $session */
|
||||
$session = $this->requestStack->getCurrentRequest()->getSession();
|
||||
|
||||
$order = $event->getOrder();
|
||||
|
||||
$deliveryModuleId = $order->getDeliveryModuleId();
|
||||
if ($deliveryModuleId == LivraisonParSecteurs::getModuleId()) {
|
||||
$scheduleId = $session->get(LivraisonParSecteurs::LPS_AREA_SCHEDULE_ID);
|
||||
$orderId = $order->getId();
|
||||
|
||||
$con = Propel::getConnection();
|
||||
$con->beginTransaction();
|
||||
$query = new OrderDeliverySchedule();
|
||||
try {
|
||||
$query->setOrderId($orderId);
|
||||
$query->setScheduleId($scheduleId);
|
||||
$query->setDeliveryAddressId($session->get('choosenDeliveryAddress'));
|
||||
|
||||
$schedule = LpsAreaScheduleQuery::create()->findOneById($scheduleId);
|
||||
$chosenDate = LivraisonParSecteurs::calculateRelativeDate($schedule->getDay());
|
||||
|
||||
$format = 'Y-m-d H:i:s';
|
||||
$startDate = DateTime::createFromFormat($format, $chosenDate->format('Y-m-d ') . $schedule->getBeginTime()->format('H:i:s'));
|
||||
$query->setDueDeliveryTimeStart($startDate);
|
||||
$endDate = DateTime::createFromFormat($format, $chosenDate->format('Y-m-d ') . $schedule->getEndTime()->format('H:i:s'));
|
||||
$query->setDueDeliveryTimeEnd($endDate);
|
||||
|
||||
$query->save($con);
|
||||
$con->commit();
|
||||
}
|
||||
catch (ProcessFileException $e) {
|
||||
throw new TheliaProcessException("PlanificationLivraison : Impossible to record this schedule");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
TheliaEvents::ORDER_SET_DELIVERY_MODULE => ['updateCurrentDeliveryAddress', 64]
|
||||
TheliaEvents::ORDER_SET_DELIVERY_MODULE => ['recordCurrentDeliveryAddress', 64],
|
||||
TheliaEvents::ORDER_BEFORE_PAYMENT => ['updateCurrentDeliveryAddress', 64]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user