Merge branch 'master' into template

Conflicts:
	core/lib/Thelia/Core/Event/TheliaEvents.php
This commit is contained in:
Manuel Raynaud
2013-09-16 10:19:40 +02:00
148 changed files with 18129 additions and 3349 deletions

View File

@@ -39,6 +39,8 @@ use Thelia\Model\AttributeAvQuery;
use Thelia\Core\Event\UpdatePositionEvent;
use Thelia\Core\Event\CategoryEvent;
use Thelia\Core\Event\AttributeEvent;
use Thelia\Model\AttributeTemplate;
use Thelia\Model\AttributeTemplateQuery;
class Attribute extends BaseAction implements EventSubscriberInterface
{
@@ -137,10 +139,10 @@ class Attribute extends BaseAction implements EventSubscriberInterface
public function addToAllTemplates(AttributeEvent $event)
{
$templates = ProductTemplateAttributeQuery::create()->find();
$templates = AttributeTemplateQuery::create()->find();
foreach($templates as $template) {
$pat = new ProductTemplateAttribute();
$pat = new AttributeTemplate();
$pat->setTemplate($template->getId())
->setAttributeId($event->getAttribute()->getId())
@@ -151,7 +153,7 @@ class Attribute extends BaseAction implements EventSubscriberInterface
public function removeFromAllTemplates(AttributeEvent $event)
{
// Delete this attribute from all product templates
ProductTemplateAttributeQuery::create()->filterByAttributeId($event->getAttribute()->getId())->delete();
AttributeTemplateQuery::create()->filterByAttributeId($event->getAttribute()->getId())->delete();
}
/**

View File

@@ -23,10 +23,16 @@
namespace Thelia\Action;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Constraint\ConstraintFactory;
use Thelia\Core\Event\Coupon\CouponConsumeEvent;
use Thelia\Core\Event\Coupon\CouponCreateOrUpdateEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Coupon\CouponFactory;
use Thelia\Coupon\CouponManager;
use Thelia\Coupon\Type\CouponInterface;
use Thelia\Model\Coupon as CouponModel;
/**
@@ -45,7 +51,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
/**
* Occurring when a Coupon is about to be created
*
* @param CouponCreateOrUpdateEvent $event Event creation or update Event
* @param CouponCreateOrUpdateEvent $event Event creation or update Coupon
*/
public function create(CouponCreateOrUpdateEvent $event)
{
@@ -57,7 +63,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
/**
* Occurring when a Coupon is about to be updated
*
* @param CouponCreateOrUpdateEvent $event Event creation or update Event
* @param CouponCreateOrUpdateEvent $event Event creation or update Coupon
*/
public function update(CouponCreateOrUpdateEvent $event)
{
@@ -69,7 +75,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
/**
* Occurring when a Coupon rule is about to be updated
*
* @param CouponCreateOrUpdateEvent $event Event creation or update Event
* @param CouponCreateOrUpdateEvent $event Event creation or update Coupon Rule
*/
public function updateRule(CouponCreateOrUpdateEvent $event)
{
@@ -81,11 +87,43 @@ class Coupon extends BaseAction implements EventSubscriberInterface
/**
* Occurring when a Coupon rule is about to be consumed
*
* @param CouponCreateOrUpdateEvent $event Event creation or update Event
* @param CouponConsumeEvent $event Event consuming Coupon
*/
public function consume(CouponCreateOrUpdateEvent $event)
public function consume(CouponConsumeEvent $event)
{
// @todo implements
$totalDiscount = 0;
/** @var CouponFactory $couponFactory */
$couponFactory = $this->container->get('thelia.coupon.factory');
/** @var CouponManager $couponManager */
$couponManager = $this->container->get('thelia.coupon.manager');
/** @var CouponInterface $coupon */
$coupon = $couponFactory->buildCouponFromCode($event->getCode());
$isValid = $coupon->isMatching();
if ($isValid) {
/** @var Request $request */
$request = $this->container->get('request');
$consumedCoupons = $request->getSession()->getConsumedCoupons();
if (!isset($consumedCoupons) || !$consumedCoupons) {
$consumedCoupons = array();
}
// Prevent accumulation of the same Coupon on a Checkout
$consumedCoupons[$event->getCode()] = $event->getCode();
$request->getSession()->setConsumedCoupons($consumedCoupons);
$totalDiscount = $couponManager->getDiscount();
// @todo modify Cart total discount
}
$event->setIsValid($isValid);
$event->setDiscount($totalDiscount);
}
/**
@@ -165,8 +203,6 @@ class Coupon extends BaseAction implements EventSubscriberInterface
return array(
TheliaEvents::COUPON_CREATE => array("create", 128),
TheliaEvents::COUPON_UPDATE => array("update", 128),
TheliaEvents::COUPON_DISABLE => array("disable", 128),
TheliaEvents::COUPON_ENABLE => array("enable", 128),
TheliaEvents::COUPON_CONSUME => array("consume", 128),
TheliaEvents::COUPON_RULE_UPDATE => array("updateRule", 128)
);

View File

@@ -0,0 +1,127 @@
<?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\Action;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Model\TemplateQuery;
use Thelia\Model\Template as TemplateModel;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Event\TemplateUpdateEvent;
use Thelia\Core\Event\TemplateCreateEvent;
use Thelia\Core\Event\TemplateDeleteEvent;
use Thelia\Model\ConfigQuery;
use Thelia\Model\TemplateAv;
use Thelia\Model\TemplateAvQuery;
use Thelia\Core\Event\UpdatePositionEvent;
use Thelia\Core\Event\CategoryEvent;
use Thelia\Core\Event\TemplateEvent;
use Thelia\Model\TemplateTemplate;
use Thelia\Model\TemplateTemplateQuery;
use Thelia\Model\ProductQuery;
class Template extends BaseAction implements EventSubscriberInterface
{
/**
* Create a new template entry
*
* @param TemplateCreateEvent $event
*/
public function create(TemplateCreateEvent $event)
{
$template = new TemplateModel();
$template
->setDispatcher($this->getDispatcher())
->setLocale($event->getLocale())
->setName($event->getTemplateName())
->save()
;
$event->setTemplate($template);
}
/**
* Change a product template
*
* @param TemplateUpdateEvent $event
*/
public function update(TemplateUpdateEvent $event)
{
$search = TemplateQuery::create();
if (null !== $template = TemplateQuery::create()->findPk($event->getTemplateId())) {
$template
->setDispatcher($this->getDispatcher())
->setLocale($event->getLocale())
->setName($event->getTemplateName())
->save();
$event->setTemplate($template);
}
}
/**
* Delete a product template entry
*
* @param TemplateDeleteEvent $event
*/
public function delete(TemplateDeleteEvent $event)
{
if (null !== ($template = TemplateQuery::create()->findPk($event->getTemplateId()))) {
// Check if template is used by a product
$product_count = ProductQuery::create()->findByTemplateId($template->getId())->count();
if ($product_count <= 0) {
$template
->setDispatcher($this->getDispatcher())
->delete()
;
}
$event->setTemplate($template);
$event->setProductCount($product_count);
}
}
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents()
{
return array(
TheliaEvents::TEMPLATE_CREATE => array("create", 128),
TheliaEvents::TEMPLATE_UPDATE => array("update", 128),
TheliaEvents::TEMPLATE_DELETE => array("delete", 128),
);
}
}