Restored previous version

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

View File

@@ -27,10 +27,8 @@ 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 * Class Delivery
@@ -64,11 +62,9 @@ class Delivery extends BaseSpecificModule
$country = $this->container->get('thelia.taxEngine')->getDeliveryCountry(); $country = $this->container->get('thelia.taxEngine')->getDeliveryCountry();
} }
/** @var Module $deliveryModule */
foreach ($loopResult->getResultDataCollection() as $deliveryModule) { foreach ($loopResult->getResultDataCollection() as $deliveryModule) {
$loopResultRow = new LoopResultRow($deliveryModule); $loopResultRow = new LoopResultRow($deliveryModule);
/** @var DeliveryModuleInterface $moduleInstance */
$moduleInstance = $this->container->get(sprintf('module.%s', $deliveryModule->getCode())); $moduleInstance = $this->container->get(sprintf('module.%s', $deliveryModule->getCode()));
if (false === $moduleInstance instanceof DeliveryModuleInterface) { if (false === $moduleInstance instanceof DeliveryModuleInterface) {
@@ -76,27 +72,28 @@ class Delivery extends BaseSpecificModule
} }
try { try {
// Check if module is valid, by calling isValidDelivery(), $postage = $moduleInstance->getPostage($country);
// or catching a DeliveryException. } catch (OrderException $e) {
switch ($e->getCode()) {
if ($moduleInstance->isValidDelivery($country)) { case OrderException::DELIVERY_MODULE_UNAVAILABLE:
/* do not show this delivery module */
$postage = $moduleInstance->getPostage($country); continue(2);
break;
$loopResultRow default:
->set('ID', $deliveryModule->getId()) throw $e;
->set('TITLE', $deliveryModule->getVirtualColumn('i18n_TITLE'))
->set('CHAPO', $deliveryModule->getVirtualColumn('i18n_CHAPO'))
->set('DESCRIPTION', $deliveryModule->getVirtualColumn('i18n_DESCRIPTION'))
->set('POSTSCRIPTUM', $deliveryModule->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set('POSTAGE', $postage)
;
$loopResult->addRow($loopResultRow);
} }
} catch (DeliveryException $ex) {
// Module is not available
} }
$loopResultRow
->set('ID', $deliveryModule->getId())
->set('TITLE', $deliveryModule->getVirtualColumn('i18n_TITLE'))
->set('CHAPO', $deliveryModule->getVirtualColumn('i18n_CHAPO'))
->set('DESCRIPTION', $deliveryModule->getVirtualColumn('i18n_DESCRIPTION'))
->set('POSTSCRIPTUM', $deliveryModule->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set('POSTAGE', $postage)
;
$loopResult->addRow($loopResultRow);
} }
return $loopResult; return $loopResult;