Le module MondialRelay n'était pas commité

This commit is contained in:
2020-12-05 09:32:52 +01:00
parent 9572b71f14
commit ef16a65ce8
143 changed files with 16232 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
<?php
/*************************************************************************************/
/* Copyright (c) Franck Allimant, CQFDev */
/* email : thelia@cqfdev.fr */
/* web : http://www.cqfdev.fr */
/* */
/* For the full copyright and license information, please view the LICENSE */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace MondialRelay\Loop;
use MondialRelay\Model\MondialRelayZoneConfiguration;
use MondialRelay\Model\MondialRelayZoneConfigurationQuery;
use Propel\Runtime\ActiveQuery\Criteria;
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;
/**
* Class AreaAttributes
* @package MondialRelay\Loop
* @method int[] getAreaId()
* @method int[] getDeliveryType()
*/
class AreaAttributes extends BaseLoop implements PropelSearchLoopInterface
{
/**
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection
*/
protected function getArgDefinitions()
{
return new ArgumentCollection(
Argument::createIntListTypeArgument('area_id'),
Argument::createIntListTypeArgument('delivery_type')
);
}
public function buildModelCriteria()
{
$query = MondialRelayZoneConfigurationQuery::create();
if (null !== $areaId = $this->getAreaId()) {
$query->filterByAreaId($areaId, Criteria::IN);
}
if (null !== $delivTypes = $this->getDeliveryType()) {
$query->filterByDeliveryType($delivTypes, Criteria::IN);
}
return $query;
}
public function parseResults(LoopResult $loopResult)
{
/** @var MondialRelayZoneConfiguration $item */
foreach ($loopResult->getResultDataCollection() as $item) {
$loopResultRow = new LoopResultRow($item);
$loopResultRow
->set('ID', $item->getId())
->set('DELIVERY_TYPE', $item->getDeliveryType())
->set('DELIVERY_TIME', $item->getDeliveryTime())
->set('AREA_ID', $item->getAreaId())
;
$loopResult->addRow($loopResultRow);
}
return $loopResult;
}
}

View File

@@ -0,0 +1,209 @@
<?php
/*************************************************************************************/
/* Copyright (c) Franck Allimant, CQFDev */
/* email : thelia@cqfdev.fr */
/* web : http://www.cqfdev.fr */
/* */
/* For the full copyright and license information, please view the LICENSE */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace MondialRelay\Loop;
use MondialRelay\Model\MondialRelayDeliveryInsuranceQuery;
use MondialRelay\Model\MondialRelayDeliveryPrice;
use MondialRelay\Model\MondialRelayDeliveryPriceQuery;
use MondialRelay\Model\MondialRelayZoneConfiguration;
use MondialRelay\Model\MondialRelayZoneConfigurationQuery;
use MondialRelay\MondialRelay;
use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Core\Template\Element\ArraySearchLoopInterface;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Model\AreaDeliveryModuleQuery;
use Thelia\Model\Cart;
use Thelia\Model\CountryArea;
use Thelia\Model\CountryAreaQuery;
use Thelia\Model\CountryQuery;
use Thelia\Model\ModuleQuery;
use Thelia\Model\StateQuery;
use Thelia\Type\EnumType;
use Thelia\Type\TypeCollection;
/**
* Class Prices
* @package MondialRelay\Loop
* @method int getCountryId()
* @method int getStateId()
* @method string getMode()
* @method string getInsurance()
*/
class DeliveryPrice extends BaseLoop implements ArraySearchLoopInterface
{
/**
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection
*/
protected function getArgDefinitions()
{
return new ArgumentCollection(
Argument::createIntTypeArgument('country_id', null, true),
Argument::createIntTypeArgument('state_id'),
Argument::createBooleanTypeArgument('insurance', null, false),
new Argument(
'mode',
new TypeCollection(
new EnumType(['home', 'relay', 'all'])
),
null,
true
)
);
}
/**
* @return array
* @throws \Exception
* @throws \Propel\Runtime\Exception\PropelException
*/
public function buildArray()
{
$results = [];
if (null !== $country = CountryQuery::create()->findPk($this->getCountryId())) {
if (null !== $stateId = $this->getStateId()) {
$state = StateQuery::create()->findPk($this->$stateId());
} else {
$state = null;
}
$mode = $this->getMode();
switch ($mode) {
case 'home':
$deliveryType = MondialRelayZoneConfiguration::HOME_DELIVERY_TYPE;
if (! MondialRelay::getConfigValue(MondialRelay::ALLOW_HOME_DELIVERY, true)) {
return [];
}
break;
case 'relay':
$deliveryType = MondialRelayZoneConfiguration::RELAY_DELIVERY_TYPE;
if (! MondialRelay::getConfigValue(MondialRelay::ALLOW_RELAY_DELIVERY, true)) {
return [];
}
break;
case 'all':
$deliveryType = MondialRelayZoneConfiguration::ALL_DELIVERY_TYPE;
break;
}
// Find all areas which contains this country
$countryInAreaList = CountryAreaQuery::findByCountryAndState($country, $state);
$areaIdList = [];
$module = ModuleQuery::create()->findOneByCode(MondialRelay::getModuleCode());
/** @var CountryArea $countryInArea */
foreach ($countryInAreaList as $countryInArea) {
// Check if module is attached to the area
if (AreaDeliveryModuleQuery::create()
->filterByAreaId($countryInArea->getAreaId())
->filterByModule($module)
->count() > 0) {
$areaIdList[] = $countryInArea->getAreaId();
}
}
// Find zones with the required delivery type
$zones = MondialRelayZoneConfigurationQuery::create()
->filterByAreaId($areaIdList, Criteria::IN)
->filterByDeliveryType($deliveryType)
->find();
/** @var Cart $cart */
$cart = $this->requestStack
->getCurrentRequest()
->getSession()
->getSessionCart($this->dispatcher)
;
$cartWeight = $cart->getWeight();
$cartValue = $cart->getTaxedAmount($country);
/** @var MondialRelayZoneConfiguration $zone */
foreach ($zones as $zone) {
$result = [];
if (null !== $deliveryPrice = MondialRelayDeliveryPriceQuery::create()
->filterByAreaId($zone->getAreaId())
->filterByMaxWeight($cartWeight, Criteria::GREATER_EQUAL)
->orderByMaxWeight(Criteria::ASC)
->findOne()) {
$deliveryDate = (new \DateTime())->add(new \DateInterval("P" . $zone->getDeliveryTime() . "D"));
// We have a price
$result['PRICE'] = $deliveryPrice->getPriceWithTax();
$result['MAX_WEIGHT'] = $deliveryPrice->getMaxWeight();
$result['AREA_ID'] = $deliveryPrice->getAreaId();
$result['DELIVERY_DELAY'] = $zone->getDeliveryTime();
$result['DELIVERY_DATE'] = $deliveryDate;
switch ($zone->getDeliveryType()) {
case MondialRelayZoneConfiguration::HOME_DELIVERY_TYPE:
$result['ZONE_TYPE'] = 'home';
break;
case MondialRelayZoneConfiguration::RELAY_DELIVERY_TYPE:
$result['ZONE_TYPE'] = 'relay';
break;
default:
$result['ZONE_TYPE'] = '?';
}
$result['TYPE'] = $zone->getDeliveryType();
// Get insurance cost
if (null !== $insurance = MondialRelayDeliveryInsuranceQuery::create()
->filterByMaxValue($cartValue, Criteria::GREATER_EQUAL)
->orderByMaxValue(Criteria::ASC)
->findOne()
) {
$result['INSURANCE_AVAILABLE'] = true;
$result['INSURANCE_PRICE'] = $insurance->getPriceWithTax();
$result['INSURANCE_REF_VALUE'] = $insurance->getMaxValue();
} else {
$result['INSURANCE_AVAILABLE'] = false;
}
$results[] = $result;
}
}
}
return $results;
}
public function parseResults(LoopResult $loopResult)
{
/** @var MondialRelayDeliveryPrice $item */
foreach ($loopResult->getResultDataCollection() as $resultItem) {
$loopResultRow = new LoopResultRow($item);
foreach ($resultItem as $name => $value) {
$loopResultRow->set($name, $value);
}
$loopResult->addRow($loopResultRow);
}
return $loopResult;
}
}

View File

@@ -0,0 +1,64 @@
<?php
/*************************************************************************************/
/* Copyright (c) Franck Allimant, CQFDev */
/* email : thelia@cqfdev.fr */
/* web : http://www.cqfdev.fr */
/* */
/* For the full copyright and license information, please view the LICENSE */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace MondialRelay\Loop;
use MondialRelay\Model\MondialRelayDeliveryInsurance;
use MondialRelay\Model\MondialRelayDeliveryInsuranceQuery;
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\ArgumentCollection;
/**
* Class Insurances
* @package MondialRelay\Loop
* @method int getAreaId()
*/
class Insurances extends BaseLoop implements PropelSearchLoopInterface
{
/**
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection
*/
protected function getArgDefinitions()
{
return new ArgumentCollection(
);
}
public function buildModelCriteria()
{
$query = MondialRelayDeliveryInsuranceQuery::create();
$query->orderByMaxValue();
return $query;
}
public function parseResults(LoopResult $loopResult)
{
/** @var MondialRelayDeliveryInsurance $item */
foreach ($loopResult->getResultDataCollection() as $item) {
$loopResultRow = new LoopResultRow($item);
$loopResultRow
->set('ID', $item->getId())
->set('MAX_VALUE', $item->getMaxValue())
->set('PRICE', $item->getPriceWithTax())
;
$loopResult->addRow($loopResultRow);
}
return $loopResult;
}
}

View File

@@ -0,0 +1,90 @@
<?php
/*************************************************************************************/
/* Copyright (c) Franck Allimant, CQFDev */
/* email : thelia@cqfdev.fr */
/* web : http://www.cqfdev.fr */
/* */
/* For the full copyright and license information, please view the LICENSE */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace MondialRelay\Loop;
use MondialRelay\Event\FindRelayEvent;
use MondialRelay\Event\MondialRelayEvents;
use Thelia\Core\Template\Element\ArraySearchLoopInterface;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
require __DIR__ . "/../vendor/autoload.php";
/**
* Class Prices
* @package MondialRelay\Loop
* @method int getCountryId()
* @method int getCity()
* @method string getZipcode()
* @method string getSearchRadius()
*/
class PickupPoints extends BaseLoop implements ArraySearchLoopInterface
{
/**
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection
*/
protected function getArgDefinitions()
{
return new ArgumentCollection(
Argument::createIntTypeArgument('country_id', null, true),
Argument::createAnyTypeArgument('city', null, true),
Argument::createAnyTypeArgument('zipcode', null, true),
Argument::createFloatTypeArgument('search_radius', 10)
);
}
/**
* @return array
* @throws \Exception
* @throws \Propel\Runtime\Exception\PropelException
*/
public function buildArray()
{
$event = new FindRelayEvent(
$this->getCountryId(),
$this->getCity(),
$this->getZipcode(),
$this->getSearchRadius()
);
$this->dispatcher->dispatch(MondialRelayEvents::FIND_RELAYS, $event);
return $event->getPoints();
}
public function parseResults(LoopResult $loopResult)
{
foreach ($loopResult->getResultDataCollection() as $item) {
$loopResultRow = new LoopResultRow($item);
$loopResultRow
->set("ID", $item['id'])
->set("LATITUDE", $item['latitude'])
->set("LONGITUDE", $item['longitude'])
->set("ZIPCODE", $item['zipcode'])
->set("CITY", $item['city'])
->set("COUNTRY", $item['country'])
->set("NAME", $item['name'])
->set("ADDRESS", $item['address'])
->set("DISTANCE", $item['distance'])
->set("OPENINGS", $item['openings'])
;
$loopResult->addRow($loopResultRow);
}
return $loopResult;
}
}

View File

@@ -0,0 +1,72 @@
<?php
/*************************************************************************************/
/* Copyright (c) Franck Allimant, CQFDev */
/* email : thelia@cqfdev.fr */
/* web : http://www.cqfdev.fr */
/* */
/* For the full copyright and license information, please view the LICENSE */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace MondialRelay\Loop;
use MondialRelay\Model\MondialRelayDeliveryPrice;
use MondialRelay\Model\MondialRelayDeliveryPriceQuery;
use Propel\Runtime\ActiveQuery\Criteria;
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;
/**
* Class Prices
* @package MondialRelay\Loop
* @method int getAreaId()
*/
class Prices extends BaseLoop implements PropelSearchLoopInterface
{
/**
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection
*/
protected function getArgDefinitions()
{
return new ArgumentCollection(
Argument::createIntListTypeArgument('area_id')
);
}
public function buildModelCriteria()
{
$query = MondialRelayDeliveryPriceQuery::create();
if (null !== $areaId = $this->getAreaId()) {
$query->filterByAreaId($areaId, Criteria::IN);
}
$query->orderByMaxWeight();
return $query;
}
public function parseResults(LoopResult $loopResult)
{
/** @var MondialRelayDeliveryPrice $item */
foreach ($loopResult->getResultDataCollection() as $item) {
$loopResultRow = new LoopResultRow($item);
$loopResultRow
->set('ID', $item->getId())
->set('MAX_WEIGHT', $item->getMaxWeight())
->set('PRICE', $item->getPriceWithTax())
->set('AREA_ID', $item->getAreaId())
;
$loopResult->addRow($loopResultRow);
}
return $loopResult;
}
}

View File

@@ -0,0 +1,89 @@
<?php
/*************************************************************************************/
/* Copyright (c) Franck Allimant, CQFDev */
/* email : thelia@cqfdev.fr */
/* web : http://www.cqfdev.fr */
/* */
/* For the full copyright and license information, please view the LICENSE */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace MondialRelay\Loop;
use MondialRelay\Model\MondialRelayPickupAddress;
use MondialRelay\Model\MondialRelayPickupAddressQuery;
use MondialRelay\MondialRelay;
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 MondialRelay\Loop
* @method int getOrderAddressId()
* @method int getOrderId()
*/
class SelectedPickupPoint extends BaseLoop implements PropelSearchLoopInterface
{
/**
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection
*/
protected function getArgDefinitions()
{
return new ArgumentCollection(
Argument::createIntTypeArgument('order_address_id'),
Argument::createIntTypeArgument('order_id')
);
}
/**
* @throws \Exception
* @return MondialRelayPickupAddressQuery|null
*/
public function buildModelCriteria()
{
if (null !== $relayId = $this->getCurrentRequest()->getSession()->get(MondialRelay::SESSION_SELECTED_PICKUP_RELAY_ID)) {
return MondialRelayPickupAddressQuery::create()->filterById($relayId);
} elseif (null !== $orderAddressId = $this->getOrderAddressId()) {
return MondialRelayPickupAddressQuery::create()->filterByOrderAddressId($orderAddressId);
} elseif (null !== $orderId = $this->getOrderId()) {
if (null !== $order = OrderQuery::create()->findPk($orderId)) {
return MondialRelayPickupAddressQuery::create()
->filterByOrderAddressId($order->getDeliveryOrderAddressId());
}
}
return null;
}
public function parseResults(LoopResult $loopResult)
{
/** @var MondialRelayPickupAddress $item */
foreach ($loopResult->getResultDataCollection() as $item) {
$loopResultRow = new LoopResultRow($item);
$relayData = json_decode($item->getJsonRelayData(), true);
$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;
}
}