Inital commit
This commit is contained in:
@@ -28,7 +28,7 @@ use Thelia\Model\CountryQuery;
|
||||
abstract class AbstractMatchCountries extends ConditionAbstract
|
||||
{
|
||||
/** Condition 1st parameter : quantity */
|
||||
CONST COUNTRIES_LIST = 'countries';
|
||||
const COUNTRIES_LIST = 'countries';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
@@ -70,7 +70,8 @@ abstract class AbstractMatchCountries extends ConditionAbstract
|
||||
// Check that at least one category is selected
|
||||
if (empty($values[self::COUNTRIES_LIST])) {
|
||||
throw new InvalidConditionValueException(
|
||||
get_class(), self::COUNTRIES_LIST
|
||||
get_class(),
|
||||
self::COUNTRIES_LIST
|
||||
);
|
||||
}
|
||||
|
||||
@@ -102,7 +103,8 @@ abstract class AbstractMatchCountries extends ConditionAbstract
|
||||
public function getSummary()
|
||||
{
|
||||
$i18nOperator = Operators::getI18n(
|
||||
$this->translator, $this->operators[self::COUNTRIES_LIST]
|
||||
$this->translator,
|
||||
$this->operators[self::COUNTRIES_LIST]
|
||||
);
|
||||
|
||||
$cntryStrList = '';
|
||||
@@ -110,10 +112,9 @@ abstract class AbstractMatchCountries extends ConditionAbstract
|
||||
$cntryIds = $this->values[self::COUNTRIES_LIST];
|
||||
|
||||
if (null !== $cntryList = CountryQuery::create()->findPks($cntryIds)) {
|
||||
|
||||
/** @var Country $cntry */
|
||||
foreach ($cntryList as $cntry) {
|
||||
$cntryStrList .= $cntry->getTitle() . ', ';
|
||||
$cntryStrList .= $cntry->setLocale($this->getCurrentLocale())->getTitle() . ', ';
|
||||
}
|
||||
|
||||
$cntryStrList = rtrim($cntryStrList, ', ');
|
||||
@@ -141,7 +142,9 @@ abstract class AbstractMatchCountries extends ConditionAbstract
|
||||
*/
|
||||
public function drawBackOfficeInputs()
|
||||
{
|
||||
return $this->facade->getParser()->render('coupon/condition-fragments/countries-condition.html', [
|
||||
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(),
|
||||
|
||||
@@ -29,7 +29,7 @@ use Thelia\Model\CategoryQuery;
|
||||
class CartContainsCategories extends ConditionAbstract
|
||||
{
|
||||
/** Condition 1st parameter : quantity */
|
||||
CONST CATEGORIES_LIST = 'categories';
|
||||
const CATEGORIES_LIST = 'categories';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
@@ -75,7 +75,8 @@ class CartContainsCategories extends ConditionAbstract
|
||||
// Check that at least one category is selected
|
||||
if (empty($values[self::CATEGORIES_LIST])) {
|
||||
throw new InvalidConditionValueException(
|
||||
get_class(), self::CATEGORIES_LIST
|
||||
get_class(),
|
||||
self::CATEGORIES_LIST
|
||||
);
|
||||
}
|
||||
|
||||
@@ -94,23 +95,22 @@ class CartContainsCategories extends ConditionAbstract
|
||||
|
||||
/** @var CartItem $cartItem */
|
||||
foreach ($cartItems as $cartItem) {
|
||||
|
||||
$categories = $cartItem->getProduct()->getCategories();
|
||||
|
||||
/** @var Category $category */
|
||||
foreach ($categories as $category) {
|
||||
$catecoryInCart = $this->conditionValidator->variableOpComparison(
|
||||
if (! $this->conditionValidator->variableOpComparison(
|
||||
$category->getId(),
|
||||
$this->operators[self::CATEGORIES_LIST],
|
||||
$this->values[self::CATEGORIES_LIST]
|
||||
);
|
||||
|
||||
if ($catecoryInCart) {
|
||||
return true;
|
||||
)) {
|
||||
// cart item doesn't match go to next cart item
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// cart item match
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -144,7 +144,8 @@ class CartContainsCategories extends ConditionAbstract
|
||||
public function getSummary()
|
||||
{
|
||||
$i18nOperator = Operators::getI18n(
|
||||
$this->translator, $this->operators[self::CATEGORIES_LIST]
|
||||
$this->translator,
|
||||
$this->operators[self::CATEGORIES_LIST]
|
||||
);
|
||||
|
||||
$catStrList = '';
|
||||
@@ -152,17 +153,17 @@ class CartContainsCategories extends ConditionAbstract
|
||||
$catIds = $this->values[self::CATEGORIES_LIST];
|
||||
|
||||
if (null !== $catList = CategoryQuery::create()->findPks($catIds)) {
|
||||
|
||||
/** @var Category $cat */
|
||||
foreach ($catList as $cat) {
|
||||
$catStrList .= $cat->getTitle() . ', ';
|
||||
$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>', [
|
||||
'At least one of cart products categories is %op% <strong>%categories_list%</strong>',
|
||||
[
|
||||
'%categories_list%' => $catStrList,
|
||||
'%op%' => $i18nOperator
|
||||
]
|
||||
@@ -190,7 +191,9 @@ class CartContainsCategories extends ConditionAbstract
|
||||
*/
|
||||
public function drawBackOfficeInputs()
|
||||
{
|
||||
return $this->facade->getParser()->render('coupon/condition-fragments/cart-contains-categories-condition.html', [
|
||||
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()
|
||||
|
||||
@@ -75,7 +75,8 @@ class CartContainsProducts extends ConditionAbstract
|
||||
// Check that at least one product is selected
|
||||
if (empty($values[self::PRODUCTS_LIST])) {
|
||||
throw new InvalidConditionValueException(
|
||||
get_class(), self::PRODUCTS_LIST
|
||||
get_class(),
|
||||
self::PRODUCTS_LIST
|
||||
);
|
||||
}
|
||||
|
||||
@@ -94,15 +95,14 @@ class CartContainsProducts extends ConditionAbstract
|
||||
|
||||
/** @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;
|
||||
$cartItem->getProduct()->getId(),
|
||||
$this->operators[self::PRODUCTS_LIST],
|
||||
$this->values[self::PRODUCTS_LIST]
|
||||
)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -136,7 +136,8 @@ class CartContainsProducts extends ConditionAbstract
|
||||
public function getSummary()
|
||||
{
|
||||
$i18nOperator = Operators::getI18n(
|
||||
$this->translator, $this->operators[self::PRODUCTS_LIST]
|
||||
$this->translator,
|
||||
$this->operators[self::PRODUCTS_LIST]
|
||||
);
|
||||
|
||||
$prodStrList = '';
|
||||
@@ -144,17 +145,17 @@ class CartContainsProducts extends ConditionAbstract
|
||||
$prodIds = $this->values[self::PRODUCTS_LIST];
|
||||
|
||||
if (null !== $prodList = ProductQuery::create()->findPks($prodIds)) {
|
||||
|
||||
/** @var Product $prod */
|
||||
foreach ($prodList as $prod) {
|
||||
$prodStrList .= $prod->getTitle() . ', ';
|
||||
$prodStrList .= $prod->setLocale($this->getCurrentLocale())->getTitle() . ', ';
|
||||
}
|
||||
|
||||
$prodStrList = rtrim($prodStrList, ', ');
|
||||
}
|
||||
|
||||
$toolTip = $this->translator->trans(
|
||||
'Cart contains at least a product %op% <strong>%products_list%</strong>', [
|
||||
'Cart contains at least a product %op% <strong>%products_list%</strong>',
|
||||
[
|
||||
'%products_list%' => $prodStrList,
|
||||
'%op%' => $i18nOperator
|
||||
]
|
||||
@@ -182,7 +183,9 @@ class CartContainsProducts extends ConditionAbstract
|
||||
*/
|
||||
public function drawBackOfficeInputs()
|
||||
{
|
||||
return $this->facade->getParser()->render('coupon/condition-fragments/cart-contains-products-condition.html', [
|
||||
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()
|
||||
|
||||
@@ -82,7 +82,8 @@ abstract class ConditionAbstract implements ConditionInterface
|
||||
|
||||
if (!$isOperator1Legit) {
|
||||
throw new InvalidConditionOperatorException(
|
||||
get_class(), $parameterName
|
||||
get_class(),
|
||||
$parameterName
|
||||
);
|
||||
}
|
||||
|
||||
@@ -101,7 +102,6 @@ abstract class ConditionAbstract implements ConditionInterface
|
||||
$translatedInputs = [];
|
||||
|
||||
foreach ($this->validators as $key => $validator) {
|
||||
|
||||
$translatedOperators = [];
|
||||
|
||||
foreach ($validator['availableOperators'] as $availableOperators) {
|
||||
@@ -162,7 +162,7 @@ abstract class ConditionAbstract implements ConditionInterface
|
||||
*/
|
||||
protected function isOperatorLegit($operator, array $availableOperators)
|
||||
{
|
||||
return in_array($operator, $availableOperators);
|
||||
return in_array($operator, $availableOperators);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -201,7 +201,8 @@ abstract class ConditionAbstract implements ConditionInterface
|
||||
}
|
||||
if (!$currencyFound) {
|
||||
throw new InvalidConditionValueException(
|
||||
get_class(), 'currency'
|
||||
get_class(),
|
||||
'currency'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -221,7 +222,8 @@ abstract class ConditionAbstract implements ConditionInterface
|
||||
$floatType = new FloatType();
|
||||
if (!$floatType->isValid($priceValue) || $priceValue <= 0) {
|
||||
throw new InvalidConditionValueException(
|
||||
get_class(), 'price'
|
||||
get_class(),
|
||||
'price'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -243,8 +245,9 @@ abstract class ConditionAbstract implements ConditionInterface
|
||||
$inputs = $this->getValidators();
|
||||
|
||||
if (isset($inputs['inputs'][$inputKey])) {
|
||||
|
||||
$html = $this->facade->getParser()->render('coupon/condition-fragments/condition-selector.html', [
|
||||
$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
|
||||
@@ -273,7 +276,9 @@ abstract class ConditionAbstract implements ConditionInterface
|
||||
$currentValue = $this->values[$inputKey];
|
||||
}
|
||||
|
||||
return $this->facade->getParser()->render('coupon/conditions-fragments/base-input-text.html', [
|
||||
return $this->facade->getParser()->render(
|
||||
'coupon/conditions-fragments/base-input-text.html',
|
||||
[
|
||||
'label' => $label,
|
||||
'inputKey' => $inputKey,
|
||||
'currentValue' => $currentValue,
|
||||
@@ -294,7 +299,9 @@ abstract class ConditionAbstract implements ConditionInterface
|
||||
*/
|
||||
protected function drawBackOfficeInputQuantityValues($inputKey, $max = 10, $min = 0)
|
||||
{
|
||||
return $this->facade->getParser()->render('coupon/condition-fragments/quantity-selector.html', [
|
||||
return $this->facade->getParser()->render(
|
||||
'coupon/condition-fragments/quantity-selector.html',
|
||||
[
|
||||
'min' => $min,
|
||||
'max' => $max,
|
||||
'value' => isset($this->values[$inputKey]) ? $this->values[$inputKey] : '',
|
||||
@@ -322,11 +329,23 @@ abstract class ConditionAbstract implements ConditionInterface
|
||||
$cleanedCurrencies[$currency->getCode()] = $currency->getSymbol();
|
||||
}
|
||||
|
||||
return $this->facade->getParser()->render('coupon/condition-fragments/currency-selector.html', [
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ 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;
|
||||
|
||||
@@ -73,7 +74,8 @@ class ForSomeCustomers extends ConditionAbstract
|
||||
// Check that at least one product is selected
|
||||
if (empty($values[self::CUSTOMERS_LIST])) {
|
||||
throw new InvalidConditionValueException(
|
||||
get_class(), self::CUSTOMERS_LIST
|
||||
get_class(),
|
||||
self::CUSTOMERS_LIST
|
||||
);
|
||||
}
|
||||
|
||||
@@ -88,13 +90,15 @@ class ForSomeCustomers extends ConditionAbstract
|
||||
*/
|
||||
public function isMatching()
|
||||
{
|
||||
$customer = $this->facade->getCustomer();
|
||||
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]
|
||||
);
|
||||
return $this->conditionValidator->variableOpComparison(
|
||||
$customer->getId(),
|
||||
$this->operators[self::CUSTOMERS_LIST],
|
||||
$this->values[self::CUSTOMERS_LIST]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,7 +131,8 @@ class ForSomeCustomers extends ConditionAbstract
|
||||
public function getSummary()
|
||||
{
|
||||
$i18nOperator = Operators::getI18n(
|
||||
$this->translator, $this->operators[self::CUSTOMERS_LIST]
|
||||
$this->translator,
|
||||
$this->operators[self::CUSTOMERS_LIST]
|
||||
);
|
||||
|
||||
$custStrList = '';
|
||||
@@ -135,7 +140,6 @@ class ForSomeCustomers extends ConditionAbstract
|
||||
$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().'), ';
|
||||
@@ -145,7 +149,8 @@ class ForSomeCustomers extends ConditionAbstract
|
||||
}
|
||||
|
||||
$toolTip = $this->translator->trans(
|
||||
'Customer is %op% <strong>%customer_list%</strong>', [
|
||||
'Customer is %op% <strong>%customer_list%</strong>',
|
||||
[
|
||||
'%customer_list%' => $custStrList,
|
||||
'%op%' => $i18nOperator
|
||||
]
|
||||
@@ -173,7 +178,9 @@ class ForSomeCustomers extends ConditionAbstract
|
||||
*/
|
||||
public function drawBackOfficeInputs()
|
||||
{
|
||||
return $this->facade->getParser()->render('coupon/condition-fragments/customers-condition.html', [
|
||||
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()
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Thelia\Exception\UnmatchableConditionException;
|
||||
|
||||
/**
|
||||
* Check a Checkout against its Product number
|
||||
*
|
||||
@@ -34,7 +36,11 @@ class MatchBillingCountries extends AbstractMatchCountries
|
||||
*/
|
||||
public function isMatching()
|
||||
{
|
||||
$billingAddress = $this->facade->getCustomer()->getDefaultAddress();
|
||||
if (null === $customer = $this->facade->getCustomer()) {
|
||||
throw new UnmatchableConditionException();
|
||||
}
|
||||
|
||||
$billingAddress = $customer->getDefaultAddress();
|
||||
|
||||
return $this->conditionValidator->variableOpComparison(
|
||||
$billingAddress->getCountryId(),
|
||||
@@ -70,7 +76,8 @@ class MatchBillingCountries extends AbstractMatchCountries
|
||||
protected function getSummaryLabel($cntryStrList, $i18nOperator)
|
||||
{
|
||||
return $this->translator->trans(
|
||||
'Only if order billing country is %op% <strong>%countries_list%</strong>', [
|
||||
'Only if order billing country is %op% <strong>%countries_list%</strong>',
|
||||
[
|
||||
'%countries_list%' => $cntryStrList,
|
||||
'%op%' => $i18nOperator
|
||||
]
|
||||
@@ -80,7 +87,8 @@ class MatchBillingCountries extends AbstractMatchCountries
|
||||
protected function getFormLabel()
|
||||
{
|
||||
return $this->translator->trans(
|
||||
'Billing country is', []
|
||||
'Billing country is',
|
||||
[]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Thelia\Exception\UnmatchableConditionException;
|
||||
|
||||
/**
|
||||
* Check a Checkout against its Product number
|
||||
*
|
||||
@@ -34,7 +36,13 @@ class MatchDeliveryCountries extends AbstractMatchCountries
|
||||
*/
|
||||
public function isMatching()
|
||||
{
|
||||
$deliveryAddress = $this->facade->getDeliveryAddress();
|
||||
if (null === $customer = $this->facade->getCustomer()) {
|
||||
throw new UnmatchableConditionException();
|
||||
}
|
||||
|
||||
if (null === $deliveryAddress = $this->facade->getDeliveryAddress()) {
|
||||
throw new UnmatchableConditionException();
|
||||
}
|
||||
|
||||
return $this->conditionValidator->variableOpComparison(
|
||||
$deliveryAddress->getCountryId(),
|
||||
@@ -70,7 +78,8 @@ class MatchDeliveryCountries extends AbstractMatchCountries
|
||||
protected function getSummaryLabel($cntryStrList, $i18nOperator)
|
||||
{
|
||||
return $this->translator->trans(
|
||||
'Only if order shipping country is %op% <strong>%countries_list%</strong>', [
|
||||
'Only if order shipping country is %op% <strong>%countries_list%</strong>',
|
||||
[
|
||||
'%countries_list%' => $cntryStrList,
|
||||
'%op%' => $i18nOperator
|
||||
]
|
||||
@@ -80,7 +89,8 @@ class MatchDeliveryCountries extends AbstractMatchCountries
|
||||
protected function getFormLabel()
|
||||
{
|
||||
return $this->translator->trans(
|
||||
'Delivery country is', []
|
||||
'Delivery country is',
|
||||
[]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,5 +114,4 @@ class MatchForEveryone extends ConditionAbstract
|
||||
// No input
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,10 +28,10 @@ use Thelia\Model\CurrencyQuery;
|
||||
class MatchForTotalAmount extends ConditionAbstract
|
||||
{
|
||||
/** Condition 1st parameter : price */
|
||||
CONST CART_TOTAL = 'price';
|
||||
const CART_TOTAL = 'price';
|
||||
|
||||
/** Condition 1st parameter : currency */
|
||||
CONST CART_CURRENCY = 'currency';
|
||||
const CART_CURRENCY = 'currency';
|
||||
|
||||
public function __construct(FacadeInterface $facade)
|
||||
{
|
||||
@@ -164,7 +164,7 @@ class MatchForTotalAmount extends ConditionAbstract
|
||||
*/
|
||||
protected function generateInputs()
|
||||
{
|
||||
$currencies = CurrencyQuery::create()->find();
|
||||
$currencies = CurrencyQuery::create()->filterByVisible(true)->find();
|
||||
|
||||
$cleanedCurrencies = [];
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ use Thelia\Exception\InvalidConditionValueException;
|
||||
class MatchForXArticles extends ConditionAbstract
|
||||
{
|
||||
/** Condition 1st parameter : quantity */
|
||||
CONST CART_QUANTITY = 'quantity';
|
||||
const CART_QUANTITY = 'quantity';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
@@ -63,7 +63,8 @@ class MatchForXArticles extends ConditionAbstract
|
||||
|
||||
if (intval($values[self::CART_QUANTITY]) <= 0) {
|
||||
throw new InvalidConditionValueException(
|
||||
get_class(), 'quantity'
|
||||
get_class(),
|
||||
'quantity'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -126,7 +127,8 @@ class MatchForXArticles extends ConditionAbstract
|
||||
public function getSummary()
|
||||
{
|
||||
$i18nOperator = Operators::getI18n(
|
||||
$this->translator, $this->operators[self::CART_QUANTITY]
|
||||
$this->translator,
|
||||
$this->operators[self::CART_QUANTITY]
|
||||
);
|
||||
|
||||
$toolTip = $this->translator->trans(
|
||||
@@ -173,7 +175,9 @@ class MatchForXArticles extends ConditionAbstract
|
||||
*/
|
||||
protected function drawBackOfficeBaseInputsText($label, $inputKey)
|
||||
{
|
||||
return $this->facade->getParser()->render('coupon/condition-fragments/cart-item-count-condition.html', [
|
||||
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,82 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -63,13 +63,13 @@ class StartDate extends ConditionAbstract
|
||||
|
||||
// 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
|
||||
get_class(),
|
||||
self::START_DATE
|
||||
);
|
||||
}
|
||||
|
||||
@@ -130,9 +130,11 @@ class StartDate extends ConditionAbstract
|
||||
$strDate = $date->format($this->getDateFormat());
|
||||
|
||||
$toolTip = $this->translator->trans(
|
||||
'Valid only from %date% to the coupon expiration date', [
|
||||
'Valid only from %date% to the coupon expiration date',
|
||||
[
|
||||
'%date%' => $strDate,
|
||||
], 'condition'
|
||||
],
|
||||
'condition'
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
@@ -163,7 +165,6 @@ class StartDate extends ConditionAbstract
|
||||
public function drawBackOfficeInputs()
|
||||
{
|
||||
if (isset($this->values[self::START_DATE])) {
|
||||
|
||||
$date = new \DateTime();
|
||||
|
||||
$date->setTimestamp($this->values[self::START_DATE]);
|
||||
|
||||
Reference in New Issue
Block a user