64 lines
1.5 KiB
PHP
Executable File
64 lines
1.5 KiB
PHP
Executable File
<?php
|
|
|
|
namespace FedEx\Loop;
|
|
|
|
use FedEx\FedEx;
|
|
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\ArgumentCollection;
|
|
use Thelia\Core\Template\Loop\Argument\Argument;
|
|
|
|
/**
|
|
*
|
|
* Price loop
|
|
*
|
|
*
|
|
* Class Price
|
|
* @package FedEx\Loop
|
|
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
|
*/
|
|
class Price extends BaseLoop implements ArraySearchLoopInterface
|
|
{
|
|
/* set countable to false since we need to preserve keys */
|
|
protected $countable = false;
|
|
|
|
/**
|
|
* @return ArgumentCollection
|
|
*/
|
|
protected function getArgDefinitions()
|
|
{
|
|
return new ArgumentCollection(
|
|
Argument::createIntTypeArgument('area', null, true)
|
|
);
|
|
}
|
|
|
|
public function buildArray()
|
|
{
|
|
$area = $this->getArea();
|
|
$prices = FedEx::getPrices();
|
|
|
|
if (!isset($prices[$area]) || !isset($prices[$area]["slices"])) {
|
|
return array();
|
|
}
|
|
|
|
$areaPrices = $prices[$area]["slices"];
|
|
ksort($areaPrices);
|
|
|
|
return $areaPrices;
|
|
}
|
|
|
|
public function parseResults(LoopResult $loopResult)
|
|
{
|
|
foreach ($loopResult->getResultDataCollection() as $maxWeight => $price) {
|
|
$loopResultRow = new LoopResultRow();
|
|
$loopResultRow->set("MAX_WEIGHT", $maxWeight)
|
|
->set("PRICE", $price);
|
|
|
|
$loopResult->addRow($loopResultRow);
|
|
}
|
|
return $loopResult;
|
|
}
|
|
}
|