Ajout et config du module Chronopost
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace ChronopostHomeDelivery\Loop;
|
||||
|
||||
|
||||
use ChronopostHomeDelivery\Model\ChronopostHomeDeliveryAreaFreeshippingQuery;
|
||||
use Propel\Runtime\ActiveQuery\ModelCriteria;
|
||||
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 ChronopostHomeDeliveryAreaFreeshipping extends BaseLoop implements PropelSearchLoopInterface
|
||||
{
|
||||
/**
|
||||
* @return ArgumentCollection
|
||||
*/
|
||||
protected function getArgDefinitions()
|
||||
{
|
||||
return new ArgumentCollection(
|
||||
Argument::createIntTypeArgument('area_id'),
|
||||
Argument::createIntTypeArgument('delivery_mode_id')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ChronopostHomeDeliveryAreaFreeshippingQuery|ModelCriteria
|
||||
*/
|
||||
public function buildModelCriteria()
|
||||
{
|
||||
$areaId = $this->getAreaId();
|
||||
$mode = $this->getDeliveryModeId();
|
||||
|
||||
$modes = ChronopostHomeDeliveryAreaFreeshippingQuery::create();
|
||||
|
||||
if (null !== $mode) {
|
||||
$modes->filterByDeliveryModeId($mode);
|
||||
}
|
||||
|
||||
if (null !== $areaId) {
|
||||
$modes->filterByAreaId($areaId);
|
||||
}
|
||||
|
||||
return $modes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LoopResult $loopResult
|
||||
* @return LoopResult
|
||||
*/
|
||||
public function parseResults(LoopResult $loopResult)
|
||||
{
|
||||
/** @var \ChronopostHomeDeliveryHomeDelivery\Model\ChronopostHomeDeliveryAreaFreeshipping $mode */
|
||||
foreach ($loopResult->getResultDataCollection() as $mode) {
|
||||
$loopResultRow = new LoopResultRow($mode);
|
||||
$loopResultRow->set("ID", $mode->getId())
|
||||
->set("AREA_ID", $mode->getAreaId())
|
||||
->set("DELIVERY_MODE_ID", $mode->getDeliveryModeId())
|
||||
->set("CART_AMOUNT", $mode->getCartAmount());
|
||||
$loopResult->addRow($loopResultRow);
|
||||
}
|
||||
return $loopResult;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace ChronopostHomeDelivery\Loop;
|
||||
|
||||
|
||||
use ChronopostHomeDelivery\ChronopostHomeDelivery;
|
||||
use ChronopostHomeDelivery\Config\ChronopostHomeDeliveryConst;
|
||||
use ChronopostHomeDelivery\Model\ChronopostHomeDeliveryDeliveryModeQuery;
|
||||
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 ChronopostHomeDeliveryDeliveryMode extends BaseLoop implements PropelSearchLoopInterface
|
||||
{
|
||||
/**
|
||||
* Unused
|
||||
*/
|
||||
protected function getArgDefinitions()
|
||||
{
|
||||
return new ArgumentCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ChronopostHomeDeliveryDeliveryModeQuery|\Propel\Runtime\ActiveQuery\ModelCriteria
|
||||
*/
|
||||
public function buildModelCriteria()
|
||||
{
|
||||
$config = ChronopostHomeDeliveryConst::getConfig();
|
||||
$modes = ChronopostHomeDeliveryDeliveryModeQuery::create();
|
||||
|
||||
$enabledDeliveryTypes = [];
|
||||
foreach (ChronopostHomeDeliveryConst::getDeliveryTypesStatusKeys() as $deliveryTypeName => $statusKey) {
|
||||
$enabledDeliveryTypes[] = $config[$statusKey] ? ChronopostHomeDeliveryConst::CHRONOPOST_HOME_DELIVERY_DELIVERY_CODES[$deliveryTypeName] : '';
|
||||
}
|
||||
|
||||
$modes->filterByCode($enabledDeliveryTypes, Criteria::IN);
|
||||
|
||||
return $modes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LoopResult $loopResult
|
||||
* @return LoopResult
|
||||
*/
|
||||
public function parseResults(LoopResult $loopResult)
|
||||
{
|
||||
/** @var \ChronopostHomeDelivery\Model\ChronopostHomeDeliveryDeliveryMode $mode */
|
||||
foreach ($loopResult->getResultDataCollection() as $mode) {
|
||||
$loopResultRow = new LoopResultRow($mode);
|
||||
$loopResultRow
|
||||
->set("ID", $mode->getId())
|
||||
->set("TITLE", $mode->getTitle())
|
||||
->set("CODE", $mode->getCode())
|
||||
->set("FREESHIPPING_ACTIVE", $mode->getFreeshippingActive())
|
||||
->set("FREESHIPPING_FROM", $mode->getFreeshippingFrom());
|
||||
$loopResult->addRow($loopResultRow);
|
||||
}
|
||||
return $loopResult;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace ChronopostHomeDelivery\Loop;
|
||||
|
||||
|
||||
use ChronopostHomeDelivery\Model\ChronopostHomeDeliveryPrice;
|
||||
use ChronopostHomeDelivery\Model\ChronopostHomeDeliveryPriceQuery;
|
||||
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 ChronopostHomeDeliveryLoop
|
||||
* @package ChronopostHomeDelivery\Loop
|
||||
*
|
||||
* @method integer getAreaId
|
||||
* @method integer getDeliveryModeId
|
||||
*/
|
||||
class ChronopostHomeDeliveryLoop extends BaseLoop implements PropelSearchLoopInterface
|
||||
{
|
||||
/**
|
||||
* @return ArgumentCollection
|
||||
*/
|
||||
protected function getArgDefinitions()
|
||||
{
|
||||
return new ArgumentCollection(
|
||||
Argument::createIntTypeArgument('area_id', null, true),
|
||||
Argument::createIntTypeArgument('delivery_mode_id', null, true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ChronopostHomeDeliveryPriceQuery|\Propel\Runtime\ActiveQuery\ModelCriteria
|
||||
*/
|
||||
public function buildModelCriteria()
|
||||
{
|
||||
$areaId = $this->getAreaId();
|
||||
$modeId = $this->getDeliveryModeId();
|
||||
|
||||
$areaPrices = ChronopostHomeDeliveryPriceQuery::create()
|
||||
->filterByDeliveryModeId($modeId)
|
||||
->filterByAreaId($areaId)
|
||||
->orderByWeightMax();
|
||||
|
||||
return $areaPrices;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LoopResult $loopResult
|
||||
* @return LoopResult
|
||||
*/
|
||||
public function parseResults(LoopResult $loopResult)
|
||||
{
|
||||
/** @var ChronopostHomeDeliveryPrice $price */
|
||||
foreach ($loopResult->getResultDataCollection() as $price) {
|
||||
$loopResultRow = new LoopResultRow($price);
|
||||
$loopResultRow
|
||||
->set("SLICE_ID", $price->getId())
|
||||
->set("MAX_WEIGHT", $price->getWeightMax())
|
||||
->set("MAX_PRICE", $price->getPriceMax())
|
||||
->set("PRICE", $price->getPrice())
|
||||
->set("FRANCO", $price->getFrancoMinPrice())
|
||||
;
|
||||
$loopResult->addRow($loopResultRow);
|
||||
}
|
||||
return $loopResult;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user