Merge branch 'modules'
This commit is contained in:
@@ -56,7 +56,7 @@ class HttpException extends BaseAction implements EventSubscriberInterface
|
||||
$parser = $this->container->get("thelia.parser");
|
||||
|
||||
// Define the template thant shoud be used
|
||||
$parser->setTemplate(TemplateHelper::getInstance()->getActiveFrontTemplate()->getPath());
|
||||
$parser->setTemplate(TemplateHelper::getInstance()->getActiveFrontTemplate());
|
||||
|
||||
//$event->getRequest()->attributes->set('_view', ConfigQuery::getPageNotFoundView());
|
||||
|
||||
|
||||
@@ -279,12 +279,7 @@ 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());
|
||||
$paymentModuleInstance = $paymentModuleReflection->newInstance();
|
||||
|
||||
$paymentModuleInstance->setRequest($this->getRequest());
|
||||
$paymentModuleInstance->setDispatcher($this->getDispatcher());
|
||||
|
||||
$paymentModuleInstance = $this->container->get(sprintf('module.%s', $paymentModule->getCode()));
|
||||
$paymentModuleInstance->pay($placedOrder);
|
||||
}
|
||||
|
||||
|
||||
@@ -943,6 +943,14 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\ModuleController::deleteAction</default>
|
||||
</route>
|
||||
|
||||
<!--
|
||||
Generic module route.
|
||||
Will be use if module route is not define in module own config file.
|
||||
-->
|
||||
<route id="admin.module.configure" path="/admin/module/{module_code}">
|
||||
<default key="_controller">Thelia\Controller\Admin\ModuleController::configureAction</default>
|
||||
</route>
|
||||
|
||||
<!-- end Modules rule management -->
|
||||
|
||||
<!-- tax management -->
|
||||
|
||||
@@ -201,7 +201,7 @@ class BaseAdminController extends BaseController
|
||||
$parser = $this->container->get("thelia.parser");
|
||||
|
||||
// Define the template that should be used
|
||||
$parser->setTemplate($template ?: TemplateHelper::getInstance()->getActiveAdminTemplate()->getPath());
|
||||
$parser->setTemplate($template ?: TemplateHelper::getInstance()->getActiveAdminTemplate());
|
||||
|
||||
return $parser;
|
||||
}
|
||||
|
||||
@@ -188,6 +188,24 @@ class ModuleController extends AbstractCrudController
|
||||
return $this->render("modules");
|
||||
}
|
||||
|
||||
public function configureAction($module_code)
|
||||
{
|
||||
$module = ModuleQuery::create()->findOneByCode($module_code);
|
||||
|
||||
if(null === $module) {
|
||||
throw new \InvalidArgumentException(sprintf("Module `%s` does not exists", $module_code));
|
||||
}
|
||||
|
||||
if (null !== $response = $this->checkAuth(array(), $module_code, AccessManager::VIEW)) return $response;
|
||||
|
||||
return $this->render(
|
||||
"module-configure",
|
||||
array(
|
||||
"module_code" => $module_code,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function toggleActivationAction($module_id)
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(AdminResources::MODULE, array(), AccessManager::UPDATE)) return $response;
|
||||
|
||||
@@ -97,7 +97,7 @@ class BaseFrontController extends BaseController
|
||||
$parser = $this->container->get("thelia.parser");
|
||||
|
||||
// Define the template that should be used
|
||||
$parser->setTemplate($template ?: TemplateHelper::getInstance()->getActiveFrontTemplate()->getPath());
|
||||
$parser->setTemplate($template ?: TemplateHelper::getInstance()->getActiveFrontTemplate());
|
||||
|
||||
return $parser;
|
||||
}
|
||||
|
||||
@@ -84,8 +84,7 @@ class OrderController extends BaseFrontController
|
||||
}
|
||||
|
||||
/* get postage amount */
|
||||
$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();
|
||||
|
||||
@@ -78,7 +78,7 @@ class ViewListener implements EventSubscriberInterface
|
||||
{
|
||||
|
||||
$parser = $this->container->get('thelia.parser');
|
||||
$parser->setTemplate(TemplateHelper::getInstance()->getActiveFrontTemplate()->getPath());
|
||||
$parser->setTemplate(TemplateHelper::getInstance()->getActiveFrontTemplate());
|
||||
$request = $this->container->get('request');
|
||||
|
||||
try {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -44,10 +44,16 @@ class Module extends AbstractSmartyPlugin
|
||||
|
||||
if (false !== $location = $this->getParam($params, 'location', false)) {
|
||||
|
||||
$moduleLimit = $this->getParam($params, 'module', null);
|
||||
|
||||
$modules = ModuleQuery::getActivated();
|
||||
|
||||
foreach ($modules as $module) {
|
||||
|
||||
if(null !== $moduleLimit && $moduleLimit != $module->getCode()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$file = sprintf("%s/%s/AdminIncludes/%s.html", THELIA_MODULE_DIR, $module->getBaseDir(), $location);
|
||||
|
||||
if (file_exists($file)) {
|
||||
|
||||
@@ -13,6 +13,7 @@ use Thelia\Core\Template\ParserInterface;
|
||||
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
||||
use Thelia\Core\Template\Exception\ResourceNotFoundException;
|
||||
use Thelia\Core\Template\ParserContext;
|
||||
use Thelia\Core\Template\TemplateDefinition;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Core\Template\TemplateHelper;
|
||||
|
||||
@@ -23,13 +24,15 @@ use Thelia\Core\Template\TemplateHelper;
|
||||
*/
|
||||
class SmartyParser extends Smarty implements ParserInterface
|
||||
{
|
||||
|
||||
public $plugins = array();
|
||||
|
||||
protected $request;
|
||||
protected $dispatcher;
|
||||
protected $parserContext;
|
||||
|
||||
protected $backOfficeTemplateDirectories = array();
|
||||
protected $frontOfficeTemplateDirectories = array();
|
||||
|
||||
protected $template = "";
|
||||
|
||||
protected $status = 200;
|
||||
@@ -101,15 +104,59 @@ class SmartyParser extends Smarty implements ParserInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function setTemplate($template_path_from_template_base)
|
||||
public function addBackOfficeTemplateDirectory($templateName, $templateDirectory, $key)
|
||||
{
|
||||
$this->template = $template_path_from_template_base;
|
||||
$this->backOfficeTemplateDirectories[$templateName][$key] = $templateDirectory;
|
||||
}
|
||||
|
||||
$this->addTemplateDir(THELIA_TEMPLATE_DIR.$this->template, 0);
|
||||
public function addFrontOfficeTemplateDirectory($templateName, $templateDirectory, $key)
|
||||
{
|
||||
$this->frontOfficeTemplateDirectories[$templateName][$key] = $templateDirectory;
|
||||
}
|
||||
|
||||
$config_dir = THELIA_TEMPLATE_DIR.$this->template.'/configs';
|
||||
/**
|
||||
* @param TemplateDefinition $templateDefinition
|
||||
*/
|
||||
public function setTemplate(TemplateDefinition $templateDefinition)
|
||||
{
|
||||
$this->template = $templateDefinition->getPath();
|
||||
|
||||
$this->setConfigDir($config_dir);
|
||||
/* init template directories */
|
||||
$this->setTemplateDir(array());
|
||||
|
||||
/* add main template directory */
|
||||
$this->addTemplateDir(THELIA_TEMPLATE_DIR . $this->template, 0);
|
||||
|
||||
/* define config directory */
|
||||
$configDirectory = THELIA_TEMPLATE_DIR . $this->template . '/configs';
|
||||
$this->setConfigDir($configDirectory);
|
||||
|
||||
/* add modules template directories */
|
||||
switch($templateDefinition->getType()) {
|
||||
case TemplateDefinition::FRONT_OFFICE:
|
||||
/* do not pass array directly to addTemplateDir since we cant control on keys */
|
||||
if(isset($this->frontOfficeTemplateDirectories[$templateDefinition->getName()])) {
|
||||
foreach($this->frontOfficeTemplateDirectories[$templateDefinition->getName()] as $key => $directory) {
|
||||
$this->addTemplateDir($directory, $key);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case TemplateDefinition::BACK_OFFICE:
|
||||
/* do not pass array directly to addTemplateDir since we cant control on keys */
|
||||
if(isset($this->backOfficeTemplateDirectories[$templateDefinition->getName()])) {
|
||||
foreach($this->backOfficeTemplateDirectories[$templateDefinition->getName()] as $key => $directory) {
|
||||
$this->addTemplateDir($directory, $key);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case TemplateDefinition::PDF:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTemplate()
|
||||
|
||||
@@ -54,14 +54,20 @@ class TemplateDefinition
|
||||
$this->name = $name;
|
||||
$this->type = $type;
|
||||
|
||||
if ($type == self::BACK_OFFICE)
|
||||
$this->path = self::BACK_OFFICE_SUBDIR . $name;
|
||||
else if ($type == self::PDF)
|
||||
$this->path = self::PDF_SUBDIR . $name;
|
||||
else if ($type == self::FRONT_OFFICE)
|
||||
$this->path = self::FRONT_OFFICE_SUBDIR . $name;
|
||||
else
|
||||
$this->path = $name;
|
||||
switch($type) {
|
||||
case TemplateDefinition::FRONT_OFFICE:
|
||||
$this->path = self::FRONT_OFFICE_SUBDIR . $name;
|
||||
break;
|
||||
case TemplateDefinition::BACK_OFFICE:
|
||||
$this->path = self::BACK_OFFICE_SUBDIR . $name;
|
||||
break;
|
||||
case TemplateDefinition::PDF:
|
||||
$this->path = self::PDF_SUBDIR . $name;
|
||||
break;
|
||||
default:
|
||||
$this->path = $name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function getName()
|
||||
|
||||
@@ -46,6 +46,9 @@ class TemplateHelper
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TemplateDefinition
|
||||
*/
|
||||
public function getActivePdfTemplate() {
|
||||
return new TemplateDefinition(
|
||||
ConfigQuery::read('active-pdf-template', 'default'),
|
||||
@@ -53,6 +56,9 @@ class TemplateHelper
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TemplateDefinition
|
||||
*/
|
||||
public function getActiveAdminTemplate() {
|
||||
return new TemplateDefinition(
|
||||
ConfigQuery::read('active-admin-template', 'default'),
|
||||
@@ -60,6 +66,9 @@ class TemplateHelper
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TemplateDefinition
|
||||
*/
|
||||
public function getActiveFrontTemplate() {
|
||||
return new TemplateDefinition(
|
||||
ConfigQuery::read('active-front-template', 'default'),
|
||||
|
||||
@@ -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;
|
||||
@@ -45,6 +46,7 @@ use Thelia\Core\Bundle;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Config\DatabaseConfiguration;
|
||||
use Thelia\Config\DefinePropel;
|
||||
use Thelia\Core\Template\TemplateDefinition;
|
||||
use Thelia\Core\TheliaContainerBuilder;
|
||||
use Thelia\Core\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
@@ -126,7 +128,6 @@ class Thelia extends Kernel
|
||||
$modules = \Thelia\Model\ModuleQuery::getActivated();
|
||||
|
||||
$translationDirs = array();
|
||||
$templateDirs = array();
|
||||
$parser = $container->getDefinition('thelia.parser');
|
||||
foreach ($modules as $module) {
|
||||
|
||||
@@ -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(),
|
||||
@@ -151,9 +152,54 @@ class Thelia extends Kernel
|
||||
$translationDirs[] = $dir;
|
||||
}
|
||||
|
||||
if (is_dir($dir = THELIA_MODULE_DIR . "/" . $code . "/templates")) {
|
||||
//$templateDirs[$code] = $dir;
|
||||
$parser->addMethodCall('addTemplateDir', array($dir, $code));
|
||||
/* is there a front-office template directory ? */
|
||||
$frontOfficeModuleTemplateDirectory = sprintf("%s%s%stemplates%s%s", THELIA_MODULE_DIR, $code, DS, DS, TemplateDefinition::FRONT_OFFICE_SUBDIR);
|
||||
if (is_dir($frontOfficeModuleTemplateDirectory)) {
|
||||
try {
|
||||
$moduleFrontOfficeTemplateBrowser = new \DirectoryIterator($frontOfficeModuleTemplateDirectory);
|
||||
} catch (\UnexpectedValueException $e) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
/* browse the directory */
|
||||
foreach ($moduleFrontOfficeTemplateBrowser as $moduleFrontOfficeTemplateContent) {
|
||||
/* is it a directory which is not . or .. ? */
|
||||
if ($moduleFrontOfficeTemplateContent->isDir() && !$moduleFrontOfficeTemplateContent->isDot()) {
|
||||
$parser->addMethodCall(
|
||||
'addFrontOfficeTemplateDirectory',
|
||||
array(
|
||||
$moduleFrontOfficeTemplateContent->getFilename(),
|
||||
$frontOfficeModuleTemplateDirectory,
|
||||
$code,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* is there a back-office template directory ? */
|
||||
$backOfficeModuleTemplateDirectory = sprintf("%s%s%stemplates%s%s", THELIA_MODULE_DIR, $code, DS, DS, TemplateDefinition::BACK_OFFICE_SUBDIR);
|
||||
if (is_dir($backOfficeModuleTemplateDirectory)) {
|
||||
try {
|
||||
$moduleBackOfficeTemplateBrowser = new \DirectoryIterator($backOfficeModuleTemplateDirectory);
|
||||
} catch (\UnexpectedValueException $e) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
/* browse the directory */
|
||||
foreach ($moduleBackOfficeTemplateBrowser as $moduleBackOfficeTemplateContent) {
|
||||
/* is it a directory which is not . or .. ? */
|
||||
if ($moduleBackOfficeTemplateContent->isDir() && !$moduleBackOfficeTemplateContent->isDot()) {
|
||||
$parser->addMethodCall(
|
||||
'addBackOfficeTemplateDirectory',
|
||||
array(
|
||||
$moduleBackOfficeTemplateContent->getFilename(),
|
||||
$backOfficeModuleTemplateDirectory,
|
||||
$code,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
// TODO: process module configuration exception
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user