Merge branch 'delivery'

Conflicts:
	composer.lock
	install/insert.sql
This commit is contained in:
Manuel Raynaud
2013-09-07 16:37:54 +02:00
23 changed files with 669 additions and 51 deletions

View File

@@ -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");
}
}

View File

@@ -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
*/

View File

@@ -0,0 +1,109 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
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 <mraynaud@openstudio.fr>
*/
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;
}
}

View File

@@ -0,0 +1,85 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
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 <mraynaud@openstudio.fr>
*/
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;
}
}

View File

@@ -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) {