Ca avance pas mal sur DHL...

This commit is contained in:
2020-12-04 20:59:52 +01:00
parent 2453c207aa
commit 9572b71f14
12 changed files with 2518 additions and 558 deletions

View File

@@ -1,24 +1,16 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace DHL\Loop;
use DHL\DHL;
use Thelia\Core\Template\Element\ArraySearchLoopInterface;
use DHL\Model\DHLDeliveryPrice;
use DHL\Model\DHLDeliveryPriceQuery;
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\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
/**
*
@@ -27,47 +19,52 @@ use Thelia\Core\Template\Loop\Argument\Argument;
*
* Class Price
* @package DHL\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr>
* @method int getAreaId()
* @author Laurent LE CORRE <laurent@thecoredev.>
*/
class Price extends BaseLoop implements ArraySearchLoopInterface
class Price extends BaseLoop implements PropelSearchLoopInterface
{
/* set countable to false since we need to preserve keys */
protected $countable = false;
/**
* @return ArgumentCollection
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection
*/
protected function getArgDefinitions()
{
return new ArgumentCollection(
Argument::createIntTypeArgument('area', null, true)
Argument::createIntListTypeArgument('area_id')
);
}
public function buildArray()
public function buildModelCriteria()
{
$area = $this->getArea();
$prices = DHL::getPrices();
$query = DHLDeliveryPriceQuery::create();
if (!isset($prices[$area]) || !isset($prices[$area]["slices"])) {
return array();
if (null !== $areaId = $this->getAreaId()) {
$query->filterByAreaId($areaId, Criteria::IN);
}
$query->orderByMaxWeight();
$areaPrices = $prices[$area]["slices"];
ksort($areaPrices);
return $areaPrices;
return $query;
}
public function parseResults(LoopResult $loopResult)
{
foreach ($loopResult->getResultDataCollection() as $maxWeight => $price) {
$loopResultRow = new LoopResultRow();
$loopResultRow->set("MAX_WEIGHT", $maxWeight)
->set("PRICE", $price);
/** @var DHLDeliveryPrice $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;
}
}