This commit is contained in:
Franck Allimant
2014-04-17 23:52:01 +02:00
parent 307217665b
commit 52ecfe7dad

View File

@@ -25,10 +25,11 @@ 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\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
@@ -62,9 +63,11 @@ 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) {
@@ -72,28 +75,27 @@ class Delivery extends BaseSpecificModule
} }
try { try {
$postage = $moduleInstance->getPostage($country); // Check if module is valid, by calling isValidDelivery(),
} catch (OrderException $e) { // or catching a DeliveryException.
switch ($e->getCode()) {
case OrderException::DELIVERY_MODULE_UNAVAILABLE: if ($moduleInstance->isValidDelivery($country)) {
/* do not show this delivery module */
continue(2); $postage = $moduleInstance->getPostage($country);
break;
default: $loopResultRow
throw $e; ->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);
} }
} 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;
@@ -103,4 +105,4 @@ class Delivery extends BaseSpecificModule
{ {
return BaseModule::DELIVERY_MODULE_TYPE; return BaseModule::DELIVERY_MODULE_TYPE;
} }
} }