ClickAndCollect : module finalisé

This commit is contained in:
2021-03-16 11:22:27 +01:00
parent 27d98adf28
commit 2ad54772ff
16 changed files with 156 additions and 531 deletions

View File

@@ -3,6 +3,8 @@
namespace PlanificationLivraison;
use DateInterval;
use DateTime;
use PointRetrait\Model\PdrScheduleQuery;
use Propel\Runtime\Connection\ConnectionInterface;
use Thelia\Core\Translation\Translator;
use Thelia\Install\Database;
@@ -13,7 +15,17 @@ class PlanificationLivraison extends BaseModule
/** @var string */
const DOMAIN_NAME = 'planificationlivraison';
const FORMAT_DATES = 'd/m/Y';
const FORMAT_DATE_AVEC_JOUR = 'w d/m/Y';
const FORMAT_DATE_COMPLETE = 'Y-m-d H:i:s';
const DAYS_OF_WEEK = [
0 => 'monday',
1 => 'tuesday',
2 => 'wednesday',
3 => 'thursday',
4 => 'friday',
5 => 'saturday',
6 => 'sunday'
];
const CONFIG_API_KEY = 'googlemap_api_key';
const CONFIG_MAP_CENTER_LAT = 'map_center_latitude';
@@ -32,36 +44,53 @@ class PlanificationLivraison extends BaseModule
$database->insertSql(null, array(__DIR__ . '/Config/thelia.sql'));
}
static public function calculateRelativeDate($baseDay)
static public function calculateRelativeDate($baseDay, $placeId = null)
{
$minimumDelayBeforeOrder = PlanificationLivraison::getConfigValue(PlanificationLivraison::CONFIG_PREPARATION_DELAY, 0, "en_US");
$date = new \DateTime();
$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;
if (null !== $baseDay) { // Cas où l'on a choisi une date
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;
}
}
else {
// Cas du Click and Collect où l'on doit prendre la première date dispo
if (null !== $placeId) {
$allPossibleDaysOfWeek = PdrScheduleQuery::create()->filterByIdPlace($placeId)->orderByDay()->find()->getData();
$allPossibleDays = [];
foreach ($allPossibleDaysOfWeek as $theDay) {
$dow = self::DAYS_OF_WEEK[$theDay->getDay()];
array_push($allPossibleDays, date(self::FORMAT_DATE_COMPLETE, strtotime("next $dow", $date->getTimestamp())));
}
$nextPossibleDay = new DateTime(min($allPossibleDays));
}
}
return $nextPossibleDay;