Added Model\Module::getModuleInstance() method
This commit is contained in:
@@ -161,7 +161,7 @@ class Module extends BaseAction implements EventSubscriberInterface
|
||||
);
|
||||
}
|
||||
|
||||
$paymentModuleInstance = $this->container->get(sprintf('module.%s', $paymentModule->getCode()));
|
||||
$paymentModuleInstance = $paymentModule->getModuleInstance($this->container);
|
||||
|
||||
$response = $paymentModuleInstance->pay($order);
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ class Delivery extends BaseSpecificModule
|
||||
$loopResultRow = new LoopResultRow($deliveryModule);
|
||||
|
||||
/** @var DeliveryModuleInterface $moduleInstance */
|
||||
$moduleInstance = $this->container->get(sprintf('module.%s', $deliveryModule->getCode()));
|
||||
$moduleInstance = $deliveryModule->getModuleInstance($this->container);
|
||||
|
||||
if (false === $moduleInstance instanceof DeliveryModuleInterface) {
|
||||
throw new \RuntimeException(sprintf("delivery module %s is not a Thelia\Module\DeliveryModuleInterface", $deliveryModule->getCode()));
|
||||
|
||||
@@ -37,7 +37,7 @@ class Payment extends BaseSpecificModule implements PropelSearchLoopInterface
|
||||
foreach ($loopResult->getResultDataCollection() as $paymentModule) {
|
||||
$loopResultRow = new LoopResultRow($paymentModule);
|
||||
|
||||
$moduleInstance = $this->container->get(sprintf('module.%s', $paymentModule->getCode()));
|
||||
$moduleInstance = $paymentModule->getModuleInstance($this->container);
|
||||
|
||||
if (false === $moduleInstance instanceof PaymentModuleInterface) {
|
||||
throw new \RuntimeException(sprintf("payment module %s is not a Thelia\Module\PaymentModuleInterface", $paymentModule->getCode()));
|
||||
|
||||
@@ -169,7 +169,7 @@ class CartPostage extends AbstractSmartyPlugin
|
||||
foreach ($deliveryModules as $deliveryModule) {
|
||||
|
||||
/** @var DeliveryModuleInterface $moduleInstance */
|
||||
$moduleInstance = $this->container->get(sprintf('module.%s', $deliveryModule->getCode()));
|
||||
$moduleInstance = $deliveryModule->getModuleInstance($this->container);
|
||||
|
||||
if (false === $moduleInstance instanceof DeliveryModuleInterface) {
|
||||
throw new \RuntimeException(sprintf("delivery module %s is not a Thelia\Module\DeliveryModuleInterface", $deliveryModule->getCode()));
|
||||
|
||||
@@ -3,10 +3,12 @@
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Thelia\Core\Template\TemplateDefinition;
|
||||
use Thelia\Model\Base\Module as BaseModule;
|
||||
use Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
use Thelia\Model\Tools\PositionManagementTrait;
|
||||
use Thelia\Module\BaseModuleInterface;
|
||||
|
||||
class Module extends BaseModule
|
||||
{
|
||||
@@ -182,6 +184,21 @@ class Module extends BaseModule
|
||||
return $moduleReflection->implementsInterface("Thelia\Module\PaymentModuleInterface");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerInterface $container the Thelia container
|
||||
* @return BaseModuleInterface a module instance
|
||||
* @throws \InvalidArgumentException if the module could not be found in the container/
|
||||
*/
|
||||
public function getModuleInstance(ContainerInterface $container) {
|
||||
|
||||
$instance = $this->container->get(sprintf('module.%s', $this->getCode()));
|
||||
|
||||
if ($instance == null) {
|
||||
throw new \InvalidArgumentException(sprintf('Undefined module in container: "%s"', $this->getCode()));
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
/**
|
||||
* @return BaseModule a new module instance.
|
||||
*/
|
||||
|
||||
@@ -177,7 +177,7 @@ class CartController extends BaseFrontController
|
||||
$deliveryAddress = AddressQuery::create()->findPk($order->chosenDeliveryAddress);
|
||||
|
||||
if (null !== $deliveryModule && null !== $deliveryAddress) {
|
||||
$moduleInstance = $this->container->get(sprintf('module.%s', $deliveryModule->getCode()));
|
||||
$moduleInstance = $deliveryModule->getModuleInstance($this->container);
|
||||
|
||||
$orderEvent = new OrderEvent($order);
|
||||
|
||||
|
||||
@@ -69,12 +69,14 @@ class CouponController extends BaseFrontController
|
||||
|
||||
/* recalculate postage amount */
|
||||
$order = $this->getSession()->getOrder();
|
||||
|
||||
if (null !== $order) {
|
||||
$deliveryModule = $order->getModuleRelatedByDeliveryModuleId();
|
||||
$deliveryAddress = AddressQuery::create()->findPk($order->chosenDeliveryAddress);
|
||||
|
||||
if (null !== $deliveryModule && null !== $deliveryAddress) {
|
||||
$moduleInstance = $this->container->get(sprintf('module.%s', $deliveryModule->getCode()));
|
||||
|
||||
$moduleInstance = $deliveryModule->getModuleInstance($this->container);
|
||||
|
||||
$orderEvent = new OrderEvent($order);
|
||||
|
||||
|
||||
@@ -88,7 +88,8 @@ class OrderController extends BaseFrontController
|
||||
}
|
||||
|
||||
/* get postage amount */
|
||||
$moduleInstance = $this->container->get(sprintf('module.%s', $deliveryModule->getCode()));
|
||||
$moduleInstance = $deliveryModule->getModuleInstance($this->container);
|
||||
|
||||
$postage = $moduleInstance->getPostage($deliveryAddress->getCountry());
|
||||
|
||||
$orderEvent = $this->getOrderEvent();
|
||||
|
||||
Reference in New Issue
Block a user