PlanificationLivraison : on avance sur les templates d'email

This commit is contained in:
2021-03-09 21:31:05 +01:00
parent c97324ff5f
commit 1196868062
42 changed files with 556 additions and 512 deletions

View File

@@ -14,11 +14,18 @@
<hook id="pdr.admin.hook" class="PointRetrait\Hook\AdminHook">
<tag name="hook.event_listener" event="home.block" type="back" method="displayScheduledWithdrawals" />
<tag name="hook.event_listener" event="main.in-top-menu-items" type="back" method="onMainTopMenuTools" />
<tag name="hook.event_listener" event="order-edit.bill-delivery-address" type="back" method="displayDeliveryDate" />
<argument type="service" id="thelia.securityContext"/>
</hook>
<hook id="pdr.front.hook" class="PointRetrait\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="displayWithdrawalDate" />
</hook>
<hook id="pdr.email.hookmanager" class="PointRetrait\Hook\EmailHook">
<tag name="hook.event_listener" event="email-html.order-confirmation.delivery-address" type="email" method="displayDeliveryDateWithinEmail" />
<tag name="hook.event_listener" event="email-html.order-notification.before-products" type="email" method="displayCompleteInformationWithinEmail" />
</hook>
</hooks>

View File

@@ -2,6 +2,7 @@
namespace PointRetrait\Form;
use PlanificationLivraison\PlanificationLivraison;
use PointRetrait\PointRetrait;
use Thelia\Form\BaseForm;
use Symfony\Component\Validator\Constraints;
@@ -25,7 +26,7 @@ class CreateScheduleForm extends BaseForm
"constraints" => [new Constraints\NotBlank()]
])
->add("day", "choice", [
"choices" => PointRetrait::getDayLabel(null),
"choices" => PlanificationLivraison::getDayLabel(null),
"label" => $this->translator->trans("Withdrawal day", [], PointRetrait::MESSAGE_DOMAIN),
"label_attr" => ["for" => "attr-place-schedule-day"],
"required" => true,

View File

@@ -2,6 +2,7 @@
namespace PointRetrait\Form;
use PlanificationLivraison\PlanificationLivraison;
use PointRetrait\PointRetrait;
use Thelia\Form\BaseForm;
use Symfony\Component\Validator\Constraints;
@@ -31,7 +32,7 @@ class UpdateScheduleForm extends BaseForm
"constraints" => [new Constraints\NotBlank()]
])
->add("day", "choice", [
"choices" => PointRetrait::getDayLabel(null),
"choices" => PlanificationLivraison::getDayLabel(null),
"label" => $this->translator->trans("Withdrawal day", [], PointRetrait::MESSAGE_DOMAIN),
"label_attr" => ["for" => "attr-place-schedule-day"],
"required" => true,

View File

@@ -2,6 +2,7 @@
namespace PointRetrait\Form;
use PlanificationLivraison\PlanificationLivraison;
use PointRetrait\PointRetrait;
use Thelia\Form\BaseForm;
use Symfony\Component\Validator\Constraints;
@@ -25,7 +26,7 @@ class ViewScheduleForm extends BaseForm
"constraints" => [new Constraints\NotBlank()]
])
->add("day", "choice", [
"choices" => PointRetrait::getDayLabel(null),
"choices" => PlanificationLivraison::getDayLabel(null),
"label" => $this->translator->trans("Delivery day", [], PointRetrait::MESSAGE_DOMAIN),
"label_attr" => ["for" => "attr-place-schedule-day"],
"required" => true,

View File

@@ -51,4 +51,31 @@ class AdminHook extends BaseHook
}
}
/* Pour intégrer la date prévue de retrait dans différents formulaires (email, backOffice, ...) */
public function displayDeliveryDate(HookRenderEvent $event)
{
$moduleId = $event->getArgument('module');
$orderId = $event->getArgument('order_id');
if ((null !== $orderId) && ($moduleId == PointRetrait::getModuleId()))
{
$sessionData = $this->getSession()->get('pdrData');
$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
])
);
}
}
}
}

View File

@@ -0,0 +1,83 @@
<?php
namespace PointRetrait\Hook;
use PlanificationLivraison\Model\SessionData;
use PointRetrait\Model\PdrPlacesQuery;
use PointRetrait\PointRetrait;
use Thelia\Core\Event\Hook\HookRenderEvent;
use Thelia\Core\Hook\BaseHook;
use Thelia\Exception\TheliaProcessException;
use Thelia\Model\OrderQuery;
class EmailHook extends BaseHook
{
public function displayDeliveryDateWithinEmail(HookRenderEvent $event)
{
$moduleId = $event->getArgument('module');
$orderId = $event->getArgument('order');
if ((null !== $orderId) && ($moduleId == PointRetrait::getModuleId()))
{
$sessionData = $this->getSession()->get('pdrData');
$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("PointRetrait : Impossible de récupérer les données de session SessionData");
}
}
public function displayCompleteInformationWithinEmail(HookRenderEvent $event)
{
$orderId = $event->getArgument('order');
$moduleId = OrderQuery::create()->findOneById($orderId)->getDeliveryModuleId();
if ((null !== $orderId) && ($moduleId == PointRetrait::getModuleId()))
{
$sessionData = $this->getSession()->get('pdrData');
$selectedDay = $sessionData->getDeliveryDate();
$beginTime = $sessionData->getDeliveryStartTime();
$endTime = $sessionData->getDeliveryEndTime();
if ( (null !== $selectedDay) && (null !== $beginTime) && (null !== $endTime) )
{
$place = PdrPlacesQuery::create()->findOneById($sessionData->getPlaceId());
$event->add(
$this->render(
'delivery-address-full.html', [
'day' => $selectedDay,
'begin_time' => $beginTime,
'end_time' => $endTime,
'placeName' => $place->getTitle(),
'address1' => $place->getAddress1() . ' ' . $place->getAddress2(),
'zipcode' => $place->getZipcode(),
'city' => $place->getCity()
])
);
}
else
throw new TheliaProcessException("PointRetrait : Impossible de récupérer les données de session SessionData");
}
}
}

View File

@@ -2,9 +2,11 @@
namespace PointRetrait\Hook;
use PlanificationLivraison\Model\SessionData;
use PointRetrait\PointRetrait;
use Thelia\Core\Event\Hook\HookRenderEvent;
use Thelia\Core\Hook\BaseHook;
use Thelia\Exception\TheliaProcessException;
class FrontHook extends BaseHook
{
@@ -21,6 +23,34 @@ class FrontHook extends BaseHook
);
}
public function displayWithdrawalDate(HookRenderEvent $event)
{
$order = $this->getSession()->getOrder();
if ((null !== $order) && $order->getDeliveryModuleId() == PointRetrait::getModuleId())
{
$sessionData = $this->getSession()->get('pdrData');
$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,
'place_id' => $sessionData->getPlaceId()
])
);
}
else
throw new TheliaProcessException("PointRetrait : Impossible de récupérer les données de session sessionData : ");
}
}
}

View File

@@ -26,6 +26,7 @@ return array(
'Module name' => 'Point de Retrait AuxBieauxLegumes',
'My places' => 'Point de retrait AuxBieauxLegumes',
'My withdrawal places' => 'Mes points de retrait AuxBieauxLegumes',
'Order to withdraw' => 'Commande à retirer au point retrait suivant',
'Order number' => 'N° de commande',
'Place name' => 'Nom du point de retrait',
'Please select a delivery place' => 'Veuillez sélectionner un point de retrait',
@@ -37,18 +38,13 @@ return array(
'Title of config view' => 'Point retrait AuxBieauxLegumes - Configuration',
'There is no order to withdraw' => 'Aucune commande à retirer en Point Retrait',
'There is no schedule for this place' => 'Aucun créneau de retrait sur ce point de retrait',
'When to get your order' => 'Quand pouvez-vous retirer votre commande ?',
'Where to get your order' => 'Où pouvez-vous la récupérer ?',
'Withdrawal beginning time' => 'Début du retrait',
'Withdrawal day' => 'Jour de retrait',
'Withdrawal days' => 'Jours de retrait',
'Withdrawal ending time' => 'Fin du retrait',
'Withdrawal price' => 'Coût du retrait',
'Zipcode' => 'Code postal',
'Monday' => 'Lundi',
'Tuesday' => 'Mardi',
'Wednesday' => 'Mercredi',
'Thursday' => 'Jeudi',
'Friday' => 'Vendredi',
'Saturday' => 'Samedi',
'Sunday' => 'Dimanche',
'' => '',
);

View File

@@ -2,6 +2,7 @@
namespace PointRetrait\Loop;
use PlanificationLivraison\PlanificationLivraison;
use PointRetrait\Model\PdrPlacesQuery;
use PointRetrait\Model\PdrScheduleQuery;
use PointRetrait\PointRetrait;
@@ -39,7 +40,7 @@ class GeneralLoop extends BaseLoop implements PropelSearchLoopInterface
->orderByDay();
$deliveryDays = "";
foreach ($schedule as $day) {
$deliveryDays .= PointRetrait::getDayLabel($day->getDay()) . ', ';
$deliveryDays .= PlanificationLivraison::getDayLabel($day->getDay()) . ', ';
}
$deliveryDays = substr($deliveryDays, 0, strlen($deliveryDays)-2);

View File

@@ -2,6 +2,7 @@
namespace PointRetrait\Loop;
use PlanificationLivraison\PlanificationLivraison;
use PointRetrait\Model\PdrScheduleQuery;
use PointRetrait\PointRetrait;
use Thelia\Core\Template\Element\BaseLoop;
@@ -37,10 +38,10 @@ class ScheduleLoop extends BaseLoop implements PropelSearchLoopInterface
->set("ID", $pdr_schedule->getId())
->set("PLACE_ID", $pdr_schedule->getIdPlace())
->set("DAY", $pdr_schedule->getDay())
->set("DAY_LABEL", PointRetrait::getDayLabel($pdr_schedule->getDay()))
->set("DAY_LABEL", PlanificationLivraison::getDayLabel($pdr_schedule->getDay()))
->set("BEGIN", $pdr_schedule->getBeginTime())
->set("END", $pdr_schedule->getEndTime())
->set("CALCULATED_DAY", PointRetrait::calculateRelativeDate($pdr_schedule->getDay())->format(PointRetrait::FORMAT_DATES))
->set("CALCULATED_DAY", PlanificationLivraison::calculateRelativeDate($pdr_schedule->getDay())->format(PlanificationLivraison::FORMAT_DATES))
;
$loopResult->addRow($loopResultRow);
}

View File

@@ -2,19 +2,15 @@
namespace PointRetrait;
use PlanificationLivraison\PlanificationLivraison;
use PointRetrait\Model\PdrPlacesQuery;
use PointRetrait\Model\PdrScheduleQuery;
use Propel\Runtime\Connection\ConnectionInterface;
use Propel\Runtime\Propel;
use Thelia\Core\Translation\Translator;
use Thelia\Install\Database;
use Thelia\Model\AddressQuery;
use Thelia\Model\Country;
use Thelia\Model\OrderPostage;
use Thelia\Module\AbstractDeliveryModule;
use Thelia\Module\Exception\DeliveryException;
use DateInterval;
@@ -24,13 +20,6 @@ class PointRetrait extends AbstractDeliveryModule
const DOMAIN_NAME = 'pointretrait';
const MESSAGE_DOMAIN = 'pointretrait';
const MODULE_URL = '/admin/module/PointRetrait';
const FORMAT_DATES = 'd/m/Y';
const PDR_PLACE_SCHEDULE_ID = 'pdr_place_schedule_id';
const PDR_CHOSEN_PLACE = 'pdr_chosen_place';
const PDR_DELIVERY_DATE = 'pdr_delivery_date';
const PDR_DELIVERY_BEGIN_TIME = 'pdr_begin_time';
const PDR_DELIVERY_END_TIME = 'pdr_end_time';
/**
@@ -86,59 +75,4 @@ class PointRetrait extends AbstractDeliveryModule
}
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];
}
static public function calculateRelativeDate($baseDay)
{
$minimumDelayBeforeOrder = PlanificationLivraison::getConfigValue(PlanificationLivraison::CONFIG_PREPARATION_DELAY, 0, "en_US");
$date = new \DateTime();
$date->add(new DateInterval('P'. $minimumDelayBeforeOrder . 'D'));
$nextPossibleDay = '';
switch ($baseDay) {
case 0 :
$nextPossibleDay = $date->modify('next monday');
break;
case 1 :
$nextPossibleDay = $date->modify('next tuesday');
break;
case 2 :
$nextPossibleDay = $date->modify('next wednesday');
break;
case 3 :
$nextPossibleDay = $date->modify('next thursday');
break;
case 4 :
$nextPossibleDay = $date->modify('next friday');
break;
case 5 :
$nextPossibleDay = $date->modify('next saturday');
break;
case 6 :
$nextPossibleDay = $date->modify('next sunday');
break;
}
return $nextPossibleDay;
}
}

View File

@@ -63,4 +63,9 @@
.pin-pdr {
height: 25px;
margin-left: 12px;
}
.titre {
font-weight: 900;
color: red;
}

View File

@@ -0,0 +1,8 @@
<tr><td>&nbsp;</td></tr>
<tr style="background-color:#1A712C; color:white">
<th>{intl l="Scheduled date" d="pointretrait"}</th>
<td>{$day} entre {format_date date=$begin_time format="H\hi"} et {format_date date=$end_time format="H\hi"}</td>
</tr>
<tr><td>&nbsp;</td></tr>

View File

@@ -0,0 +1,18 @@
<div class="panel panel-default col-md-12">
<div class="panel-heading"><strong>{intl l="Scheduled date" d="pointretrait"}</strong></div>
<div class="panel-body">
<span>{$day} entre {format_date date=$begin_time format="H\hi"} et {format_date date=$end_time format="H\hi"}</span>
</div>
</div>
<div class="panel panel-default col-md-12">
<div class="panel-heading"><strong>{intl l="Place name" d="pointretrait"}</strong></div>
<div class="panel-body">
<span>{format_address organization="{$placeName}"
address_line1="{$address1}"
postal_code="{$zipcode}"
locality="{$city}"
locale=$locale}
</span>
</div>
</div>

View File

@@ -0,0 +1,6 @@
<div class="panel panel-default col-sm-6">
<div class="panel-heading">{intl l="Scheduled date" d="pointretrait"}</div>
<div class="panel-body">
<span>{$day} entre {format_date date=$begin_time format="H\hi"} et {format_date date=$end_time format="H\hi"}</span>
</div>
</div>

View File

@@ -0,0 +1,24 @@
{strip}
<div class="panel panel-default col-sm-6">
{loop type="pdr_places" name="place-loop" id={$place_id}}
<div class="panel-heading">{intl l="Order to withdraw" d="pointretrait"}</div>
<div class="panel-body">
<span class="org"><strong>{$TITLE}</strong></span>
<address class="adr">
<span class="street-address">{$ADDRESS1}</span><br>
{if $ADDRESS2 != ""}
<span class="street-address">{$ADDRESS2}</span><br>
{/if}
<span class="locality">{$ZIPCODE} {$CITY}</span>
</address>
</div>
{/loop}
<div class="panel-heading">{intl l="Scheduled date" d="pointretrait"}</div>
<div class="panel-body">
<span>{$day} entre {format_date date=$begin_time format="H\hi"} et {format_date date=$end_time format="H\hi"}</span>
</div>
</div>
{/strip}