WIP
- Coupon - add rule AJAX
This commit is contained in:
@@ -219,26 +219,34 @@
|
||||
<argument type="service" id="service_container" />
|
||||
</service>
|
||||
<service id="thelia.coupon.manager" class="Thelia\Coupon\CouponManager">
|
||||
<argument type="service" id="thelia.adapter" />
|
||||
<argument type="service" id="service_container" />
|
||||
</service>
|
||||
<service id="thelia.coupon.factory" class="Thelia\Coupon\CouponFactory">
|
||||
<argument type="service" id="service_container" />
|
||||
</service>
|
||||
|
||||
<service id="thelia.constraint.factory" class="Thelia\Constraint\ConstraintFactory">
|
||||
<argument type="service" id="service_container" />
|
||||
</service>
|
||||
<service id="thelia.constraint.rule.available_for_everyone" class="Thelia\Constraint\Rule\AvailableForEveryoneManager">
|
||||
<argument type="service" id="thelia.adapter" />
|
||||
<tag name="thelia.coupon.addRule"/>
|
||||
</service>
|
||||
<service id="thelia.constraint.rule.available_for_x_articles" class="Thelia\Constraint\Rule\AvailableForXArticlesManager">
|
||||
<argument type="service" id="thelia.translator" />
|
||||
<argument type="service" id="thelia.adapter" />
|
||||
<tag name="thelia.coupon.addRule"/>
|
||||
</service>
|
||||
<service id="thelia.constraint.rule.available_for_total_amount" class="Thelia\Constraint\Rule\AvailableForTotalAmountManager">
|
||||
<argument type="service" id="thelia.translator" />
|
||||
<argument type="service" id="thelia.adapter" />
|
||||
<tag name="thelia.coupon.addRule"/>
|
||||
</service>
|
||||
|
||||
<service id="thelia.coupon.type.remove_x_amount" class="Thelia\Coupon\Type\RemoveXAmount">
|
||||
<argument type="service" id="thelia.translator" />
|
||||
<service id="thelia.coupon.type.remove_x_amount" class="Thelia\Coupon\Type\RemoveXAmountManager">
|
||||
<argument type="service" id="thelia.adapter" />
|
||||
<tag name="thelia.coupon.addCoupon"/>
|
||||
</service>
|
||||
<service id="thelia.coupon.type.remove_x_percent" class="Thelia\Coupon\Type\RemoveXPercent">
|
||||
<argument type="service" id="thelia.translator" />
|
||||
<service id="thelia.coupon.type.remove_x_percent" class="Thelia\Coupon\Type\RemoveXPercentManager">
|
||||
<argument type="service" id="thelia.adapter" />
|
||||
<tag name="thelia.coupon.addCoupon"/>
|
||||
</service>
|
||||
|
||||
|
||||
135
core/lib/Thelia/Constraint/Rule/AvailableForEveryoneManager.php
Normal file
135
core/lib/Thelia/Constraint/Rule/AvailableForEveryoneManager.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?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\Constraint\Rule;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Translation\Translator;
|
||||
use Thelia\Constraint\ConstraintValidator;
|
||||
use Thelia\Constraint\Validator\QuantityParam;
|
||||
use Thelia\Constraint\Validator\RuleValidator;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Exception\InvalidRuleException;
|
||||
use Thelia\Exception\InvalidRuleValueException;
|
||||
use Thelia\Type\FloatType;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Allow every one, perform no check
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AvailableForEveryoneManager extends CouponRuleAbstract
|
||||
{
|
||||
/** @var string Service Id from Resources/config.xml */
|
||||
protected $serviceId = 'thelia.constraint.rule.available_for_everyone';
|
||||
|
||||
/** @var array Available Operators (Operators::CONST) */
|
||||
protected $availableOperators = array();
|
||||
|
||||
/**
|
||||
* Check validators relevancy and store them
|
||||
*
|
||||
* @param array $operators Operators the Admin set in BackOffice
|
||||
* @param array $values Values the Admin set in BackOffice
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return $this
|
||||
*/
|
||||
public function setValidatorsFromForm(array $operators, array $values)
|
||||
{
|
||||
$this->setValidators();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check validators relevancy and store them
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return $this
|
||||
*/
|
||||
protected function setValidators()
|
||||
{
|
||||
$this->operators = array();
|
||||
$this->values = array();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if Customer meets conditions
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isMatching()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->translator->trans(
|
||||
'Everybody can use it (no condition)',
|
||||
array(),
|
||||
'constraint'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
$toolTip = $this->translator->trans(
|
||||
'Will return always true',
|
||||
array(),
|
||||
'constraint'
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate inputs ready to be drawn
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function generateInputs()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,6 +32,8 @@ use Thelia\Constraint\Validator\RuleValidator;
|
||||
use Thelia\Exception\InvalidRuleException;
|
||||
use Thelia\Exception\InvalidRuleOperatorException;
|
||||
use Thelia\Exception\InvalidRuleValueException;
|
||||
use Thelia\Model\Currency;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Type\FloatType;
|
||||
|
||||
/**
|
||||
@@ -297,7 +299,7 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->adapter->get('thelia.translator')->trans(
|
||||
return $this->translator->trans(
|
||||
'Cart total amount',
|
||||
array(),
|
||||
'constraint'
|
||||
@@ -328,6 +330,40 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract
|
||||
return $toolTip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate inputs ready to be drawn
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function generateInputs()
|
||||
{
|
||||
$currencies = CurrencyQuery::create()->find();
|
||||
$cleanedCurrencies = array();
|
||||
/** @var Currency $currency */
|
||||
foreach ($currencies as $currency) {
|
||||
$cleanedCurrencies[$currency->getCode()] = $currency->getSymbol();
|
||||
}
|
||||
|
||||
return array(
|
||||
self::INPUT1 => array(
|
||||
'availableOperators' => $this->availableOperators[self::INPUT1],
|
||||
'availableValues' => '',
|
||||
'type' => 'text',
|
||||
'class' => 'form-control',
|
||||
'value' => '',
|
||||
'selectedOperator' => ''
|
||||
),
|
||||
self::INPUT2 => array(
|
||||
'availableOperators' => $this->availableOperators[self::INPUT2],
|
||||
'availableValues' => $cleanedCurrencies,
|
||||
'type' => 'select',
|
||||
'class' => 'form-control',
|
||||
'value' => '',
|
||||
'selectedOperator' => Operators::EQUAL
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Populate a Rule from a form admin
|
||||
// *
|
||||
|
||||
@@ -297,4 +297,22 @@ class AvailableForXArticlesManager extends CouponRuleAbstract
|
||||
// return $this;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Generate inputs ready to be drawn
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function generateInputs()
|
||||
{
|
||||
return array(
|
||||
self::INPUT1 => array(
|
||||
'availableOperators' => $this->availableOperators[self::INPUT1],
|
||||
'type' => 'text',
|
||||
'class' => 'form-control',
|
||||
'value' => '',
|
||||
'selectedOperator' => ''
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -188,9 +188,35 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
*/
|
||||
public function getValidators()
|
||||
{
|
||||
return array(
|
||||
$this->operators,
|
||||
$this->values
|
||||
$this->validators = $this->generateInputs();
|
||||
|
||||
$translatedInputs = array();
|
||||
foreach ($this->validators as $key => $validator) {
|
||||
$translatedOperators = array();
|
||||
foreach ($validator['availableOperators'] as $availableOperators) {
|
||||
$translatedOperators[$availableOperators] = Operators::getI18n(
|
||||
$this->translator,
|
||||
$availableOperators
|
||||
);
|
||||
}
|
||||
|
||||
$validator['availableOperators'] = $translatedOperators;
|
||||
$translatedInputs[$key] = $validator;
|
||||
}
|
||||
|
||||
return $translatedInputs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate inputs ready to be drawn
|
||||
*
|
||||
* @throws \Thelia\Exception\NotImplementedException
|
||||
* @return array
|
||||
*/
|
||||
protected function generateInputs()
|
||||
{
|
||||
throw new \Thelia\Exception\NotImplementedException(
|
||||
'The generateInputs method must be implemented in ' . get_class()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -141,4 +141,6 @@ interface CouponRuleInterface
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Router;
|
||||
use Thelia\Constraint\ConstraintFactory;
|
||||
use Thelia\Constraint\ConstraintFactoryTest;
|
||||
use Thelia\Constraint\Rule\AvailableForTotalAmount;
|
||||
@@ -38,7 +39,9 @@ use Thelia\Core\Security\Exception\AuthenticationException;
|
||||
use Thelia\Core\Security\Exception\AuthorizationException;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Coupon\CouponManager;
|
||||
use Thelia\Coupon\CouponRuleCollection;
|
||||
use Thelia\Coupon\Type\CouponInterface;
|
||||
use Thelia\Form\CouponCreationForm;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Log\Tlog;
|
||||
@@ -142,7 +145,7 @@ class CouponController extends BaseAdminController
|
||||
|
||||
$i18n = new I18n();
|
||||
/** @var Lang $lang */
|
||||
$lang = $this->getSession()->get('lang');
|
||||
$lang = $this->getSession()->getLang();
|
||||
$eventToDispatch = TheliaEvents::COUPON_UPDATE;
|
||||
|
||||
if ($this->getRequest()->isMethod('POST')) {
|
||||
@@ -172,14 +175,16 @@ class CouponController extends BaseAdminController
|
||||
'locale' => $coupon->getLocale(),
|
||||
);
|
||||
|
||||
/** @var CouponAdapterInterface $adapter */
|
||||
$adapter = $this->container->get('thelia.adapter');
|
||||
/** @var Translator $translator */
|
||||
$translator = $this->container->get('thelia.translator');
|
||||
|
||||
$args['rulesObject'] = array();
|
||||
|
||||
/** @var ConstraintFactory $constraintFactory */
|
||||
$constraintFactory = $this->container->get('thelia.constraint.factory');
|
||||
$rules = $constraintFactory->unserializeCouponRuleCollection(
|
||||
$coupon->getSerializedRules()
|
||||
);
|
||||
|
||||
/** @var CouponRuleInterface $rule */
|
||||
foreach ($coupon->getRules()->getRules() as $rule) {
|
||||
foreach ($rules as $rule) {
|
||||
$args['rulesObject'][] = array(
|
||||
'name' => $rule->getName(),
|
||||
'tooltip' => $rule->getToolTip(),
|
||||
@@ -194,6 +199,15 @@ class CouponController extends BaseAdminController
|
||||
$this->getParserContext()->addForm($changeForm);
|
||||
}
|
||||
|
||||
$args['availableCoupons'] = $this->getAvailableCoupons();
|
||||
$args['availableRules'] = $this->getAvailableRules();
|
||||
$args['urlAjaxGetRuleInput'] = $this->getRouteFromRouter(
|
||||
'router.admin',
|
||||
'admin.coupon.rule.input',
|
||||
array('ruleId' => 'ruleId'),
|
||||
Router::ABSOLUTE_URL
|
||||
);
|
||||
|
||||
$args['formAction'] = 'admin/coupon/update/' . $couponId;
|
||||
|
||||
return $this->render(
|
||||
@@ -489,6 +503,52 @@ class CouponController extends BaseAdminController
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all available rules
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getAvailableRules()
|
||||
{
|
||||
/** @var CouponManager $couponManager */
|
||||
$couponManager = $this->container->get('thelia.coupon.manager');
|
||||
$availableRules = $couponManager->getAvailableRules();
|
||||
$cleanedRules = array();
|
||||
/** @var CouponRuleInterface $availableRule */
|
||||
foreach ($availableRules as $availableRule) {
|
||||
$rule = array();
|
||||
$rule['serviceId'] = $availableRule->getServiceId();
|
||||
$rule['name'] = $availableRule->getName();
|
||||
$rule['toolTip'] = $availableRule->getToolTip();
|
||||
$cleanedRules[] = $rule;
|
||||
}
|
||||
|
||||
return $cleanedRules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all available coupons
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getAvailableCoupons()
|
||||
{
|
||||
/** @var CouponManager $couponManager */
|
||||
$couponManager = $this->container->get('thelia.coupon.manager');
|
||||
$availableCoupons = $couponManager->getAvailableCoupons();
|
||||
$cleanedRules = array();
|
||||
/** @var CouponInterface $availableCoupon */
|
||||
foreach ($availableCoupons as $availableCoupon) {
|
||||
$rule = array();
|
||||
$rule['serviceId'] = $availableCoupon->getServiceId();
|
||||
$rule['name'] = $availableCoupon->getName();
|
||||
$rule['toolTip'] = $availableCoupon->getToolTip();
|
||||
$cleanedRules[] = $rule;
|
||||
}
|
||||
|
||||
return $cleanedRules;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Validation Rule creation
|
||||
// *
|
||||
@@ -511,4 +571,6 @@ class CouponController extends BaseAdminController
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -55,11 +55,11 @@ class RegisterRulePass implements CompilerPassInterface
|
||||
}
|
||||
|
||||
$couponManager = $container->getDefinition('thelia.coupon.manager');
|
||||
$services = $container->findTaggedServiceIds("thelia.coupon.addCoupon");
|
||||
$services = $container->findTaggedServiceIds("thelia.coupon.addRule");
|
||||
|
||||
foreach ($services as $id => $rule) {
|
||||
$couponManager->addMethodCall(
|
||||
'addAvailableCoupon',
|
||||
'addAvailableRule',
|
||||
array(
|
||||
new Reference($id)
|
||||
)
|
||||
|
||||
@@ -147,7 +147,7 @@ class CouponBaseAdapter implements CouponAdapterInterface
|
||||
*/
|
||||
public function getCurrentCoupons()
|
||||
{
|
||||
$couponFactory = new CouponFactory($this);
|
||||
$couponFactory = $this->container->get('thelia.coupon.factory');
|
||||
|
||||
// @todo Get from Session
|
||||
$couponCodes = array('XMAS', 'SPRINGBREAK');
|
||||
|
||||
@@ -23,7 +23,9 @@
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Translation\Exception\NotFoundResourceException;
|
||||
use Thelia\Constraint\ConstraintFactory;
|
||||
use Thelia\Constraint\Rule\CouponRuleInterface;
|
||||
use Thelia\Coupon\Type\CouponInterface;
|
||||
use Thelia\Exception\CouponExpiredException;
|
||||
@@ -44,17 +46,21 @@ use Symfony\Component\Serializer\Encoder\JsonEncoder;
|
||||
*/
|
||||
class CouponFactory
|
||||
{
|
||||
/** @var ContainerInterface Service Container */
|
||||
protected $container = null;
|
||||
|
||||
/** @var CouponAdapterInterface Provide necessary value from Thelia*/
|
||||
protected $adapter;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
|
||||
* @param ContainerInterface $container Service container
|
||||
*/
|
||||
function __construct(CouponAdapterInterface $adapter)
|
||||
function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->adapter = $adapter;
|
||||
$this->container = $container;
|
||||
$this->adapter = $container->get('thelia.adapter');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,10 +108,15 @@ class CouponFactory
|
||||
{
|
||||
$isCumulative = ($model->getIsCumulative() == 1 ? true : false);
|
||||
$isRemovingPostage = ($model->getIsRemovingPostage() == 1 ? true : false);
|
||||
$couponClass = $model->getType();
|
||||
|
||||
/** @var CouponInterface $coupon*/
|
||||
$coupon = new $couponClass(
|
||||
if (!$this->container->has($model->getType())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var CouponInterface $couponManager*/
|
||||
$couponManager = $this->container->get($model->getType());
|
||||
$couponManager->set(
|
||||
$this->adapter,
|
||||
$model->getCode(),
|
||||
$model->getTitle(),
|
||||
$model->getShortDescription(),
|
||||
@@ -119,12 +130,15 @@ class CouponFactory
|
||||
$model->getExpirationDate()
|
||||
);
|
||||
|
||||
/** @var CouponRuleCollection $rules */
|
||||
$rules = unserialize(base64_decode($model->getSerializedRules()));
|
||||
/** @var ConstraintFactory $constraintFactory */
|
||||
$constraintFactory = $this->container->get('thelia.constraint.factory');
|
||||
$rules = $constraintFactory->unserializeCouponRuleCollection(
|
||||
$model->getSerializedRules()
|
||||
);
|
||||
|
||||
$coupon->setRules($rules);
|
||||
$couponManager->setRules($rules);
|
||||
|
||||
return $coupon;
|
||||
return $couponManager;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -49,6 +49,12 @@ class CouponManager
|
||||
/** @var array CouponInterface to process*/
|
||||
protected $coupons = array();
|
||||
|
||||
/** @var array Available Coupons (Services) */
|
||||
protected $availableCoupons = array();
|
||||
|
||||
/** @var array Available Rules (Services) */
|
||||
protected $availableRules = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@@ -208,4 +214,44 @@ class CouponManager
|
||||
|
||||
return $rule;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an available CouponManager (Services)
|
||||
*
|
||||
* @param CouponInterface $coupon CouponManager
|
||||
*/
|
||||
public function addAvailableCoupon(CouponInterface $coupon)
|
||||
{
|
||||
$this->availableCoupons[] = $coupon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all available CouponManagers (Services)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAvailableCoupons()
|
||||
{
|
||||
return $this->availableCoupons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an available ConstraintManager (Services)
|
||||
*
|
||||
* @param CouponRuleInterface $rule CouponRuleInterface
|
||||
*/
|
||||
public function addAvailableRule(CouponRuleInterface $rule)
|
||||
{
|
||||
$this->availableRules[] = $rule;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all available ConstraintManagers (Services)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAvailableRules()
|
||||
{
|
||||
return $this->availableRules;
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,7 @@ class CouponRuleCollection
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
return isEmpty($this->rules);
|
||||
return (empty($this->rules));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace Thelia\Coupon\Type;
|
||||
|
||||
use Symfony\Component\Intl\Exception\NotImplementedException;
|
||||
use Thelia\Constraint\ConstraintManager;
|
||||
use Thelia\Constraint\ConstraintValidator;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Coupon\CouponRuleCollection;
|
||||
use Thelia\Coupon\RuleOrganizerInterface;
|
||||
@@ -43,17 +44,23 @@ use Thelia\Exception\InvalidRuleException;
|
||||
*/
|
||||
abstract class CouponAbstract implements CouponInterface
|
||||
{
|
||||
/** @var CouponAdapterInterface Provides necessary value from Thelia */
|
||||
/** @var string Service Id */
|
||||
protected $serviceId = null;
|
||||
|
||||
/** @var CouponAdapterInterface Provide necessary value from Thelia */
|
||||
protected $adapter = null;
|
||||
|
||||
/** @var Translator Service Translator */
|
||||
protected $translator = null;
|
||||
|
||||
/** @var RuleOrganizerInterface */
|
||||
protected $organizer = null;
|
||||
|
||||
/** @var CouponRuleCollection Array of CouponRuleInterface */
|
||||
protected $rules = null;
|
||||
|
||||
/** @var ConstraintManager CouponRuleInterface Manager*/
|
||||
protected $constraintManager = null;
|
||||
/** @var ConstraintValidator Constraint validator */
|
||||
protected $constraintValidator = null;
|
||||
|
||||
/** @var string Coupon code (ex: XMAS) */
|
||||
protected $code = null;
|
||||
@@ -88,6 +95,18 @@ abstract class CouponAbstract implements CouponInterface
|
||||
/** @var bool if Coupon is available for Products already on special offers */
|
||||
protected $isAvailableOnSpecialOffers = false;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Service adapter
|
||||
*/
|
||||
function __construct(CouponAdapterInterface $adapter)
|
||||
{
|
||||
$this->adapter = $adapter;
|
||||
$this->translator = $adapter->getTranslator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Rule Organizer
|
||||
*
|
||||
@@ -197,10 +216,6 @@ abstract class CouponAbstract implements CouponInterface
|
||||
public function setRules(CouponRuleCollection $rules)
|
||||
{
|
||||
$this->rules = $rules;
|
||||
$this->constraintManager = new ConstraintManager(
|
||||
$this->adapter,
|
||||
$this->rules
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -209,14 +224,11 @@ abstract class CouponAbstract implements CouponInterface
|
||||
* Check if the current Coupon is matching its conditions (Rules)
|
||||
* Thelia variables are given by the CouponAdapterInterface
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter allowing to gather
|
||||
* all necessary Thelia variables
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isMatching(CouponAdapterInterface $adapter)
|
||||
public function isMatching()
|
||||
{
|
||||
return $this->constraintManager->isMatching();
|
||||
return $this->constraintValidator->test($this->rules);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -278,4 +290,16 @@ abstract class CouponAbstract implements CouponInterface
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Coupon Manager service Id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getServiceId()
|
||||
{
|
||||
return $this->serviceId;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -39,6 +39,37 @@ use Thelia\Coupon\CouponRuleCollection;
|
||||
*/
|
||||
interface CouponInterface
|
||||
{
|
||||
/**
|
||||
* Set Coupon
|
||||
*
|
||||
* @param CouponInterface $adapter Provides necessary value from Thelia
|
||||
* @param string $code Coupon code (ex: XMAS)
|
||||
* @param string $title Coupon title (ex: Coupon for XMAS)
|
||||
* @param string $shortDescription Coupon short description
|
||||
* @param string $description Coupon description
|
||||
* @param float $effect Coupon amount/percentage to deduce
|
||||
* @param bool $isCumulative If Coupon is cumulative
|
||||
* @param bool $isRemovingPostage If Coupon is removing postage
|
||||
* @param bool $isAvailableOnSpecialOffers If available on Product already
|
||||
* on special offer price
|
||||
* @param bool $isEnabled False if Coupon is disabled by admin
|
||||
* @param int $maxUsage How many usage left
|
||||
* @param \Datetime $expirationDate When the Code is expiring
|
||||
*/
|
||||
public function set(
|
||||
$adapter,
|
||||
$code,
|
||||
$title,
|
||||
$shortDescription,
|
||||
$description,
|
||||
$effect,
|
||||
$isCumulative,
|
||||
$isRemovingPostage,
|
||||
$isAvailableOnSpecialOffers,
|
||||
$isEnabled,
|
||||
$maxUsage,
|
||||
\DateTime $expirationDate);
|
||||
|
||||
/**
|
||||
* Return Coupon code (ex: XMAS)
|
||||
*
|
||||
@@ -107,12 +138,9 @@ interface CouponInterface
|
||||
* Check if the current Coupon is matching its conditions (Rules)
|
||||
* Thelia variables are given by the CouponAdapterInterface
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter allowing to gather
|
||||
* all necessary Thelia variables
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isMatching(CouponAdapterInterface $adapter);
|
||||
public function isMatching();
|
||||
|
||||
/**
|
||||
* Replace the existing Rules by those given in parameter
|
||||
@@ -177,4 +205,11 @@ interface CouponInterface
|
||||
*/
|
||||
public function getToolTip();
|
||||
|
||||
/**
|
||||
* Get Coupon Manager service Id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getServiceId();
|
||||
|
||||
}
|
||||
|
||||
@@ -37,10 +37,13 @@ use Thelia\Coupon\Type\CouponAbstract;
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RemoveXAmount extends CouponAbstract
|
||||
class RemoveXAmountManager extends CouponAbstract
|
||||
{
|
||||
/** @var string Service Id */
|
||||
protected $serviceId = 'thelia.coupon.type.remove_x_amount';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Set Coupon
|
||||
*
|
||||
* @param CouponInterface $adapter Provides necessary value from Thelia
|
||||
* @param string $code Coupon code (ex: XMAS)
|
||||
@@ -56,7 +59,7 @@ class RemoveXAmount extends CouponAbstract
|
||||
* @param int $maxUsage How many usage left
|
||||
* @param \Datetime $expirationDate When the Code is expiring
|
||||
*/
|
||||
function __construct(
|
||||
public function set(
|
||||
$adapter,
|
||||
$code,
|
||||
$title,
|
||||
@@ -97,7 +100,7 @@ class RemoveXAmount extends CouponAbstract
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans('Remove X amount to total cart', null, 'constraint');
|
||||
->trans('Remove X amount to total cart', array(), 'constraint');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,7 +114,7 @@ class RemoveXAmount extends CouponAbstract
|
||||
->getTranslator()
|
||||
->trans(
|
||||
'This coupon will remove the entered amount to the customer total checkout. If the discount is superior to the total checkout price the customer will only pay the postage. Unless if the coupon is set to remove postage too.',
|
||||
null,
|
||||
array(),
|
||||
'constraint'
|
||||
);
|
||||
|
||||
@@ -36,12 +36,15 @@ use Thelia\Exception\MissingAdapterException;
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RemoveXPercent extends CouponAbstract
|
||||
class RemoveXPercentManager extends CouponAbstract
|
||||
{
|
||||
/** @var string Service Id */
|
||||
protected $serviceId = 'thelia.coupon.type.remove_x_percent';
|
||||
|
||||
protected $percent = 0;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Set Coupon
|
||||
*
|
||||
* @param CouponInterface $adapter Provides necessary value from Thelia
|
||||
* @param string $code Coupon code (ex: XMAS)
|
||||
@@ -57,7 +60,7 @@ class RemoveXPercent extends CouponAbstract
|
||||
* @param int $maxUsage How many usage left
|
||||
* @param \Datetime $expirationDate When the Code is expiring
|
||||
*/
|
||||
function __construct(
|
||||
public function set(
|
||||
$adapter,
|
||||
$code,
|
||||
$title,
|
||||
@@ -119,7 +122,7 @@ class RemoveXPercent extends CouponAbstract
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans('Remove X percent to total cart', null, 'constraint');
|
||||
->trans('Remove X percent to total cart', array(), 'constraint');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,7 +136,7 @@ class RemoveXPercent extends CouponAbstract
|
||||
->getTranslator()
|
||||
->trans(
|
||||
'This coupon will remove the entered percentage to the customer total checkout. If the discount is superior to the total checkout price the customer will only pay the postage. Unless if the coupon is set to remove postage too.',
|
||||
null,
|
||||
array(),
|
||||
'constraint'
|
||||
);
|
||||
|
||||
@@ -25,10 +25,10 @@ namespace Thelia\Coupon;
|
||||
|
||||
use Thelia\Constraint\Validator\PriceParam;
|
||||
use Thelia\Constraint\Validator\RuleValidator;
|
||||
use Thelia\Constraint\Rule\AvailableForTotalAmount;
|
||||
use Thelia\Constraint\Rule\AvailableForTotalAmountManager;
|
||||
use Thelia\Constraint\Rule\Operators;
|
||||
use Thelia\Coupon\Type\CouponInterface;
|
||||
use Thelia\Coupon\Type\RemoveXAmount;
|
||||
use Thelia\Coupon\Type\RemoveXAmountManager;
|
||||
use Thelia\Tools\PhpUnitUtils;
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,9 +25,9 @@ namespace Thelia\Coupon;
|
||||
|
||||
use Thelia\Constraint\Validator\PriceParam;
|
||||
use Thelia\Constraint\Validator\RuleValidator;
|
||||
use Thelia\Constraint\Rule\AvailableForTotalAmount;
|
||||
use Thelia\Constraint\Rule\AvailableForTotalAmountManager;
|
||||
use Thelia\Constraint\Rule\Operators;
|
||||
use Thelia\Coupon\Type\RemoveXAmount;
|
||||
use Thelia\Coupon\Type\RemoveXAmountManager;
|
||||
|
||||
require_once '../CouponManagerTest.php';
|
||||
|
||||
@@ -56,10 +56,10 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test if a Coupon is well displayed
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getCode
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getTitle
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getShortDescription
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getDescription
|
||||
* @covers Thelia\Coupon\type\RemoveXAmountManager::getCode
|
||||
* @covers Thelia\Coupon\type\RemoveXAmountManager::getTitle
|
||||
* @covers Thelia\Coupon\type\RemoveXAmountManager::getShortDescription
|
||||
* @covers Thelia\Coupon\type\RemoveXAmountManager::getDescription
|
||||
*
|
||||
*/
|
||||
public function testDisplay()
|
||||
@@ -86,7 +86,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test if a Coupon can be Cumulative
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::isCumulative
|
||||
* @covers Thelia\Coupon\type\RemoveXAmountManager::isCumulative
|
||||
*
|
||||
*/
|
||||
public function testIsCumulative()
|
||||
@@ -100,7 +100,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test if a Coupon can be non cumulative
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::isCumulative
|
||||
* @covers Thelia\Coupon\type\RemoveXAmountManager::isCumulative
|
||||
*
|
||||
*/
|
||||
public function testIsNotCumulative()
|
||||
@@ -115,7 +115,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test if a Coupon can remove postage
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::isRemovingPostage
|
||||
* @covers Thelia\Coupon\type\RemoveXAmountManager::isRemovingPostage
|
||||
*
|
||||
*/
|
||||
public function testIsRemovingPostage()
|
||||
@@ -129,7 +129,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test if a Coupon won't remove postage if not set to
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::isRemovingPostage
|
||||
* @covers Thelia\Coupon\type\RemoveXAmountManager::isRemovingPostage
|
||||
*/
|
||||
public function testIsNotRemovingPostage()
|
||||
{
|
||||
@@ -143,7 +143,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test if a Coupon has the effect expected (discount 10euros)
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
* @covers Thelia\Coupon\type\RemoveXAmountManager::getEffect
|
||||
*/
|
||||
public function testGetEffect()
|
||||
{
|
||||
@@ -158,8 +158,8 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test Coupon rule setter
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::setRules
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getRules
|
||||
* @covers Thelia\Coupon\type\RemoveXAmountManager::setRules
|
||||
* @covers Thelia\Coupon\type\RemoveXAmountManager::getRules
|
||||
*/
|
||||
public function testSetRulesValid()
|
||||
{
|
||||
@@ -190,7 +190,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test Coupon rule setter
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::setRules
|
||||
* @covers Thelia\Coupon\type\RemoveXAmountManager::setRules
|
||||
* @expectedException \Thelia\Exception\InvalidRuleException
|
||||
*
|
||||
*/
|
||||
@@ -216,7 +216,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test Coupon effect for rule Total Amount < 400
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
* @covers Thelia\Coupon\type\RemoveXAmountManager::getEffect
|
||||
*
|
||||
*/
|
||||
public function testGetEffectIfTotalAmountInferiorTo400Valid()
|
||||
@@ -241,7 +241,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test Coupon effect for rule Total Amount <= 400
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
* @covers Thelia\Coupon\type\RemoveXAmountManager::getEffect
|
||||
*
|
||||
*/
|
||||
public function testGetEffectIfTotalAmountInferiorOrEqualTo400Valid()
|
||||
@@ -266,7 +266,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test Coupon effect for rule Total Amount == 400
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
* @covers Thelia\Coupon\type\RemoveXAmountManager::getEffect
|
||||
*
|
||||
*/
|
||||
public function testGetEffectIfTotalAmountEqualTo400Valid()
|
||||
@@ -291,7 +291,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test Coupon effect for rule Total Amount >= 400
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
* @covers Thelia\Coupon\type\RemoveXAmountManager::getEffect
|
||||
*
|
||||
*/
|
||||
public function testGetEffectIfTotalAmountSuperiorOrEqualTo400Valid()
|
||||
@@ -316,7 +316,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test Coupon effect for rule Total Amount > 400
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
* @covers Thelia\Coupon\type\RemoveXAmountManager::getEffect
|
||||
*
|
||||
*/
|
||||
public function testGetEffectIfTotalAmountSuperiorTo400Valid()
|
||||
|
||||
@@ -58,7 +58,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test if a Coupon can be Cumulative
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::isCumulative
|
||||
* @covers Thelia\Coupon\type\RemoveXPercentManager::isCumulative
|
||||
*
|
||||
*/
|
||||
public function testIsCumulative()
|
||||
@@ -72,7 +72,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test if a Coupon can be non cumulative
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::isCumulative
|
||||
* @covers Thelia\Coupon\type\RemoveXPercentManager::isCumulative
|
||||
*
|
||||
*/
|
||||
public function testIsNotCumulative()
|
||||
@@ -87,7 +87,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test if a Coupon can remove postage
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::isRemovingPostage
|
||||
* @covers Thelia\Coupon\type\RemoveXPercentManager::isRemovingPostage
|
||||
*
|
||||
*/
|
||||
public function testIsRemovingPostage()
|
||||
@@ -101,7 +101,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test if a Coupon won't remove postage if not set to
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::isRemovingPostage
|
||||
* @covers Thelia\Coupon\type\RemoveXPercentManager::isRemovingPostage
|
||||
*/
|
||||
public function testIsNotRemovingPostage()
|
||||
{
|
||||
@@ -115,7 +115,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test if a Coupon has the effect expected (discount 10euros)
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
* @covers Thelia\Coupon\type\RemoveXPercentManager::getEffect
|
||||
*/
|
||||
public function testGetEffect()
|
||||
{
|
||||
@@ -130,8 +130,8 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test Coupon rule setter
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::setRules
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getRules
|
||||
* @covers Thelia\Coupon\type\RemoveXPercentManager::setRules
|
||||
* @covers Thelia\Coupon\type\RemoveXPercentManager::getRules
|
||||
*/
|
||||
public function testSetRulesValid()
|
||||
{
|
||||
@@ -162,7 +162,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test Coupon rule setter
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::setRules
|
||||
* @covers Thelia\Coupon\type\RemoveXPercentManager::setRules
|
||||
* @expectedException \Thelia\Exception\InvalidRuleException
|
||||
*
|
||||
*/
|
||||
@@ -188,7 +188,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test Coupon effect for rule Total Amount < 400
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
* @covers Thelia\Coupon\type\RemoveXPercentManager::getEffect
|
||||
*
|
||||
*/
|
||||
public function testGetEffectIfTotalAmountInferiorTo400Valid()
|
||||
@@ -212,7 +212,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test Coupon effect for rule Total Amount <= 400
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
* @covers Thelia\Coupon\type\RemoveXPercentManager::getEffect
|
||||
*
|
||||
*/
|
||||
public function testGetEffectIfTotalAmountInferiorOrEqualTo400Valid()
|
||||
@@ -236,7 +236,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test Coupon effect for rule Total Amount == 400
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
* @covers Thelia\Coupon\type\RemoveXPercentManager::getEffect
|
||||
*
|
||||
*/
|
||||
public function testGetEffectIfTotalAmountEqualTo400Valid()
|
||||
@@ -260,7 +260,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test Coupon effect for rule Total Amount >= 400
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
* @covers Thelia\Coupon\type\RemoveXPercentManager::getEffect
|
||||
*
|
||||
*/
|
||||
public function testGetEffectIfTotalAmountSuperiorOrEqualTo400Valid()
|
||||
@@ -284,7 +284,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test Coupon effect for rule Total Amount > 400
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
* @covers Thelia\Coupon\type\RemoveXPercentManager::getEffect
|
||||
*
|
||||
*/
|
||||
public function testGetEffectIfTotalAmountSuperiorTo400Valid()
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
<?php
|
||||
use Thelia\Constraint\ConstraintFactory;
|
||||
use Thelia\Constraint\ConstraintManager;
|
||||
use Thelia\Constraint\Rule\AvailableForTotalAmount;
|
||||
use Thelia\Constraint\Rule\AvailableForTotalAmountManager;
|
||||
use Thelia\Constraint\Rule\AvailableForXArticlesManager;
|
||||
use Thelia\Constraint\Rule\Operators;
|
||||
use Thelia\Coupon\CouponRuleCollection;
|
||||
use Thelia\Model\ProductImage;
|
||||
@@ -498,12 +501,11 @@ function generateCouponFixtures($thelia)
|
||||
{
|
||||
$container = $thelia->getContainer();
|
||||
$adapter = $container->get('thelia.adapter');
|
||||
$translator = $container->get('thelia.translator');
|
||||
|
||||
// Coupons
|
||||
$coupon1 = new Thelia\Model\Coupon();
|
||||
$coupon1->setCode('XMAS');
|
||||
$coupon1->setType('Thelia\Coupon\Type\RemoveXAmount');
|
||||
$coupon1->setType('thelia.coupon.type.remove_x_amount');
|
||||
$coupon1->setTitle('Christmas coupon');
|
||||
$coupon1->setShortDescription('Coupon for Christmas removing 10€ if your total checkout is more than 40€');
|
||||
$coupon1->setDescription('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras at luctus tellus. Integer turpis mauris, aliquet vitae risus tristique, pellentesque vestibulum urna. Vestibulum sodales laoreet lectus dictum suscipit. Praesent vulputate, sem id varius condimentum, quam magna tempor elit, quis venenatis ligula nulla eget libero. Cras egestas euismod tellus, id pharetra leo suscipit quis. Donec lacinia ac lacus et ultricies. Nunc in porttitor neque. Proin at quam congue, consectetur orci sed, congue nulla. Nulla eleifend nunc ligula, nec pharetra elit tempus quis. Vivamus vel mauris sed est dictum blandit. Maecenas blandit dapibus velit ut sollicitudin. In in euismod mauris, consequat viverra magna. Cras velit velit, sollicitudin commodo tortor gravida, tempus varius nulla.
|
||||
@@ -521,33 +523,89 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
|
||||
$date = new \DateTime();
|
||||
$coupon1->setExpirationDate($date->setTimestamp(strtotime("today + 2 months")));
|
||||
|
||||
$rule1 = new AvailableForTotalAmount($adapter);
|
||||
$operators = array(AvailableForTotalAmount::PARAM1_PRICE => Operators::SUPERIOR);
|
||||
$values = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => 40.00,
|
||||
AvailableForTotalAmount::PARAM1_CURRENCY => 'EUR'
|
||||
$rule1 = new AvailableForTotalAmountManager($adapter);
|
||||
$operators = array(
|
||||
AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
|
||||
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
|
||||
);
|
||||
$rule1->populateFromForm($operators, $values);
|
||||
$values = array(
|
||||
AvailableForTotalAmountManager::INPUT1 => 40.00,
|
||||
AvailableForTotalAmountManager::INPUT2 => 'EUR'
|
||||
);
|
||||
$rule1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$rule2 = new AvailableForTotalAmount($adapter);
|
||||
$operators = array(AvailableForTotalAmount::PARAM1_PRICE => Operators::INFERIOR);
|
||||
$values = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => 400.00,
|
||||
AvailableForTotalAmount::PARAM1_CURRENCY => 'EUR'
|
||||
$rule2 = new AvailableForTotalAmountManager($adapter);
|
||||
$operators = array(
|
||||
AvailableForTotalAmountManager::INPUT1 => Operators::INFERIOR,
|
||||
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
|
||||
);
|
||||
$rule2->populateFromForm($operators, $values);
|
||||
$values = array(
|
||||
AvailableForTotalAmountManager::INPUT1 => 400.00,
|
||||
AvailableForTotalAmountManager::INPUT2 => 'EUR'
|
||||
);
|
||||
$rule2->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$rules = new CouponRuleCollection();
|
||||
$rules->add($rule1);
|
||||
$rules->add($rule2);
|
||||
|
||||
/** @var ConstraintManager $constraintManager */
|
||||
$constraintManager = new ConstraintManager($container);
|
||||
/** @var ConstraintFactory $constraintFactory */
|
||||
$constraintFactory = $container->get('thelia.constraint.factory');
|
||||
|
||||
$serializedRules = $constraintManager->serializeCouponRuleCollection($rules);
|
||||
$serializedRules = $constraintFactory->serializeCouponRuleCollection($rules);
|
||||
$coupon1->setSerializedRules($serializedRules);
|
||||
|
||||
$coupon1->setIsCumulative(1);
|
||||
$coupon1->setIsRemovingPostage(0);
|
||||
$coupon1->save();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Coupons
|
||||
$coupon2 = new Thelia\Model\Coupon();
|
||||
$coupon2->setCode('SPRINGBREAK');
|
||||
$coupon2->setType('thelia.coupon.type.remove_x_percent');
|
||||
$coupon2->setTitle('Springbreak coupon');
|
||||
$coupon2->setShortDescription('Coupon for Springbreak removing 10% if you have more than 4 articles in your cart');
|
||||
$coupon2->setDescription('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras at luctus tellus. Integer turpis mauris, aliquet vitae risus tristique, pellentesque vestibulum urna. Vestibulum sodales laoreet lectus dictum suscipit. Praesent vulputate, sem id varius condimentum, quam magna tempor elit, quis venenatis ligula nulla eget libero. Cras egestas euismod tellus, id pharetra leo suscipit quis. Donec lacinia ac lacus et ultricies. Nunc in porttitor neque. Proin at quam congue, consectetur orci sed, congue nulla. Nulla eleifend nunc ligula, nec pharetra elit tempus quis. Vivamus vel mauris sed est dictum blandit. Maecenas blandit dapibus velit ut sollicitudin. In in euismod mauris, consequat viverra magna. Cras velit velit, sollicitudin commodo tortor gravida, tempus varius nulla.
|
||||
|
||||
Donec rhoncus leo mauris, id porttitor ante luctus tempus. Curabitur quis augue feugiat, ullamcorper mauris ac, interdum mi. Quisque aliquam lorem vitae felis lobortis, id interdum turpis mattis. Vestibulum diam massa, ornare congue blandit quis, facilisis at nisl. In tortor metus, venenatis non arcu nec, sollicitudin ornare nisl. Nunc erat risus, varius nec urna at, iaculis lacinia elit. Aenean ut felis tempus, tincidunt odio non, sagittis nisl. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec vitae hendrerit elit. Nunc sit amet gravida risus, euismod lobortis massa. Nam a erat mauris. Nam a malesuada lorem. Nulla id accumsan dolor, sed rhoncus tellus. Quisque dictum felis sed leo auctor, at volutpat lectus viverra. Morbi rutrum, est ac aliquam imperdiet, nibh sem sagittis justo, ac mattis magna lacus eu nulla.
|
||||
|
||||
Duis interdum lectus nulla, nec pellentesque sapien condimentum at. Suspendisse potenti. Sed eu purus tellus. Nunc quis rhoncus metus. Fusce vitae tellus enim. Interdum et malesuada fames ac ante ipsum primis in faucibus. Etiam tempor porttitor erat vitae iaculis. Sed est elit, consequat non ornare vitae, vehicula eget lectus. Etiam consequat sapien mauris, eget consectetur magna imperdiet eget. Nunc sollicitudin luctus velit, in commodo nulla adipiscing fermentum. Fusce nisi sapien, posuere vitae metus sit amet, facilisis sollicitudin dui. Fusce ultricies auctor enim sit amet iaculis. Morbi at vestibulum enim, eget adipiscing eros.
|
||||
|
||||
Praesent ligula lorem, faucibus ut metus quis, fermentum iaculis erat. Pellentesque elit erat, lacinia sed semper ac, sagittis vel elit. Nam eu convallis est. Curabitur rhoncus odio vitae consectetur pellentesque. Nam vitae arcu nec ante scelerisque dignissim vel nec neque. Suspendisse augue nulla, mollis eget dui et, tempor facilisis erat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi ac diam ipsum. Donec convallis dui ultricies velit auctor, non lobortis nulla ultrices. Morbi vitae dignissim ante, sit amet lobortis tortor. Nunc dapibus condimentum augue, in molestie neque congue non.
|
||||
|
||||
Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesuada tortor vel erat volutpat tincidunt. In vehicula diam est, a convallis eros scelerisque ut. Donec aliquet venenatis iaculis. Ut a arcu gravida, placerat dui eu, iaculis nisl. Quisque adipiscing orci sit amet dui dignissim lacinia. Sed vulputate lorem non dolor adipiscing ornare. Morbi ornare id nisl id aliquam. Ut fringilla elit ante, nec lacinia enim fermentum sit amet. Aenean rutrum lorem eu convallis pharetra. Cras malesuada varius metus, vitae gravida velit. Nam a varius ipsum, ac commodo dolor. Phasellus nec elementum elit. Etiam vel adipiscing leo.');
|
||||
$coupon2->setAmount(10.00);
|
||||
$coupon2->setIsUsed(1);
|
||||
$coupon2->setIsEnabled(1);
|
||||
$date = new \DateTime();
|
||||
$coupon2->setExpirationDate($date->setTimestamp(strtotime("today + 2 months")));
|
||||
|
||||
$rule1 = new AvailableForXArticlesManager($adapter);
|
||||
$operators = array(
|
||||
AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR,
|
||||
);
|
||||
$values = array(
|
||||
AvailableForXArticlesManager::INPUT1 => 4,
|
||||
);
|
||||
$rule1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$rules = new CouponRuleCollection();
|
||||
$rules->add($rule1);
|
||||
|
||||
/** @var ConstraintFactory $constraintFactory */
|
||||
$constraintFactory = $container->get('thelia.constraint.factory');
|
||||
|
||||
$serializedRules = $constraintFactory->serializeCouponRuleCollection($rules);
|
||||
$coupon2->setSerializedRules($serializedRules);
|
||||
|
||||
$coupon2->setIsCumulative(0);
|
||||
$coupon2->setIsRemovingPostage(1);
|
||||
$coupon2->save();
|
||||
}
|
||||
|
||||
@@ -36,6 +36,34 @@
|
||||
<script>
|
||||
$(function($){
|
||||
miniBrowser(0, '/test_to_remove/datas_coupon_edit.json');
|
||||
|
||||
$('#effect').on('change', function (e) {
|
||||
var optionSelected = $("option:selected", this);
|
||||
$('#effectToolTip').html(optionSelected.attr("data-description"));
|
||||
});
|
||||
|
||||
$('#category-rule').on('change', function (e) {
|
||||
var url = "{$urlAjaxGetRuleInput}";
|
||||
url = url.replace('ruleId', $(this).val())
|
||||
console.log(url);
|
||||
$.ajax({
|
||||
url: url,
|
||||
statusCode: {
|
||||
404: function() {
|
||||
alert("page not found");
|
||||
}
|
||||
},
|
||||
context: document.body
|
||||
}).done(function(data) {
|
||||
console.log(data);
|
||||
$(this).addClass("done");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
{/block}
|
||||
|
||||
@@ -104,13 +104,13 @@
|
||||
<label for="effect">{intl l='Effect :'}</label>
|
||||
{form_field form=$form field='effect'}
|
||||
<select name="{$name}" value="{$value}" id="effect" class="col-md-12 form-control">
|
||||
<option value="1" data-description="More description n°1 about item">Remove x percents for category Y</option>
|
||||
<option value="2" data-description="More description n°2 about item">Remove x percents</option>
|
||||
<option value="3" data-description="More description n°3 about item">Remove x amount</option>
|
||||
{foreach from=$availableCoupons item=availableCoupon}
|
||||
<option value="{$availableCoupon.serviceId}" data-description="{$availableCoupon.toolTip}">{$availableCoupon.name}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
{if $error}{$message}{/if}
|
||||
{/form_field}
|
||||
<span class="help-block">More description n°1 about item</span>
|
||||
<span id="effectToolTip" class="help-block">{$availableCoupons.0.toolTip}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -206,25 +206,11 @@
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-4">
|
||||
<label for="category-rule">{intl l='Rule\'s category :'}</label>
|
||||
<label for="categoryRule">{intl l='Rule\'s category :'}</label>
|
||||
<select name="categoryRule" id="category-rule" class="form-control">
|
||||
<option value="1" selected>Total amount</option>
|
||||
<option value="2">Date</option>
|
||||
<option value="3">NbArtFromCategory</option>
|
||||
</select>
|
||||
|
||||
<label for="category-rule">Rule's category :</label>
|
||||
<select name="categoryRule" id="category-rule" class="form-control">
|
||||
<option value="1">Total amount</option>
|
||||
<option value="2" selected>Date</option>
|
||||
<option value="3">NbArtFromCategory</option>
|
||||
</select>
|
||||
|
||||
<label for="category-rule">Rule's category :</label>
|
||||
<select name="categoryRule" id="category-rule" class="form-control">
|
||||
<option value="1">Total amount</option>
|
||||
<option value="2">Date</option>
|
||||
<option value="3" selected>NbArtFromCategory</option>
|
||||
{foreach from=$availableRules item=availableRule}
|
||||
<option value="{$availableRule.serviceId}" data-description="{$availableRule.toolTip}">{$availableRule.name}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1 +1,74 @@
|
||||
test
|
||||
{*test*}
|
||||
{*{$ruleId}*}
|
||||
{*{$inputs|var_dump}*}
|
||||
|
||||
{foreach from=$inputs key=name item=input}
|
||||
<label for="operator">Operator :</label>
|
||||
<div class="row">
|
||||
<div class="col-lg-6">
|
||||
<select class="form-control" id="{$name}[operator]" name="{$name}[operator]">
|
||||
{foreach from=$input.availableOperators key=k item=availableOperator}
|
||||
<option value="{$availableOperator}">{$availableOperator}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</div>
|
||||
<div class="input-group col-lg-6">
|
||||
{if $input.type == 'select'}
|
||||
<select class="{$input.class}" id="{$name}[value]" name="{$name}[value]">
|
||||
{foreach from=$input.availableValues key=code item=availableValue}
|
||||
<option value="{$code}">{$availableValue}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
{else}
|
||||
<input type="{$input.type}" class="{$input.class}" id="{$name}[value]" name="{$name}[value]">
|
||||
{*<span class="input-group-addon">€</span>*}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/foreach}
|
||||
{*<label for="operator">Operator :</label>*}
|
||||
{*<div class="row">*}
|
||||
{*<div class="col-lg-6">*}
|
||||
{*<select class="form-control" id="operator" name="operator">*}
|
||||
{*<option value="1">is superior to</option>*}
|
||||
{*<option value="2">equals to</option>*}
|
||||
{*<option value="3">is inferior to</option>*}
|
||||
{*<option value="4">is inferior or equals to</option>*}
|
||||
{*<option value="5">is superior or equals to</option>*}
|
||||
{*</select>*}
|
||||
{*</div>*}
|
||||
{*<div data-date-format="dd/mm/yyyy" data-date="12/02/2012" class="input-group col-lg-6 date">*}
|
||||
{*<input type="text" class="form-control" name="value">*}
|
||||
{*<span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>*}
|
||||
{*</div>*}
|
||||
{*</div>*}
|
||||
{*<label for="operator">Operator :</label>*}
|
||||
{*<div class="row">*}
|
||||
{*<div class="col-lg-6">*}
|
||||
{*<select class="form-control" id="operator" name="operator">*}
|
||||
{*<option value="1">is superior to</option>*}
|
||||
{*<option value="2">equals to</option>*}
|
||||
{*<option value="3">is inferior to</option>*}
|
||||
{*<option value="4">is inferior or equals to</option>*}
|
||||
{*<option value="5">is superior or equals to</option>*}
|
||||
{*</select>*}
|
||||
{*</div>*}
|
||||
{*<div class="col-lg-6">*}
|
||||
{*<input type="text" class="form-control" name="value">*}
|
||||
{*</div>*}
|
||||
{*</div>*}
|
||||
{*<div class="row">*}
|
||||
{*<div class="col-lg-12">*}
|
||||
{*<table class="table table-bordered">*}
|
||||
{*<tbody><tr>*}
|
||||
{*<td id="minibrowser-breadcrumb"><div><span> > </span><a href="#">Racine</a></div></td>*}
|
||||
{*</tr>*}
|
||||
{*<tr>*}
|
||||
{*<th><span class="icon-th-list"></span> Categories list</th>*}
|
||||
{*</tr>*}
|
||||
{*<tr>*}
|
||||
{*<td id="minibrowser-categories"><div><p><a href="#">Boyaux</a></p><p><a href="#">Epices / condiments</a></p><p><a href="#">Emballage</a></p><p><a href="#">Petits matériels</a></p><p><a href="#">Materiel de cuisine</a></p><p><a href="#">Bacs</a></p><p><a href="#">Hygiène & entretien</a></p><p><a href="#">Art de la table</a></p><p><a href="#">Matériels</a></p></div></td>*}
|
||||
{*</tr>*}
|
||||
{*</tbody></table>*}
|
||||
{*</div>*}
|
||||
{*</div>*}
|
||||
Reference in New Issue
Block a user