WIP : Refactor contraint/rule becomes conditions (more generic)

This commit is contained in:
gmorel
2013-09-25 14:51:42 +02:00
parent cb389f126c
commit d6172f23cf
75 changed files with 582 additions and 2787 deletions

View File

@@ -0,0 +1,106 @@
<?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\Condition;
use Thelia\Core\Event\ActionEvent;
use Thelia\Coupon\ConditionCollection;
use Thelia\Coupon\Type\CouponInterface;
/**
* Created by JetBrains PhpStorm.
* Date: 8/29/13
* Time: 3:45 PM
*
* Occurring when a Condition is created or updated
*
* @package Coupon
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class ConditionCreateOrUpdateEvent extends ActionEvent
{
/** @var ConditionCollection Array of ConditionManagerInterface */
protected $conditions = null;
/** @var CouponInterface Coupon model associated with this conditions */
protected $couponModel = null;
/**
* Constructor
*
* @param ConditionCollection $conditions Array of ConditionManagerInterface
*/
public function __construct(ConditionCollection $conditions)
{
$this->conditions = $conditions;
}
/**
* Get Conditions
*
* @return null|ConditionCollection Array of ConditionManagerInterface
*/
public function getConditions()
{
return $this->conditions;
}
/**
* Set Conditions
*
* @param ConditionCollection $conditions Array of ConditionManagerInterface
*
* @return $this
*/
public function setConditions(ConditionCollection $conditions)
{
$this->conditions = $conditions;
return $this;
}
/**
* Set Coupon Model associated to this condition
*
* @param CouponInterface $couponModel Coupon Model
*
* @return $this
*/
public function setCouponModel($couponModel)
{
$this->couponModel = $couponModel;
return $this;
}
/**
* Get Coupon Model associated to this condition
*
* @return null|CouponInterface
*/
public function getCouponModel()
{
return $this->couponModel;
}
}

View File

@@ -23,8 +23,6 @@
namespace Thelia\Core\Event\Coupon;
use Thelia\Core\Event\ActionEvent;
use Thelia\Coupon\CouponRuleCollection;
use Thelia\Model\Coupon;
/**
* Created by JetBrains PhpStorm.
@@ -56,7 +54,7 @@ class CouponConsumeEvent extends ActionEvent
* @param bool $isValid If Coupon is valid or
* if Customer meets coupon conditions
*/
function __construct($code, $discount = null, $isValid = null)
public function __construct($code, $discount = null, $isValid = null)
{
$this->code = $code;
$this->discount = $discount;
@@ -136,7 +134,4 @@ class CouponConsumeEvent extends ActionEvent
return $this->isValid;
}
}

View File

@@ -23,7 +23,7 @@
namespace Thelia\Core\Event\Coupon;
use Thelia\Core\Event\ActionEvent;
use Thelia\Coupon\CouponRuleCollection;
use Thelia\Coupon\ConditionCollection;
use Thelia\Model\Coupon;
/**
@@ -39,8 +39,8 @@ use Thelia\Model\Coupon;
*/
class CouponCreateOrUpdateEvent extends ActionEvent
{
/** @var CouponRuleCollection Array of CouponRuleInterface */
protected $rules = null;
/** @var ConditionCollection Array of ConditionManagerInterface */
protected $conditions = null;
/** @var string Coupon code (ex: XMAS) */
protected $code = null;
@@ -87,23 +87,24 @@ class CouponCreateOrUpdateEvent extends ActionEvent
/**
* Constructor
*
* @param string $code Coupon Code
* @param string $title Coupon title
* @param float $amount Amount removed from the Total Checkout
* @param string $type Coupon type
* @param string $shortDescription Coupon short description
* @param string $description Coupon description
* @param boolean $isEnabled Enable/Disable
* @param string $code Coupon Code
* @param string $title Coupon title
* @param float $amount Amount removed from the Total Checkout
* @param string $type Coupon type
* @param string $shortDescription Coupon short description
* @param string $description Coupon description
* @param bool $isEnabled Enable/Disable
* @param \DateTime $expirationDate Coupon expiration date
* @param boolean $isAvailableOnSpecialOffers Is available on special offers
* @param boolean $isCumulative Is cumulative
* @param boolean $isRemovingPostage Is removing Postage
* @param int $maxUsage Coupon quantity
* @param string $locale Coupon Language code ISO (ex: fr_FR)
* @param boolean $isAvailableOnSpecialOffers Is available on special offers
* @param boolean $isCumulative Is cumulative
* @param boolean $isRemovingPostage Is removing Postage
* @param int $maxUsage Coupon quantity
* @param string $locale Coupon Language code ISO (ex: fr_FR)
*/
public function __construct(
$code, $title, $amount, $type, $shortDescription, $description, $isEnabled, \DateTime $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $isRemovingPostage, $maxUsage, $locale
) {
)
{
$this->amount = $amount;
$this->code = $code;
$this->description = $description;
@@ -276,4 +277,28 @@ class CouponCreateOrUpdateEvent extends ActionEvent
return $this->coupon;
}
/**
* Get Rules
*
* @return null|ConditionCollection Array of ConditionManagerInterface
*/
public function getConditions()
{
return $this->conditions;
}
/**
* set Rules
*
* @param ConditionCollection $rules Array of ConditionManagerInterface
*
* @return $this
*/
public function setConditions(ConditionCollection $rules)
{
$this->conditions = $rules;
return $this;
}
}

View File

@@ -365,19 +365,19 @@ final class TheliaEvents
const AFTER_CONSUME_COUPON = "action.after_consume_coupon";
/**
* Sent when attempting to update Coupon Rule
* Sent when attempting to update Coupon Condition
*/
const COUPON_RULE_UPDATE = "action.update_coupon_rule";
const COUPON_CONDITION_UPDATE = "action.update_coupon_condition";
/**
* Sent just before an attempt to update a Coupon Rule
* Sent just before an attempt to update a Coupon Condition
*/
const BEFORE_COUPON_RULE_UPDATE = "action.before_update_coupon_rule";
const BEFORE_COUPON_CONDITION_UPDATE = "action.before_update_coupon_condition";
/**
* Sent just after an attempt to update a Coupon Rule
* Sent just after an attempt to update a Coupon Condition
*/
const AFTER_COUPON_RULE_UPDATE = "action.after_update_coupon_rule";
const AFTER_COUPON_CONDITION_UPDATE = "action.after_update_coupon_condition";
// -- Configuration management ---------------------------------------------

View File

@@ -95,7 +95,7 @@ class Coupon extends BaseI18nLoop
$loopResult = new LoopResult();
/** @var ConstraintFactory $constraintFactory */
$constraintFactory = $this->container->get('thelia.constraint.factory');
$constraintFactory = $this->container->get('thelia.condition.factory');
/** @var Request $request */
$request = $this->container->get('request');