Colissimo in progress

This commit is contained in:
Etienne Roudeix
2013-11-14 11:21:34 +01:00
parent e8b4a4ac74
commit 48409c29a9
10 changed files with 236 additions and 158 deletions

View File

@@ -279,12 +279,13 @@ class Order extends BaseAction implements EventSubscriberInterface
$this->getDispatcher()->dispatch(TheliaEvents::CART_CLEAR, new CartEvent($this->getCart($this->getRequest())));
/* call pay method */
$paymentModuleReflection = new \ReflectionClass($paymentModule->getFullNamespace());
/*$paymentModuleReflection = new \ReflectionClass($paymentModule->getFullNamespace());
$paymentModuleInstance = $paymentModuleReflection->newInstance();
$paymentModuleInstance->setRequest($this->getRequest());
$paymentModuleInstance->setDispatcher($this->getDispatcher());
$paymentModuleInstance->setDispatcher($this->getDispatcher());*/
$paymentModuleInstance = $this->container->get(sprintf('module.%s', $paymentModule->getCode()));
$paymentModuleInstance->pay($placedOrder);
}

View File

@@ -84,8 +84,10 @@ class OrderController extends BaseFrontController
}
/* get postage amount */
$moduleReflection = new \ReflectionClass($deliveryModule->getFullNamespace());
$moduleInstance = $moduleReflection->newInstance();
/*$moduleReflection = new \ReflectionClass($deliveryModule->getFullNamespace());
$moduleInstance = $moduleReflection->newInstance();*/
$moduleInstance = $this->container->get(sprintf('module.%s', $deliveryModule->getCode()));
$postage = $moduleInstance->getPostage($deliveryAddress->getCountry());
$orderEvent = $this->getOrderEvent();

View File

@@ -25,8 +25,10 @@ namespace Thelia\Core\Template\Loop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Exception\OrderException;
use Thelia\Model\CountryQuery;
use Thelia\Module\BaseModule;
use Thelia\Module\DeliveryModuleInterface;
/**
* Class Delivery
@@ -63,14 +65,24 @@ class Delivery extends BaseSpecificModule
foreach ($loopResult->getResultDataCollection() as $deliveryModule) {
$loopResultRow = new LoopResultRow($deliveryModule);
$moduleReflection = new \ReflectionClass($deliveryModule->getFullNamespace());
if ($moduleReflection->isSubclassOf("Thelia\Module\DeliveryModuleInterface") === false) {
$moduleInstance = $this->container->get(sprintf('module.%s', $deliveryModule->getCode()));
if (false === $moduleInstance instanceof DeliveryModuleInterface) {
throw new \RuntimeException(sprintf("delivery module %s is not a Thelia\Module\DeliveryModuleInterface", $deliveryModule->getCode()));
}
$moduleInstance = $moduleReflection->newInstance();
$moduleInstance->setRequest($this->request);
$moduleInstance->setDispatcher($this->dispatcher);
try {
$postage = $moduleInstance->getPostage($country);
} catch(OrderException $e) {
switch($e->getCode()) {
case OrderException::DELIVERY_MODULE_UNAVAILABLE:
/* do not show this delivery module */
continue(2);
break;
default:
throw $e;
}
}
$loopResultRow
->set('ID', $deliveryModule->getId())
@@ -78,7 +90,7 @@ class Delivery extends BaseSpecificModule
->set('CHAPO', $deliveryModule->getVirtualColumn('i18n_CHAPO'))
->set('DESCRIPTION', $deliveryModule->getVirtualColumn('i18n_DESCRIPTION'))
->set('POSTSCRIPTUM', $deliveryModule->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set('POSTAGE', $moduleInstance->getPostage($country))
->set('POSTAGE', $postage)
;
$loopResult->addRow($loopResultRow);

View File

@@ -26,6 +26,7 @@ use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Module\BaseModule;
use Thelia\Module\PaymentModuleInterface;
/**
* Class Payment
@@ -47,14 +48,11 @@ class Payment extends BaseSpecificModule implements PropelSearchLoopInterface
foreach ($loopResult->getResultDataCollection() as $paymentModule) {
$loopResultRow = new LoopResultRow($paymentModule);
$moduleReflection = new \ReflectionClass($paymentModule->getFullNamespace());
if ($moduleReflection->isSubclassOf("Thelia\Module\PaymentModuleInterface") === false) {
$moduleInstance = $this->container->get(sprintf('module.%s', $paymentModule->getCode()));
if (false === $moduleInstance instanceof PaymentModuleInterface) {
throw new \RuntimeException(sprintf("payment module %s is not a Thelia\Module\PaymentModuleInterface", $paymentModule->getCode()));
}
$moduleInstance = $moduleReflection->newInstance();
$moduleInstance->setRequest($this->request);
$moduleInstance->setDispatcher($this->dispatcher);
$loopResultRow
->set('ID', $paymentModule->getId())

View File

@@ -35,6 +35,7 @@ namespace Thelia\Core;
use Propel\Runtime\Connection\ConnectionWrapper;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
@@ -134,7 +135,7 @@ class Thelia extends Kernel
$defintion = new Definition();
$defintion->setClass($module->getFullNamespace());
$defintion->addMethodCall("setContainer", array('service_container'));
$defintion->addMethodCall("setContainer", array(new Reference('service_container')));
$container->setDefinition(
"module.".$module->getCode(),

View File

@@ -38,6 +38,7 @@ class OrderException extends \RuntimeException
const CART_EMPTY = 100;
const UNDEFINED_DELIVERY = 200;
const DELIVERY_MODULE_UNAVAILABLE = 201;
public function __construct($message, $code = null, $arguments = array(), $previous = null)
{

View File

@@ -112,4 +112,18 @@ class Cart extends BaseCart
return $total;
}
public function getWeight()
{
$weight = 0;
foreach($this->getCartItems() as $cartItem) {
$itemWeight = $cartItem->getProductSaleElements()->getWeight();
$itemWeight *= $cartItem->getQuantity();
$weight += $itemWeight;
}
return $weight;
}
}