Rajout du dossier core + MAJ .gitignore
This commit is contained in:
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Coupon\FacadeInterface;
|
||||
use Thelia\Exception\InvalidConditionValueException;
|
||||
use Thelia\Model\Country;
|
||||
use Thelia\Model\CountryQuery;
|
||||
|
||||
/**
|
||||
* Check a Checkout against its Product number
|
||||
*
|
||||
* @package Condition
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*
|
||||
*/
|
||||
abstract class AbstractMatchCountries extends ConditionAbstract
|
||||
{
|
||||
/** Condition 1st parameter : quantity */
|
||||
const COUNTRIES_LIST = 'countries';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function __construct(FacadeInterface $facade)
|
||||
{
|
||||
$this->availableOperators = [
|
||||
self::COUNTRIES_LIST => [
|
||||
Operators::IN,
|
||||
Operators::OUT
|
||||
]
|
||||
];
|
||||
|
||||
parent::__construct($facade);
|
||||
}
|
||||
|
||||
abstract protected function getSummaryLabel($cntryStrList, $i18nOperator);
|
||||
|
||||
abstract protected function getFormLabel();
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function setValidatorsFromForm(array $operators, array $values)
|
||||
{
|
||||
$this->checkComparisonOperatorValue($operators, self::COUNTRIES_LIST);
|
||||
|
||||
// Use default values if data is not defined.
|
||||
if (! isset($operators[self::COUNTRIES_LIST]) || ! isset($values[self::COUNTRIES_LIST])) {
|
||||
$operators[self::COUNTRIES_LIST] = Operators::IN;
|
||||
$values[self::COUNTRIES_LIST] = [];
|
||||
}
|
||||
|
||||
// Be sure that the value is an array, make one if required
|
||||
if (! is_array($values[self::COUNTRIES_LIST])) {
|
||||
$values[self::COUNTRIES_LIST] = array($values[self::COUNTRIES_LIST]);
|
||||
}
|
||||
|
||||
// Check that at least one category is selected
|
||||
if (empty($values[self::COUNTRIES_LIST])) {
|
||||
throw new InvalidConditionValueException(
|
||||
get_class(),
|
||||
self::COUNTRIES_LIST
|
||||
);
|
||||
}
|
||||
|
||||
$this->operators = [ self::COUNTRIES_LIST => $operators[self::COUNTRIES_LIST] ];
|
||||
$this->values = [ self::COUNTRIES_LIST => $values[self::COUNTRIES_LIST] ];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function isMatching()
|
||||
{
|
||||
// The delivery address should match one of the selected countries.
|
||||
|
||||
/* TODO !!!! */
|
||||
|
||||
return $this->conditionValidator->variableOpComparison(
|
||||
$this->facade->getNbArticlesInCart(),
|
||||
$this->operators[self::COUNTRIES_LIST],
|
||||
$this->values[self::COUNTRIES_LIST]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getSummary()
|
||||
{
|
||||
$i18nOperator = Operators::getI18n(
|
||||
$this->translator,
|
||||
$this->operators[self::COUNTRIES_LIST]
|
||||
);
|
||||
|
||||
$cntryStrList = '';
|
||||
|
||||
$cntryIds = $this->values[self::COUNTRIES_LIST];
|
||||
|
||||
if (null !== $cntryList = CountryQuery::create()->findPks($cntryIds)) {
|
||||
/** @var Country $cntry */
|
||||
foreach ($cntryList as $cntry) {
|
||||
$cntryStrList .= $cntry->setLocale($this->getCurrentLocale())->getTitle() . ', ';
|
||||
}
|
||||
|
||||
$cntryStrList = rtrim($cntryStrList, ', ');
|
||||
}
|
||||
|
||||
return $this->getSummaryLabel($cntryStrList, $i18nOperator);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function generateInputs()
|
||||
{
|
||||
return array(
|
||||
self::COUNTRIES_LIST => array(
|
||||
'availableOperators' => $this->availableOperators[self::COUNTRIES_LIST],
|
||||
'value' => '',
|
||||
'selectedOperator' => Operators::IN
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function drawBackOfficeInputs()
|
||||
{
|
||||
return $this->facade->getParser()->render(
|
||||
'coupon/condition-fragments/countries-condition.html',
|
||||
[
|
||||
'operatorSelectHtml' => $this->drawBackOfficeInputOperators(self::COUNTRIES_LIST),
|
||||
'countries_field_name' => self::COUNTRIES_LIST,
|
||||
'values' => isset($this->values[self::COUNTRIES_LIST]) ? $this->values[self::COUNTRIES_LIST] : array(),
|
||||
'countryLabel' => $this->getFormLabel()
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Coupon\FacadeInterface;
|
||||
use Thelia\Exception\InvalidConditionValueException;
|
||||
use Thelia\Model\CartItem;
|
||||
use Thelia\Model\Category;
|
||||
use Thelia\Model\CategoryQuery;
|
||||
|
||||
/**
|
||||
* Check a Checkout against its Product number
|
||||
*
|
||||
* @package Condition
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*
|
||||
*/
|
||||
class CartContainsCategories extends ConditionAbstract
|
||||
{
|
||||
/** Condition 1st parameter : quantity */
|
||||
const CATEGORIES_LIST = 'categories';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function __construct(FacadeInterface $facade)
|
||||
{
|
||||
$this->availableOperators = [
|
||||
self::CATEGORIES_LIST => [
|
||||
Operators::IN,
|
||||
Operators::OUT
|
||||
]
|
||||
];
|
||||
|
||||
parent::__construct($facade);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getServiceId()
|
||||
{
|
||||
return 'thelia.condition.cart_contains_categories';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function setValidatorsFromForm(array $operators, array $values)
|
||||
{
|
||||
$this->checkComparisonOperatorValue($operators, self::CATEGORIES_LIST);
|
||||
|
||||
// Use default values if data is not defined.
|
||||
if (! isset($operators[self::CATEGORIES_LIST]) || ! isset($values[self::CATEGORIES_LIST])) {
|
||||
$operators[self::CATEGORIES_LIST] = Operators::IN;
|
||||
$values[self::CATEGORIES_LIST] = [];
|
||||
}
|
||||
|
||||
// Be sure that the value is an array, make one if required
|
||||
if (! is_array($values[self::CATEGORIES_LIST])) {
|
||||
$values[self::CATEGORIES_LIST] = array($values[self::CATEGORIES_LIST]);
|
||||
}
|
||||
|
||||
// Check that at least one category is selected
|
||||
if (empty($values[self::CATEGORIES_LIST])) {
|
||||
throw new InvalidConditionValueException(
|
||||
get_class(),
|
||||
self::CATEGORIES_LIST
|
||||
);
|
||||
}
|
||||
|
||||
$this->operators = [ self::CATEGORIES_LIST => $operators[self::CATEGORIES_LIST] ];
|
||||
$this->values = [ self::CATEGORIES_LIST => $values[self::CATEGORIES_LIST] ];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function isMatching()
|
||||
{
|
||||
$cartItems = $this->facade->getCart()->getCartItems();
|
||||
|
||||
/** @var CartItem $cartItem */
|
||||
foreach ($cartItems as $cartItem) {
|
||||
$categories = $cartItem->getProduct()->getCategories();
|
||||
|
||||
/** @var Category $category */
|
||||
foreach ($categories as $category) {
|
||||
$catecoryInCart = $this->conditionValidator->variableOpComparison(
|
||||
$category->getId(),
|
||||
$this->operators[self::CATEGORIES_LIST],
|
||||
$this->values[self::CATEGORIES_LIST]
|
||||
);
|
||||
|
||||
if ($catecoryInCart) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->translator->trans(
|
||||
'Cart contains categories condition',
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
$toolTip = $this->translator->trans(
|
||||
'The coupon applies if the cart contains at least one product of the selected categories',
|
||||
[]
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getSummary()
|
||||
{
|
||||
$i18nOperator = Operators::getI18n(
|
||||
$this->translator,
|
||||
$this->operators[self::CATEGORIES_LIST]
|
||||
);
|
||||
|
||||
$catStrList = '';
|
||||
|
||||
$catIds = $this->values[self::CATEGORIES_LIST];
|
||||
|
||||
if (null !== $catList = CategoryQuery::create()->findPks($catIds)) {
|
||||
/** @var Category $cat */
|
||||
foreach ($catList as $cat) {
|
||||
$catStrList .= $cat->setLocale($this->getCurrentLocale())->getTitle() . ', ';
|
||||
}
|
||||
|
||||
$catStrList = rtrim($catStrList, ', ');
|
||||
}
|
||||
|
||||
$toolTip = $this->translator->trans(
|
||||
'At least one of cart products categories is %op% <strong>%categories_list%</strong>',
|
||||
[
|
||||
'%categories_list%' => $catStrList,
|
||||
'%op%' => $i18nOperator
|
||||
]
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function generateInputs()
|
||||
{
|
||||
return array(
|
||||
self::CATEGORIES_LIST => array(
|
||||
'availableOperators' => $this->availableOperators[self::CATEGORIES_LIST],
|
||||
'value' => '',
|
||||
'selectedOperator' => Operators::IN
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function drawBackOfficeInputs()
|
||||
{
|
||||
return $this->facade->getParser()->render(
|
||||
'coupon/condition-fragments/cart-contains-categories-condition.html',
|
||||
[
|
||||
'operatorSelectHtml' => $this->drawBackOfficeInputOperators(self::CATEGORIES_LIST),
|
||||
'categories_field_name' => self::CATEGORIES_LIST,
|
||||
'values' => isset($this->values[self::CATEGORIES_LIST]) ? $this->values[self::CATEGORIES_LIST] : array()
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Coupon\FacadeInterface;
|
||||
use Thelia\Exception\InvalidConditionValueException;
|
||||
use Thelia\Model\ProductQuery;
|
||||
use Thelia\Model\CartItem;
|
||||
use Thelia\Model\Product;
|
||||
|
||||
/**
|
||||
* Check a Checkout against its Product number
|
||||
*
|
||||
* @package Condition
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*
|
||||
*/
|
||||
class CartContainsProducts extends ConditionAbstract
|
||||
{
|
||||
/** Condition 1st parameter : quantity */
|
||||
const PRODUCTS_LIST = 'products';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function __construct(FacadeInterface $facade)
|
||||
{
|
||||
$this->availableOperators = [
|
||||
self::PRODUCTS_LIST => [
|
||||
Operators::IN,
|
||||
Operators::OUT
|
||||
]
|
||||
];
|
||||
|
||||
parent::__construct($facade);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getServiceId()
|
||||
{
|
||||
return 'thelia.condition.cart_contains_products';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function setValidatorsFromForm(array $operators, array $values)
|
||||
{
|
||||
$this->checkComparisonOperatorValue($operators, self::PRODUCTS_LIST);
|
||||
|
||||
// Use default values if data is not defined.
|
||||
if (! isset($operators[self::PRODUCTS_LIST]) || ! isset($values[self::PRODUCTS_LIST])) {
|
||||
$operators[self::PRODUCTS_LIST] = Operators::IN;
|
||||
$values[self::PRODUCTS_LIST] = [];
|
||||
}
|
||||
|
||||
// Be sure that the value is an array, make one if required
|
||||
if (! is_array($values[self::PRODUCTS_LIST])) {
|
||||
$values[self::PRODUCTS_LIST] = array($values[self::PRODUCTS_LIST]);
|
||||
}
|
||||
|
||||
// Check that at least one product is selected
|
||||
if (empty($values[self::PRODUCTS_LIST])) {
|
||||
throw new InvalidConditionValueException(
|
||||
get_class(),
|
||||
self::PRODUCTS_LIST
|
||||
);
|
||||
}
|
||||
|
||||
$this->operators = [ self::PRODUCTS_LIST => $operators[self::PRODUCTS_LIST] ];
|
||||
$this->values = [ self::PRODUCTS_LIST => $values[self::PRODUCTS_LIST] ];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function isMatching()
|
||||
{
|
||||
$cartItems = $this->facade->getCart()->getCartItems();
|
||||
|
||||
/** @var CartItem $cartItem */
|
||||
foreach ($cartItems as $cartItem) {
|
||||
if ($this->conditionValidator->variableOpComparison(
|
||||
$cartItem->getProduct()->getId(),
|
||||
$this->operators[self::PRODUCTS_LIST],
|
||||
$this->values[self::PRODUCTS_LIST]
|
||||
)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->translator->trans(
|
||||
'Cart contains specific products',
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
$toolTip = $this->translator->trans(
|
||||
'The coupon applies if the cart contains at least one product of the specified product list',
|
||||
[]
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getSummary()
|
||||
{
|
||||
$i18nOperator = Operators::getI18n(
|
||||
$this->translator,
|
||||
$this->operators[self::PRODUCTS_LIST]
|
||||
);
|
||||
|
||||
$prodStrList = '';
|
||||
|
||||
$prodIds = $this->values[self::PRODUCTS_LIST];
|
||||
|
||||
if (null !== $prodList = ProductQuery::create()->findPks($prodIds)) {
|
||||
/** @var Product $prod */
|
||||
foreach ($prodList as $prod) {
|
||||
$prodStrList .= $prod->setLocale($this->getCurrentLocale())->getTitle() . ', ';
|
||||
}
|
||||
|
||||
$prodStrList = rtrim($prodStrList, ', ');
|
||||
}
|
||||
|
||||
$toolTip = $this->translator->trans(
|
||||
'Cart contains at least a product %op% <strong>%products_list%</strong>',
|
||||
[
|
||||
'%products_list%' => $prodStrList,
|
||||
'%op%' => $i18nOperator
|
||||
]
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function generateInputs()
|
||||
{
|
||||
return array(
|
||||
self::PRODUCTS_LIST => array(
|
||||
'availableOperators' => $this->availableOperators[self::PRODUCTS_LIST],
|
||||
'value' => '',
|
||||
'selectedOperator' => Operators::IN
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function drawBackOfficeInputs()
|
||||
{
|
||||
return $this->facade->getParser()->render(
|
||||
'coupon/condition-fragments/cart-contains-products-condition.html',
|
||||
[
|
||||
'operatorSelectHtml' => $this->drawBackOfficeInputOperators(self::PRODUCTS_LIST),
|
||||
'products_field_name' => self::PRODUCTS_LIST,
|
||||
'values' => isset($this->values[self::PRODUCTS_LIST]) ? $this->values[self::PRODUCTS_LIST] : array()
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
351
core/lib/Thelia/Condition/Implementation/ConditionAbstract.php
Normal file
351
core/lib/Thelia/Condition/Implementation/ConditionAbstract.php
Normal file
@@ -0,0 +1,351 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Thelia\Condition\ConditionEvaluator;
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Condition\SerializableCondition;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Coupon\FacadeInterface;
|
||||
use Thelia\Exception\InvalidConditionOperatorException;
|
||||
use Thelia\Exception\InvalidConditionValueException;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Model\Currency;
|
||||
use Thelia\Type\FloatType;
|
||||
|
||||
/**
|
||||
* Assist in writing a condition of whether the Condition is applied or not
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
abstract class ConditionAbstract implements ConditionInterface
|
||||
{
|
||||
/** @var array Available Operators (Operators::CONST) */
|
||||
protected $availableOperators = [];
|
||||
|
||||
/** @var array Parameters validating parameters against */
|
||||
protected $validators = [];
|
||||
|
||||
/** @var FacadeInterface Provide necessary value from Thelia */
|
||||
protected $facade = null;
|
||||
|
||||
/** @var Translator Service Translator */
|
||||
protected $translator = null;
|
||||
|
||||
/** @var array Operators set by Admin in BackOffice */
|
||||
protected $operators = [];
|
||||
|
||||
/** @var array Values set by Admin in BackOffice */
|
||||
protected $values = [];
|
||||
|
||||
/** @var ConditionEvaluator Conditions validator */
|
||||
protected $conditionValidator = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param FacadeInterface $facade Service Facade
|
||||
*/
|
||||
public function __construct(FacadeInterface $facade)
|
||||
{
|
||||
$this->facade = $facade;
|
||||
$this->translator = $facade->getTranslator();
|
||||
$this->conditionValidator = $facade->getConditionEvaluator();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $operatorList the list of comparison operator values, as entered in the condition parameter form
|
||||
* @param string $parameterName the name of the parameter to check
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws \Thelia\Exception\InvalidConditionOperatorException if the operator value is not in the allowed value
|
||||
*/
|
||||
protected function checkComparisonOperatorValue($operatorList, $parameterName)
|
||||
{
|
||||
$isOperator1Legit = $this->isOperatorLegit(
|
||||
$operatorList[$parameterName],
|
||||
$this->availableOperators[$parameterName]
|
||||
);
|
||||
|
||||
if (!$isOperator1Legit) {
|
||||
throw new InvalidConditionOperatorException(
|
||||
get_class(),
|
||||
$parameterName
|
||||
);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all validators
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getValidators()
|
||||
{
|
||||
$this->validators = $this->generateInputs();
|
||||
|
||||
$translatedInputs = [];
|
||||
|
||||
foreach ($this->validators as $key => $validator) {
|
||||
$translatedOperators = [];
|
||||
|
||||
foreach ($validator['availableOperators'] as $availableOperators) {
|
||||
$translatedOperators[$availableOperators] = Operators::getI18n(
|
||||
$this->translator,
|
||||
$availableOperators
|
||||
);
|
||||
}
|
||||
|
||||
$validator['availableOperators'] = $translatedOperators;
|
||||
|
||||
$translatedInputs[$key] = $validator;
|
||||
}
|
||||
|
||||
$validators = [
|
||||
'inputs' => $translatedInputs,
|
||||
'setOperators' => $this->operators,
|
||||
'setValues' => $this->values
|
||||
];
|
||||
|
||||
return $validators;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate inputs ready to be drawn.
|
||||
*
|
||||
* TODO: what these "inputs ready to be drawn" is not clear.
|
||||
*
|
||||
* @throws \Thelia\Exception\NotImplementedException
|
||||
* @return array
|
||||
*/
|
||||
protected function generateInputs()
|
||||
{
|
||||
throw new \Thelia\Exception\NotImplementedException(
|
||||
'The generateInputs method must be implemented in ' . get_class()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ConditionManager Service id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getServiceId()
|
||||
{
|
||||
throw new \Thelia\Exception\NotImplementedException(
|
||||
'The getServiceId method must be implemented in ' . get_class()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate if Operator given is available for this Condition
|
||||
*
|
||||
* @param string $operator Operator to validate ex <
|
||||
* @param array $availableOperators Available operators
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isOperatorLegit($operator, array $availableOperators)
|
||||
{
|
||||
return in_array($operator, $availableOperators);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a serializable Condition
|
||||
*
|
||||
* @return SerializableCondition
|
||||
*/
|
||||
public function getSerializableCondition()
|
||||
{
|
||||
$serializableCondition = new SerializableCondition();
|
||||
$serializableCondition->conditionServiceId = $this->getServiceId();
|
||||
$serializableCondition->operators = $this->operators;
|
||||
|
||||
$serializableCondition->values = $this->values;
|
||||
|
||||
return $serializableCondition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if currency if valid or not
|
||||
*
|
||||
* @param string $currencyValue Currency EUR|USD|..
|
||||
*
|
||||
* @return bool
|
||||
* @throws \Thelia\Exception\InvalidConditionValueException
|
||||
*/
|
||||
protected function isCurrencyValid($currencyValue)
|
||||
{
|
||||
$availableCurrencies = $this->facade->getAvailableCurrencies();
|
||||
/** @var Currency $currency */
|
||||
$currencyFound = false;
|
||||
foreach ($availableCurrencies as $currency) {
|
||||
if ($currencyValue == $currency->getCode()) {
|
||||
$currencyFound = true;
|
||||
}
|
||||
}
|
||||
if (!$currencyFound) {
|
||||
throw new InvalidConditionValueException(
|
||||
get_class(),
|
||||
'currency'
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if price is valid
|
||||
*
|
||||
* @param float $priceValue Price value to check
|
||||
*
|
||||
* @return bool
|
||||
* @throws \Thelia\Exception\InvalidConditionValueException
|
||||
*/
|
||||
protected function isPriceValid($priceValue)
|
||||
{
|
||||
$floatType = new FloatType();
|
||||
if (!$floatType->isValid($priceValue) || $priceValue <= 0) {
|
||||
throw new InvalidConditionValueException(
|
||||
get_class(),
|
||||
'price'
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the operator input displayed in the BackOffice
|
||||
* allowing Admin to set its Coupon Conditions
|
||||
*
|
||||
* @param string $inputKey Input key (ex: self::INPUT1)
|
||||
*
|
||||
* @return string HTML string
|
||||
*/
|
||||
protected function drawBackOfficeInputOperators($inputKey)
|
||||
{
|
||||
$html = '';
|
||||
|
||||
$inputs = $this->getValidators();
|
||||
|
||||
if (isset($inputs['inputs'][$inputKey])) {
|
||||
$html = $this->facade->getParser()->render(
|
||||
'coupon/condition-fragments/condition-selector.html',
|
||||
[
|
||||
'operators' => $inputs['inputs'][$inputKey]['availableOperators'],
|
||||
'value' => isset($this->operators[$inputKey]) ? $this->operators[$inputKey] : '',
|
||||
'inputKey' => $inputKey
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the base input displayed in the BackOffice
|
||||
* allowing Admin to set its Coupon Conditions
|
||||
*
|
||||
* @param string $label I18n input label
|
||||
* @param string $inputKey Input key (ex: self::INPUT1)
|
||||
*
|
||||
* @return string HTML string
|
||||
*/
|
||||
protected function drawBackOfficeBaseInputsText($label, $inputKey)
|
||||
{
|
||||
$operatorSelectHtml = $this->drawBackOfficeInputOperators($inputKey);
|
||||
|
||||
$currentValue = '';
|
||||
if (isset($this->values) && isset($this->values[$inputKey])) {
|
||||
$currentValue = $this->values[$inputKey];
|
||||
}
|
||||
|
||||
return $this->facade->getParser()->render(
|
||||
'coupon/conditions-fragments/base-input-text.html',
|
||||
[
|
||||
'label' => $label,
|
||||
'inputKey' => $inputKey,
|
||||
'currentValue' => $currentValue,
|
||||
'operatorSelectHtml' => $operatorSelectHtml
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the quantity input displayed in the BackOffice
|
||||
* allowing Admin to set its Coupon Conditions
|
||||
*
|
||||
* @param string $inputKey Input key (ex: self::INPUT1)
|
||||
* @param int $max Maximum selectable
|
||||
* @param int $min Minimum selectable
|
||||
*
|
||||
* @return string HTML string
|
||||
*/
|
||||
protected function drawBackOfficeInputQuantityValues($inputKey, $max = 10, $min = 0)
|
||||
{
|
||||
return $this->facade->getParser()->render(
|
||||
'coupon/condition-fragments/quantity-selector.html',
|
||||
[
|
||||
'min' => $min,
|
||||
'max' => $max,
|
||||
'value' => isset($this->values[$inputKey]) ? $this->values[$inputKey] : '',
|
||||
'inputKey' => $inputKey
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the currency input displayed in the BackOffice
|
||||
* allowing Admin to set its Coupon Conditions
|
||||
*
|
||||
* @param string $inputKey Input key (ex: self::INPUT1)
|
||||
*
|
||||
* @return string HTML string
|
||||
*/
|
||||
protected function drawBackOfficeCurrencyInput($inputKey)
|
||||
{
|
||||
$currencies = CurrencyQuery::create()->find();
|
||||
|
||||
$cleanedCurrencies = [];
|
||||
|
||||
/** @var Currency $currency */
|
||||
foreach ($currencies as $currency) {
|
||||
$cleanedCurrencies[$currency->getCode()] = $currency->getSymbol();
|
||||
}
|
||||
|
||||
return $this->facade->getParser()->render(
|
||||
'coupon/condition-fragments/currency-selector.html',
|
||||
[
|
||||
'currencies' => $cleanedCurrencies,
|
||||
'value' => isset($this->values[$inputKey]) ? $this->values[$inputKey] : '',
|
||||
'inputKey' => $inputKey
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A helper to het the current locale.
|
||||
*
|
||||
* @return string the current locale.
|
||||
*/
|
||||
protected function getCurrentLocale()
|
||||
{
|
||||
return $this->facade->getRequest()->getSession()->getLang()->getLocale();
|
||||
}
|
||||
}
|
||||
107
core/lib/Thelia/Condition/Implementation/ConditionInterface.php
Normal file
107
core/lib/Thelia/Condition/Implementation/ConditionInterface.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Thelia\Condition\SerializableCondition;
|
||||
use Thelia\Coupon\FacadeInterface;
|
||||
use Thelia\Exception\InvalidConditionOperatorException;
|
||||
use Thelia\Exception\InvalidConditionValueException;
|
||||
|
||||
/**
|
||||
* Manage how the application checks its state in order to check if it matches the implemented condition
|
||||
*
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
interface ConditionInterface
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param FacadeInterface $adapter Service adapter
|
||||
*/
|
||||
public function __construct(FacadeInterface $adapter);
|
||||
|
||||
/**
|
||||
* Get Condition Service id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getServiceId();
|
||||
|
||||
/**
|
||||
* Check validators relevancy and store them
|
||||
*
|
||||
* @param array $operators an array of operators (greater than, less than, etc.) entered in the condition parameter input form, one for each condition defined by the Condition
|
||||
* @param array $values an array of values entered in in the condition parameter input form, one for each condition defined by the Condition
|
||||
*
|
||||
* @throws InvalidConditionOperatorException
|
||||
* @throws InvalidConditionValueException
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setValidatorsFromForm(array $operators, array $values);
|
||||
|
||||
/**
|
||||
* Test if the current application state matches conditions
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isMatching();
|
||||
|
||||
/**
|
||||
* Get I18n name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
* Explain in detail what the Condition checks
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip();
|
||||
|
||||
/**
|
||||
* Get I18n summary
|
||||
* Explain briefly the condition with given values
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSummary();
|
||||
|
||||
/**
|
||||
* Return all validators
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getValidators();
|
||||
|
||||
/**
|
||||
* Return a serializable Condition
|
||||
*
|
||||
* @return SerializableCondition
|
||||
*/
|
||||
public function getSerializableCondition();
|
||||
|
||||
/**
|
||||
* Draw the input displayed in the BackOffice
|
||||
* allowing Admin to set its Coupon Conditions
|
||||
*
|
||||
* @return string HTML string
|
||||
*/
|
||||
public function drawBackOfficeInputs();
|
||||
}
|
||||
190
core/lib/Thelia/Condition/Implementation/ForSomeCustomers.php
Normal file
190
core/lib/Thelia/Condition/Implementation/ForSomeCustomers.php
Normal file
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Coupon\FacadeInterface;
|
||||
use Thelia\Exception\InvalidConditionValueException;
|
||||
use Thelia\Exception\UnmatchableConditionException;
|
||||
use Thelia\Model\Customer;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
|
||||
/**
|
||||
* Check a Checkout against its Product number
|
||||
*
|
||||
* @package Condition
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*
|
||||
*/
|
||||
class ForSomeCustomers extends ConditionAbstract
|
||||
{
|
||||
const CUSTOMERS_LIST = 'customers';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function __construct(FacadeInterface $facade)
|
||||
{
|
||||
$this->availableOperators = [
|
||||
self::CUSTOMERS_LIST => [
|
||||
Operators::IN,
|
||||
Operators::OUT
|
||||
]
|
||||
];
|
||||
|
||||
parent::__construct($facade);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getServiceId()
|
||||
{
|
||||
return 'thelia.condition.for_some_customers';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function setValidatorsFromForm(array $operators, array $values)
|
||||
{
|
||||
$this->checkComparisonOperatorValue($operators, self::CUSTOMERS_LIST);
|
||||
|
||||
// Use default values if data is not defined.
|
||||
if (! isset($operators[self::CUSTOMERS_LIST]) || ! isset($values[self::CUSTOMERS_LIST])) {
|
||||
$operators[self::CUSTOMERS_LIST] = Operators::IN;
|
||||
$values[self::CUSTOMERS_LIST] = [];
|
||||
}
|
||||
|
||||
// Be sure that the value is an array, make one if required
|
||||
if (! is_array($values[self::CUSTOMERS_LIST])) {
|
||||
$values[self::CUSTOMERS_LIST] = array($values[self::CUSTOMERS_LIST]);
|
||||
}
|
||||
|
||||
// Check that at least one product is selected
|
||||
if (empty($values[self::CUSTOMERS_LIST])) {
|
||||
throw new InvalidConditionValueException(
|
||||
get_class(),
|
||||
self::CUSTOMERS_LIST
|
||||
);
|
||||
}
|
||||
|
||||
$this->operators = [ self::CUSTOMERS_LIST => $operators[self::CUSTOMERS_LIST] ];
|
||||
$this->values = [ self::CUSTOMERS_LIST => $values[self::CUSTOMERS_LIST] ];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function isMatching()
|
||||
{
|
||||
if (null === $customer = $this->facade->getCustomer()) {
|
||||
throw new UnmatchableConditionException();
|
||||
}
|
||||
|
||||
return $this->conditionValidator->variableOpComparison(
|
||||
$customer->getId(),
|
||||
$this->operators[self::CUSTOMERS_LIST],
|
||||
$this->values[self::CUSTOMERS_LIST]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->translator->trans(
|
||||
'For one ore more customers',
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
$toolTip = $this->translator->trans(
|
||||
'The coupon applies to some customers only',
|
||||
[]
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getSummary()
|
||||
{
|
||||
$i18nOperator = Operators::getI18n(
|
||||
$this->translator,
|
||||
$this->operators[self::CUSTOMERS_LIST]
|
||||
);
|
||||
|
||||
$custStrList = '';
|
||||
|
||||
$custIds = $this->values[self::CUSTOMERS_LIST];
|
||||
|
||||
if (null !== $custList = CustomerQuery::create()->findPks($custIds)) {
|
||||
/** @var Customer $cust */
|
||||
foreach ($custList as $cust) {
|
||||
$custStrList .= $cust->getLastname() . ' ' . $cust->getFirstname() . ' ('.$cust->getRef().'), ';
|
||||
}
|
||||
|
||||
$custStrList = rtrim($custStrList, ', ');
|
||||
}
|
||||
|
||||
$toolTip = $this->translator->trans(
|
||||
'Customer is %op% <strong>%customer_list%</strong>',
|
||||
[
|
||||
'%customer_list%' => $custStrList,
|
||||
'%op%' => $i18nOperator
|
||||
]
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function generateInputs()
|
||||
{
|
||||
return array(
|
||||
self::CUSTOMERS_LIST => array(
|
||||
'availableOperators' => $this->availableOperators[self::CUSTOMERS_LIST],
|
||||
'value' => '',
|
||||
'selectedOperator' => Operators::IN
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function drawBackOfficeInputs()
|
||||
{
|
||||
return $this->facade->getParser()->render(
|
||||
'coupon/condition-fragments/customers-condition.html',
|
||||
[
|
||||
'operatorSelectHtml' => $this->drawBackOfficeInputOperators(self::CUSTOMERS_LIST),
|
||||
'customers_field_name' => self::CUSTOMERS_LIST,
|
||||
'values' => isset($this->values[self::CUSTOMERS_LIST]) ? $this->values[self::CUSTOMERS_LIST] : array()
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Thelia\Exception\UnmatchableConditionException;
|
||||
|
||||
/**
|
||||
* Check a Checkout against its Product number
|
||||
*
|
||||
* @package Condition
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*
|
||||
*/
|
||||
class MatchBillingCountries extends AbstractMatchCountries
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getServiceId()
|
||||
{
|
||||
return 'thelia.condition.match_billing_countries';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function isMatching()
|
||||
{
|
||||
if (null === $customer = $this->facade->getCustomer()) {
|
||||
throw new UnmatchableConditionException();
|
||||
}
|
||||
|
||||
$billingAddress = $customer->getDefaultAddress();
|
||||
|
||||
return $this->conditionValidator->variableOpComparison(
|
||||
$billingAddress->getCountryId(),
|
||||
$this->operators[self::COUNTRIES_LIST],
|
||||
$this->values[self::COUNTRIES_LIST]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->translator->trans(
|
||||
'Billing country',
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
$toolTip = $this->translator->trans(
|
||||
'The coupon applies to the selected billing countries',
|
||||
[]
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
|
||||
protected function getSummaryLabel($cntryStrList, $i18nOperator)
|
||||
{
|
||||
return $this->translator->trans(
|
||||
'Only if order billing country is %op% <strong>%countries_list%</strong>',
|
||||
[
|
||||
'%countries_list%' => $cntryStrList,
|
||||
'%op%' => $i18nOperator
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
protected function getFormLabel()
|
||||
{
|
||||
return $this->translator->trans(
|
||||
'Billing country is',
|
||||
[]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Thelia\Exception\UnmatchableConditionException;
|
||||
|
||||
/**
|
||||
* Check a Checkout against its Product number
|
||||
*
|
||||
* @package Condition
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*
|
||||
*/
|
||||
class MatchDeliveryCountries extends AbstractMatchCountries
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getServiceId()
|
||||
{
|
||||
return 'thelia.condition.match_delivery_countries';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function isMatching()
|
||||
{
|
||||
if (null === $customer = $this->facade->getCustomer()) {
|
||||
throw new UnmatchableConditionException();
|
||||
}
|
||||
|
||||
if (null === $deliveryAddress = $this->facade->getDeliveryAddress()) {
|
||||
throw new UnmatchableConditionException();
|
||||
}
|
||||
|
||||
return $this->conditionValidator->variableOpComparison(
|
||||
$deliveryAddress->getCountryId(),
|
||||
$this->operators[self::COUNTRIES_LIST],
|
||||
$this->values[self::COUNTRIES_LIST]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->translator->trans(
|
||||
'Delivery country',
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
$toolTip = $this->translator->trans(
|
||||
'The coupon applies to the selected delivery countries',
|
||||
[]
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
|
||||
protected function getSummaryLabel($cntryStrList, $i18nOperator)
|
||||
{
|
||||
return $this->translator->trans(
|
||||
'Only if order shipping country is %op% <strong>%countries_list%</strong>',
|
||||
[
|
||||
'%countries_list%' => $cntryStrList,
|
||||
'%op%' => $i18nOperator
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
protected function getFormLabel()
|
||||
{
|
||||
return $this->translator->trans(
|
||||
'Delivery country is',
|
||||
[]
|
||||
);
|
||||
}
|
||||
}
|
||||
117
core/lib/Thelia/Condition/Implementation/MatchForEveryone.php
Normal file
117
core/lib/Thelia/Condition/Implementation/MatchForEveryone.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Thelia\Coupon\FacadeInterface;
|
||||
|
||||
/**
|
||||
* Allow every one, perform no check
|
||||
*
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class MatchForEveryone extends ConditionAbstract
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function __construct(FacadeInterface $facade)
|
||||
{
|
||||
// Define the allowed comparison operators
|
||||
$this->availableOperators = [];
|
||||
|
||||
parent::__construct($facade);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getServiceId()
|
||||
{
|
||||
return 'thelia.condition.match_for_everyone';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function setValidatorsFromForm(array $operators, array $values)
|
||||
{
|
||||
$this->operators = [];
|
||||
$this->values = [];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function isMatching()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->translator->trans(
|
||||
'Unconditional usage',
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
$toolTip = $this->translator->trans(
|
||||
'This condition is always true',
|
||||
[]
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getSummary()
|
||||
{
|
||||
$toolTip = $this->translator->trans(
|
||||
'Unconditionnal usage',
|
||||
[]
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function generateInputs()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function drawBackOfficeInputs()
|
||||
{
|
||||
// No input
|
||||
return '';
|
||||
}
|
||||
}
|
||||
224
core/lib/Thelia/Condition/Implementation/MatchForTotalAmount.php
Normal file
224
core/lib/Thelia/Condition/Implementation/MatchForTotalAmount.php
Normal file
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Coupon\FacadeInterface;
|
||||
use Thelia\Model\Currency;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
|
||||
/**
|
||||
* Condition AvailableForTotalAmount
|
||||
* Check if a Checkout total amount match criteria
|
||||
*
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>, Franck Allimant <franck@cqfdev.fr>
|
||||
*
|
||||
*/
|
||||
class MatchForTotalAmount extends ConditionAbstract
|
||||
{
|
||||
/** Condition 1st parameter : price */
|
||||
const CART_TOTAL = 'price';
|
||||
|
||||
/** Condition 1st parameter : currency */
|
||||
const CART_CURRENCY = 'currency';
|
||||
|
||||
public function __construct(FacadeInterface $facade)
|
||||
{
|
||||
// Define the allowed comparison operators
|
||||
$this->availableOperators = [
|
||||
self::CART_TOTAL => [
|
||||
Operators::INFERIOR,
|
||||
Operators::INFERIOR_OR_EQUAL,
|
||||
Operators::EQUAL,
|
||||
Operators::SUPERIOR_OR_EQUAL,
|
||||
Operators::SUPERIOR
|
||||
],
|
||||
self::CART_CURRENCY => [
|
||||
Operators::EQUAL,
|
||||
]
|
||||
];
|
||||
|
||||
parent::__construct($facade);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getServiceId()
|
||||
{
|
||||
return 'thelia.condition.match_for_total_amount';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function setValidatorsFromForm(array $operators, array $values)
|
||||
{
|
||||
$this
|
||||
->checkComparisonOperatorValue($operators, self::CART_TOTAL)
|
||||
->checkComparisonOperatorValue($operators, self::CART_CURRENCY);
|
||||
|
||||
$this->isPriceValid($values[self::CART_TOTAL]);
|
||||
|
||||
$this->isCurrencyValid($values[self::CART_CURRENCY]);
|
||||
|
||||
$this->operators = array(
|
||||
self::CART_TOTAL => $operators[self::CART_TOTAL],
|
||||
self::CART_CURRENCY => $operators[self::CART_CURRENCY],
|
||||
);
|
||||
$this->values = array(
|
||||
self::CART_TOTAL => $values[self::CART_TOTAL],
|
||||
self::CART_CURRENCY => $values[self::CART_CURRENCY],
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if Customer meets conditions
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isMatching()
|
||||
{
|
||||
$condition1 = $this->conditionValidator->variableOpComparison(
|
||||
$this->facade->getCartTotalTaxPrice(),
|
||||
$this->operators[self::CART_TOTAL],
|
||||
$this->values[self::CART_TOTAL]
|
||||
);
|
||||
|
||||
if ($condition1) {
|
||||
$condition2 = $this->conditionValidator->variableOpComparison(
|
||||
$this->facade->getCheckoutCurrency(),
|
||||
$this->operators[self::CART_CURRENCY],
|
||||
$this->values[self::CART_CURRENCY]
|
||||
);
|
||||
|
||||
if ($condition2) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->translator->trans(
|
||||
'Cart total amount',
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
$toolTip = $this->translator->trans(
|
||||
'Check the total Cart amount in the given currency',
|
||||
[]
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getSummary()
|
||||
{
|
||||
$i18nOperator = Operators::getI18n(
|
||||
$this->translator,
|
||||
$this->operators[self::CART_TOTAL]
|
||||
);
|
||||
|
||||
$toolTip = $this->translator->trans(
|
||||
'If cart total amount is <strong>%operator%</strong> %amount% %currency%',
|
||||
array(
|
||||
'%operator%' => $i18nOperator,
|
||||
'%amount%' => $this->values[self::CART_TOTAL],
|
||||
'%currency%' => $this->values[self::CART_CURRENCY]
|
||||
)
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function generateInputs()
|
||||
{
|
||||
$currencies = CurrencyQuery::create()->filterByVisible(true)->find();
|
||||
|
||||
$cleanedCurrencies = [];
|
||||
|
||||
/** @var Currency $currency */
|
||||
foreach ($currencies as $currency) {
|
||||
$cleanedCurrencies[$currency->getCode()] = $currency->getSymbol();
|
||||
}
|
||||
|
||||
return array(
|
||||
self::CART_TOTAL => array(
|
||||
'availableOperators' => $this->availableOperators[self::CART_TOTAL],
|
||||
'availableValues' => '',
|
||||
'value' => '',
|
||||
'selectedOperator' => ''
|
||||
),
|
||||
self::CART_CURRENCY => array(
|
||||
'availableOperators' => $this->availableOperators[self::CART_CURRENCY],
|
||||
'availableValues' => $cleanedCurrencies,
|
||||
'value' => '',
|
||||
'selectedOperator' => Operators::EQUAL
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function drawBackOfficeInputs()
|
||||
{
|
||||
$labelPrice = $this->facade
|
||||
->getTranslator()
|
||||
->trans('Cart total amount is', []);
|
||||
|
||||
$html = $this->drawBackOfficeBaseInputsText($labelPrice, self::CART_TOTAL);
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function drawBackOfficeBaseInputsText($label, $inputKey)
|
||||
{
|
||||
return $this->facade->getParser()->render(
|
||||
'coupon/condition-fragments/cart-total-amount-condition.html',
|
||||
[
|
||||
'label' => $label,
|
||||
'inputKey' => $inputKey,
|
||||
'value' => isset($this->values[$inputKey]) ? $this->values[$inputKey] : '',
|
||||
'field_1_name' => self::CART_TOTAL,
|
||||
'field_2_name' => self::CART_CURRENCY,
|
||||
'operatorSelectHtml' => $this->drawBackOfficeInputOperators(self::CART_TOTAL),
|
||||
'currencySelectHtml' => $this->drawBackOfficeCurrencyInput(self::CART_CURRENCY),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
187
core/lib/Thelia/Condition/Implementation/MatchForXArticles.php
Normal file
187
core/lib/Thelia/Condition/Implementation/MatchForXArticles.php
Normal file
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Coupon\FacadeInterface;
|
||||
use Thelia\Exception\InvalidConditionValueException;
|
||||
|
||||
/**
|
||||
* Check a Checkout against its Product number
|
||||
*
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>, Franck Allimant <franck@cqfdev.fr>
|
||||
*
|
||||
*/
|
||||
class MatchForXArticles extends ConditionAbstract
|
||||
{
|
||||
/** Condition 1st parameter : quantity */
|
||||
const CART_QUANTITY = 'quantity';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function __construct(FacadeInterface $facade)
|
||||
{
|
||||
$this->availableOperators = array(
|
||||
self::CART_QUANTITY => array(
|
||||
Operators::INFERIOR,
|
||||
Operators::INFERIOR_OR_EQUAL,
|
||||
Operators::EQUAL,
|
||||
Operators::SUPERIOR_OR_EQUAL,
|
||||
Operators::SUPERIOR
|
||||
)
|
||||
);
|
||||
|
||||
parent::__construct($facade);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getServiceId()
|
||||
{
|
||||
return 'thelia.condition.match_for_x_articles';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function setValidatorsFromForm(array $operators, array $values)
|
||||
{
|
||||
$this->checkComparisonOperatorValue($operators, self::CART_QUANTITY);
|
||||
|
||||
if (intval($values[self::CART_QUANTITY]) <= 0) {
|
||||
throw new InvalidConditionValueException(
|
||||
get_class(),
|
||||
'quantity'
|
||||
);
|
||||
}
|
||||
|
||||
$this->operators = [
|
||||
self::CART_QUANTITY => $operators[self::CART_QUANTITY]
|
||||
];
|
||||
|
||||
$this->values = [
|
||||
self::CART_QUANTITY => $values[self::CART_QUANTITY]
|
||||
];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function isMatching()
|
||||
{
|
||||
$condition1 = $this->conditionValidator->variableOpComparison(
|
||||
$this->facade->getNbArticlesInCart(),
|
||||
$this->operators[self::CART_QUANTITY],
|
||||
$this->values[self::CART_QUANTITY]
|
||||
);
|
||||
|
||||
if ($condition1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->translator->trans(
|
||||
'Cart item count',
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
$toolTip = $this->translator->trans(
|
||||
'The cart item count should match the condition',
|
||||
[]
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getSummary()
|
||||
{
|
||||
$i18nOperator = Operators::getI18n(
|
||||
$this->translator,
|
||||
$this->operators[self::CART_QUANTITY]
|
||||
);
|
||||
|
||||
$toolTip = $this->translator->trans(
|
||||
'If cart item count is <strong>%operator%</strong> %quantity%',
|
||||
array(
|
||||
'%operator%' => $i18nOperator,
|
||||
'%quantity%' => $this->values[self::CART_QUANTITY]
|
||||
)
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function generateInputs()
|
||||
{
|
||||
return array(
|
||||
self::CART_QUANTITY => array(
|
||||
'availableOperators' => $this->availableOperators[self::CART_QUANTITY],
|
||||
'value' => '',
|
||||
'selectedOperator' => ''
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function drawBackOfficeInputs()
|
||||
{
|
||||
$labelQuantity = $this->facade
|
||||
->getTranslator()
|
||||
->trans('Cart item count is');
|
||||
|
||||
$html = $this->drawBackOfficeBaseInputsText($labelQuantity, self::CART_QUANTITY);
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function drawBackOfficeBaseInputsText($label, $inputKey)
|
||||
{
|
||||
return $this->facade->getParser()->render(
|
||||
'coupon/condition-fragments/cart-item-count-condition.html',
|
||||
[
|
||||
'label' => $label,
|
||||
'operatorSelectHtml' => $this->drawBackOfficeInputOperators($inputKey),
|
||||
'quantitySelectHtml' => $this->drawBackOfficeInputQuantityValues($inputKey, 20, 1)
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Thelia\Condition\Operators;
|
||||
|
||||
/**
|
||||
* Class MatchForXArticlesIncludeQuantity
|
||||
* @package Thelia\Condition\Implementation
|
||||
* @author Baixas Alban <abaixas@openstudio.fr>
|
||||
*/
|
||||
class MatchForXArticlesIncludeQuantity extends MatchForXArticles
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getServiceId()
|
||||
{
|
||||
return 'thelia.condition.match_for_x_articles_include_quantity';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->translator->trans('Cart item include quantity count');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function isMatching()
|
||||
{
|
||||
return $this->conditionValidator->variableOpComparison(
|
||||
$this->facade->getNbArticlesInCartIncludeQuantity(),
|
||||
$this->operators[self::CART_QUANTITY],
|
||||
$this->values[self::CART_QUANTITY]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function drawBackOfficeInputs()
|
||||
{
|
||||
$labelQuantity = $this->facade->getTranslator()->trans('Cart item include quantity count is');
|
||||
|
||||
return $this->drawBackOfficeBaseInputsText($labelQuantity, self::CART_QUANTITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getSummary()
|
||||
{
|
||||
$i18nOperator = Operators::getI18n(
|
||||
$this->translator,
|
||||
$this->operators[self::CART_QUANTITY]
|
||||
);
|
||||
|
||||
$toolTip = $this->translator->trans(
|
||||
'If cart item (include quantity) count is <strong>%operator%</strong> %quantity%',
|
||||
array(
|
||||
'%operator%' => $i18nOperator,
|
||||
'%quantity%' => $this->values[self::CART_QUANTITY]
|
||||
)
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
|
||||
}
|
||||
184
core/lib/Thelia/Condition/Implementation/StartDate.php
Normal file
184
core/lib/Thelia/Condition/Implementation/StartDate.php
Normal file
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Coupon\FacadeInterface;
|
||||
use Thelia\Exception\InvalidConditionValueException;
|
||||
use Thelia\Tools\DateTimeFormat;
|
||||
|
||||
/**
|
||||
* Check a Checkout against its Product number
|
||||
*
|
||||
* @package Condition
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*
|
||||
*/
|
||||
class StartDate extends ConditionAbstract
|
||||
{
|
||||
const START_DATE = 'start_date';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function __construct(FacadeInterface $facade)
|
||||
{
|
||||
$this->availableOperators = [
|
||||
self::START_DATE => [
|
||||
Operators::SUPERIOR_OR_EQUAL
|
||||
]
|
||||
];
|
||||
|
||||
parent::__construct($facade);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getServiceId()
|
||||
{
|
||||
return 'thelia.condition.start_date';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function setValidatorsFromForm(array $operators, array $values)
|
||||
{
|
||||
$this->checkComparisonOperatorValue($operators, self::START_DATE);
|
||||
|
||||
if (! isset($values[self::START_DATE])) {
|
||||
$values[self::START_DATE] = time();
|
||||
}
|
||||
|
||||
// Parse the entered date to get a timestamp, if we don't already have one
|
||||
if (! is_int($values[self::START_DATE])) {
|
||||
$date = \DateTime::createFromFormat($this->getDateFormat(), $values[self::START_DATE]);
|
||||
|
||||
// Check that the date is valid
|
||||
if (false === $date) {
|
||||
throw new InvalidConditionValueException(
|
||||
get_class(),
|
||||
self::START_DATE
|
||||
);
|
||||
}
|
||||
|
||||
$timestamp = $date->getTimestamp();
|
||||
} else {
|
||||
$timestamp = $values[self::START_DATE];
|
||||
}
|
||||
|
||||
$this->operators = [ self::START_DATE => $operators[self::START_DATE] ];
|
||||
$this->values = [ self::START_DATE => $timestamp ];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function isMatching()
|
||||
{
|
||||
return $this->conditionValidator->variableOpComparison(
|
||||
time(),
|
||||
$this->operators[self::START_DATE],
|
||||
$this->values[self::START_DATE]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->translator->trans(
|
||||
'Start date',
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
$toolTip = $this->translator->trans(
|
||||
'The coupon is valid after a given date',
|
||||
[]
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getSummary()
|
||||
{
|
||||
$date = new \DateTime();
|
||||
$date->setTimestamp($this->values[self::START_DATE]);
|
||||
$strDate = $date->format($this->getDateFormat());
|
||||
|
||||
$toolTip = $this->translator->trans(
|
||||
'Valid only from %date% to the coupon expiration date',
|
||||
[
|
||||
'%date%' => $strDate,
|
||||
],
|
||||
'condition'
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
|
||||
private function getDateFormat()
|
||||
{
|
||||
return DateTimeFormat::getInstance($this->facade->getRequest())->getFormat("date");
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function generateInputs()
|
||||
{
|
||||
return array(
|
||||
self::START_DATE => array(
|
||||
'availableOperators' => $this->availableOperators[self::START_DATE],
|
||||
'value' => '',
|
||||
'selectedOperator' => Operators::SUPERIOR_OR_EQUAL
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function drawBackOfficeInputs()
|
||||
{
|
||||
if (isset($this->values[self::START_DATE])) {
|
||||
$date = new \DateTime();
|
||||
|
||||
$date->setTimestamp($this->values[self::START_DATE]);
|
||||
|
||||
$strDate = $date->format($this->getDateFormat());
|
||||
} else {
|
||||
$strDate = '';
|
||||
}
|
||||
|
||||
return $this->facade->getParser()->render('coupon/condition-fragments/start-date-condition.html', [
|
||||
'fieldName' => self::START_DATE,
|
||||
'criteria' => Operators::SUPERIOR_OR_EQUAL,
|
||||
'dateFormat' => $this->getDateFormat(),
|
||||
'currentValue' => $strDate
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user