Restored previous version

This commit is contained in:
Franck Allimant
2014-04-17 23:51:05 +02:00
parent 68cbc986e1
commit 307217665b

View File

@@ -1,109 +1,106 @@
<?php <?php
/*************************************************************************************/ /*************************************************************************************/
/* */ /* */
/* Thelia */ /* Thelia */
/* */ /* */
/* Copyright (c) OpenStudio */ /* Copyright (c) OpenStudio */
/* email : info@thelia.net */ /* email : info@thelia.net */
/* web : http://www.thelia.net */ /* web : http://www.thelia.net */
/* */ /* */
/* This program is free software; you can redistribute it and/or modify */ /* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */ /* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */ /* the Free Software Foundation; either version 3 of the License */
/* */ /* */
/* This program is distributed in the hope that it will be useful, */ /* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */ /* GNU General Public License for more details. */
/* */ /* */
/* You should have received a copy of the GNU General Public License */ /* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */ /* */
/*************************************************************************************/ /*************************************************************************************/
namespace Thelia\Core\Template\Loop; namespace Thelia\Core\Template\Loop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Exception\OrderException; use Thelia\Exception\OrderException;
use Thelia\Model\CountryQuery; use Thelia\Model\CountryQuery;
use Thelia\Model\Module; use Thelia\Module\BaseModule;
use Thelia\Module\BaseModule; use Thelia\Module\DeliveryModuleInterface;
use Thelia\Module\DeliveryModuleInterface;
use Thelia\Module\Exception\DeliveryException; /**
* Class Delivery
/** * @package Thelia\Core\Template\Loop
* Class Delivery * @author Manuel Raynaud <mraynaud@openstudio.fr>
* @package Thelia\Core\Template\Loop * @author Etienne Roudeix <eroudeix@gmail.com>
* @author Manuel Raynaud <mraynaud@openstudio.fr> */
* @author Etienne Roudeix <eroudeix@gmail.com> class Delivery extends BaseSpecificModule
*/ {
class Delivery extends BaseSpecificModule
{ public function getArgDefinitions()
{
public function getArgDefinitions() $collection = parent::getArgDefinitions();
{
$collection = parent::getArgDefinitions(); $collection->addArgument(
Argument::createIntTypeArgument("country")
$collection->addArgument( );
Argument::createIntTypeArgument("country")
); return $collection;
}
return $collection;
} public function parseResults(LoopResult $loopResult)
{
public function parseResults(LoopResult $loopResult) $countryId = $this->getCountry();
{ if (null !== $countryId) {
$countryId = $this->getCountry(); $country = CountryQuery::create()->findPk($countryId);
if (null !== $countryId) { if (null === $country) {
$country = CountryQuery::create()->findPk($countryId); throw new \InvalidArgumentException('Cannot found country id: `' . $countryId . '` in delivery loop');
if (null === $country) { }
throw new \InvalidArgumentException('Cannot found country id: `' . $countryId . '` in delivery loop'); } else {
} $country = $this->container->get('thelia.taxEngine')->getDeliveryCountry();
} else { }
$country = $this->container->get('thelia.taxEngine')->getDeliveryCountry();
} foreach ($loopResult->getResultDataCollection() as $deliveryModule) {
$loopResultRow = new LoopResultRow($deliveryModule);
/** @var Module $deliveryModule */
foreach ($loopResult->getResultDataCollection() as $deliveryModule) { $moduleInstance = $this->container->get(sprintf('module.%s', $deliveryModule->getCode()));
$loopResultRow = new LoopResultRow($deliveryModule);
if (false === $moduleInstance instanceof DeliveryModuleInterface) {
/** @var DeliveryModuleInterface $moduleInstance */ throw new \RuntimeException(sprintf("delivery module %s is not a Thelia\Module\DeliveryModuleInterface", $deliveryModule->getCode()));
$moduleInstance = $this->container->get(sprintf('module.%s', $deliveryModule->getCode())); }
if (false === $moduleInstance instanceof DeliveryModuleInterface) { try {
throw new \RuntimeException(sprintf("delivery module %s is not a Thelia\Module\DeliveryModuleInterface", $deliveryModule->getCode())); $postage = $moduleInstance->getPostage($country);
} } catch (OrderException $e) {
switch ($e->getCode()) {
try { case OrderException::DELIVERY_MODULE_UNAVAILABLE:
// Check if module is valid, by calling isValidDelivery(), /* do not show this delivery module */
// or catching a DeliveryException. continue(2);
break;
if ($moduleInstance->isValidDelivery($country)) { default:
throw $e;
$postage = $moduleInstance->getPostage($country); }
}
$loopResultRow
->set('ID', $deliveryModule->getId()) $loopResultRow
->set('TITLE', $deliveryModule->getVirtualColumn('i18n_TITLE')) ->set('ID', $deliveryModule->getId())
->set('CHAPO', $deliveryModule->getVirtualColumn('i18n_CHAPO')) ->set('TITLE', $deliveryModule->getVirtualColumn('i18n_TITLE'))
->set('DESCRIPTION', $deliveryModule->getVirtualColumn('i18n_DESCRIPTION')) ->set('CHAPO', $deliveryModule->getVirtualColumn('i18n_CHAPO'))
->set('POSTSCRIPTUM', $deliveryModule->getVirtualColumn('i18n_POSTSCRIPTUM')) ->set('DESCRIPTION', $deliveryModule->getVirtualColumn('i18n_DESCRIPTION'))
->set('POSTAGE', $postage) ->set('POSTSCRIPTUM', $deliveryModule->getVirtualColumn('i18n_POSTSCRIPTUM'))
; ->set('POSTAGE', $postage)
;
$loopResult->addRow($loopResultRow);
} $loopResult->addRow($loopResultRow);
} catch (DeliveryException $ex) { }
// Module is not available
} return $loopResult;
} }
return $loopResult; protected function getModuleType()
} {
return BaseModule::DELIVERY_MODULE_TYPE;
protected function getModuleType() }
{ }
return BaseModule::DELIVERY_MODULE_TYPE;
}
}