This commit is contained in:
mespeche
2013-09-16 12:56:47 +02:00
46 changed files with 1423 additions and 373 deletions

View File

@@ -65,7 +65,7 @@ class Cart extends BaseAction implements EventSubscriberInterface
->filterByProductSaleElementsId($productSaleElementsId)
->findOne();
$this->doAddItem($cart, $productId, $productSaleElementsId, $quantity, $productPrice);
$this->doAddItem($cart, $productId, $productPrice->getProductSaleElements(), $quantity, $productPrice);
}
if ($append && $cartItem !== null) {
@@ -166,17 +166,18 @@ class Cart extends BaseAction implements EventSubscriberInterface
* @param float $quantity
* @param ProductPrice $productPrice
*/
protected function doAddItem(\Thelia\Model\Cart $cart, $productId, $productSaleElementsId, $quantity, ProductPrice $productPrice)
protected function doAddItem(\Thelia\Model\Cart $cart, $productId, \Thelia\Model\ProductSaleElements $productSaleElements, $quantity, ProductPrice $productPrice)
{
$cartItem = new CartItem();
$cartItem->setDisptacher($this->getDispatcher());
$cartItem
->setCart($cart)
->setProductId($productId)
->setProductSaleElementsId($productSaleElementsId)
->setProductSaleElementsId($productSaleElements->getId())
->setQuantity($quantity)
->setPrice($productPrice->getPrice())
->setPromoPrice($productPrice->getPromoPrice())
->setPromo($productSaleElements->getPromo())
->setPriceEndOfLife(time() + ConfigQuery::read("cart.priceEOF", 60*60*24*30))
->save();
}

View File

@@ -26,6 +26,7 @@ namespace Thelia\Action;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\KernelEvents;
use Thelia\Model\ConfigQuery;
@@ -43,6 +44,10 @@ class HttpException extends BaseAction implements EventSubscriberInterface
if ($event->getException() instanceof NotFoundHttpException) {
$this->display404($event);
}
if($event->getException() instanceof AccessDeniedHttpException) {
$this->display403($event);
}
}
protected function display404(GetResponseForExceptionEvent $event)

View File

@@ -42,6 +42,14 @@ use Thelia\Core\Event\TemplateEvent;
use Thelia\Model\TemplateTemplate;
use Thelia\Model\TemplateTemplateQuery;
use Thelia\Model\ProductQuery;
use Thelia\Core\Event\TemplateAddAttributeEvent;
use Thelia\Core\Event\TemplateDeleteAttributeEvent;
use Thelia\Model\AttributeTemplateQuery;
use Thelia\Model\AttributeTemplate;
use Thelia\Core\Event\TemplateDeleteFeatureEvent;
use Thelia\Core\Event\TemplateAddFeatureEvent;
use Thelia\Model\FeatureTemplateQuery;
use Thelia\Model\FeatureTemplate;
class Template extends BaseAction implements EventSubscriberInterface
{
@@ -113,6 +121,54 @@ class Template extends BaseAction implements EventSubscriberInterface
}
}
public function addAttribute(TemplateAddAttributeEvent $event) {
if (null === AttributeTemplateQuery::create()->filterByAttributeId($event->getAttributeId())->filterByTemplate($event->getTemplate())->findOne()) {
$attribute_template = new AttributeTemplate();
$attribute_template
->setAttributeId($event->getAttributeId())
->setTemplate($event->getTemplate())
->save()
;
}
}
public function deleteAttribute(TemplateDeleteAttributeEvent $event) {
$attribute_template = AttributeTemplateQuery::create()
->filterByAttributeId($event->getAttributeId())
->filterByTemplate($event->getTemplate())->findOne()
;
if ($attribute_template !== null) $attribute_template->delete();
}
public function addFeature(TemplateAddFeatureEvent $event) {
if (null === FeatureTemplateQuery::create()->filterByFeatureId($event->getFeatureId())->filterByTemplate($event->getTemplate())->findOne()) {
$feature_template = new FeatureTemplate();
$feature_template
->setFeatureId($event->getFeatureId())
->setTemplate($event->getTemplate())
->save()
;
}
}
public function deleteFeature(TemplateDeleteFeatureEvent $event) {
$feature_template = FeatureTemplateQuery::create()
->filterByFeatureId($event->getFeatureId())
->filterByTemplate($event->getTemplate())->findOne()
;
if ($feature_template !== null) $feature_template->delete();
}
/**
* {@inheritDoc}
*/
@@ -122,6 +178,13 @@ class Template extends BaseAction implements EventSubscriberInterface
TheliaEvents::TEMPLATE_CREATE => array("create", 128),
TheliaEvents::TEMPLATE_UPDATE => array("update", 128),
TheliaEvents::TEMPLATE_DELETE => array("delete", 128),
TheliaEvents::TEMPLATE_ADD_ATTRIBUTE => array("addAttribute", 128),
TheliaEvents::TEMPLATE_DELETE_ATTRIBUTE => array("deleteAttribute", 128),
TheliaEvents::TEMPLATE_ADD_FEATURE => array("addFeature", 128),
TheliaEvents::TEMPLATE_DELETE_FEATURE => array("deleteFeature", 128),
);
}
}

View File

@@ -234,6 +234,30 @@
<default key="_controller">Thelia\Controller\Admin\TemplateController::deleteAction</default>
</route>
<route id="admin.configuration.templates.features.list" path="/admin/configuration/templates/features/list">
<default key="_controller">Thelia\Controller\Admin\TemplateController::getAjaxFeaturesAction</default>
</route>
<route id="admin.configuration.templates.features.add" path="/admin/configuration/templates/features/add">
<default key="_controller">Thelia\Controller\Admin\TemplateController::addFeatureAction</default>
</route>
<route id="admin.configuration.templates.features.delete" path="/admin/configuration/templates/features/delete">
<default key="_controller">Thelia\Controller\Admin\TemplateController::deleteFeatureAction</default>
</route>
<route id="admin.configuration.templates.attributes.list" path="/admin/configuration/templates/attributes/list">
<default key="_controller">Thelia\Controller\Admin\TemplateController::getAjaxAttributesAction</default>
</route>
<route id="admin.configuration.templates.attributes.add" path="/admin/configuration/templates/attributes/add">
<default key="_controller">Thelia\Controller\Admin\TemplateController::addAttributeAction</default>
</route>
<route id="admin.configuration.templates.attributes.delete" path="/admin/configuration/templates/attributes/delete">
<default key="_controller">Thelia\Controller\Admin\TemplateController::deleteAttributeAction</default>
</route>
<!-- attribute and attributes value management -->

View File

@@ -99,7 +99,6 @@
</route>
<route id="cart.add.process" path="/cart/add">
<default key="_controller">Thelia\Controller\Front\CartController::addItem</default>
<default key="_view">cart</default>
</route>
<route id="cart.delete.process" path="/cart/delete/{cart_item}">

View File

@@ -69,10 +69,10 @@ class ConstraintValidator
/**
* Do variable comparison
*
* @param mixed $v1 Variable 1
* @param mixed $v1 Variable 1
* @param string $o Operator
* @param mixed $v2 Variable 2
*
* @param mixed $v2 Variable 2
* @throws \Exception
* @return bool
*/

View File

@@ -24,6 +24,7 @@
namespace Thelia\Constraint\Rule;
use Symfony\Component\Intl\Exception\NotImplementedException;
use Thelia\Constraint\ConstraintValidator;
use Thelia\Core\Translation\Translator;
use Thelia\Coupon\CouponAdapterInterface;
use Thelia\Constraint\Validator\ComparableInterface;
@@ -73,6 +74,9 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
/** @var array Values set by Admin in BackOffice */
protected $values = array();
/** @var ConstraintValidator Constaints validator */
protected $constraintValidator = null;
/**
* Constructor
*

View File

@@ -35,6 +35,10 @@ use Thelia\Model\TemplateAv;
use Thelia\Model\TemplateAvQuery;
use Thelia\Core\Event\TemplateAvUpdateEvent;
use Thelia\Core\Event\TemplateEvent;
use Thelia\Core\Event\TemplateDeleteAttributeEvent;
use Thelia\Core\Event\TemplateAddAttributeEvent;
use Thelia\Core\Event\TemplateAddFeatureEvent;
use Thelia\Core\Event\TemplateDeleteFeatureEvent;
/**
* Manages templates sent by mail
@@ -193,4 +197,106 @@ class TemplateController extends AbstractCrudController
return null;
}
public function getAjaxFeaturesAction() {
return $this->render(
'ajax/template-feature-list',
array('template_id' => $this->getRequest()->get('template_id'))
);
}
public function getAjaxAttributesAction() {
return $this->render(
'ajax/template-attribute-list',
array('template_id' => $this->getRequest()->get('template_id'))
);
}
public function addAttributeAction() {
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.template.attribute.add")) return $response;
$attribute_id = intval($this->getRequest()->get('attribute_id'));
if ($attribute_id > 0) {
$event = new TemplateAddAttributeEvent(
$this->getExistingObject(),
$attribute_id
);
try {
$this->dispatch(TheliaEvents::TEMPLATE_ADD_ATTRIBUTE, $event);
} catch (\Exception $ex) {
// Any error
return $this->errorPage($ex);
}
}
$this->redirectToEditionTemplate();
}
public function deleteAttributeAction() {
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.template.attribute.delete")) return $response;
$event = new TemplateDeleteAttributeEvent(
$this->getExistingObject(),
intval($this->getRequest()->get('attribute_id'))
);
try {
$this->dispatch(TheliaEvents::TEMPLATE_DELETE_ATTRIBUTE, $event);
} catch (\Exception $ex) {
// Any error
return $this->errorPage($ex);
}
$this->redirectToEditionTemplate();
}
public function addFeatureAction() {
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.template.feature.add")) return $response;
$feature_id = intval($this->getRequest()->get('feature_id'));
if ($feature_id > 0) {
$event = new TemplateAddFeatureEvent(
$this->getExistingObject(),
$feature_id
);
try {
$this->dispatch(TheliaEvents::TEMPLATE_ADD_FEATURE, $event);
} catch (\Exception $ex) {
// Any error
return $this->errorPage($ex);
}
}
$this->redirectToEditionTemplate();
}
public function deleteFeatureAction() {
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.template.feature.delete")) return $response;
$event = new TemplateDeleteFeatureEvent(
$this->getExistingObject(),
intval($this->getRequest()->get('feature_id'))
);
try {
$this->dispatch(TheliaEvents::TEMPLATE_DELETE_FEATURE, $event);
} catch (\Exception $ex) {
// Any error
return $this->errorPage($ex);
}
$this->redirectToEditionTemplate();
}
}

View File

@@ -47,6 +47,7 @@ class AddressController extends BaseFrontController
*/
public function generateModalAction($address_id)
{
$this->checkAuth();
$this->checkXmlHttpRequest();
@@ -62,6 +63,7 @@ class AddressController extends BaseFrontController
*/
public function createAction()
{
$this->checkAuth();
$addressCreate = new AddressCreateForm($this->getRequest());

View File

@@ -0,0 +1,51 @@
<?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\Event;
use Thelia\Model\Template;
class TemplateAddAttributeEvent extends TemplateEvent
{
protected $attribute_id;
public function __construct(Template $template, $attribute_id)
{
parent::__construct($template);
$this->attribute_id = $attribute_id;
}
public function getAttributeId()
{
return $this->attribute_id;
}
public function setAttributeId($attribute_id)
{
$this->attribute_id = $attribute_id;
return $this;
}
}

View File

@@ -0,0 +1,51 @@
<?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\Event;
use Thelia\Model\Template;
class TemplateAddFeatureEvent extends TemplateEvent
{
protected $feature_id;
public function __construct(Template $template, $feature_id)
{
parent::__construct($template);
$this->feature_id = $feature_id;
}
public function getFeatureId()
{
return $this->feature_id;
}
public function setFeatureId($feature_id)
{
$this->feature_id = $feature_id;
return $this;
}
}

View File

@@ -0,0 +1,51 @@
<?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\Event;
use Thelia\Model\Template;
class TemplateDeleteAttributeEvent extends TemplateEvent
{
protected $attribute_id;
public function __construct(Template $template, $attribute_id)
{
parent::__construct($template);
$this->attribute_id = $attribute_id;
}
public function getAttributeId()
{
return $this->attribute_id;
}
public function setAttributeId($attribute_id)
{
$this->attribute_id = $attribute_id;
return $this;
}
}

View File

@@ -0,0 +1,51 @@
<?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\Event;
use Thelia\Model\Template;
class TemplateDeleteFeatureEvent extends TemplateEvent
{
protected $feature_id;
public function __construct(Template $template, $feature_id)
{
parent::__construct($template);
$this->feature_id = $feature_id;
}
public function getFeatureId()
{
return $this->feature_id;
}
public function setFeatureId($feature_id)
{
$this->feature_id = $feature_id;
return $this;
}
}

View File

@@ -337,12 +337,19 @@ final class TheliaEvents
const BEFORE_DELETECURRENCY = "action.before_deleteCurrency";
const AFTER_DELETECURRENCY = "action.after_deleteCurrency";
const CHANGE_DEFAULT_CURRENCY = 'action.changeDefaultCurrency';
// -- Product templates management -----------------------------------------
const TEMPLATE_CREATE = "action.createTemplate";
const TEMPLATE_UPDATE = "action.updateTemplate";
const TEMPLATE_DELETE = "action.deleteTemplate";
const TEMPLATE_ADD_ATTRIBUTE = "action.templateAddAttribute";
const TEMPLATE_DELETE_ATTRIBUTE = "action.templateDeleteAttribute";
const TEMPLATE_ADD_FEATURE = "action.templateAddFeature";
const TEMPLATE_DELETE_FEATURE = "action.templateDeleteFeature";
const BEFORE_CREATETEMPLATE = "action.before_createTemplate";
const AFTER_CREATETEMPLATE = "action.after_createTemplate";

View File

@@ -94,7 +94,7 @@ class ViewListener implements EventSubscriberInterface
{
$request = $this->container->get('request');
if (!$view = $request->attributes->get('_view')) {
if (null === $view = $request->attributes->get('_view')) {
$request->attributes->set('_view', $this->findView($request));
}

View File

@@ -164,10 +164,12 @@ class Session extends BaseSession
$cart = null;
if ($cart_id) {
$cart = CartQuery::create()->findPk($cart_id);
try {
$this->verifyValidCart($cart);
} catch (InvalidCartException $e) {
$cart = null;
if($cart) {
try {
$this->verifyValidCart($cart);
} catch (InvalidCartException $e) {
$cart = null;
}
}
}

View File

@@ -73,7 +73,7 @@ abstract class BaseI18nLoop extends BaseLoop
$columns,
$foreignTable,
$foreignKey,
$forceReturn
$this->getForce_return()
);
}
}

View File

@@ -89,6 +89,7 @@ abstract class BaseLoop
Argument::createIntTypeArgument('page'),
Argument::createIntTypeArgument('limit', PHP_INT_MAX),
Argument::createBooleanTypeArgument('backend_context', false),
Argument::createBooleanTypeArgument('force_return', false),
);
}

View File

@@ -64,6 +64,7 @@ class Attribute extends BaseI18nLoop
Argument::createIntListTypeArgument('id'),
Argument::createIntListTypeArgument('product'),
Argument::createIntListTypeArgument('template'),
Argument::createIntListTypeArgument('exclude_template'),
Argument::createIntListTypeArgument('exclude'),
new Argument(
'order',
@@ -115,15 +116,25 @@ class Attribute extends BaseI18nLoop
$template = $productObj->getTemplate();
}
// If we have to filter by template, find all attributes assigned to this template, and filter by found IDs
if (null !== $template) {
$search->filterById(
AttributeTemplateQuery::create()->filterByTemplateId($template)->select('id')->find(),
AttributeTemplateQuery::create()->filterByTemplateId($template)->select('attribute_id')->find(),
Criteria::IN
);
}
$exclude_template = $this->getExcludeTemplate();
// If we have to filter by template, find all attributes assigned to this template, and filter by found IDs
if (null !== $exclude_template) {
// Exclure tous les attribut qui sont attachés aux templates indiqués
$search->filterById(
AttributeTemplateQuery::create()->filterByTemplateId($exclude_template)->select('attribute_id')->find(),
Criteria::NOT_IN
);
}
$orders = $this->getOrder();
foreach ($orders as $order) {

View File

@@ -38,6 +38,7 @@ use Thelia\Model\Map\ProductCategoryTableMap;
use Thelia\Type\TypeCollection;
use Thelia\Type;
use Thelia\Type\BooleanOrBothType;
use Thelia\Model\FeatureTemplateQuery;
/**
*
@@ -60,7 +61,8 @@ class Feature extends BaseI18nLoop
return new ArgumentCollection(
Argument::createIntListTypeArgument('id'),
Argument::createIntListTypeArgument('product'),
Argument::createIntListTypeArgument('category'),
Argument::createIntListTypeArgument('template'),
Argument::createIntListTypeArgument('exclude_template'),
Argument::createBooleanOrBothTypeArgument('visible', 1),
Argument::createIntListTypeArgument('exclude'),
new Argument(
@@ -102,22 +104,33 @@ class Feature extends BaseI18nLoop
if ($visible != BooleanOrBothType::ANY) $search->filterByVisible($visible);
$product = $this->getProduct();
$category = $this->getCategory();
$template = $this->getTemplate();
if (null !== $product) {
$productCategories = ProductCategoryQuery::create()->select(array(ProductCategoryTableMap::CATEGORY_ID))->filterByProductId($product, Criteria::IN)->find()->getData();
// Find the template assigned to the product.
$productObj = ProductQuery::create()->findPk($product);
if (null === $category) {
$category = $productCategories;
} else {
$category = array_merge($category, $productCategories);
}
// Ignore if the product cannot be found.
if ($productObj !== null)
$template = $productObj->getTemplate();
}
// If we have to filter by template, find all features assigned to this template, and filter by found IDs
if (null !== $template) {
$search->filterById(
FeatureTemplateQuery::create()->filterByTemplateId($template)->select('feature_id')->find(),
Criteria::IN
);
}
if (null !== $category) {
$search->filterByCategory(
CategoryQuery::create()->filterById($category)->find(),
Criteria::IN
$exclude_template = $this->getExcludeTemplate();
// If we have to filter by template, find all features assigned to this template, and filter by found IDs
if (null !== $exclude_template) {
// Exclure tous les attribut qui sont attachés aux templates indiqués
$search->filterById(
FeatureTemplateQuery::create()->filterByTemplateId($exclude_template)->select('feature_id')->find(),
Criteria::NOT_IN
);
}

View File

@@ -37,6 +37,7 @@ use Thelia\Model\Product;
use Thelia\Model\ProductQuery;
use Thelia\Model\Tools\ModelCriteriaTools;
use Thelia\Tools\DateTimeFormat;
use Thelia\Cart\CartTrait;
/**
* Implementation of data access to main Thelia objects (users, cart, etc.)
@@ -46,6 +47,8 @@ use Thelia\Tools\DateTimeFormat;
*/
class DataAccessFunctions extends AbstractSmartyPlugin
{
use CartTrait;
private $securityContext;
protected $parserContext;
protected $request;
@@ -151,6 +154,20 @@ class DataAccessFunctions extends AbstractSmartyPlugin
}
}
public function cartDataAccess($params, $smarty)
{
$cart = $this->getCart($this->request);
$result = "";
switch($params["attr"]) {
case "count_item":
$result = $cart->getCartItems()->count();
break;
}
return $result;
}
/**
* Lang global data
*
@@ -263,6 +280,7 @@ class DataAccessFunctions extends AbstractSmartyPlugin
new SmartyPluginDescriptor('function', 'folder', $this, 'folderDataAccess'),
new SmartyPluginDescriptor('function', 'currency', $this, 'currencyDataAccess'),
new SmartyPluginDescriptor('function', 'lang', $this, 'langDataAccess'),
new SmartyPluginDescriptor('function', 'cart', $this, 'cartDataAccess'),
);
}
}

View File

@@ -32,6 +32,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Session;
use Thelia\Core\Event\CurrencyEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Model;
/**
@@ -146,6 +148,9 @@ class TheliaHttpKernel extends HttpKernel
$currency = null;
if ($request->query->has("currency")) {
$currency = Model\CurrencyQuery::create()->findOneByCode($request->query->get("currency"));
if($currency) {
$this->container->get("event_dispatcher")->dispatch(TheliaEvents::CHANGE_DEFAULT_CURRENCY, new CurrencyEvent($currency));
}
} else {
$currency = $request->getSession()->getCurrency(false);
}

View File

@@ -29,6 +29,7 @@ use Thelia\Form\Exception\ProductNotFoundException;
use Thelia\Model\ProductSaleElementsQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Model\ProductQuery;
use Thelia\Core\Translation\Translator;
/**
* Class CartAdd
@@ -75,13 +76,15 @@ class CartAdd extends BaseForm
))
->add("product_sale_elements_id", "text", array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Callback(array("methods" => array(
array($this, "checkStockAvailability")
)))
)
),
"required" => true
))
->add("quantity", "text", array(
->add("quantity", "number", array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Callback(array("methods" => array(
@@ -90,6 +93,10 @@ class CartAdd extends BaseForm
new Constraints\GreaterThanOrEqual(array(
"value" => 0
))
),
"label" => Translator::getInstance()->trans("Quantity"),
"label_attr" => array(
"for" => "quantity"
)
))
->add("append", "hidden")
@@ -126,13 +133,17 @@ class CartAdd extends BaseForm
{
$data = $context->getRoot()->getData();
$productSaleElements = ProductSaleElementsQuery::create()
->filterById($data["product_sale_elements_id"])
->filterByProductId($data["product"])
->findOne();
if (null === $data["product_sale_elements_id"]) {
$context->addViolationAt("quantity", Translator::getInstance()->trans("Invalid product_sale_elements"));
} else {
$productSaleElements = ProductSaleElementsQuery::create()
->filterById($data["product_sale_elements_id"])
->filterByProductId($data["product"])
->findOne();
if ($productSaleElements->getQuantity() < $value && ConfigQuery::read("verifyStock", 1) == 1) {
$context->addViolation("quantity value is not valid");
if ($productSaleElements->getQuantity() < $value && ConfigQuery::read("verifyStock", 1) == 1) {
$context->addViolation("quantity value is not valid");
}
}
}

View File

@@ -44,16 +44,18 @@ class Cart extends BaseCart
$item->setQuantity($cartItem->getQuantity());
$item->setProductSaleElements($productSaleElements);
if ($currentDateTime <= $cartItem->getPriceEndOfLife()) {
$item->setPrice($cartItem->getPrice());
$item->setPromoPrice($cartItem->getPromoPrice());
$item->setPrice($cartItem->getPrice())
->setPromoPrice($cartItem->getPromoPrice())
->setPromo($productSaleElements->getPromo())
// TODO : new price EOF or duplicate current priceEOF from $cartItem ?
$item->setPriceEndOfLife($cartItem->getPriceEndOfLife());
->setPriceEndOfLife($cartItem->getPriceEndOfLife());
} else {
$productPrices = ProductPriceQuery::create()->filterByProductSaleElements($productSaleElements)->findOne();
$item->setPrice($productPrices->getPrice());
$item->setPromoPrice($productPrices->getPromoPrice());
$item->setPriceEndOfLife(time() + ConfigQuery::read("cart.priceEOF", 60*60*24*30));
$item->setPrice($productPrices->getPrice())
->setPromoPrice($productPrices->getPromoPrice())
->setPromo($productSaleElements->getPromo())
->setPriceEndOfLife(time() + ConfigQuery::read("cart.priceEOF", 60*60*24*30));
}
$item->save();
}
@@ -76,4 +78,17 @@ class Cart extends BaseCart
{
}
public function getTotalAmount()
{
$total = 0;
foreach($this->getCartItems() as $cartItem) {
$total += $cartItem->getPrice()-$cartItem->getDiscount();
}
$total -= $this->getDiscount();
return $total;
}
}

View File

@@ -65,6 +65,7 @@ class Config extends BaseConfig {
*/
public function postUpdate(ConnectionInterface $con = null)
{
$this->resetQueryCache();
$this->dispatchEvent(TheliaEvents::AFTER_UPDATECONFIG, new ConfigEvent($this));
}
@@ -83,6 +84,12 @@ class Config extends BaseConfig {
*/
public function postDelete(ConnectionInterface $con = null)
{
$this->resetQueryCache();
$this->dispatchEvent(TheliaEvents::AFTER_DELETECONFIG, new ConfigEvent($this));
}
public function resetQueryCache()
{
ConfigQuery::resetCache($this->getName());
}
}

View File

@@ -16,11 +16,32 @@ use Thelia\Model\Base\ConfigQuery as BaseConfigQuery;
*
*/
class ConfigQuery extends BaseConfigQuery {
protected static $cache = array();
public static function read($search, $default = null)
{
if (array_key_exists($search, self::$cache)) {
return self::$cache[$search];
}
$value = self::create()->findOneByName($search);
return $value ? $value->getValue() : $default;
self::$cache[$search] = $value ? $value->getValue() : $default;
return self::$cache[$search];
}
public static function resetCache($key = null)
{
if($key) {
if(array_key_exists($key, self::$cache)) {
unset(self::$cache[$key]);
return true;
}
}
self::$cache = array();
return true;
}
public static function getDefaultLangWhenNoTranslationAvailable()

View File

@@ -65,6 +65,9 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getCheckoutCurrency')
->will($this->returnValue('EUR'));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue($ConstraintValidator));
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
@@ -99,6 +102,9 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getCheckoutCurrency')
->will($this->returnValue('EUR'));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue($ConstraintValidator));
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
@@ -136,6 +142,9 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(5));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue($ConstraintValidator));
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
@@ -183,6 +192,9 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(5));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue($ConstraintValidator));
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(

View File

@@ -23,6 +23,7 @@
namespace Thelia\Coupon;
use Thelia\Constraint\ConstraintValidator;
use Thelia\Constraint\Rule\AvailableForTotalAmountManager;
use Thelia\Constraint\Rule\Operators;
@@ -169,6 +170,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getCheckoutCurrency')
->will($this->returnValue('EUR'));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
@@ -205,6 +209,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getCheckoutCurrency')
->will($this->returnValue('EUR'));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
@@ -241,6 +248,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getCheckoutCurrency')
->will($this->returnValue('EUR'));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
@@ -277,6 +287,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getCheckoutCurrency')
->will($this->returnValue('EUR'));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
@@ -313,6 +326,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getCheckoutCurrency')
->will($this->returnValue('EUR'));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
@@ -349,6 +365,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getCheckoutCurrency')
->will($this->returnValue('EUR'));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
@@ -385,6 +404,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getCheckoutCurrency')
->will($this->returnValue('EUR'));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
@@ -421,6 +443,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getCheckoutCurrency')
->will($this->returnValue('EUR'));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
@@ -457,6 +482,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getCheckoutCurrency')
->will($this->returnValue('EUR'));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
@@ -493,6 +521,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getCheckoutCurrency')
->will($this->returnValue('EUR'));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
@@ -529,6 +560,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getCheckoutCurrency')
->will($this->returnValue('EUR'));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
@@ -565,6 +599,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getCheckoutCurrency')
->will($this->returnValue('EUR'));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
@@ -601,6 +638,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getCheckoutCurrency')
->will($this->returnValue('EUR'));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
@@ -637,6 +677,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getCheckoutCurrency')
->will($this->returnValue('EUR'));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(

View File

@@ -23,6 +23,7 @@
namespace Thelia\Coupon;
use Thelia\Constraint\ConstraintValidator;
use Thelia\Constraint\Rule\AvailableForXArticlesManager;
use Thelia\Constraint\Rule\Operators;
use Thelia\Constraint\Rule\SerializableRule;
@@ -192,6 +193,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -224,6 +228,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -256,6 +263,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -288,6 +298,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -320,6 +333,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -352,6 +368,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -384,6 +403,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -416,6 +438,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -448,6 +473,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -480,6 +508,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -512,6 +543,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -544,6 +578,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -570,6 +607,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -602,6 +642,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(