diff --git a/composer.lock b/composer.lock index 22f9b819e..0215c3d0f 100755 --- a/composer.lock +++ b/composer.lock @@ -4,6 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], "hash": "ba2f3e0943f00c7c3bf0c086bc611b0f", + "packages": [ { "name": "imagine/imagine", diff --git a/core/lib/Thelia/Command/Skeleton/Module/Class.php b/core/lib/Thelia/Command/Skeleton/Module/Class.php index c9c7109ac..c4c90aa60 100755 --- a/core/lib/Thelia/Command/Skeleton/Module/Class.php +++ b/core/lib/Thelia/Command/Skeleton/Module/Class.php @@ -25,7 +25,7 @@ namespace %%NAMESPACE%%; use Thelia\Module\BaseModule; -class Class extends BaseModule +class %%CLASSNAME%% extends BaseModule { /** * YOU HAVE TO IMPLEMENT HERE ABSTRACT METHODD FROM BaseModule Class diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 974de091c..1f254f70e 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -34,6 +34,7 @@ + diff --git a/core/lib/Thelia/Config/Resources/routing/front.xml b/core/lib/Thelia/Config/Resources/routing/front.xml index f8b156946..aeff55d7c 100755 --- a/core/lib/Thelia/Config/Resources/routing/front.xml +++ b/core/lib/Thelia/Config/Resources/routing/front.xml @@ -60,4 +60,11 @@ cart + + + Thelia\Controller\Front\DeliveryController::select + \d+ + + + diff --git a/core/lib/Thelia/Controller/Front/DeliveryController.php b/core/lib/Thelia/Controller/Front/DeliveryController.php new file mode 100644 index 000000000..ef84be6ab --- /dev/null +++ b/core/lib/Thelia/Controller/Front/DeliveryController.php @@ -0,0 +1,56 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Controller\Front; +use Thelia\Model\ModuleQuery; +use Thelia\Tools\URL; + + +/** + * Class DeliveryController + * @package Thelia\Controller\Front + * @author Manuel Raynaud + */ +class DeliveryController extends BaseFrontController +{ + public function select($delivery_id) + { + if ($this->getSecurityContext()->hasCustomerUser() === false) { + $this->redirect(URL::getInstance()->getIndexPage()); + } + + $request = $this->getRequest(); + + $deliveryModule = ModuleQuery::create() + ->filterById($delivery_id) + ->filterByActivate(1) + ->findOne() + ; + + if ($deliveryModule) { + $request->getSession()->setDelivery($delivery_id); + } else { + $this->pageNotFound(); + } + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/HttpFoundation/Session/Session.php b/core/lib/Thelia/Core/HttpFoundation/Session/Session.php index 4a486e488..8c6a241ec 100755 --- a/core/lib/Thelia/Core/HttpFoundation/Session/Session.php +++ b/core/lib/Thelia/Core/HttpFoundation/Session/Session.php @@ -164,10 +164,28 @@ class Session extends BaseSession * assign cart id in session * * @param $cart_id + * @return $this */ public function setCart($cart_id) { $this->set("thelia.cart_id", $cart_id); return $this; } + + /** + * assign delivery id in session + * + * @param $delivery_id + * @return $this + */ + public function setDelivery($delivery_id) + { + $this->set("thelia.delivery_id", $delivery_id); + return $this; + } + + public function getDelivery() + { + return $this->get("thelia.delivery_id"); + } } \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Element/BaseLoop.php b/core/lib/Thelia/Core/Template/Element/BaseLoop.php index 98ed8af33..d74f9894b 100755 --- a/core/lib/Thelia/Core/Template/Element/BaseLoop.php +++ b/core/lib/Thelia/Core/Template/Element/BaseLoop.php @@ -243,23 +243,9 @@ abstract class BaseLoop * * this function have to be implement in your own loop class. * - * All your parameters are defined in defineArgs() and can be accessible like a class property. + * All loops parameters can be accessible via getter. * - * example : - * - * public function defineArgs() - * { - * return array ( - * "ref", - * "id" => "optional", - * "stock" => array( - * "optional", - * "default" => 10 - * ) - * ); - * } - * - * you can retrieve ref value using $this->ref + * for example, ref parameter is accessible through getRef method * * @param $pagination * @@ -271,18 +257,31 @@ abstract class BaseLoop * * define all args used in your loop * - * array key is your arg name. * * example : * - * return array ( - * "ref", - * "id" => "optional", - * "stock" => array( - * "optional", - * "default" => 10 - * ) - * ); + * public function getArgDefinitions() + * { + * return new ArgumentCollection( + * Argument::createIntListTypeArgument('id'), + * new Argument( + * 'ref', + * new TypeCollection( + * new Type\AlphaNumStringListType() + * ) + * ), + * Argument::createIntListTypeArgument('category'), + * Argument::createBooleanTypeArgument('new'), + * Argument::createBooleanTypeArgument('promo'), + * Argument::createFloatTypeArgument('min_price'), + * Argument::createFloatTypeArgument('max_price'), + * Argument::createIntTypeArgument('min_stock'), + * Argument::createFloatTypeArgument('min_weight'), + * Argument::createFloatTypeArgument('max_weight'), + * Argument::createBooleanTypeArgument('current'), + * + * ); + * } * * @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection */ diff --git a/core/lib/Thelia/Core/Template/Loop/BaseSpecificModule.php b/core/lib/Thelia/Core/Template/Loop/BaseSpecificModule.php new file mode 100644 index 000000000..3b4e54be6 --- /dev/null +++ b/core/lib/Thelia/Core/Template/Loop/BaseSpecificModule.php @@ -0,0 +1,109 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Template\Loop; +use Propel\Runtime\ActiveQuery\Criteria; +use Thelia\Core\Template\Element\BaseI18nLoop; +use Thelia\Core\Template\Loop\Argument\Argument; +use Thelia\Core\Template\Loop\Argument\ArgumentCollection; +use Thelia\Model\ModuleQuery; + + +/** + * Class Delivery + * @package Thelia\Core\Template\Loop + * @author Manuel Raynaud + */ +class BaseSpecificModule extends BaseI18nLoop { + public $timestampable = true; + + /** + * + * define all args used in your loop + * + * + * example : + * + * public function getArgDefinitions() + * { + * return new ArgumentCollection( + * Argument::createIntListTypeArgument('id'), + * new Argument( + * 'ref', + * new TypeCollection( + * new Type\AlphaNumStringListType() + * ) + * ), + * Argument::createIntListTypeArgument('category'), + * Argument::createBooleanTypeArgument('new'), + * Argument::createBooleanTypeArgument('promo'), + * Argument::createFloatTypeArgument('min_price'), + * Argument::createFloatTypeArgument('max_price'), + * Argument::createIntTypeArgument('min_stock'), + * Argument::createFloatTypeArgument('min_weight'), + * Argument::createFloatTypeArgument('max_weight'), + * Argument::createBooleanTypeArgument('current'), + * + * ); + * } + * + * @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection + */ + protected function getArgDefinitions() + { + return new ArgumentCollection( + Argument::createIntTypeArgument('id'), + Argument::createIntListTypeArgument('exclude') + ); + } + + /** + * + * this function have to be implement in your own loop class. + * + * All loops parameters can be accesible via getter. + * + * for example, ref parameter is accessible through getRef method + * + * @param $pagination + * + * @return \Thelia\Model\ModuleQuery + */ + public function exec(&$pagination) + { + $search = ModuleQuery::create(); + + if(null !== $id = $this->getId()) + { + $search->filterById($id); + } + + + if (null !== $exclude = $this->getExclude()) { + $search->filterById($exclude, Criteria::NOT_IN); + } + + return $search; + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Loop/Delivery.php b/core/lib/Thelia/Core/Template/Loop/Delivery.php new file mode 100644 index 000000000..7ef46eedc --- /dev/null +++ b/core/lib/Thelia/Core/Template/Loop/Delivery.php @@ -0,0 +1,85 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Template\Loop; +use Thelia\Core\Template\Element\LoopResult; +use Thelia\Core\Template\Element\LoopResultRow; +use Thelia\Core\Template\Loop\Argument\Argument; + + +/** + * Class Delivery + * @package Thelia\Core\Template\Loop + * @author Manuel Raynaud + */ +class Delivery extends BaseSpecificModule +{ + + public function getArgDefinitions() + { + $collection = parent::getArgDefinitions(); + + $collection->addArgument( + Argument::createIntTypeArgument("country") + ); + + return $collection; + } + + public function exec(&$pagination) + { + $search = parent::exec($pagination); + /* manage translations */ + $locale = $this->configureI18nProcessing($search); + /* perform search */ + $deliveryModules = $this->search($search, $pagination); + + $loopResult = new LoopResult($deliveryModules); + + foreach ($deliveryModules as $deliveryModule) { + $loopResultRow = new LoopResultRow($loopResult, $deliveryModule, $this->versionable, $this->timestampable, $this->countable); + + $moduleReflection = new \ReflectionClass($deliveryModule->getFullNamespace()); + if($moduleReflection->isSubclassOf("Thelia\Module\DeliveryModuleInterface") === false) { + 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); + + $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('PRICE', $moduleInstance->calculate($this->getCountry())) + ; + + $loopResult->addRow($loopResultRow); + } + + return $loopResult; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Thelia.php b/core/lib/Thelia/Core/Thelia.php index 207cced9c..759f1108b 100755 --- a/core/lib/Thelia/Core/Thelia.php +++ b/core/lib/Thelia/Core/Thelia.php @@ -33,8 +33,10 @@ namespace Thelia\Core; */ use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Config\Loader\LoaderInterface; +use Symfony\Component\Validator\Tests\Fixtures\Reference; use Symfony\Component\Yaml\Yaml; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; @@ -118,6 +120,16 @@ class Thelia extends Kernel foreach ($modules as $module) { try { + + $defintion = new Definition(); + $defintion->setClass($module->getFullNamespace()); + $defintion->addMethodCall("setContainer", array('service_container')); + + $container->setDefinition( + "module.".$module->getCode(), + $defintion + ); + $loader = new XmlFileLoader($container, new FileLocator(THELIA_MODULE_DIR . "/" . ucfirst($module->getCode()) . "/Config")); $loader->load("config.xml"); } catch (\InvalidArgumentException $e) { diff --git a/core/lib/Thelia/Model/Base/Module.php b/core/lib/Thelia/Model/Base/Module.php index 556ef9ff6..9cc89381a 100755 --- a/core/lib/Thelia/Model/Base/Module.php +++ b/core/lib/Thelia/Model/Base/Module.php @@ -89,6 +89,12 @@ abstract class Module implements ActiveRecordInterface */ protected $position; + /** + * The value for the full_namespace field. + * @var string + */ + protected $full_namespace; + /** * The value for the created_at field. * @var string @@ -456,6 +462,17 @@ abstract class Module implements ActiveRecordInterface return $this->position; } + /** + * Get the [full_namespace] column value. + * + * @return string + */ + public function getFullNamespace() + { + + return $this->full_namespace; + } + /** * Get the [optionally formatted] temporal [created_at] column value. * @@ -601,6 +618,27 @@ abstract class Module implements ActiveRecordInterface return $this; } // setPosition() + /** + * Set the value of [full_namespace] column. + * + * @param string $v new value + * @return \Thelia\Model\Module The current object (for fluent API support) + */ + public function setFullNamespace($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->full_namespace !== $v) { + $this->full_namespace = $v; + $this->modifiedColumns[] = ModuleTableMap::FULL_NAMESPACE; + } + + + return $this; + } // setFullNamespace() + /** * Sets the value of [created_at] column to a normalized version of the date/time value specified. * @@ -695,13 +733,16 @@ abstract class Module implements ActiveRecordInterface $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : ModuleTableMap::translateFieldName('Position', TableMap::TYPE_PHPNAME, $indexType)]; $this->position = (null !== $col) ? (int) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : ModuleTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : ModuleTableMap::translateFieldName('FullNamespace', TableMap::TYPE_PHPNAME, $indexType)]; + $this->full_namespace = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : ModuleTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : ModuleTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : ModuleTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } @@ -714,7 +755,7 @@ abstract class Module implements ActiveRecordInterface $this->ensureConsistency(); } - return $startcol + 7; // 7 = ModuleTableMap::NUM_HYDRATE_COLUMNS. + return $startcol + 8; // 8 = ModuleTableMap::NUM_HYDRATE_COLUMNS. } catch (Exception $e) { throw new PropelException("Error populating \Thelia\Model\Module object", 0, $e); @@ -987,6 +1028,9 @@ abstract class Module implements ActiveRecordInterface if ($this->isColumnModified(ModuleTableMap::POSITION)) { $modifiedColumns[':p' . $index++] = 'POSITION'; } + if ($this->isColumnModified(ModuleTableMap::FULL_NAMESPACE)) { + $modifiedColumns[':p' . $index++] = 'FULL_NAMESPACE'; + } if ($this->isColumnModified(ModuleTableMap::CREATED_AT)) { $modifiedColumns[':p' . $index++] = 'CREATED_AT'; } @@ -1019,6 +1063,9 @@ abstract class Module implements ActiveRecordInterface case 'POSITION': $stmt->bindValue($identifier, $this->position, PDO::PARAM_INT); break; + case 'FULL_NAMESPACE': + $stmt->bindValue($identifier, $this->full_namespace, PDO::PARAM_STR); + break; case 'CREATED_AT': $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); break; @@ -1103,9 +1150,12 @@ abstract class Module implements ActiveRecordInterface return $this->getPosition(); break; case 5: - return $this->getCreatedAt(); + return $this->getFullNamespace(); break; case 6: + return $this->getCreatedAt(); + break; + case 7: return $this->getUpdatedAt(); break; default: @@ -1142,8 +1192,9 @@ abstract class Module implements ActiveRecordInterface $keys[2] => $this->getType(), $keys[3] => $this->getActivate(), $keys[4] => $this->getPosition(), - $keys[5] => $this->getCreatedAt(), - $keys[6] => $this->getUpdatedAt(), + $keys[5] => $this->getFullNamespace(), + $keys[6] => $this->getCreatedAt(), + $keys[7] => $this->getUpdatedAt(), ); $virtualColumns = $this->virtualColumns; foreach($virtualColumns as $key => $virtualColumn) @@ -1208,9 +1259,12 @@ abstract class Module implements ActiveRecordInterface $this->setPosition($value); break; case 5: - $this->setCreatedAt($value); + $this->setFullNamespace($value); break; case 6: + $this->setCreatedAt($value); + break; + case 7: $this->setUpdatedAt($value); break; } // switch() @@ -1242,8 +1296,9 @@ abstract class Module implements ActiveRecordInterface if (array_key_exists($keys[2], $arr)) $this->setType($arr[$keys[2]]); if (array_key_exists($keys[3], $arr)) $this->setActivate($arr[$keys[3]]); if (array_key_exists($keys[4], $arr)) $this->setPosition($arr[$keys[4]]); - if (array_key_exists($keys[5], $arr)) $this->setCreatedAt($arr[$keys[5]]); - if (array_key_exists($keys[6], $arr)) $this->setUpdatedAt($arr[$keys[6]]); + if (array_key_exists($keys[5], $arr)) $this->setFullNamespace($arr[$keys[5]]); + if (array_key_exists($keys[6], $arr)) $this->setCreatedAt($arr[$keys[6]]); + if (array_key_exists($keys[7], $arr)) $this->setUpdatedAt($arr[$keys[7]]); } /** @@ -1260,6 +1315,7 @@ abstract class Module implements ActiveRecordInterface if ($this->isColumnModified(ModuleTableMap::TYPE)) $criteria->add(ModuleTableMap::TYPE, $this->type); if ($this->isColumnModified(ModuleTableMap::ACTIVATE)) $criteria->add(ModuleTableMap::ACTIVATE, $this->activate); if ($this->isColumnModified(ModuleTableMap::POSITION)) $criteria->add(ModuleTableMap::POSITION, $this->position); + if ($this->isColumnModified(ModuleTableMap::FULL_NAMESPACE)) $criteria->add(ModuleTableMap::FULL_NAMESPACE, $this->full_namespace); if ($this->isColumnModified(ModuleTableMap::CREATED_AT)) $criteria->add(ModuleTableMap::CREATED_AT, $this->created_at); if ($this->isColumnModified(ModuleTableMap::UPDATED_AT)) $criteria->add(ModuleTableMap::UPDATED_AT, $this->updated_at); @@ -1329,6 +1385,7 @@ abstract class Module implements ActiveRecordInterface $copyObj->setType($this->getType()); $copyObj->setActivate($this->getActivate()); $copyObj->setPosition($this->getPosition()); + $copyObj->setFullNamespace($this->getFullNamespace()); $copyObj->setCreatedAt($this->getCreatedAt()); $copyObj->setUpdatedAt($this->getUpdatedAt()); @@ -1876,6 +1933,7 @@ abstract class Module implements ActiveRecordInterface $this->type = null; $this->activate = null; $this->position = null; + $this->full_namespace = null; $this->created_at = null; $this->updated_at = null; $this->alreadyInSave = false; diff --git a/core/lib/Thelia/Model/Base/ModuleQuery.php b/core/lib/Thelia/Model/Base/ModuleQuery.php index e1bd9de68..6f8d4b551 100755 --- a/core/lib/Thelia/Model/Base/ModuleQuery.php +++ b/core/lib/Thelia/Model/Base/ModuleQuery.php @@ -27,6 +27,7 @@ use Thelia\Model\Map\ModuleTableMap; * @method ChildModuleQuery orderByType($order = Criteria::ASC) Order by the type column * @method ChildModuleQuery orderByActivate($order = Criteria::ASC) Order by the activate column * @method ChildModuleQuery orderByPosition($order = Criteria::ASC) Order by the position column + * @method ChildModuleQuery orderByFullNamespace($order = Criteria::ASC) Order by the full_namespace column * @method ChildModuleQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column * @method ChildModuleQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column * @@ -35,6 +36,7 @@ use Thelia\Model\Map\ModuleTableMap; * @method ChildModuleQuery groupByType() Group by the type column * @method ChildModuleQuery groupByActivate() Group by the activate column * @method ChildModuleQuery groupByPosition() Group by the position column + * @method ChildModuleQuery groupByFullNamespace() Group by the full_namespace column * @method ChildModuleQuery groupByCreatedAt() Group by the created_at column * @method ChildModuleQuery groupByUpdatedAt() Group by the updated_at column * @@ -58,6 +60,7 @@ use Thelia\Model\Map\ModuleTableMap; * @method ChildModule findOneByType(int $type) Return the first ChildModule filtered by the type column * @method ChildModule findOneByActivate(int $activate) Return the first ChildModule filtered by the activate column * @method ChildModule findOneByPosition(int $position) Return the first ChildModule filtered by the position column + * @method ChildModule findOneByFullNamespace(string $full_namespace) Return the first ChildModule filtered by the full_namespace column * @method ChildModule findOneByCreatedAt(string $created_at) Return the first ChildModule filtered by the created_at column * @method ChildModule findOneByUpdatedAt(string $updated_at) Return the first ChildModule filtered by the updated_at column * @@ -66,6 +69,7 @@ use Thelia\Model\Map\ModuleTableMap; * @method array findByType(int $type) Return ChildModule objects filtered by the type column * @method array findByActivate(int $activate) Return ChildModule objects filtered by the activate column * @method array findByPosition(int $position) Return ChildModule objects filtered by the position column + * @method array findByFullNamespace(string $full_namespace) Return ChildModule objects filtered by the full_namespace column * @method array findByCreatedAt(string $created_at) Return ChildModule objects filtered by the created_at column * @method array findByUpdatedAt(string $updated_at) Return ChildModule objects filtered by the updated_at column * @@ -156,7 +160,7 @@ abstract class ModuleQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT ID, CODE, TYPE, ACTIVATE, POSITION, CREATED_AT, UPDATED_AT FROM module WHERE ID = :p0'; + $sql = 'SELECT ID, CODE, TYPE, ACTIVATE, POSITION, FULL_NAMESPACE, CREATED_AT, UPDATED_AT FROM module WHERE ID = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); @@ -438,6 +442,35 @@ abstract class ModuleQuery extends ModelCriteria return $this->addUsingAlias(ModuleTableMap::POSITION, $position, $comparison); } + /** + * Filter the query on the full_namespace column + * + * Example usage: + * + * $query->filterByFullNamespace('fooValue'); // WHERE full_namespace = 'fooValue' + * $query->filterByFullNamespace('%fooValue%'); // WHERE full_namespace LIKE '%fooValue%' + * + * + * @param string $fullNamespace The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildModuleQuery The current query, for fluid interface + */ + public function filterByFullNamespace($fullNamespace = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($fullNamespace)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $fullNamespace)) { + $fullNamespace = str_replace('*', '%', $fullNamespace); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(ModuleTableMap::FULL_NAMESPACE, $fullNamespace, $comparison); + } + /** * Filter the query on the created_at column * diff --git a/core/lib/Thelia/Model/Map/ModuleTableMap.php b/core/lib/Thelia/Model/Map/ModuleTableMap.php index cccaa890a..dae9fda4a 100755 --- a/core/lib/Thelia/Model/Map/ModuleTableMap.php +++ b/core/lib/Thelia/Model/Map/ModuleTableMap.php @@ -57,7 +57,7 @@ class ModuleTableMap extends TableMap /** * The total number of columns */ - const NUM_COLUMNS = 7; + const NUM_COLUMNS = 8; /** * The number of lazy-loaded columns @@ -67,7 +67,7 @@ class ModuleTableMap extends TableMap /** * The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */ - const NUM_HYDRATE_COLUMNS = 7; + const NUM_HYDRATE_COLUMNS = 8; /** * the column name for the ID field @@ -94,6 +94,11 @@ class ModuleTableMap extends TableMap */ const POSITION = 'module.POSITION'; + /** + * the column name for the FULL_NAMESPACE field + */ + const FULL_NAMESPACE = 'module.FULL_NAMESPACE'; + /** * the column name for the CREATED_AT field */ @@ -125,12 +130,12 @@ class ModuleTableMap extends TableMap * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ protected static $fieldNames = array ( - self::TYPE_PHPNAME => array('Id', 'Code', 'Type', 'Activate', 'Position', 'CreatedAt', 'UpdatedAt', ), - self::TYPE_STUDLYPHPNAME => array('id', 'code', 'type', 'activate', 'position', 'createdAt', 'updatedAt', ), - self::TYPE_COLNAME => array(ModuleTableMap::ID, ModuleTableMap::CODE, ModuleTableMap::TYPE, ModuleTableMap::ACTIVATE, ModuleTableMap::POSITION, ModuleTableMap::CREATED_AT, ModuleTableMap::UPDATED_AT, ), - self::TYPE_RAW_COLNAME => array('ID', 'CODE', 'TYPE', 'ACTIVATE', 'POSITION', 'CREATED_AT', 'UPDATED_AT', ), - self::TYPE_FIELDNAME => array('id', 'code', 'type', 'activate', 'position', 'created_at', 'updated_at', ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, ) + self::TYPE_PHPNAME => array('Id', 'Code', 'Type', 'Activate', 'Position', 'FullNamespace', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'code', 'type', 'activate', 'position', 'fullNamespace', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(ModuleTableMap::ID, ModuleTableMap::CODE, ModuleTableMap::TYPE, ModuleTableMap::ACTIVATE, ModuleTableMap::POSITION, ModuleTableMap::FULL_NAMESPACE, ModuleTableMap::CREATED_AT, ModuleTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'CODE', 'TYPE', 'ACTIVATE', 'POSITION', 'FULL_NAMESPACE', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'code', 'type', 'activate', 'position', 'full_namespace', 'created_at', 'updated_at', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, ) ); /** @@ -140,12 +145,12 @@ class ModuleTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'Code' => 1, 'Type' => 2, 'Activate' => 3, 'Position' => 4, 'CreatedAt' => 5, 'UpdatedAt' => 6, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'activate' => 3, 'position' => 4, 'createdAt' => 5, 'updatedAt' => 6, ), - self::TYPE_COLNAME => array(ModuleTableMap::ID => 0, ModuleTableMap::CODE => 1, ModuleTableMap::TYPE => 2, ModuleTableMap::ACTIVATE => 3, ModuleTableMap::POSITION => 4, ModuleTableMap::CREATED_AT => 5, ModuleTableMap::UPDATED_AT => 6, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'CODE' => 1, 'TYPE' => 2, 'ACTIVATE' => 3, 'POSITION' => 4, 'CREATED_AT' => 5, 'UPDATED_AT' => 6, ), - self::TYPE_FIELDNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'activate' => 3, 'position' => 4, 'created_at' => 5, 'updated_at' => 6, ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, ) + self::TYPE_PHPNAME => array('Id' => 0, 'Code' => 1, 'Type' => 2, 'Activate' => 3, 'Position' => 4, 'FullNamespace' => 5, 'CreatedAt' => 6, 'UpdatedAt' => 7, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'activate' => 3, 'position' => 4, 'fullNamespace' => 5, 'createdAt' => 6, 'updatedAt' => 7, ), + self::TYPE_COLNAME => array(ModuleTableMap::ID => 0, ModuleTableMap::CODE => 1, ModuleTableMap::TYPE => 2, ModuleTableMap::ACTIVATE => 3, ModuleTableMap::POSITION => 4, ModuleTableMap::FULL_NAMESPACE => 5, ModuleTableMap::CREATED_AT => 6, ModuleTableMap::UPDATED_AT => 7, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'CODE' => 1, 'TYPE' => 2, 'ACTIVATE' => 3, 'POSITION' => 4, 'FULL_NAMESPACE' => 5, 'CREATED_AT' => 6, 'UPDATED_AT' => 7, ), + self::TYPE_FIELDNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'activate' => 3, 'position' => 4, 'full_namespace' => 5, 'created_at' => 6, 'updated_at' => 7, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, ) ); /** @@ -169,6 +174,7 @@ class ModuleTableMap extends TableMap $this->addColumn('TYPE', 'Type', 'TINYINT', true, null, null); $this->addColumn('ACTIVATE', 'Activate', 'TINYINT', false, null, null); $this->addColumn('POSITION', 'Position', 'INTEGER', false, null, null); + $this->addColumn('FULL_NAMESPACE', 'FullNamespace', 'VARCHAR', false, 255, null); $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); } // initialize() @@ -349,6 +355,7 @@ class ModuleTableMap extends TableMap $criteria->addSelectColumn(ModuleTableMap::TYPE); $criteria->addSelectColumn(ModuleTableMap::ACTIVATE); $criteria->addSelectColumn(ModuleTableMap::POSITION); + $criteria->addSelectColumn(ModuleTableMap::FULL_NAMESPACE); $criteria->addSelectColumn(ModuleTableMap::CREATED_AT); $criteria->addSelectColumn(ModuleTableMap::UPDATED_AT); } else { @@ -357,6 +364,7 @@ class ModuleTableMap extends TableMap $criteria->addSelectColumn($alias . '.TYPE'); $criteria->addSelectColumn($alias . '.ACTIVATE'); $criteria->addSelectColumn($alias . '.POSITION'); + $criteria->addSelectColumn($alias . '.FULL_NAMESPACE'); $criteria->addSelectColumn($alias . '.CREATED_AT'); $criteria->addSelectColumn($alias . '.UPDATED_AT'); } diff --git a/core/lib/Thelia/Module/BaseModule.php b/core/lib/Thelia/Module/BaseModule.php index 07cc1d116..145da3c02 100755 --- a/core/lib/Thelia/Module/BaseModule.php +++ b/core/lib/Thelia/Module/BaseModule.php @@ -24,7 +24,9 @@ namespace Thelia\Module; -abstract class BaseModule +use Symfony\Component\DependencyInjection\ContainerAware; + +abstract class BaseModule extends ContainerAware { public function __construct() @@ -37,6 +39,19 @@ abstract class BaseModule } + public function hasContainer() + { + return null === $this->container; + } + + public function getContainer() + { + if($this->hasContainer() === false) { + throw new \RuntimeException("Sorry, container his not available in this context"); + } + return $this->container; + } + abstract public function install(); abstract public function destroy(); diff --git a/core/lib/Thelia/Module/BaseModuleInterface.php b/core/lib/Thelia/Module/BaseModuleInterface.php new file mode 100644 index 000000000..2db450830 --- /dev/null +++ b/core/lib/Thelia/Module/BaseModuleInterface.php @@ -0,0 +1,37 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Module; + + +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\HttpFoundation\Request; + +interface BaseModuleInterface { + + public function setRequest(Request $request); + public function getRequest(); + + public function setDispatcher(EventDispatcherInterface $dispatcher); + public function getDispatcher(); +} \ No newline at end of file diff --git a/core/lib/Thelia/Module/DeliveryModuleInterface.php b/core/lib/Thelia/Module/DeliveryModuleInterface.php new file mode 100644 index 000000000..b8ffcfc01 --- /dev/null +++ b/core/lib/Thelia/Module/DeliveryModuleInterface.php @@ -0,0 +1,36 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Module; + + +interface DeliveryModuleInterface extends BaseModuleInterface { + + /** + * + * calculate and return delivery price + * + * @return mixed + */ + public function calculate($country = null); +} \ No newline at end of file diff --git a/install/thelia.sql b/install/thelia.sql index 879f323b9..2fb3723ca 100755 --- a/install/thelia.sql +++ b/install/thelia.sql @@ -803,6 +803,7 @@ CREATE TABLE `module` `type` TINYINT NOT NULL, `activate` TINYINT, `position` INTEGER, + `full_namespace` VARCHAR(255), `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), diff --git a/local/config/schema.xml b/local/config/schema.xml index a9d7badc4..e6e68c4b2 100755 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -605,6 +605,7 @@ + diff --git a/local/modules/Colissimo/Colissimo.php b/local/modules/Colissimo/Colissimo.php new file mode 100644 index 000000000..4d24cc059 --- /dev/null +++ b/local/modules/Colissimo/Colissimo.php @@ -0,0 +1,83 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Colissimo; + +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\HttpFoundation\Request; +use Thelia\Module\BaseModule; +use Thelia\Module\DeliveryModuleInterface; + +class Colissimo extends BaseModule implements DeliveryModuleInterface +{ + protected $request; + protected $dispatcher; + + public function setRequest(Request $request) + { + $this->request = $request; + } + + public function getRequest() + { + return $this->request; + } + + public function setDispatcher(EventDispatcherInterface $dispatcher) + { + $this->dispatcher = $dispatcher; + } + + public function getDispatcher() + { + return $this->dispatcher; + } + + /** + * + * calculate and return delivery price + * + * @param null $country + * @return mixed + */ + public function calculate($country = null) + { + // TODO: Implement calculate() method. + return 2; + } + + /** + * YOU HAVE TO IMPLEMENT HERE ABSTRACT METHODD FROM BaseModule Class + * Like install and destroy + */ + public function install() + { + // TODO: Implement install() method. + } + + public function destroy() + { + // TODO: Implement destroy() method. + } + +} diff --git a/local/modules/Colissimo/Config/config.xml b/local/modules/Colissimo/Config/config.xml new file mode 100644 index 000000000..2430f5027 --- /dev/null +++ b/local/modules/Colissimo/Config/config.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/local/modules/Colissimo/Config/plugin.xml b/local/modules/Colissimo/Config/plugin.xml new file mode 100644 index 000000000..e69de29bb diff --git a/local/modules/Colissimo/Config/schema.xml b/local/modules/Colissimo/Config/schema.xml new file mode 100644 index 000000000..a4e2315b0 --- /dev/null +++ b/local/modules/Colissimo/Config/schema.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/templates/default/delivery_list.html b/templates/default/delivery_list.html new file mode 100644 index 000000000..2ea3cc166 --- /dev/null +++ b/templates/default/delivery_list.html @@ -0,0 +1,15 @@ +{include file="includes/header.html"} + +
    +{loop type="delivery" name="delivery.list"} +
  • +
      +
    • id : {#ID}
    • +
    • prix : {#PRICE}
    • +
    • Choisir : Choisir
    • +
    +
  • +{/loop} +
+ +{include file="includes/footer.html"} \ No newline at end of file