Merge branch 'master' of https://github.com/thelia/thelia
Conflicts: templates/admin/default/admin-layout.tpl
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -22,3 +22,6 @@ web/cache/*
|
||||
web/.htaccess
|
||||
phpdoc*.log
|
||||
php-cs
|
||||
xhprof
|
||||
phpunit.phar
|
||||
.DS_Store
|
||||
@@ -36,6 +36,7 @@
|
||||
"simplepie/simplepie": "dev-master",
|
||||
|
||||
"imagine/imagine": "dev-master",
|
||||
"symfony/serializer": "dev-master",
|
||||
"symfony/icu": "1.0"
|
||||
},
|
||||
"require-dev" : {
|
||||
|
||||
179
core/lib/Thelia/Action/Coupon.php
Executable file
179
core/lib/Thelia/Action/Coupon.php
Executable file
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Action;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Core\Event\Coupon\CouponCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Model\Coupon as CouponModel;
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Propel\Runtime\Propel;
|
||||
use Thelia\Model\Map\CategoryTableMap;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Process Coupon Events
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class Coupon extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* Occurring when a Coupon is about to be created
|
||||
*
|
||||
* @param CouponCreateOrUpdateEvent $event Event creation or update Event
|
||||
*/
|
||||
public function create(CouponCreateOrUpdateEvent $event)
|
||||
{
|
||||
$coupon = new CouponModel();
|
||||
|
||||
$this->createOrUpdate($coupon, $event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Occurring when a Coupon is about to be updated
|
||||
*
|
||||
* @param CouponCreateOrUpdateEvent $event Event creation or update Event
|
||||
*/
|
||||
public function update(CouponCreateOrUpdateEvent $event)
|
||||
{
|
||||
$coupon = $event->getCoupon();
|
||||
|
||||
$this->createOrUpdate($coupon, $event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Occurring when a Coupon rule is about to be created
|
||||
*
|
||||
* @param CouponCreateOrUpdateEvent $event Event creation or update Event
|
||||
*/
|
||||
public function createRule(CouponCreateOrUpdateEvent $event)
|
||||
{
|
||||
$coupon = $event->getCoupon();
|
||||
|
||||
$this->createOrUpdate($coupon, $event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Occurring when a Coupon rule is about to be updated
|
||||
*
|
||||
* @param CouponCreateOrUpdateEvent $event Event creation or update Event
|
||||
*/
|
||||
public function updateRule(CouponCreateOrUpdateEvent $event)
|
||||
{
|
||||
$coupon = $event->getCoupon();
|
||||
|
||||
$this->createOrUpdate($coupon, $event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Occurring when a Coupon rule is about to be deleted
|
||||
*
|
||||
* @param CouponCreateOrUpdateEvent $event Event creation or update Event
|
||||
*/
|
||||
public function deleteRule(CouponCreateOrUpdateEvent $event)
|
||||
{
|
||||
$coupon = $event->getCoupon();
|
||||
|
||||
$this->createOrUpdate($coupon, $event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Occurring when a Coupon rule is about to be consumed
|
||||
*
|
||||
* @param CouponCreateOrUpdateEvent $event Event creation or update Event
|
||||
*/
|
||||
public function consume(CouponCreateOrUpdateEvent $event)
|
||||
{
|
||||
// @todo implements
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the Model and delegate the create or delete action
|
||||
* Feed the Event with the updated model
|
||||
*
|
||||
* @param CouponModel $coupon Model to save
|
||||
* @param CouponCreateOrUpdateEvent $event Event containing data
|
||||
*/
|
||||
protected function createOrUpdate(CouponModel $coupon, CouponCreateOrUpdateEvent $event)
|
||||
{
|
||||
$coupon->setDispatcher($this->getDispatcher());
|
||||
|
||||
$coupon->createOrUpdate(
|
||||
$event->getCode(),
|
||||
$event->getTitle(),
|
||||
$event->getAmount(),
|
||||
$event->getEffect(),
|
||||
$event->getShortDescription(),
|
||||
$event->getDescription(),
|
||||
$event->isEnabled(),
|
||||
$event->getExpirationDate(),
|
||||
$event->isAvailableOnSpecialOffers(),
|
||||
$event->isCumulative(),
|
||||
$event->getMaxUsage(),
|
||||
$event->getRules(),
|
||||
$event->getLocale()
|
||||
);
|
||||
|
||||
$event->setCoupon($coupon);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of event names this subscriber listens to.
|
||||
*
|
||||
* The array keys are event names and the value can be:
|
||||
*
|
||||
* * The method name to call (priority defaults to 0)
|
||||
* * An array composed of the method name to call and the priority
|
||||
* * An array of arrays composed of the method names to call and respective
|
||||
* priorities, or 0 if unset
|
||||
*
|
||||
* For instance:
|
||||
*
|
||||
* * array('eventName' => 'methodName')
|
||||
* * array('eventName' => array('methodName', $priority))
|
||||
* * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
|
||||
*
|
||||
* @return array The event names to listen to
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
TheliaEvents::COUPON_CREATE => array("create", 128),
|
||||
TheliaEvents::COUPON_UPDATE => array("update", 128),
|
||||
TheliaEvents::COUPON_DISABLE => array("disable", 128),
|
||||
TheliaEvents::COUPON_ENABLE => array("enable", 128),
|
||||
TheliaEvents::COUPON_CONSUME => array("consume", 128),
|
||||
TheliaEvents::COUPON_RULE_UPDATE => array("updateRule", 128),
|
||||
TheliaEvents::COUPON_RULE_DELETE => array("deleteRule", 128)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,34 @@ class CreateAdminUser extends ContainerAwareCommand
|
||||
->setName("thelia:create-admin")
|
||||
->setDescription("Create a new adminsitration user")
|
||||
->setHelp("The <info>thelia:create-admin</info> command create a new administration user.")
|
||||
->addOption(
|
||||
'login_name',
|
||||
null,
|
||||
InputOption::VALUE_OPTIONAL,
|
||||
'Admin login name',
|
||||
null
|
||||
)
|
||||
->addOption(
|
||||
'first_name',
|
||||
null,
|
||||
InputOption::VALUE_OPTIONAL,
|
||||
'User first name',
|
||||
null
|
||||
)
|
||||
->addOption(
|
||||
"last_name",
|
||||
null,
|
||||
InputOption::VALUE_OPTIONAL,
|
||||
'User last name',
|
||||
null
|
||||
)
|
||||
->addOption(
|
||||
'password',
|
||||
null,
|
||||
InputOption::VALUE_OPTIONAL,
|
||||
'Password',
|
||||
null
|
||||
)
|
||||
;
|
||||
|
||||
}
|
||||
@@ -54,25 +82,25 @@ class CreateAdminUser extends ContainerAwareCommand
|
||||
$admin->save();
|
||||
|
||||
$output->writeln(array(
|
||||
"",
|
||||
"<info>User ".$admin->getLogin()." successfully created.</info>",
|
||||
""
|
||||
));
|
||||
"",
|
||||
"<info>User ".$admin->getLogin()." successfully created.</info>",
|
||||
""
|
||||
));
|
||||
}
|
||||
|
||||
protected function enterData($dialog, $output, $label, $error_message)
|
||||
{
|
||||
return $dialog->askAndValidate(
|
||||
$output,
|
||||
$this->decorateInfo($label),
|
||||
function ($answer) {
|
||||
$answer = trim($answer);
|
||||
if (empty($answer)) {
|
||||
throw new \RuntimeException("This information is mandatory.");
|
||||
}
|
||||
|
||||
return $answer;
|
||||
$output,
|
||||
$this->decorateInfo($label),
|
||||
function ($answer) {
|
||||
$answer = trim($answer);
|
||||
if (empty($answer)) {
|
||||
throw new \RuntimeException("This information is mandatory.");
|
||||
}
|
||||
|
||||
return $answer;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -89,13 +117,13 @@ class CreateAdminUser extends ContainerAwareCommand
|
||||
|
||||
$admin = new Admin();
|
||||
|
||||
$admin->setLogin($this->enterData($dialog, $output, "Admin login name : ", "Please enter a login name."));
|
||||
$admin->setFirstname($this->enterData($dialog, $output, "User first name : ", "Please enter user first name."));
|
||||
$admin->setLastname($this->enterData($dialog, $output, "User last name : ", "Please enter user last name."));
|
||||
$admin->setLogin($input->getOption("login_name") ?: $this->enterData($dialog, $output, "Admin login name : ", "Please enter a login name."));
|
||||
$admin->setFirstname($input->getOption("first_name") ?: $this->enterData($dialog, $output, "User first name : ", "Please enter user first name."));
|
||||
$admin->setLastname($input->getOption("last_name") ?: $this->enterData($dialog, $output, "User last name : ", "Please enter user last name."));
|
||||
|
||||
do {
|
||||
$password = $this->enterData($dialog, $output, "Password : ", "Please enter a password.");
|
||||
$password_again = $this->enterData($dialog, $output, "Password (again): ", "Please enter the password again.");
|
||||
$password = $input->getOption("password") ?: $this->enterData($dialog, $output, "Password : ", "Please enter a password.");
|
||||
$password_again = $input->getOption("password") ?: $this->enterData($dialog, $output, "Password (again): ", "Please enter the password again.");
|
||||
|
||||
if (! empty($password) && $password == $password_again) {
|
||||
|
||||
@@ -109,11 +137,11 @@ class CreateAdminUser extends ContainerAwareCommand
|
||||
while (true);
|
||||
|
||||
return $admin;
|
||||
}
|
||||
}
|
||||
|
||||
protected function decorateInfo($text)
|
||||
{
|
||||
return sprintf("<info>%s</info>", $text);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,11 @@
|
||||
<tag name="kernel.event_subscriber"/>
|
||||
</service>
|
||||
|
||||
<service id="thelia.action.coupon" class="Thelia\Action\Coupon">
|
||||
<argument type="service" id="service_container"/>
|
||||
<tag name="kernel.event_subscriber"/>
|
||||
</service>
|
||||
|
||||
<service id="thelia.action.currency" class="Thelia\Action\Currency">
|
||||
<argument type="service" id="service_container"/>
|
||||
<tag name="kernel.event_subscriber"/>
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
<loop class="Thelia\Core\Template\Loop\Cart" name="cart"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Image" name="image"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Config" name="config"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Coupon" name="coupon"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Message" name="message"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Delivery" name="delivery"/>
|
||||
</loops>
|
||||
@@ -63,6 +64,8 @@
|
||||
|
||||
<form name="thelia.admin.currency.creation" class="Thelia\Form\CurrencyCreationForm"/>
|
||||
<form name="thelia.admin.currency.modification" class="Thelia\Form\CurrencyModificationForm"/>
|
||||
|
||||
<form name="thelia.admin.coupon.creation" class="Thelia\Form\CouponCreationForm"/>
|
||||
</forms>
|
||||
|
||||
|
||||
@@ -146,11 +149,7 @@
|
||||
|
||||
<service id="smarty.plugin.thelialoop" class="Thelia\Core\Template\Smarty\Plugins\TheliaLoop" scope="request">
|
||||
<tag name="thelia.parser.register_plugin"/>
|
||||
|
||||
<argument type="service" id="request" />
|
||||
<argument type="service" id="event_dispatcher"/>
|
||||
<argument type="service" id="thelia.securityContext"/>
|
||||
|
||||
<argument type="service" id="service_container" />
|
||||
<call method="setLoopList">
|
||||
<argument>%thelia.parser.loops%</argument>
|
||||
</call>
|
||||
@@ -210,6 +209,44 @@
|
||||
<service id="service_container" synthetic="true" />
|
||||
|
||||
<service id="kernel" synthetic="true" />
|
||||
|
||||
<!-- Coupon module -->
|
||||
<service id="thelia.adapter" class="Thelia\Coupon\CouponBaseAdapter">
|
||||
<argument type="service" id="service_container" />
|
||||
</service>
|
||||
<service id="thelia.coupon.manager" class="Thelia\Coupon\CouponManager">
|
||||
<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.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.adapter" />
|
||||
<tag name="thelia.coupon.addRule"/>
|
||||
</service>
|
||||
|
||||
<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\RemoveXPercentManager">
|
||||
<argument type="service" id="thelia.adapter" />
|
||||
<tag name="thelia.coupon.addCoupon"/>
|
||||
</service>
|
||||
|
||||
|
||||
</services>
|
||||
|
||||
</config>
|
||||
|
||||
@@ -31,6 +31,14 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\CategoryController::defaultAction</default>
|
||||
</route>
|
||||
|
||||
<!-- Customer rule management -->
|
||||
|
||||
<route id="admin.customers" path="/admin/customers">
|
||||
<default key="_controller">Thelia\Controller\Admin\CustomerController::indexAction</default>
|
||||
</route>
|
||||
|
||||
<!-- end Customer rule management -->
|
||||
|
||||
<!-- Categories management -->
|
||||
|
||||
<route id="admin.categories.default" path="/admin/categories">
|
||||
@@ -60,6 +68,41 @@
|
||||
<route id="admin.categories.update-position" path="/admin/categories/update-position">
|
||||
<default key="_controller">Thelia\Controller\Admin\CategoryController::updatePositionAction</default>
|
||||
</route>
|
||||
<route id="admin.category.ajax" path="/admin/catalog/category/parent/{parentId}.{_format}" methods="GET">
|
||||
<default key="_controller">Thelia\Controller\Admin\CategoryController::getByParentIdAction</default>
|
||||
<requirement key="_format">xml|json</requirement>
|
||||
</route>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- Route to the Coupon controller (process Coupon browsing) -->
|
||||
<route id="admin.coupon.list" path="/admin/coupon">
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::browseAction</default>
|
||||
</route>
|
||||
<route id="admin.coupon.create" path="/admin/coupon/create">
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::createAction</default>
|
||||
</route>
|
||||
<route id="admin.coupon.update" path="/admin/coupon/update/{couponId}">
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::updateAction</default>
|
||||
</route>
|
||||
<route id="admin.coupon.read" path="/admin/coupon/read/{couponId}">
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::readAction</default>
|
||||
</route>
|
||||
<route id="admin.coupon.rule.input" path="/admin/coupon/rule/{ruleId}">
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::getRuleInputAction</default>
|
||||
</route>
|
||||
<route id="admin.coupon.rule.update" path="/admin/coupon/{couponId}/rule/update/">
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::updateRulesAction</default>
|
||||
</route>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- Routes to the Config (system variables) controller -->
|
||||
|
||||
|
||||
@@ -15,17 +15,29 @@
|
||||
<default key="_view">connexion</default>
|
||||
</route>
|
||||
|
||||
<route id="customer.create.view" path="/register">
|
||||
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
|
||||
<default key="_view">register</default>
|
||||
</route>
|
||||
|
||||
<route id="customer.update.process" path="/customer/update" methods="post">
|
||||
<default key="_controller">Thelia\Controller\Front\CustomerController::updateAction</default>
|
||||
</route>
|
||||
|
||||
<route id="customer.login.process" path="/customer/login" methods="post">
|
||||
<default key="_controller">Thelia\Controller\Front\CustomerController::loginAction</default>
|
||||
<default key="_view">login</default>
|
||||
</route>
|
||||
|
||||
<route id="customer.login.view" path="/login">
|
||||
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
|
||||
<default key="_view">login</default>
|
||||
</route>
|
||||
|
||||
<route id="customer.logout.process" path="/customer/logout">
|
||||
<default key="_controller">Thelia\Controller\Front\CustomerController::logoutAction</default>
|
||||
</route>
|
||||
|
||||
<!-- end customer routes -->
|
||||
|
||||
<!-- customer address routes -->
|
||||
|
||||
162
core/lib/Thelia/Constraint/ConstraintFactory.php
Normal file
162
core/lib/Thelia/Constraint/ConstraintFactory.php
Normal file
@@ -0,0 +1,162 @@
|
||||
<?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;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Serializer\Encoder\JsonEncoder;
|
||||
use Thelia\Constraint\Rule\AvailableForTotalAmountManager;
|
||||
use Thelia\Constraint\Rule\CouponRuleInterface;
|
||||
use Thelia\Constraint\Rule\SerializableRule;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Coupon\CouponRuleCollection;
|
||||
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Manage how Constraint could interact
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ConstraintFactory
|
||||
{
|
||||
/** @var ContainerInterface Service Container */
|
||||
protected $container = null;
|
||||
|
||||
/** @var CouponAdapterInterface Provide necessary value from Thelia*/
|
||||
protected $adapter;
|
||||
|
||||
/** @var array CouponRuleCollection to process*/
|
||||
protected $rules = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param ContainerInterface $container Service container
|
||||
*/
|
||||
function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->adapter = $container->get('thelia.adapter');
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a collection of rules
|
||||
*
|
||||
* @param CouponRuleCollection $collection A collection of rules
|
||||
*
|
||||
* @return string A ready to be stored Rule collection
|
||||
*/
|
||||
public function serializeCouponRuleCollection(CouponRuleCollection $collection)
|
||||
{
|
||||
$serializableRules = array();
|
||||
$rules = $collection->getRules();
|
||||
if ($rules !== null) {
|
||||
/** @var $rule CouponRuleInterface */
|
||||
foreach ($rules as $rule) {
|
||||
$serializableRules[] = $rule->getSerializableRule();
|
||||
}
|
||||
}
|
||||
|
||||
return base64_encode(json_encode($serializableRules));
|
||||
}
|
||||
|
||||
/**
|
||||
* Unserialize a collection of rules
|
||||
*
|
||||
* @param string $serializedRules Serialized Rules
|
||||
*
|
||||
* @return CouponRuleCollection Rules ready to be processed
|
||||
*/
|
||||
public function unserializeCouponRuleCollection($serializedRules)
|
||||
{
|
||||
$unserializedRules = json_decode(base64_decode($serializedRules));
|
||||
|
||||
$collection = new CouponRuleCollection();
|
||||
|
||||
if (!empty($serializedRules) && !empty($unserializedRules)) {
|
||||
/** @var SerializableRule $rule */
|
||||
foreach ($unserializedRules as $rule) {
|
||||
if ($this->container->has($rule->ruleServiceId)) {
|
||||
/** @var CouponRuleInterface $couponRule */
|
||||
$couponRule = $this->build(
|
||||
$rule->ruleServiceId,
|
||||
(array) $rule->operators,
|
||||
(array) $rule->values
|
||||
);
|
||||
$collection->add(clone $couponRule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build a Coupon Rule from form
|
||||
*
|
||||
* @param string $ruleServiceId Rule class name
|
||||
* @param array $operators Rule Operator (<, >, = )
|
||||
* @param array $values Values setting this Rule
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return CouponRuleInterface Ready to use Rule or false
|
||||
*/
|
||||
public function build($ruleServiceId, array $operators, array $values)
|
||||
{
|
||||
if (!$this->container->has($ruleServiceId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var CouponRuleInterface $rule */
|
||||
$rule = $this->container->get($ruleServiceId);
|
||||
$rule->setValidatorsFromForm($operators, $values);
|
||||
|
||||
return $rule;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Coupon Rule inputs from serviceId
|
||||
*
|
||||
* @param string $ruleServiceId Rule class name
|
||||
*
|
||||
* @return array Ready to be drawn rule inputs
|
||||
*/
|
||||
public function getInputs($ruleServiceId)
|
||||
{
|
||||
if (!$this->container->has($ruleServiceId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var CouponRuleInterface $rule */
|
||||
$rule = $this->container->get($ruleServiceId);
|
||||
|
||||
return $rule->getValidators();
|
||||
}
|
||||
}
|
||||
133
core/lib/Thelia/Constraint/ConstraintValidator.php
Normal file
133
core/lib/Thelia/Constraint/ConstraintValidator.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?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;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Serializer\Encoder\JsonEncoder;
|
||||
use Thelia\Constraint\Rule\AvailableForTotalAmountManager;
|
||||
use Thelia\Constraint\Rule\CouponRuleInterface;
|
||||
use Thelia\Constraint\Rule\Operators;
|
||||
use Thelia\Coupon\CouponRuleCollection;
|
||||
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Validate Constraints
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ConstraintValidator
|
||||
{
|
||||
|
||||
/**
|
||||
* Check if a Customer meets SerializableRule
|
||||
*
|
||||
* @param CouponRuleCollection $rules Rules to check against the Customer
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function test(CouponRuleCollection $rules)
|
||||
{
|
||||
$isMatching = true;
|
||||
/** @var CouponRuleInterface $rule */
|
||||
foreach ($rules->getRules() as $rule) {
|
||||
if (!$rule->isMatching()) {
|
||||
$isMatching = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $isMatching;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Do variable comparison
|
||||
*
|
||||
* @param mixed $v1 Variable 1
|
||||
* @param string $o Operator
|
||||
*
|
||||
* @param mixed $v2 Variable 2
|
||||
* @throws \Exception
|
||||
* @return bool
|
||||
*/
|
||||
public function variableOpComparison($v1, $o, $v2) {
|
||||
if ($o == Operators::DIFFERENT) {
|
||||
return ($v1 != $v2);
|
||||
} // could put this elsewhere...
|
||||
// $operators = str_split($o);
|
||||
// foreach($o as $operator) {
|
||||
switch ($o) { // return will exit switch, foreach loop, function
|
||||
case Operators::SUPERIOR : // >
|
||||
if ($v1 > $v2) {
|
||||
return true;
|
||||
} else {
|
||||
continue;
|
||||
} break;
|
||||
case Operators::SUPERIOR_OR_EQUAL : // >=
|
||||
if ($v1 >= $v2) {
|
||||
return true;
|
||||
} else {
|
||||
continue;
|
||||
} break;
|
||||
case Operators::INFERIOR : // <
|
||||
if ($v1 < $v2) {
|
||||
return true;
|
||||
} else {
|
||||
continue;
|
||||
} break;
|
||||
case Operators::INFERIOR_OR_EQUAL : // <=
|
||||
if ($v1 <= $v2) {
|
||||
return true;
|
||||
} else {
|
||||
continue;
|
||||
} break;
|
||||
case Operators::EQUAL : // ==
|
||||
if ($v1 == $v2) {
|
||||
return true;
|
||||
} else {
|
||||
continue;
|
||||
} break;
|
||||
case Operators::IN:
|
||||
if (in_array($v1, $v2)) { // in
|
||||
return true;
|
||||
} else {
|
||||
continue;
|
||||
} break;
|
||||
case Operators::OUT:
|
||||
if (!in_array($v1, $v2)) { // not in
|
||||
return true;
|
||||
} else {
|
||||
continue;
|
||||
} break;
|
||||
default: throw new \Exception('Unrecognized operator ' . $o);
|
||||
}
|
||||
// }
|
||||
return false;
|
||||
}
|
||||
}
|
||||
178
core/lib/Thelia/Constraint/Rule/AvailableForCustomer.php
Normal file
178
core/lib/Thelia/Constraint/Rule/AvailableForCustomer.php
Normal file
@@ -0,0 +1,178 @@
|
||||
<?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 Thelia\Constraint\Validator\CustomerParam;
|
||||
use Thelia\Constraint\Validator\RuleValidator;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Exception\InvalidRuleException;
|
||||
use Thelia\Exception\InvalidRuleOperatorException;
|
||||
use Thelia\Exception\InvalidRuleValueException;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AvailableForCustomer extends CouponRuleAbstract
|
||||
{
|
||||
|
||||
/** Rule 1st parameter : customer id */
|
||||
CONST PARAM1 = 'customerId';
|
||||
|
||||
/** @var array Available Operators (Operators::CONST) */
|
||||
protected $availableOperators = array(
|
||||
Operators::EQUAL,
|
||||
);
|
||||
|
||||
/** @var RuleValidator Customer Validator */
|
||||
protected $customerValidator = null;
|
||||
|
||||
/**
|
||||
* Check if backoffice inputs are relevant or not
|
||||
*
|
||||
* @throws InvalidRuleOperatorException if Operator is not allowed
|
||||
* @throws InvalidRuleValueException if Value is not allowed
|
||||
* @return bool
|
||||
*/
|
||||
public function checkBackOfficeInput()
|
||||
{
|
||||
if (!isset($this->validators)
|
||||
|| empty($this->validators)
|
||||
||!isset($this->validators[self::PARAM1])
|
||||
||!isset($this->validators[self::PARAM1])
|
||||
) {
|
||||
throw new InvalidRuleValueException(get_class(), self::PARAM1);
|
||||
}
|
||||
|
||||
/** @var RuleValidator $ruleValidator */
|
||||
$ruleValidator = $this->validators[self::PARAM1];
|
||||
/** @var CustomerParam $customer */
|
||||
$customer = $ruleValidator->getParam();
|
||||
|
||||
if (!$customer instanceof CustomerParam) {
|
||||
throw new InvalidRuleValueException(get_class(), self::PARAM1);
|
||||
}
|
||||
|
||||
$this->checkBackOfficeInputsOperators();
|
||||
|
||||
return $this->isCustomerValid($customer->getInteger());
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate current Rule param to be validated from adapter
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function setParametersToValidate()
|
||||
{
|
||||
$this->paramsToValidate = array(
|
||||
self::PARAM1 => $this->adapter->getCustomer()->getId()
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Checkout inputs are relevant or not
|
||||
*
|
||||
* @throws \Thelia\Exception\InvalidRuleValueException
|
||||
* @return bool
|
||||
*/
|
||||
public function checkCheckoutInput()
|
||||
{
|
||||
if (!isset($this->paramsToValidate)
|
||||
|| empty($this->paramsToValidate)
|
||||
||!isset($this->paramsToValidate[self::PARAM1])
|
||||
) {
|
||||
throw new InvalidRuleValueException(get_class(), self::PARAM1);
|
||||
}
|
||||
|
||||
$customerId = $this->paramsToValidate[self::PARAM1];
|
||||
|
||||
return $this->isCustomerValid($customerId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a Customer is valid
|
||||
*
|
||||
* @param int $customerId Customer to check
|
||||
*
|
||||
* @throws InvalidRuleValueException if Value is not allowed
|
||||
* @return bool
|
||||
*/
|
||||
protected function isCustomerValid($customerId)
|
||||
{
|
||||
$customerValidator = $this->customerValidator;
|
||||
try {
|
||||
$customerValidator->getParam()->compareTo($customerId);
|
||||
} catch(\InvalidArgumentException $e) {
|
||||
throw new InvalidRuleValueException(get_class(), self::PARAM1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans('Customer', null, 'constraint');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
/** @var CustomerParam $param */
|
||||
$param = $this->customerValidator->getParam();
|
||||
$toolTip = $this->adapter
|
||||
->getTranslator()
|
||||
->trans(
|
||||
'If customer is %fistname% %lastname% (%email%)',
|
||||
array(
|
||||
'%fistname%' => $param->getFirstName(),
|
||||
'%lastname%' => $param->getLastName(),
|
||||
'%email%' => $param->getEmail(),
|
||||
),
|
||||
'constraint'
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
59
core/lib/Thelia/Constraint/Rule/AvailableForDate.php
Normal file
59
core/lib/Thelia/Constraint/Rule/AvailableForDate.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AvailableForDate extends AvailableForPeriod
|
||||
{
|
||||
|
||||
/**
|
||||
* Check if backoffice inputs are relevant or not
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkBackOfficeInput()
|
||||
{
|
||||
// TODO: Implement checkBackOfficeInput() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Checkout inputs are relevant or not
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkCheckoutInput()
|
||||
{
|
||||
// TODO: Implement checkCheckoutInput() method.
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
59
core/lib/Thelia/Constraint/Rule/AvailableForLocationX.php
Normal file
59
core/lib/Thelia/Constraint/Rule/AvailableForLocationX.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AvailableForLocationX extends CouponRuleAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
* Check if backoffice inputs are relevant or not
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkBackOfficeInput()
|
||||
{
|
||||
// TODO: Implement checkBackOfficeInput() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Checkout inputs are relevant or not
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkCheckoutInput()
|
||||
{
|
||||
// TODO: Implement checkCheckoutInput() method.
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
57
core/lib/Thelia/Constraint/Rule/AvailableForPeriod.php
Normal file
57
core/lib/Thelia/Constraint/Rule/AvailableForPeriod.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AvailableForPeriod extends CouponRuleAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
* Check if backoffice inputs are relevant or not
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkBackOfficeInput()
|
||||
{
|
||||
// TODO: Implement checkBackOfficeInput() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Checkout inputs are relevant or not
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkCheckoutInput()
|
||||
{
|
||||
// TODO: Implement checkCheckoutInput() method.
|
||||
}
|
||||
}
|
||||
57
core/lib/Thelia/Constraint/Rule/AvailableForRepeatedDate.php
Normal file
57
core/lib/Thelia/Constraint/Rule/AvailableForRepeatedDate.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AvailableForRepeatedDate extends AvailableForDate
|
||||
{
|
||||
|
||||
/**
|
||||
* Check if backoffice inputs are relevant or not
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkBackOfficeInput()
|
||||
{
|
||||
// TODO: Implement checkBackOfficeInput() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Checkout inputs are relevant or not
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkCheckoutInput()
|
||||
{
|
||||
// TODO: Implement checkCheckoutInput() method.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?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 Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AvailableForRepeatedPeriod extends AvailableForPeriod
|
||||
{
|
||||
|
||||
/**
|
||||
* Generate current Rule param to be validated from adapter
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter allowing to gather
|
||||
* all necessary Thelia variables
|
||||
*
|
||||
* @throws \Symfony\Component\Intl\Exception\NotImplementedException
|
||||
* @return $this
|
||||
*/
|
||||
public function setParametersToValidate(CouponAdapterInterface $adapter)
|
||||
{
|
||||
// @todo implement
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if backoffice inputs are relevant or not
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkBackOfficeInput()
|
||||
{
|
||||
// TODO: Implement checkBackOfficeInput() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Checkout inputs are relevant or not
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkCheckoutInput()
|
||||
{
|
||||
// TODO: Implement checkCheckoutInput() method.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AvailableForTotalAmountForCategoryY extends AvailableForTotalAmount
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,417 @@
|
||||
<?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 Symfony\Component\Intl\Exception\NotImplementedException;
|
||||
use Symfony\Component\Translation\Translator;
|
||||
use Thelia\Constraint\ConstraintValidator;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Constraint\Validator\PriceParam;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Rule AvailableForTotalAmount
|
||||
* Check if a Checkout total amount match criteria
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AvailableForTotalAmountManager extends CouponRuleAbstract
|
||||
{
|
||||
/** Rule 1st parameter : price */
|
||||
CONST INPUT1 = 'price';
|
||||
|
||||
/** Rule 1st parameter : currency */
|
||||
CONST INPUT2 = 'currency';
|
||||
|
||||
/** @var string Service Id from Resources/config.xml */
|
||||
protected $serviceId = 'thelia.constraint.rule.available_for_total_amount';
|
||||
|
||||
/** @var array Available Operators (Operators::CONST) */
|
||||
protected $availableOperators = array(
|
||||
self::INPUT1 => array(
|
||||
Operators::INFERIOR,
|
||||
Operators::INFERIOR_OR_EQUAL,
|
||||
Operators::EQUAL,
|
||||
Operators::SUPERIOR_OR_EQUAL,
|
||||
Operators::SUPERIOR
|
||||
),
|
||||
self::INPUT2 => array(
|
||||
Operators::EQUAL,
|
||||
)
|
||||
);
|
||||
|
||||
// /** @var RuleValidator Price Validator */
|
||||
// protected $priceValidator = null;
|
||||
|
||||
// /**
|
||||
// * Check if backoffice inputs are relevant or not
|
||||
// *
|
||||
// * @throws InvalidRuleOperatorException if Operator is not allowed
|
||||
// * @throws InvalidRuleValueException if Value is not allowed
|
||||
// * @return bool
|
||||
// */
|
||||
// public function checkBackOfficeInput()
|
||||
// {
|
||||
// if (!isset($this->validators)
|
||||
// || empty($this->validators)
|
||||
// ||!isset($this->validators[self::PARAM1_PRICE])
|
||||
// ||!isset($this->validators[self::PARAM1_PRICE])
|
||||
// ) {
|
||||
// throw new InvalidRuleValueException(get_class(), self::PARAM1_PRICE);
|
||||
// }
|
||||
//
|
||||
// /** @var RuleValidator $ruleValidator */
|
||||
// $ruleValidator = $this->validators[self::PARAM1_PRICE];
|
||||
// /** @var PriceParam $price */
|
||||
// $price = $ruleValidator->getParam();
|
||||
//
|
||||
// if (!$price instanceof PriceParam) {
|
||||
// throw new InvalidRuleValueException(get_class(), self::PARAM1_PRICE);
|
||||
// }
|
||||
//
|
||||
// $this->checkBackOfficeInputsOperators();
|
||||
//
|
||||
// return $this->isPriceValid($price->getPrice(), $price->getCurrency());
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Check if Checkout inputs are relevant or not
|
||||
// *
|
||||
// * @throws InvalidRuleValueException if Value is not allowed
|
||||
// * @return bool
|
||||
// */
|
||||
// public function checkCheckoutInput()
|
||||
// {
|
||||
// $currency = $this->adapter->getCheckoutCurrency();
|
||||
// if (empty($currency)) {
|
||||
// throw new InvalidRuleValueException(
|
||||
// get_class(), self::PARAM1_CURRENCY
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// $price = $this->adapter->getCartTotalPrice();
|
||||
// if (empty($price)) {
|
||||
// throw new InvalidRuleValueException(
|
||||
// get_class(), self::PARAM1_PRICE
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// $this->paramsToValidate = array(
|
||||
// self::PARAM1_PRICE => $this->adapter->getCartTotalPrice(),
|
||||
// self::PARAM1_CURRENCY => $this->adapter->getCheckoutCurrency()
|
||||
// );
|
||||
//
|
||||
// return $this->isPriceValid($price, $currency);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 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(
|
||||
$operators[self::INPUT1],
|
||||
$values[self::INPUT1],
|
||||
$operators[self::INPUT2],
|
||||
$values[self::INPUT2]
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check validators relevancy and store them
|
||||
*
|
||||
* @param string $priceOperator Price Operator ex <
|
||||
* @param float $priceValue Price set to meet condition
|
||||
* @param string $currencyOperator Currency Operator ex =
|
||||
* @param string $currencyValue Currency set to meet condition
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return $this
|
||||
*/
|
||||
protected function setValidators($priceOperator, $priceValue, $currencyOperator, $currencyValue)
|
||||
{
|
||||
$isOperator1Legit = $this->isOperatorLegit(
|
||||
$priceOperator,
|
||||
$this->availableOperators[self::INPUT1]
|
||||
);
|
||||
if (!$isOperator1Legit) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Operator for price field is not legit'
|
||||
);
|
||||
}
|
||||
|
||||
$isOperator1Legit = $this->isOperatorLegit(
|
||||
$currencyOperator,
|
||||
$this->availableOperators[self::INPUT2]
|
||||
);
|
||||
if (!$isOperator1Legit) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Operator for currency field is not legit'
|
||||
);
|
||||
}
|
||||
|
||||
$floatType = new FloatType();
|
||||
if (!$floatType->isValid($priceValue) || $priceValue <= 0) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Value for price field is not legit'
|
||||
);
|
||||
}
|
||||
|
||||
// @todo check currency is legit or not
|
||||
|
||||
$this->operators = array(
|
||||
self::INPUT1 => $priceOperator,
|
||||
self::INPUT2 => $currencyOperator,
|
||||
);
|
||||
$this->values = array(
|
||||
self::INPUT1 => $priceValue,
|
||||
self::INPUT2 => $currencyValue,
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if Customer meets conditions
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isMatching()
|
||||
{
|
||||
$isOperator1Legit = $this->isOperatorLegit(
|
||||
$this->operators[self::INPUT1],
|
||||
$this->availableOperators[self::INPUT1]
|
||||
);
|
||||
$isOperator2Legit = $this->isOperatorLegit(
|
||||
$this->operators[self::INPUT2],
|
||||
$this->availableOperators[self::INPUT2]
|
||||
);
|
||||
|
||||
if (!$isOperator1Legit || !$isOperator2Legit) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$constrainValidator = new ConstraintValidator();
|
||||
$constraint1 =$constrainValidator->variableOpComparison(
|
||||
$this->adapter->getCartTotalPrice(),
|
||||
$this->operators[self::INPUT1],
|
||||
$this->values[self::INPUT1]
|
||||
);
|
||||
$constraint2 =$constrainValidator->variableOpComparison(
|
||||
$this->adapter->getCheckoutCurrency(),
|
||||
$this->operators[self::INPUT2],
|
||||
$this->values[self::INPUT2]
|
||||
);
|
||||
if ($constraint1 && $constraint2) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Check if a price is valid
|
||||
// *
|
||||
// * @param float $price Price to check
|
||||
// * @param string $currency Price currency
|
||||
// *
|
||||
// * @throws InvalidRuleValueException if Value is not allowed
|
||||
// * @return bool
|
||||
// */
|
||||
// protected function isPriceValid($price, $currency)
|
||||
// {
|
||||
// $priceValidator = $this->priceValidator;
|
||||
//
|
||||
// /** @var PriceParam $param */
|
||||
// $param = $priceValidator->getParam();
|
||||
// if ($currency == $param->getCurrency()) {
|
||||
// try {
|
||||
// $priceValidator->getParam()->compareTo($price);
|
||||
// } catch(\InvalidArgumentException $e) {
|
||||
// throw new InvalidRuleValueException(get_class(), self::PARAM1_PRICE);
|
||||
// }
|
||||
// } else {
|
||||
// throw new InvalidRuleValueException(get_class(), self::PARAM1_CURRENCY);
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Generate current Rule param to be validated from adapter
|
||||
// *
|
||||
// * @return $this
|
||||
// */
|
||||
// protected function setParametersToValidate()
|
||||
// {
|
||||
// $this->paramsToValidate = array(
|
||||
// self::PARAM1_PRICE => $this->adapter->getCartTotalPrice(),
|
||||
// self::PARAM1_CURRENCY => $this->adapter->getCheckoutCurrency()
|
||||
// );
|
||||
//
|
||||
// return $this;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Get I18n name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->translator->trans(
|
||||
'Cart total amount',
|
||||
array(),
|
||||
'constraint'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
$i18nOperator = Operators::getI18n(
|
||||
$this->translator, $this->operators[self::INPUT1]
|
||||
);
|
||||
|
||||
$toolTip = $this->translator->trans(
|
||||
'If cart total amount is <strong>%operator%</strong> %amount% %currency%',
|
||||
array(
|
||||
'%operator%' => $i18nOperator,
|
||||
'%amount%' => $this->values[self::INPUT1],
|
||||
'%currency%' => $this->values[self::INPUT2]
|
||||
),
|
||||
'constraint'
|
||||
);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
$name1 = $this->translator->trans(
|
||||
'Price',
|
||||
array(),
|
||||
'constraint'
|
||||
);
|
||||
$name2 = $this->translator->trans(
|
||||
'Currency',
|
||||
array(),
|
||||
'constraint'
|
||||
);
|
||||
|
||||
return array(
|
||||
self::INPUT1 => array(
|
||||
'title' => $name1,
|
||||
'availableOperators' => $this->availableOperators[self::INPUT1],
|
||||
'availableValues' => '',
|
||||
'type' => 'text',
|
||||
'class' => 'form-control',
|
||||
'value' => '',
|
||||
'selectedOperator' => ''
|
||||
),
|
||||
self::INPUT2 => array(
|
||||
'title' => $name2,
|
||||
'availableOperators' => $this->availableOperators[self::INPUT2],
|
||||
'availableValues' => $cleanedCurrencies,
|
||||
'type' => 'select',
|
||||
'class' => 'form-control',
|
||||
'value' => '',
|
||||
'selectedOperator' => Operators::EQUAL
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Populate a Rule from a form admin
|
||||
// *
|
||||
// * @param array $operators Rule Operator set by the Admin
|
||||
// * @param array $values Rule Values set by the Admin
|
||||
// *
|
||||
// * @throws \InvalidArgumentException
|
||||
// * @return $this
|
||||
// */
|
||||
// public function populateFromForm(array $operators, array $values)
|
||||
// {
|
||||
// if ($values[self::PARAM1_PRICE] === null
|
||||
// || $values[self::PARAM1_CURRENCY] === null
|
||||
// ) {
|
||||
// throw new \InvalidArgumentException(
|
||||
// 'The Rule ' . get_class() . 'needs at least a quantity set (' . self::PARAM1_PRICE . ', ' . self::PARAM1_CURRENCY . ')'
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// $this->priceValidator = new RuleValidator(
|
||||
// $operators[self::PARAM1_PRICE],
|
||||
// new PriceParam(
|
||||
// $this->translator,
|
||||
// $values[self::PARAM1_PRICE],
|
||||
// $values[self::PARAM1_CURRENCY]
|
||||
// )
|
||||
// );
|
||||
//
|
||||
// $this->validators = array(self::PARAM1_PRICE => $this->priceValidator);
|
||||
//
|
||||
// return $this;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
325
core/lib/Thelia/Constraint/Rule/AvailableForXArticlesManager.php
Normal file
325
core/lib/Thelia/Constraint/Rule/AvailableForXArticlesManager.php
Normal file
@@ -0,0 +1,325 @@
|
||||
<?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
|
||||
*
|
||||
* Check a Checkout against its Product number
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AvailableForXArticlesManager extends CouponRuleAbstract
|
||||
{
|
||||
/** Rule 1st parameter : quantity */
|
||||
CONST INPUT1 = 'quantity';
|
||||
|
||||
/** @var string Service Id from Resources/config.xml */
|
||||
protected $serviceId = 'thelia.constraint.rule.available_for_x_articles';
|
||||
|
||||
/** @var array Available Operators (Operators::CONST) */
|
||||
protected $availableOperators = array(
|
||||
self::INPUT1 => array(
|
||||
Operators::INFERIOR,
|
||||
Operators::INFERIOR_OR_EQUAL,
|
||||
Operators::EQUAL,
|
||||
Operators::SUPERIOR_OR_EQUAL,
|
||||
Operators::SUPERIOR
|
||||
)
|
||||
);
|
||||
|
||||
// /** @var QuantityParam Quantity Validator */
|
||||
// protected $quantityValidator = null;
|
||||
|
||||
// /**
|
||||
// * Check if backoffice inputs are relevant or not
|
||||
// *
|
||||
// * @throws InvalidRuleOperatorException if Operator is not allowed
|
||||
// * @throws InvalidRuleValueException if Value is not allowed
|
||||
// * @return bool
|
||||
// */
|
||||
// public function checkBackOfficeInput()
|
||||
// {
|
||||
// if (!isset($this->validators)
|
||||
// || empty($this->validators)
|
||||
// ||!isset($this->validators[self::PARAM1_QUANTITY])
|
||||
// ||!isset($this->validators[self::PARAM1_QUANTITY])
|
||||
// ) {
|
||||
// throw new InvalidRuleValueException(get_class(), self::PARAM1_QUANTITY);
|
||||
// }
|
||||
//
|
||||
// /** @var RuleValidator $ruleValidator */
|
||||
// $ruleValidator = $this->validators[self::PARAM1_QUANTITY];
|
||||
// /** @var QuantityParam $quantity */
|
||||
// $quantity = $ruleValidator->getParam();
|
||||
//
|
||||
// if (!$quantity instanceof QuantityParam) {
|
||||
// throw new InvalidRuleValueException(get_class(), self::PARAM1_QUANTITY);
|
||||
// }
|
||||
//
|
||||
// $this->checkBackOfficeInputsOperators();
|
||||
//
|
||||
// return $this->isQuantityValid($quantity->getInteger());
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Generate current Rule param to be validated from adapter
|
||||
// *
|
||||
// * @param CouponAdapterInterface $adapter allowing to gather
|
||||
// * all necessary Thelia variables
|
||||
// *
|
||||
// * @return $this
|
||||
// */
|
||||
// protected function setParametersToValidate()
|
||||
// {
|
||||
// $this->paramsToValidate = array(
|
||||
// self::PARAM1_QUANTITY => $this->adapter->getNbArticlesInCart()
|
||||
// );
|
||||
//
|
||||
// return $this;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Check if Checkout inputs are relevant or not
|
||||
// *
|
||||
// * @throws \Thelia\Exception\InvalidRuleValueException
|
||||
// * @return bool
|
||||
// */
|
||||
// public function checkCheckoutInput()
|
||||
// {
|
||||
// if (!isset($this->paramsToValidate)
|
||||
// || empty($this->paramsToValidate)
|
||||
// ||!isset($this->paramsToValidate[self::PARAM1_QUANTITY])
|
||||
// ) {
|
||||
// throw new InvalidRuleValueException(get_class(), self::PARAM1_QUANTITY);
|
||||
// }
|
||||
//
|
||||
// $price = $this->paramsToValidate[self::PARAM1_QUANTITY];
|
||||
//
|
||||
// return $this->isQuantityValid($price);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 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(
|
||||
$operators[self::INPUT1],
|
||||
$values[self::INPUT1]
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check validators relevancy and store them
|
||||
*
|
||||
* @param string $quantityOperator Quantity Operator ex <
|
||||
* @param int $quantityValue Quantity set to meet condition
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return $this
|
||||
*/
|
||||
protected function setValidators($quantityOperator, $quantityValue)
|
||||
{
|
||||
$isOperator1Legit = $this->isOperatorLegit(
|
||||
$quantityOperator,
|
||||
$this->availableOperators[self::INPUT1]
|
||||
);
|
||||
if (!$isOperator1Legit) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Operator for quantity field is not legit'
|
||||
);
|
||||
}
|
||||
|
||||
if (!is_int($quantityValue) || $quantityValue <= 0) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Value for quantity field is not legit'
|
||||
);
|
||||
}
|
||||
|
||||
$this->operators = array(
|
||||
self::INPUT1 => $quantityOperator,
|
||||
);
|
||||
$this->values = array(
|
||||
self::INPUT1 => $quantityValue,
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if Customer meets conditions
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isMatching()
|
||||
{
|
||||
$constrainValidator = new ConstraintValidator();
|
||||
$constraint1 =$constrainValidator->variableOpComparison(
|
||||
$this->adapter->getNbArticlesInCart(),
|
||||
$this->operators[self::INPUT1],
|
||||
$this->values[self::INPUT1]
|
||||
);
|
||||
|
||||
if ($constraint1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Check if a quantity is valid
|
||||
// *
|
||||
// * @param int $quantity Quantity to check
|
||||
// *
|
||||
// * @throws InvalidRuleValueException if Value is not allowed
|
||||
// * @return bool
|
||||
// */
|
||||
// protected function isQuantityValid($quantity)
|
||||
// {
|
||||
// $quantityValidator = $this->quantityValidator;
|
||||
// try {
|
||||
// $quantityValidator->getParam()->compareTo($quantity);
|
||||
// } catch(InvalidArgumentException $e) {
|
||||
// throw new InvalidRuleValueException(get_class(), self::PARAM1_QUANTITY);
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Get I18n name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->translator->trans(
|
||||
'Number of articles in cart',
|
||||
array(),
|
||||
'constraint'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
$i18nOperator = Operators::getI18n(
|
||||
$this->translator, $this->operators[self::INPUT1]
|
||||
);
|
||||
|
||||
$toolTip = $this->translator->trans(
|
||||
'If cart products quantity is <strong>%operator%</strong> %quantity%',
|
||||
array(
|
||||
'%operator%' => $i18nOperator,
|
||||
'%quantity%' => $this->values[self::INPUT1]
|
||||
),
|
||||
'constraint'
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Populate a Rule from a form admin
|
||||
// *
|
||||
// * @param array $operators Rule Operator set by the Admin
|
||||
// * @param array $values Rule Values set by the Admin
|
||||
// *
|
||||
// * @throws InvalidArgumentException
|
||||
// * @return $this
|
||||
// */
|
||||
// public function populateFromForm(array $operators, array $values)
|
||||
// {
|
||||
// if ($values[self::PARAM1_QUANTITY] === null) {
|
||||
// throw new InvalidArgumentException(
|
||||
// 'The Rule ' . get_class() . 'needs at least a quantity set (' . self::PARAM1_QUANTITY. ')'
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// $this->quantityValidator = new RuleValidator(
|
||||
// $operators[self::PARAM1_QUANTITY],
|
||||
// new QuantityParam(
|
||||
// $this->adapter,
|
||||
// $values[self::PARAM1_QUANTITY]
|
||||
// )
|
||||
// );
|
||||
//
|
||||
// $this->validators = array(self::PARAM1_QUANTITY => $this->quantityValidator);
|
||||
//
|
||||
// return $this;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Generate inputs ready to be drawn
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function generateInputs()
|
||||
{
|
||||
$name1 = $this->translator->trans(
|
||||
'Quantity',
|
||||
array(),
|
||||
'constraint'
|
||||
);
|
||||
|
||||
return array(
|
||||
self::INPUT1 => array(
|
||||
'title' => $name1,
|
||||
'availableOperators' => $this->availableOperators[self::INPUT1],
|
||||
'type' => 'text',
|
||||
'class' => 'form-control',
|
||||
'value' => '',
|
||||
'selectedOperator' => ''
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
266
core/lib/Thelia/Constraint/Rule/CouponRuleAbstract.php
Normal file
266
core/lib/Thelia/Constraint/Rule/CouponRuleAbstract.php
Normal file
@@ -0,0 +1,266 @@
|
||||
<?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 Symfony\Component\Intl\Exception\NotImplementedException;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Constraint\Validator\ComparableInterface;
|
||||
use Thelia\Constraint\Validator\RuleValidator;
|
||||
use Thelia\Exception\InvalidRuleException;
|
||||
use Thelia\Exception\InvalidRuleOperatorException;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Assist in writing a condition of whether the Rule is applied or not
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
{
|
||||
// /** Operator key in $validators */
|
||||
// CONST OPERATOR = 'operator';
|
||||
// /** Value key in $validators */
|
||||
// CONST VALUE = 'value';
|
||||
|
||||
/** @var string Service Id from Resources/config.xml */
|
||||
protected $serviceId = null;
|
||||
|
||||
/** @var array Available Operators (Operators::CONST) */
|
||||
protected $availableOperators = array();
|
||||
|
||||
/** @var array Parameters validating parameters against */
|
||||
protected $validators = array();
|
||||
|
||||
// /** @var array Parameters to be validated */
|
||||
// protected $paramsToValidate = array();
|
||||
|
||||
/** @var CouponAdapterInterface Provide necessary value from Thelia */
|
||||
protected $adapter = null;
|
||||
|
||||
/** @var Translator Service Translator */
|
||||
protected $translator = null;
|
||||
|
||||
/** @var array Operators set by Admin in BackOffice */
|
||||
protected $operators = array();
|
||||
|
||||
/** @var array Values set by Admin in BackOffice */
|
||||
protected $values = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Service adapter
|
||||
*/
|
||||
function __construct(CouponAdapterInterface $adapter)
|
||||
{
|
||||
$this->adapter = $adapter;
|
||||
$this->translator = $adapter->getTranslator();
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Check validator relevancy and store them
|
||||
// *
|
||||
// * @param array $validators Array of RuleValidator
|
||||
// * validating $paramsToValidate against
|
||||
// *
|
||||
// * @return $this
|
||||
// * @throws InvalidRuleException
|
||||
// */
|
||||
// protected function setValidators(array $validators)
|
||||
// {
|
||||
// foreach ($validators as $validator) {
|
||||
// if (!$validator instanceof RuleValidator) {
|
||||
// throw new InvalidRuleException(get_class());
|
||||
// }
|
||||
// if (!in_array($validator->getOperator(), $this->availableOperators)) {
|
||||
// throw new InvalidRuleOperatorException(
|
||||
// get_class(),
|
||||
// $validator->getOperator()
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// $this->validators = $validators;
|
||||
//
|
||||
// return $this;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// /**
|
||||
// * Check if the current Checkout matches this condition
|
||||
// *
|
||||
// * @return bool
|
||||
// */
|
||||
// public function isMatching()
|
||||
// {
|
||||
// $this->checkBackOfficeInput();
|
||||
// $this->checkCheckoutInput();
|
||||
//
|
||||
// $isMatching = true;
|
||||
// /** @var $validator RuleValidator*/
|
||||
// foreach ($this->validators as $param => $validator) {
|
||||
// $a = $this->paramsToValidate[$param];
|
||||
// $operator = $validator->getOperator();
|
||||
// /** @var ComparableInterface, RuleParameterAbstract $b */
|
||||
// $b = $validator->getParam();
|
||||
//
|
||||
// if (!Operators::isValid($a, $operator, $b)) {
|
||||
// $isMatching = false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return $isMatching;
|
||||
//
|
||||
// }
|
||||
|
||||
/**
|
||||
* Return all available Operators for this Rule
|
||||
*
|
||||
* @return array Operators::CONST
|
||||
*/
|
||||
public function getAvailableOperators()
|
||||
{
|
||||
return $this->availableOperators;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Check if Operators set for this Rule in the BackOffice are legit
|
||||
// *
|
||||
// * @throws InvalidRuleOperatorException if Operator is not allowed
|
||||
// * @return bool
|
||||
// */
|
||||
// protected function checkBackOfficeInputsOperators()
|
||||
// {
|
||||
// /** @var RuleValidator $param */
|
||||
// foreach ($this->validators as $key => $param) {
|
||||
// $operator = $param->getOperator();
|
||||
// if (!isset($operator)
|
||||
// ||!in_array($operator, $this->availableOperators)
|
||||
// ) {
|
||||
// throw new InvalidRuleOperatorException(get_class(), $key);
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Generate current Rule param to be validated from adapter
|
||||
// *
|
||||
// * @throws \Thelia\Exception\NotImplementedException
|
||||
// * @return $this
|
||||
// */
|
||||
// protected function setParametersToValidate()
|
||||
// {
|
||||
// throw new \Thelia\Exception\NotImplementedException();
|
||||
// }
|
||||
|
||||
/**
|
||||
* Return all validators
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getValidators()
|
||||
{
|
||||
$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;
|
||||
}
|
||||
$validators = array();
|
||||
$validators['inputs'] = $translatedInputs;
|
||||
$validators['setOperators'] = $this->operators;
|
||||
$validators['setValues'] = $this->values;
|
||||
|
||||
return $validators;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Rule Service id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getServiceId()
|
||||
{
|
||||
return $this->serviceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate if Operator given is available for this Coupon
|
||||
*
|
||||
* @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 Rule
|
||||
*
|
||||
* @return SerializableRule
|
||||
*/
|
||||
public function getSerializableRule()
|
||||
{
|
||||
$serializableRule = new SerializableRule();
|
||||
$serializableRule->ruleServiceId = $this->serviceId;
|
||||
$serializableRule->operators = $this->operators;
|
||||
|
||||
$serializableRule->values = $this->values;
|
||||
|
||||
return $serializableRule;
|
||||
}
|
||||
|
||||
}
|
||||
146
core/lib/Thelia/Constraint/Rule/CouponRuleInterface.php
Normal file
146
core/lib/Thelia/Constraint/Rule/CouponRuleInterface.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?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 Thelia\Core\Translation\Translator;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Represents a condition of whether the Rule is applied or not
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
interface CouponRuleInterface
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Service adapter
|
||||
*/
|
||||
function __construct(CouponAdapterInterface $adapter);
|
||||
|
||||
/**
|
||||
* Get Rule Service id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getServiceId();
|
||||
|
||||
// /**
|
||||
// * Check if backoffice inputs are relevant or not
|
||||
// *
|
||||
// * @return bool
|
||||
// */
|
||||
// public function checkBackOfficeInput();
|
||||
|
||||
// /**
|
||||
// * Check if Checkout inputs are relevant or not
|
||||
// *
|
||||
// * @return bool
|
||||
// */
|
||||
// public function checkCheckoutInput();
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
// /**
|
||||
// * Check if the current Checkout matches this condition
|
||||
// *
|
||||
// * @return bool
|
||||
// */
|
||||
// public function isMatching();
|
||||
|
||||
/**
|
||||
* Test if Customer meets conditions
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isMatching();
|
||||
|
||||
/**
|
||||
* Return all available Operators for this Rule
|
||||
*
|
||||
* @return array Operators::CONST
|
||||
*/
|
||||
public function getAvailableOperators();
|
||||
|
||||
|
||||
/**
|
||||
* Get I18n name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip();
|
||||
|
||||
/**
|
||||
* Return all validators
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getValidators();
|
||||
|
||||
// /**
|
||||
// * Populate a Rule from a form admin
|
||||
// *
|
||||
// * @param array $operators Rule Operator set by the Admin
|
||||
// * @param array $values Rule Values set by the Admin
|
||||
// *
|
||||
// * @return bool
|
||||
// */
|
||||
// public function populateFromForm(array$operators, array $values);
|
||||
|
||||
|
||||
/**
|
||||
* Return a serializable Rule
|
||||
*
|
||||
* @return SerializableRule
|
||||
*/
|
||||
public function getSerializableRule();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
188
core/lib/Thelia/Constraint/Rule/Operators.php
Normal file
188
core/lib/Thelia/Constraint/Rule/Operators.php
Normal file
@@ -0,0 +1,188 @@
|
||||
<?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 Symfony\Component\Translation\Translator;
|
||||
use Thelia\Constraint\Validator\ComparableInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Represent available Operations in rule checking
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
abstract class Operators
|
||||
{
|
||||
/** Param1 is inferior to Param2 */
|
||||
CONST INFERIOR = '<';
|
||||
/** Param1 is inferior to Param2 */
|
||||
CONST INFERIOR_OR_EQUAL = '<=';
|
||||
/** Param1 is equal to Param2 */
|
||||
CONST EQUAL = '==';
|
||||
/** Param1 is superior to Param2 */
|
||||
CONST SUPERIOR_OR_EQUAL = '>=';
|
||||
/** Param1 is superior to Param2 */
|
||||
CONST SUPERIOR = '>';
|
||||
/** Param1 is different to Param2 */
|
||||
CONST DIFFERENT = '!=';
|
||||
/** Param1 is in Param2 */
|
||||
CONST IN = 'in';
|
||||
/** Param1 is not in Param2 */
|
||||
CONST OUT = 'out';
|
||||
|
||||
// /**
|
||||
// * Check if a parameter is valid against a ComparableInterface from its operator
|
||||
// *
|
||||
// * @param mixed $a Parameter to validate
|
||||
// * @param string $operator Operator to validate against
|
||||
// * @param ComparableInterface $b Comparable to validate against
|
||||
// *
|
||||
// * @return bool
|
||||
// */
|
||||
// public static function isValid($a, $operator, ComparableInterface $b)
|
||||
// {
|
||||
// $ret = false;
|
||||
//
|
||||
// try {
|
||||
// $comparison = $b->compareTo($a);
|
||||
// } catch (\Exception $e) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// switch ($operator) {
|
||||
// case self::INFERIOR:
|
||||
// if ($comparison == 1) {
|
||||
// return true;
|
||||
// }
|
||||
// break;
|
||||
// case self::INFERIOR_OR_EQUAL:
|
||||
// if ($comparison == 1 || $comparison == 0) {
|
||||
// return true;
|
||||
// }
|
||||
// break;
|
||||
// case self::EQUAL:
|
||||
// if ($comparison == 0) {
|
||||
// return true;
|
||||
// }
|
||||
// break;
|
||||
// case self::SUPERIOR_OR_EQUAL:
|
||||
// if ($comparison == -1 || $comparison == 0) {
|
||||
// return true;
|
||||
// }
|
||||
// break;
|
||||
// case self::SUPERIOR:
|
||||
// if ($comparison == -1) {
|
||||
// return true;
|
||||
// }
|
||||
// break;
|
||||
// case self::DIFFERENT:
|
||||
// if ($comparison != 0) {
|
||||
// return true;
|
||||
// }
|
||||
// break;
|
||||
// default:
|
||||
// }
|
||||
//
|
||||
// return $ret;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Get operator translation
|
||||
*
|
||||
* @param Translator $translator Provide necessary value from Thelia
|
||||
* @param string $operator Operator const
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getI18n(Translator $translator, $operator)
|
||||
{
|
||||
$ret = $operator;
|
||||
switch ($operator) {
|
||||
case self::INFERIOR:
|
||||
$ret = $translator->trans(
|
||||
'inferior to',
|
||||
array(),
|
||||
'constraint'
|
||||
);
|
||||
break;
|
||||
case self::INFERIOR_OR_EQUAL:
|
||||
$ret = $translator->trans(
|
||||
'inferior or equals to',
|
||||
array(),
|
||||
'constraint'
|
||||
);
|
||||
break;
|
||||
case self::EQUAL:
|
||||
$ret = $translator->trans(
|
||||
'equals to',
|
||||
array(),
|
||||
'constraint'
|
||||
);
|
||||
break;
|
||||
case self::SUPERIOR_OR_EQUAL:
|
||||
$ret = $translator->trans(
|
||||
'superior or equals to',
|
||||
array(),
|
||||
'constraint'
|
||||
);
|
||||
break;
|
||||
case self::SUPERIOR:
|
||||
$ret = $translator->trans(
|
||||
'superior to',
|
||||
array(),
|
||||
'constraint'
|
||||
);
|
||||
break;
|
||||
case self::DIFFERENT:
|
||||
$ret = $translator->trans(
|
||||
'different from',
|
||||
array(),
|
||||
'constraint'
|
||||
);
|
||||
break;
|
||||
case self::IN:
|
||||
$ret = $translator->trans(
|
||||
'in',
|
||||
array(),
|
||||
'constraint'
|
||||
);
|
||||
break;
|
||||
case self::OUT:
|
||||
$ret = $translator->trans(
|
||||
'not in',
|
||||
array(),
|
||||
'constraint'
|
||||
);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
81
core/lib/Thelia/Constraint/Rule/SerializableRule.php
Normal file
81
core/lib/Thelia/Constraint/Rule/SerializableRule.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* A rule set by an admin ready to be serialized and stored in DataBase
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class SerializableRule
|
||||
{
|
||||
/** @var string Rule Service id */
|
||||
public $ruleServiceId = null;
|
||||
|
||||
/** @var array Operators set by Admin for this Rule */
|
||||
public $operators = array();
|
||||
|
||||
/** @var array Values set by Admin for this Rule */
|
||||
public $values = array();
|
||||
|
||||
/**
|
||||
* Get Operators set by Admin for this Rule
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOperators()
|
||||
{
|
||||
return $this->operators;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Rule Service id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRuleServiceId()
|
||||
{
|
||||
return $this->ruleServiceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Values set by Admin for this Rule
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getValues()
|
||||
{
|
||||
return $this->values;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
49
core/lib/Thelia/Constraint/Validator/ComparableInterface.php
Normal file
49
core/lib/Thelia/Constraint/Validator/ComparableInterface.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?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\Validator;
|
||||
|
||||
/**
|
||||
* Comparable interface
|
||||
* Allows to compare two value objects to each other for similarity.
|
||||
*
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
*/
|
||||
interface ComparableInterface
|
||||
{
|
||||
/**
|
||||
* Compare the current object to the passed $other.
|
||||
*
|
||||
* Returns 0 if they are semantically equal, 1 if the other object
|
||||
* is less than the current one, or -1 if its more than the current one.
|
||||
*
|
||||
* This method should not check for identity using ===, only for semantically equality for example
|
||||
* when two different DateTime instances point to the exact same Date + TZ.
|
||||
*
|
||||
* @param mixed $other Object
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function compareTo($other);
|
||||
}
|
||||
158
core/lib/Thelia/Constraint/Validator/CustomerParam.php
Normal file
158
core/lib/Thelia/Constraint/Validator/CustomerParam.php
Normal file
@@ -0,0 +1,158 @@
|
||||
<?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\Validator;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Propel\Runtime\ActiveQuery\ModelCriteria;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Model\Customer;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Represent a Customer
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class CustomerParam extends IntegerParam
|
||||
{
|
||||
/** @var string Model Class name */
|
||||
protected $modelClass = '\Thelia\Model\Customer';
|
||||
|
||||
/** @var ModelCriteria */
|
||||
protected $queryBuilder = null;
|
||||
|
||||
/** @var string Customer firstname */
|
||||
protected $firstName = null;
|
||||
|
||||
/** @var string Customer lastname */
|
||||
protected $lastName = null;
|
||||
|
||||
/** @var string Customer email */
|
||||
protected $email = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
|
||||
* @param int $integer Integer
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __construct(CouponAdapterInterface $adapter, $integer)
|
||||
{
|
||||
$this->integer = $integer;
|
||||
$this->adapter = $adapter;
|
||||
|
||||
$this->queryBuilder = CustomerQuery::create();
|
||||
/** @var Customer $customer */
|
||||
$customer = $this->queryBuilder->findById($integer);
|
||||
if ($customer !== null) {
|
||||
$this->firstName = $customer->getFirstname();
|
||||
$this->lastName = $customer->getLastname();
|
||||
$this->email = $customer->getEmail();
|
||||
} else {
|
||||
throw new \InvalidArgumentException(
|
||||
'CustomerParam can compare only existing Customers'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare the current object to the passed $other.
|
||||
*
|
||||
* Returns 0 if they are semantically equal, 1 if the other object
|
||||
* is less than the current one, or -1 if its more than the current one.
|
||||
*
|
||||
* This method should not check for identity using ===, only for semantically equality for example
|
||||
* when two different DateTime instances point to the exact same Date + TZ.
|
||||
*
|
||||
* @param mixed $other Object
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
* @return int
|
||||
*/
|
||||
public function compareTo($other)
|
||||
{
|
||||
if (!is_integer($other) || $other < 0) {
|
||||
throw new InvalidArgumentException(
|
||||
'IntegerParam can compare only positive int'
|
||||
);
|
||||
}
|
||||
|
||||
return parent::compareTo($other);
|
||||
}
|
||||
|
||||
/**
|
||||
* Customer email
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEmail()
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* Customer first name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFirstName()
|
||||
{
|
||||
return $this->firstName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Customer last name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLastName()
|
||||
{
|
||||
return $this->lastName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans(
|
||||
'A Customer',
|
||||
null,
|
||||
'constraint'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
120
core/lib/Thelia/Constraint/Validator/DateParam.php
Normal file
120
core/lib/Thelia/Constraint/Validator/DateParam.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?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\Validator;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Represent a DateTime
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class DateParam extends RuleParameterAbstract
|
||||
{
|
||||
/** @var \DateTime Date */
|
||||
protected $dateTime = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
|
||||
* @param \DateTime $dateTime DateTime
|
||||
*/
|
||||
public function __construct(CouponAdapterInterface $adapter, \DateTime $dateTime)
|
||||
{
|
||||
$this->dateTime = $dateTime;
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get DateTime
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getDateTime()
|
||||
{
|
||||
return clone $this->dateTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare the current object to the passed $other.
|
||||
*
|
||||
* Returns 0 if they are semantically equal, 1 if the other object
|
||||
* is less than the current one, or -1 if its more than the current one.
|
||||
*
|
||||
* This method should not check for identity using ===, only for semantically equality for example
|
||||
* when two different DateTime instances point to the exact same Date + TZ.
|
||||
*
|
||||
* @param mixed $other Object
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return int
|
||||
*/
|
||||
public function compareTo($other)
|
||||
{
|
||||
if (!$other instanceof \DateTime) {
|
||||
throw new \InvalidArgumentException('DateParam can compare only DateTime');
|
||||
}
|
||||
|
||||
$ret = -1;
|
||||
if ($this->dateTime == $other) {
|
||||
$ret = 0;
|
||||
} elseif ($this->dateTime > $other) {
|
||||
$ret = 1;
|
||||
} else {
|
||||
$ret = -1;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Parameter value to test against
|
||||
*
|
||||
* @return \Datetime
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return clone $this->dateTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans('A date (ex: YYYY-MM-DD HH:MM:SS)', null, 'constraint');
|
||||
}
|
||||
|
||||
}
|
||||
121
core/lib/Thelia/Constraint/Validator/IntegerParam.php
Normal file
121
core/lib/Thelia/Constraint/Validator/IntegerParam.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?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\Validator;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Represent an Integer
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class IntegerParam extends RuleParameterAbstract
|
||||
{
|
||||
/** @var int Integer to compare with */
|
||||
protected $integer = 0;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
|
||||
* @param int $integer Integer
|
||||
*/
|
||||
public function __construct(CouponAdapterInterface $adapter, $integer)
|
||||
{
|
||||
$this->integer = $integer;
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get integer
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getInteger()
|
||||
{
|
||||
return $this->integer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compare the current object to the passed $other.
|
||||
*
|
||||
* Returns 0 if they are semantically equal, 1 if the other object
|
||||
* is less than the current one, or -1 if its more than the current one.
|
||||
*
|
||||
* This method should not check for identity using ===, only for semantically equality for example
|
||||
* when two different DateTime instances point to the exact same Date + TZ.
|
||||
*
|
||||
* @param mixed $other Object
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return int
|
||||
*/
|
||||
public function compareTo($other)
|
||||
{
|
||||
if (!is_integer($other)) {
|
||||
throw new \InvalidArgumentException('IntegerParam can compare only int');
|
||||
}
|
||||
|
||||
$ret = -1;
|
||||
if ($this->integer == $other) {
|
||||
$ret = 0;
|
||||
} elseif ($this->integer > $other) {
|
||||
$ret = 1;
|
||||
} else {
|
||||
$ret = -1;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Parameter value to test against
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->integer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans('A number (ex: 42)', null, 'constraint');
|
||||
}
|
||||
|
||||
}
|
||||
165
core/lib/Thelia/Constraint/Validator/IntervalParam.php
Normal file
165
core/lib/Thelia/Constraint/Validator/IntervalParam.php
Normal file
@@ -0,0 +1,165 @@
|
||||
<?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\Validator;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Represent an DateTime period
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class IntervalParam extends RuleParameterAbstract
|
||||
{
|
||||
/** @var \DatePeriod Date period */
|
||||
protected $datePeriod = null;
|
||||
|
||||
/** @var \DateTime Start date */
|
||||
protected $start = null;
|
||||
|
||||
/** @var \DateInterval Interval date */
|
||||
protected $interval = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
|
||||
* @param \DateTime $start Start interval
|
||||
* @param \DateInterval $interval Period
|
||||
*/
|
||||
public function __construct(CouponAdapterInterface $adapter, \DateTime $start, \DateInterval $interval)
|
||||
{
|
||||
$this->datePeriod = new \DatePeriod($start, $interval, 1);
|
||||
$this->adapter = $adapter;
|
||||
|
||||
$this->start = $start;
|
||||
$this->interval = $interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Interval
|
||||
*
|
||||
* @return \DateInterval
|
||||
*/
|
||||
public function getInterval()
|
||||
{
|
||||
return $this->interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get start date
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getStart()
|
||||
{
|
||||
return $this->start;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get DatePeriod
|
||||
*
|
||||
* @return \DatePeriod
|
||||
*/
|
||||
public function getDatePeriod()
|
||||
{
|
||||
return clone $this->datePeriod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare the current object to the passed $other.
|
||||
*
|
||||
* Returns 0 if they are semantically equal, 1 if the other object
|
||||
* is less than the current one, or -1 if its more than the current one.
|
||||
*
|
||||
* This method should not check for identity using ===, only for semantically equality for example
|
||||
* when two different DateTime instances point to the exact same Date + TZ.
|
||||
*
|
||||
* @param mixed $other Object
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return int
|
||||
*/
|
||||
public function compareTo($other)
|
||||
{
|
||||
if (!$other instanceof \DateTime) {
|
||||
throw new \InvalidArgumentException('IntervalParam can compare only DateTime');
|
||||
}
|
||||
|
||||
/** @var \DateTime Start Date */
|
||||
$startDate = null;
|
||||
/** @var \DateTime End Date */
|
||||
$endDate = null;
|
||||
|
||||
foreach ($this->datePeriod as $key => $value) {
|
||||
if ($key == 0) {
|
||||
$startDate = $value;
|
||||
}
|
||||
if ($key == 1) {
|
||||
$endDate = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$ret = -1;
|
||||
if ($startDate <= $other && $other <= $endDate) {
|
||||
$ret = 0;
|
||||
} elseif ($startDate > $other) {
|
||||
$ret = 1;
|
||||
} else {
|
||||
$ret = -1;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Parameter value to test against
|
||||
*
|
||||
* @return \DatePeriod
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return clone $this->datePeriod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans('An interval between two dates', null, 'constraint');
|
||||
}
|
||||
}
|
||||
115
core/lib/Thelia/Constraint/Validator/ModelParam.php
Normal file
115
core/lib/Thelia/Constraint/Validator/ModelParam.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?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\Validator;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Represent a Model
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ModelParam extends IntegerParam
|
||||
{
|
||||
/** @var string Model Class name */
|
||||
protected $modelClass = null;
|
||||
|
||||
/** @var ModelCriteria */
|
||||
protected $queryBuilder = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
|
||||
* @param int $integer Integer
|
||||
* @param string $modelClass Model class name
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __construct(CouponAdapterInterface $adapter, $integer, $modelClass)
|
||||
{
|
||||
if ($integer < 0) {
|
||||
$integer = 0;
|
||||
}
|
||||
$this->integer = $integer;
|
||||
$this->adapter = $adapter;
|
||||
|
||||
$this->modelClass = $modelClass;
|
||||
$queryClassName = $modelClass . 'Query';
|
||||
try {
|
||||
$this->queryBuilder = $queryClassName::create();
|
||||
} catch (\Exception $e) {
|
||||
throw new InvalidArgumentException('ModelParam can only compare Models');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare the current object to the passed $other.
|
||||
*
|
||||
* Returns 0 if they are semantically equal, 1 if the other object
|
||||
* is less than the current one, or -1 if its more than the current one.
|
||||
*
|
||||
* This method should not check for identity using ===, only for semantically equality for example
|
||||
* when two different DateTime instances point to the exact same Date + TZ.
|
||||
*
|
||||
* @param mixed $other Object
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
* @return int
|
||||
*/
|
||||
public function compareTo($other)
|
||||
{
|
||||
if (!is_integer($other) || $other < 0) {
|
||||
throw new InvalidArgumentException(
|
||||
'IntegerParam can compare only positive int'
|
||||
);
|
||||
}
|
||||
|
||||
return parent::compareTo($other);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans(
|
||||
'A Model',
|
||||
null,
|
||||
'constraint'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
145
core/lib/Thelia/Constraint/Validator/PriceParam.php
Normal file
145
core/lib/Thelia/Constraint/Validator/PriceParam.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?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\Validator;
|
||||
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Represent a Price
|
||||
* Positive value with currency
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class PriceParam extends RuleParameterAbstract
|
||||
{
|
||||
/** @var float Positive Float to compare with */
|
||||
protected $price = null;
|
||||
|
||||
/** @var string Currency Code ISO 4217 EUR|USD|GBP */
|
||||
protected $currency = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Translator $translator Service translator
|
||||
* @param float $price Positive float
|
||||
* @param string $currency Currency Code ISO 4217 EUR|USD|GBP
|
||||
*/
|
||||
public function __construct(Translator $translator, $price, $currency)
|
||||
{
|
||||
$this->price = $price;
|
||||
$this->currency = $currency;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get currency code
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrency()
|
||||
{
|
||||
return $this->currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get price
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getPrice()
|
||||
{
|
||||
return $this->price;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare the current object to the passed $other.
|
||||
*
|
||||
* Returns 0 if they are semantically equal, 1 if the other object
|
||||
* is less than the current one, or -1 if its more than the current one.
|
||||
*
|
||||
* This method should not check for identity using ===, only for semantically equality for example
|
||||
* when two different DateTime instances point to the exact same Date + TZ.
|
||||
*
|
||||
* @param mixed $other Object
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return int
|
||||
*/
|
||||
public function compareTo($other)
|
||||
{
|
||||
if (!is_float($other)) {
|
||||
throw new \InvalidArgumentException(
|
||||
'PriceParam can compare only positive float'
|
||||
);
|
||||
}
|
||||
|
||||
$epsilon = 0.00001;
|
||||
|
||||
$ret = -1;
|
||||
if (abs($this->price - $other) < $epsilon) {
|
||||
$ret = 0;
|
||||
} elseif ($this->price > $other) {
|
||||
$ret = 1;
|
||||
} else {
|
||||
$ret = -1;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Parameter value to test against
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->price;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return $this->translator
|
||||
->trans(
|
||||
'A price in %currency% (ex: 14.50)',
|
||||
array(
|
||||
'%currency%' => $this->currency
|
||||
),
|
||||
'constraint'
|
||||
);
|
||||
}
|
||||
}
|
||||
96
core/lib/Thelia/Constraint/Validator/QuantityParam.php
Normal file
96
core/lib/Thelia/Constraint/Validator/QuantityParam.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?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\Validator;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Represent a Quantity
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class QuantityParam extends IntegerParam
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
|
||||
* @param int $integer Integer
|
||||
*/
|
||||
public function __construct(CouponAdapterInterface $adapter, $integer)
|
||||
{
|
||||
$this->integer = $integer;
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare the current object to the passed $other.
|
||||
*
|
||||
* Returns 0 if they are semantically equal, 1 if the other object
|
||||
* is less than the current one, or -1 if its more than the current one.
|
||||
*
|
||||
* This method should not check for identity using ===, only for semantically equality for example
|
||||
* when two different DateTime instances point to the exact same Date + TZ.
|
||||
*
|
||||
* @param mixed $other Object
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return int
|
||||
*/
|
||||
public function compareTo($other)
|
||||
{
|
||||
if (!is_integer($other) || $other < 0) {
|
||||
throw new \InvalidArgumentException(
|
||||
'IntegerParam can compare only positive int'
|
||||
);
|
||||
}
|
||||
|
||||
return parent::compareTo($other);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans(
|
||||
'A positive quantity (ex: 42)',
|
||||
null,
|
||||
'constraint'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
117
core/lib/Thelia/Constraint/Validator/RepeatedDateParam.php
Normal file
117
core/lib/Thelia/Constraint/Validator/RepeatedDateParam.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?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\Validator;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Represent A repeated Date across the time
|
||||
* Ex :
|
||||
* A date repeated every 1 months 5 times
|
||||
* ---------*---*---*---*---*---*---------------------------> time
|
||||
* 1 2 3 4 5 6
|
||||
* 1 : $this->from Start date of the repetition
|
||||
* *--- : $this->interval Duration of a whole cycle
|
||||
* x5 : $this->recurrences How many repeated cycle, 1st excluded
|
||||
* x6 : How many occurrence
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RepeatedDateParam extends RepeatedParam
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
|
||||
*/
|
||||
public function __construct(CouponAdapterInterface $adapter)
|
||||
{
|
||||
$this->defaultConstructor();
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare the current object to the passed $other.
|
||||
*
|
||||
* Returns 0 if they are semantically equal, 1 if the other object
|
||||
* is less than the current one, or -1 if its more than the current one.
|
||||
*
|
||||
* This method should not check for identity using ===, only for semantically equality for example
|
||||
* when two different DateTime instances point to the exact same Date + TZ.
|
||||
*
|
||||
* @param mixed $other Object
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return int
|
||||
*/
|
||||
public function compareTo($other)
|
||||
{
|
||||
if (!$other instanceof \DateTime) {
|
||||
throw new \InvalidArgumentException('RepeatedDateParam can compare only DateTime');
|
||||
}
|
||||
|
||||
$ret = -1;
|
||||
$dates = array();
|
||||
/** @var $value \DateTime */
|
||||
foreach ($this->datePeriod as $value) {
|
||||
$dates[$value->getTimestamp()] = $value;
|
||||
}
|
||||
|
||||
foreach ($dates as $date) {
|
||||
if ($date == $other) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Parameter value to test against
|
||||
*
|
||||
* @return \DatePeriod
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return clone $this->datePeriod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans('A date (ex: YYYY-MM-DD HH:MM:SS)', null, 'constraint');
|
||||
}
|
||||
}
|
||||
151
core/lib/Thelia/Constraint/Validator/RepeatedIntervalParam.php
Normal file
151
core/lib/Thelia/Constraint/Validator/RepeatedIntervalParam.php
Normal file
@@ -0,0 +1,151 @@
|
||||
<?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\Validator;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Represent A repeated DateInterval across the time
|
||||
* Ex :
|
||||
* A duration of 1 month repeated every 2 months 5 times
|
||||
* ---------****----****----****----****----****----****-----------------> time
|
||||
* 1 2 3 4 5 6
|
||||
* 1 : $this->from Start date of the repetition
|
||||
* ****---- : $this->interval Duration of a whole cycle
|
||||
* x5 : $this->recurrences How many repeated cycle, 1st excluded
|
||||
* x6 : How many occurrence
|
||||
* **** : $this->durationInDays Duration of a period
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RepeatedIntervalParam extends RepeatedParam
|
||||
{
|
||||
|
||||
/** @var int duration of the param */
|
||||
protected $durationInDays = 1;
|
||||
|
||||
/**
|
||||
* Get how many day a Param is lasting
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getDurationInDays()
|
||||
{
|
||||
return $this->durationInDays;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set how many day a Param is lasting
|
||||
*
|
||||
* @param int $durationInDays How many day a Param is lasting
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDurationInDays($durationInDays = 1)
|
||||
{
|
||||
$this->durationInDays = $durationInDays;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
|
||||
*/
|
||||
public function __construct(CouponAdapterInterface $adapter)
|
||||
{
|
||||
$this->defaultConstructor();
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare the current object to the passed $other.
|
||||
*
|
||||
* Returns 0 if they are semantically equal, 1 if the other object
|
||||
* is less than the current one, or -1 if its more than the current one.
|
||||
*
|
||||
* This method should not check for identity using ===, only for semantically equality for example
|
||||
* when two different DateTime instances point to the exact same Date + TZ.
|
||||
*
|
||||
* @param mixed $other Object
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return int
|
||||
*/
|
||||
public function compareTo($other)
|
||||
{
|
||||
if (!$other instanceof \DateTime) {
|
||||
throw new \InvalidArgumentException('RepeatedIntervalParam can compare only DateTime');
|
||||
}
|
||||
|
||||
$ret = -1;
|
||||
$dates = array();
|
||||
/** @var $value \DateTime */
|
||||
foreach ($this->datePeriod as $value) {
|
||||
$dates[$value->getTimestamp()]['startDate'] = $value;
|
||||
$endDate = new \DateTime();
|
||||
$dates[$value->getTimestamp()]['endDate'] = $endDate->setTimestamp(
|
||||
$value->getTimestamp() + ($this->durationInDays * 60 *60 *24)
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($dates as $date) {
|
||||
if ($date['startDate'] <= $other && $other <= $date['endDate']) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Parameter value to test against
|
||||
*
|
||||
* @return \DatePeriod
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return clone $this->datePeriod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans('A date (ex: YYYY-MM-DD HH:MM:SS)', null, 'constraint');
|
||||
}
|
||||
}
|
||||
297
core/lib/Thelia/Constraint/Validator/RepeatedParam.php
Normal file
297
core/lib/Thelia/Constraint/Validator/RepeatedParam.php
Normal file
@@ -0,0 +1,297 @@
|
||||
<?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\Validator;
|
||||
|
||||
use DateInterval;
|
||||
use DatePeriod;
|
||||
use DateTime;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Allow to set the way a parameter can be repeated across the time
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
abstract class RepeatedParam extends RuleParameterAbstract
|
||||
{
|
||||
/** @var DateTime The start date of the period. */
|
||||
protected $from = null;
|
||||
|
||||
/** @var DateInterval The interval between recurrences within the period. */
|
||||
protected $interval = null;
|
||||
|
||||
/** @var int Nb time the object will be repeated (1st occurrence excluded). */
|
||||
protected $recurrences = null;
|
||||
|
||||
/** @var DatePeriod dates recurring at regular intervals, over a given period */
|
||||
protected $datePeriod = null;
|
||||
|
||||
/** @var int Frequency the object will be repeated */
|
||||
protected $frequency = null;
|
||||
|
||||
/** @var int $nbRepetition Time the object will be repeated */
|
||||
protected $nbRepetition = null;
|
||||
|
||||
/**
|
||||
* Get frequency
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getFrequency()
|
||||
{
|
||||
return $this->frequency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Interval
|
||||
*
|
||||
* @return \DateInterval
|
||||
*/
|
||||
public function getInterval()
|
||||
{
|
||||
return $this->interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of time it will be repeated
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getNbRepetition()
|
||||
{
|
||||
return $this->nbRepetition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of recurrences
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getRecurrences()
|
||||
{
|
||||
return $this->recurrences;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate default repetition
|
||||
* Every 1 week 100 times from now
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function defaultConstructor()
|
||||
{
|
||||
$this->from = new \DateTime();
|
||||
$this->interval = new \DateInterval('P1W'); // 1 week
|
||||
$this->recurrences = 100;
|
||||
$this->generateDatePeriod();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate DatePeriod from class attributes
|
||||
* Will repeat every DatePeriod
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function generateDatePeriod()
|
||||
{
|
||||
$this->datePeriod = new DatePeriod(
|
||||
$this->from,
|
||||
$this->interval,
|
||||
$this->recurrences
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Object to be repeated every days
|
||||
* Ex : $obj->repeatEveryDay() will occur once
|
||||
* $obj->repeatEveryDay(10) will occur once
|
||||
* $obj->repeatEveryDay(10, 0) will occur once
|
||||
* $obj->repeatEveryDay(10, 4) will occur every 10 days 5 times
|
||||
*
|
||||
* @param int $frequency Frequency the object will be repeated
|
||||
* @param int $nbRepetition Time the object will be repeated
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function repeatEveryDay($frequency = 1, $nbRepetition = 0)
|
||||
{
|
||||
$this->_repeatEveryPeriod($period = 'D', $frequency, $nbRepetition);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Object to be repeated every week
|
||||
* Ex : $obj->repeatEveryWeek() will occur once
|
||||
* $obj->repeatEveryWeek(10) will occur once
|
||||
* $obj->repeatEveryWeek(10, 0) will occur once
|
||||
* $obj->repeatEveryWeek(10, 4) will occur every 10 weeks (70days) 5 times
|
||||
*
|
||||
* @param int $frequency Frequency the object will be repeated
|
||||
* @param int $nbRepetition Time the object will be repeated
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function repeatEveryWeek($frequency = 1, $nbRepetition = 0)
|
||||
{
|
||||
$this->_repeatEveryPeriod($period = 'W', $frequency, $nbRepetition);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Object to be repeated every month
|
||||
* Ex : $obj->repeatEveryWeek() will occur once
|
||||
* $obj->repeatEveryWeek(10) will occur once
|
||||
* $obj->repeatEveryWeek(10, 0) will occur once
|
||||
* $obj->repeatEveryWeek(10, 4) will occur every 10 month (70days) 5times
|
||||
*
|
||||
* @param int $frequency Frequency the object will be repeated
|
||||
* @param int $nbRepetition Time the object will be repeated
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function repeatEveryMonth($frequency = 1, $nbRepetition = 0)
|
||||
{
|
||||
$this->_repeatEveryPeriod($period = 'M', $frequency, $nbRepetition);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Object to be repeated every year
|
||||
* Ex : $obj->repeatEveryWeek() will occur once
|
||||
* $obj->repeatEveryWeek(10) will occur once
|
||||
* $obj->repeatEveryWeek(10, 0) will occur once
|
||||
* $obj->repeatEveryWeek(10, 4) will occur every 10 year 5 times
|
||||
*
|
||||
* @param int $frequency Frequency the object will be repeated
|
||||
* @param int $nbRepetition Time the object will be repeated
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function repeatEveryYear($frequency = 1, $nbRepetition = 0)
|
||||
{
|
||||
$this->_repeatEveryPeriod($period = 'Y', $frequency, $nbRepetition);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Object to be repeated every Period
|
||||
* Ex : $obj->repeatEveryPeriod('D') will occur once
|
||||
* $obj->repeatEveryPeriod('W', 10) will occur once
|
||||
* $obj->repeatEveryPeriod('W', 10, 0) will occur once
|
||||
* $obj->repeatEveryPeriod('M', 10, 4) will occur every 10 month 5 times
|
||||
*
|
||||
* @param string $period Period Y|M||D|W
|
||||
* @param int $frequency Frequency the object will be repeated
|
||||
* @param int $nbRepetition Time the object will be repeated
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
private function _repeatEveryPeriod($period, $frequency = 1, $nbRepetition = 0)
|
||||
{
|
||||
if (is_numeric($frequency) && $frequency > 0) {
|
||||
$this->interval = new \DateInterval('P' . $frequency . $period);
|
||||
}
|
||||
|
||||
if (is_numeric($nbRepetition) && $nbRepetition >= 0) {
|
||||
$this->recurrences = $nbRepetition;
|
||||
}
|
||||
|
||||
$this->generateDatePeriod();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set Start time
|
||||
*
|
||||
* @param \DateTime $from Start time
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setFrom($from)
|
||||
{
|
||||
$this->from = $from;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Start time
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getFrom()
|
||||
{
|
||||
return clone $this->from;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set DatePeriod
|
||||
*
|
||||
* @param DatePeriod $datePeriod DatePeriod
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDatePeriod(DatePeriod $datePeriod)
|
||||
{
|
||||
$this->datePeriod = $datePeriod;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get date DatePeriod
|
||||
*
|
||||
* @return \DatePeriod
|
||||
*/
|
||||
public function getDatePeriod()
|
||||
{
|
||||
return clone $this->datePeriod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Parameter value to test against
|
||||
*
|
||||
* @return \DatePeriod
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return clone $this->datePeriod;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?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\Validator;
|
||||
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Exception\NotImplementedException;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Get a Param value
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
abstract class RuleParameterAbstract implements ComparableInterface
|
||||
{
|
||||
/** @var Translator Service Translator */
|
||||
protected $translator = null;
|
||||
|
||||
/**
|
||||
* Get Parameter value to test against
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return new NotImplementedException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
77
core/lib/Thelia/Constraint/Validator/RuleValidator.php
Normal file
77
core/lib/Thelia/Constraint/Validator/RuleValidator.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?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\Validator;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Allow to validate parameters
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RuleValidator
|
||||
{
|
||||
/** @var string Operator ex: Operators::INFERIOR */
|
||||
protected $operator = null;
|
||||
|
||||
/** @var ComparableInterface Validator */
|
||||
protected $param = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $operator Operator ex: Operators::INFERIOR
|
||||
* @param ComparableInterface $param Validator ex: PriceParam
|
||||
*/
|
||||
function __construct($operator, ComparableInterface $param)
|
||||
{
|
||||
$this->operator = $operator;
|
||||
$this->param = $param;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Validator Operator
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOperator()
|
||||
{
|
||||
return $this->operator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Validator Param
|
||||
*
|
||||
* @return ComparableInterface
|
||||
*/
|
||||
public function getParam()
|
||||
{
|
||||
return $this->param;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,6 +22,9 @@
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Symfony\Component\Routing\Exception\InvalidParameterException;
|
||||
use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
|
||||
use Symfony\Component\Routing\Exception\RouteNotFoundException;
|
||||
use Thelia\Controller\BaseController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Thelia\Core\Security\Exception\AuthorizationException;
|
||||
@@ -211,12 +214,26 @@ class BaseAdminController extends BaseController
|
||||
/**
|
||||
* Return the route path defined for the givent route ID
|
||||
*
|
||||
* @param string $routeId a route ID, as defines in Config/Resources/routing/admin.xml
|
||||
* @param string $routeId a route ID, as defines in Config/Resources/routing/admin.xml
|
||||
* @param mixed $parameters An array of parameters
|
||||
* @param Boolean|string $referenceType The type of reference to be generated (one of the constants)
|
||||
*
|
||||
* @throws RouteNotFoundException If the named route doesn't exist
|
||||
* @throws MissingMandatoryParametersException When some parameters are missing that are mandatory for the route
|
||||
* @throws InvalidParameterException When a parameter value for a placeholder is not correct because
|
||||
* it does not match the requirement
|
||||
* @throws \InvalidArgumentException When the router doesn't exist
|
||||
* @return string The generated URL
|
||||
*
|
||||
* @see \Thelia\Controller\BaseController::getRouteFromRouter()
|
||||
*/
|
||||
protected function getRoute($routeId) {
|
||||
return $this->getRouteFromRouter('router.admin', $routeId);
|
||||
protected function getRoute($routeId, $parameters = array(), $referenceType = Router::ABSOLUTE_PATH) {
|
||||
return $this->getRouteFromRouter(
|
||||
'router.admin',
|
||||
$routeId,
|
||||
$parameters,
|
||||
$referenceType
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
702
core/lib/Thelia/Controller/Admin/CouponController.php
Executable file
702
core/lib/Thelia/Controller/Admin/CouponController.php
Executable file
@@ -0,0 +1,702 @@
|
||||
<?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\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;
|
||||
use Thelia\Constraint\Rule\CouponRuleInterface;
|
||||
use Thelia\Constraint\Validator\PriceParam;
|
||||
use Thelia\Core\Event\Coupon\CouponCreateEvent;
|
||||
use Thelia\Core\Event\Coupon\CouponCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\Coupon\CouponEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\HttpFoundation\Session\Session;
|
||||
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;
|
||||
use Thelia\Model\Coupon;
|
||||
use Thelia\Model\CouponQuery;
|
||||
use Thelia\Model\Lang;
|
||||
use Thelia\Tools\I18n;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Control View and Action (Model) via Events
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class CouponController extends BaseAdminController
|
||||
{
|
||||
/**
|
||||
* Manage Coupons list display
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function browseAction()
|
||||
{
|
||||
$this->checkAuth('ADMIN', 'admin.coupon.view');
|
||||
|
||||
return $this->render('coupon-list');
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage Coupons creation display
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function createAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
$response = $this->checkAuth('admin.coupon.create');
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
// Parameters given to the template
|
||||
$args = array();
|
||||
|
||||
$i18n = new I18n();
|
||||
/** @var Lang $lang */
|
||||
$lang = $this->getSession()->get('lang');
|
||||
$eventToDispatch = TheliaEvents::COUPON_CREATE;
|
||||
|
||||
if ($this->getRequest()->isMethod('POST')) {
|
||||
$this->validateCreateOrUpdateForm(
|
||||
$i18n,
|
||||
$lang,
|
||||
$eventToDispatch,
|
||||
'created',
|
||||
'creation'
|
||||
);
|
||||
} else {
|
||||
// If no input for expirationDate, now + 2 months
|
||||
$defaultDate = new \DateTime();
|
||||
$args['defaultDate'] = $defaultDate->modify('+2 month')
|
||||
->format($lang->getDateFormat());
|
||||
}
|
||||
|
||||
$args['formAction'] = 'admin/coupon/create';
|
||||
|
||||
return $this->render(
|
||||
'coupon-create',
|
||||
$args
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage Coupons edition display
|
||||
*
|
||||
* @param int $couponId Coupon id
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function updateAction($couponId)
|
||||
{
|
||||
// Check current user authorization
|
||||
$response = $this->checkAuth('admin.coupon.update');
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
/** @var Coupon $coupon */
|
||||
$coupon = CouponQuery::create()->findOneById($couponId);
|
||||
if (!$coupon) {
|
||||
$this->pageNotFound();
|
||||
}
|
||||
|
||||
// Parameters given to the template
|
||||
$args = array();
|
||||
|
||||
$i18n = new I18n();
|
||||
/** @var Lang $lang */
|
||||
$lang = $this->getSession()->getLang();
|
||||
$eventToDispatch = TheliaEvents::COUPON_UPDATE;
|
||||
|
||||
if ($this->getRequest()->isMethod('POST')) {
|
||||
$this->validateCreateOrUpdateForm(
|
||||
$i18n,
|
||||
$lang,
|
||||
$eventToDispatch,
|
||||
'updated',
|
||||
'update'
|
||||
);
|
||||
} else {
|
||||
// Prepare the data that will hydrate the form
|
||||
$data = array(
|
||||
'code' => $coupon->getCode(),
|
||||
'title' => $coupon->getTitle(),
|
||||
'amount' => $coupon->getAmount(),
|
||||
'effect' => $coupon->getType(),
|
||||
'shortDescription' => $coupon->getShortDescription(),
|
||||
'description' => $coupon->getDescription(),
|
||||
'isEnabled' => ($coupon->getIsEnabled() == 1),
|
||||
'expirationDate' => $coupon->getExpirationDate($lang->getDateFormat()),
|
||||
'isAvailableOnSpecialOffers' => ($coupon->getIsAvailableOnSpecialOffers() == 1),
|
||||
'isCumulative' => ($coupon->getIsCumulative() == 1),
|
||||
'isRemovingPostage' => ($coupon->getIsRemovingPostage() == 1),
|
||||
'maxUsage' => $coupon->getMaxUsage(),
|
||||
'rules' => new CouponRuleCollection(array()),
|
||||
'locale' => $coupon->getLocale(),
|
||||
);
|
||||
|
||||
$args['rulesObject'] = array();
|
||||
|
||||
/** @var ConstraintFactory $constraintFactory */
|
||||
$constraintFactory = $this->container->get('thelia.constraint.factory');
|
||||
$rules = $constraintFactory->unserializeCouponRuleCollection(
|
||||
$coupon->getSerializedRules()
|
||||
);
|
||||
|
||||
/** @var CouponRuleInterface $rule */
|
||||
foreach ($rules->getRules() as $rule) {
|
||||
$args['rulesObject'][] = array(
|
||||
'serviceId' => $rule->getServiceId(),
|
||||
'name' => $rule->getName(),
|
||||
'tooltip' => $rule->getToolTip(),
|
||||
'validators' => $rule->getValidators()
|
||||
);
|
||||
}
|
||||
|
||||
// Setup the object form
|
||||
$changeForm = new CouponCreationForm($this->getRequest(), 'form', $data);
|
||||
|
||||
// Pass it to the parser
|
||||
$this->getParserContext()->addForm($changeForm);
|
||||
}
|
||||
|
||||
$args['availableCoupons'] = $this->getAvailableCoupons();
|
||||
$args['availableRules'] = $this->getAvailableRules();
|
||||
$args['urlAjaxGetRuleInput'] = $this->getRoute(
|
||||
'admin.coupon.rule.input',
|
||||
array('ruleId' => 'ruleId'),
|
||||
Router::ABSOLUTE_URL
|
||||
);
|
||||
|
||||
$args['urlAjaxUpdateRules'] = $this->getRoute(
|
||||
'admin.coupon.rule.update',
|
||||
array('couponId' => $couponId),
|
||||
Router::ABSOLUTE_URL
|
||||
);
|
||||
|
||||
$args['formAction'] = 'admin/coupon/update/' . $couponId;
|
||||
|
||||
return $this->render(
|
||||
'coupon-update',
|
||||
$args
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Manage Coupons Rule creation display
|
||||
*
|
||||
* @param int $couponId Coupon id
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function createRuleAction($couponId)
|
||||
{
|
||||
// Check current user authorization
|
||||
$response = $this->checkAuth('admin.coupon.update');
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
/** @var Coupon $coupon */
|
||||
$coupon = CouponQuery::create()->findOneById($couponId);
|
||||
if (!$coupon) {
|
||||
$this->pageNotFound();
|
||||
}
|
||||
|
||||
// Parameters given to the template
|
||||
$args = array();
|
||||
|
||||
$i18n = new I18n();
|
||||
/** @var Lang $lang */
|
||||
$lang = $this->getSession()->get('lang');
|
||||
$eventToDispatch = TheliaEvents::COUPON_RULE_CREATE;
|
||||
|
||||
if ($this->getRequest()->isMethod('POST')) {
|
||||
$this->validateCreateOrUpdateForm(
|
||||
$i18n,
|
||||
$lang,
|
||||
$eventToDispatch,
|
||||
'updated',
|
||||
'update'
|
||||
);
|
||||
} else {
|
||||
// Prepare the data that will hydrate the form
|
||||
$data = array(
|
||||
'code' => $coupon->getCode(),
|
||||
'title' => $coupon->getTitle(),
|
||||
'amount' => $coupon->getAmount(),
|
||||
'effect' => $coupon->getType(),
|
||||
'shortDescription' => $coupon->getShortDescription(),
|
||||
'description' => $coupon->getDescription(),
|
||||
'isEnabled' => ($coupon->getIsEnabled() == 1),
|
||||
'expirationDate' => $coupon->getExpirationDate($lang->getDateFormat()),
|
||||
'isAvailableOnSpecialOffers' => ($coupon->getIsAvailableOnSpecialOffers() == 1),
|
||||
'isCumulative' => ($coupon->getIsCumulative() == 1),
|
||||
'isRemovingPostage' => ($coupon->getIsRemovingPostage() == 1),
|
||||
'maxUsage' => $coupon->getMaxUsage(),
|
||||
'rules' => new CouponRuleCollection(array()),
|
||||
'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 CouponRuleInterface $rule */
|
||||
foreach ($coupon->getRules()->getRules() as $rule) {
|
||||
$args['rulesObject'][] = array(
|
||||
'name' => $rule->getName($translator),
|
||||
'tooltip' => $rule->getToolTip($translator),
|
||||
'validators' => $rule->getValidators()
|
||||
);
|
||||
}
|
||||
|
||||
// $args['rules'] = $this->cleanRuleForTemplate($coupon->getRules()->getRules());
|
||||
|
||||
// Setup the object form
|
||||
$changeForm = new CouponCreationForm($this->getRequest(), 'form', $data);
|
||||
|
||||
// Pass it to the parser
|
||||
$this->getParserContext()->addForm($changeForm);
|
||||
}
|
||||
|
||||
$args['formAction'] = 'admin/coupon/update/' . $couponId;
|
||||
|
||||
return $this->render(
|
||||
'coupon-update',
|
||||
$args
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Manage Coupons read display
|
||||
*
|
||||
* @param int $couponId Coupon Id
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function readAction($couponId)
|
||||
{
|
||||
$this->checkAuth('ADMIN', 'admin.coupon.read');
|
||||
|
||||
// Database request repeated in the loop but cached
|
||||
$search = CouponQuery::create();
|
||||
$coupon = $search->findOneById($couponId);
|
||||
|
||||
if ($coupon === null) {
|
||||
return $this->pageNotFound();
|
||||
}
|
||||
|
||||
return $this->render('coupon-read', array('couponId' => $couponId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage Coupons read display
|
||||
*
|
||||
* @param string $ruleId Rule service id
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function getRuleInputAction($ruleId)
|
||||
{
|
||||
$this->checkAuth('ADMIN', 'admin.coupon.read');
|
||||
|
||||
if ($this->isDebug()) {
|
||||
if (!$this->getRequest()->isXmlHttpRequest()) {
|
||||
$this->redirect(
|
||||
$this->getRoute(
|
||||
'admin',
|
||||
array(),
|
||||
Router::ABSOLUTE_URL
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/** @var ConstraintFactory $constraintFactory */
|
||||
$constraintFactory = $this->container->get('thelia.constraint.factory');
|
||||
$inputs = $constraintFactory->getInputs($ruleId);
|
||||
|
||||
if ($inputs === null) {
|
||||
return $this->pageNotFound();
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'coupon/rule-input-ajax',
|
||||
array(
|
||||
'ruleId' => $ruleId,
|
||||
'inputs' => $inputs
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Manage Coupons read display
|
||||
*
|
||||
* @param int $couponId Coupon id
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function updateRulesAction($couponId)
|
||||
{
|
||||
$this->checkAuth('ADMIN', 'admin.coupon.read');
|
||||
|
||||
if ($this->isDebug()) {
|
||||
if (!$this->getRequest()->isXmlHttpRequest()) {
|
||||
$this->redirect(
|
||||
$this->getRoute(
|
||||
'admin',
|
||||
array(),
|
||||
Router::ABSOLUTE_URL
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$search = CouponQuery::create();
|
||||
/** @var Coupon $coupon */
|
||||
$coupon = $search->findOneById($couponId);
|
||||
|
||||
if (!$coupon) {
|
||||
return $this->pageNotFound();
|
||||
}
|
||||
|
||||
$rules = new CouponRuleCollection();
|
||||
|
||||
/** @var ConstraintFactory $constraintFactory */
|
||||
$constraintFactory = $this->container->get('thelia.constraint.factory');
|
||||
$rulesReceived = json_decode($this->getRequest()->get('rules'));
|
||||
foreach ($rulesReceived as $ruleReceived) {
|
||||
var_dump('building ', $ruleReceived->values);
|
||||
$rule = $constraintFactory->build(
|
||||
$ruleReceived->serviceId,
|
||||
(array) $ruleReceived->operators,
|
||||
(array) $ruleReceived->values
|
||||
);
|
||||
$rules->add(clone $rule);
|
||||
}
|
||||
|
||||
$coupon->setSerializedRules(
|
||||
$constraintFactory->serializeCouponRuleCollection($rules)
|
||||
);
|
||||
|
||||
$couponEvent = new CouponCreateOrUpdateEvent(
|
||||
$coupon->getCode(),
|
||||
$coupon->getTitle(),
|
||||
$coupon->getAmount(),
|
||||
$coupon->getType(),
|
||||
$coupon->getShortDescription(),
|
||||
$coupon->getDescription(),
|
||||
$coupon->getIsEnabled(),
|
||||
$coupon->getExpirationDate(),
|
||||
$coupon->getIsAvailableOnSpecialOffers(),
|
||||
$coupon->getIsCumulative(),
|
||||
$coupon->getIsRemovingPostage(),
|
||||
$coupon->getMaxUsage(),
|
||||
$rules,
|
||||
$coupon->getLocale()
|
||||
);
|
||||
|
||||
$eventToDispatch = TheliaEvents::COUPON_RULE_UPDATE;
|
||||
// Dispatch Event to the Action
|
||||
$this->dispatch(
|
||||
$eventToDispatch,
|
||||
$couponEvent
|
||||
);
|
||||
|
||||
$this->adminLogAppend(
|
||||
sprintf(
|
||||
'Coupon %s (ID %s) rules updated',
|
||||
$couponEvent->getTitle(),
|
||||
$couponEvent->getCoupon()->getId()
|
||||
)
|
||||
);
|
||||
|
||||
$cleanedRules = $this->cleanRuleForTemplate($rules);
|
||||
|
||||
return $this->render(
|
||||
'coupon/rules',
|
||||
array(
|
||||
'couponId' => $couponId,
|
||||
'rules' => $cleanedRules,
|
||||
'urlEdit' => $couponId,
|
||||
'urlDelete' => $couponId
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a Coupon from its form
|
||||
*
|
||||
* @param array $data Form data
|
||||
*
|
||||
* @return Coupon
|
||||
*/
|
||||
protected function buildCouponFromForm(array $data)
|
||||
{
|
||||
$couponBeingCreated = new Coupon();
|
||||
$couponBeingCreated->setCode($data['code']);
|
||||
$couponBeingCreated->setType($data['type']);
|
||||
$couponBeingCreated->setTitle($data['title']);
|
||||
$couponBeingCreated->setShortDescription($data['shortDescription']);
|
||||
$couponBeingCreated->setDescription($data['description']);
|
||||
$couponBeingCreated->setAmount($data['amount']);
|
||||
$couponBeingCreated->setIsEnabled($data['isEnabled']);
|
||||
$couponBeingCreated->setExpirationDate($data['expirationDate']);
|
||||
$couponBeingCreated->setSerializedRules(
|
||||
new CouponRuleCollection(
|
||||
array()
|
||||
)
|
||||
);
|
||||
$couponBeingCreated->setIsCumulative($data['isCumulative']);
|
||||
$couponBeingCreated->setIsRemovingPostage(
|
||||
$data['isRemovingPostage']
|
||||
);
|
||||
$couponBeingCreated->setMaxUsage($data['maxUsage']);
|
||||
$couponBeingCreated->setIsAvailableOnSpecialOffers(
|
||||
$data['isAvailableOnSpecialOffers']
|
||||
);
|
||||
|
||||
return $couponBeingCreated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log error message
|
||||
*
|
||||
* @param string $action Creation|Update|Delete
|
||||
* @param string $message Message to log
|
||||
* @param \Exception $e Exception to log
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function logError($action, $message, $e)
|
||||
{
|
||||
Tlog::getInstance()->error(
|
||||
sprintf(
|
||||
'Error during Coupon ' . $action . ' process : %s. Exception was %s',
|
||||
$message,
|
||||
$e->getMessage()
|
||||
)
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the CreateOrUpdate form
|
||||
*
|
||||
* @param string $i18n Local code (fr_FR)
|
||||
* @param Lang $lang Local variables container
|
||||
* @param string $eventToDispatch Event which will activate actions
|
||||
* @param string $log created|edited
|
||||
* @param string $action creation|edition
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function validateCreateOrUpdateForm($i18n, $lang, $eventToDispatch, $log, $action)
|
||||
{
|
||||
// Create the form from the request
|
||||
$creationForm = new CouponCreationForm($this->getRequest());
|
||||
|
||||
$message = false;
|
||||
try {
|
||||
// Check the form against constraints violations
|
||||
$form = $this->validateForm($creationForm, 'POST');
|
||||
|
||||
// Get the form field values
|
||||
$data = $form->getData();
|
||||
$couponEvent = new CouponCreateOrUpdateEvent(
|
||||
$data['code'],
|
||||
$data['title'],
|
||||
$data['amount'],
|
||||
$data['effect'],
|
||||
$data['shortDescription'],
|
||||
$data['description'],
|
||||
$data['isEnabled'],
|
||||
$i18n->getDateTimeFromForm($lang, $data['expirationDate']),
|
||||
$data['isAvailableOnSpecialOffers'],
|
||||
$data['isCumulative'],
|
||||
$data['isRemovingPostage'],
|
||||
$data['maxUsage'],
|
||||
new CouponRuleCollection(array()),
|
||||
$data['locale']
|
||||
);
|
||||
|
||||
// Dispatch Event to the Action
|
||||
$this->dispatch(
|
||||
$eventToDispatch,
|
||||
$couponEvent
|
||||
);
|
||||
|
||||
$this->adminLogAppend(
|
||||
sprintf(
|
||||
'Coupon %s (ID ) ' . $log,
|
||||
$couponEvent->getTitle(),
|
||||
$couponEvent->getCoupon()->getId()
|
||||
)
|
||||
);
|
||||
|
||||
$this->redirect(
|
||||
str_replace(
|
||||
'{id}',
|
||||
$couponEvent->getCoupon()->getId(),
|
||||
$creationForm->getSuccessUrl()
|
||||
)
|
||||
);
|
||||
|
||||
} catch (FormValidationException $e) {
|
||||
// Invalid data entered
|
||||
$message = 'Please check your input:';
|
||||
$this->logError($action, $message, $e);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// Any other error
|
||||
$message = 'Sorry, an error occurred:';
|
||||
$this->logError($action, $message, $e);
|
||||
}
|
||||
|
||||
if ($message !== false) {
|
||||
// Mark the form as with error
|
||||
$creationForm->setErrorMessage($message);
|
||||
|
||||
// Send the form and the error to the parser
|
||||
$this->getParserContext()
|
||||
->addForm($creationForm)
|
||||
->setGeneralError($message);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $rules
|
||||
* @return array
|
||||
*/
|
||||
protected function cleanRuleForTemplate($rules)
|
||||
{
|
||||
$cleanedRules = array();
|
||||
/** @var $rule CouponRuleInterface */
|
||||
foreach ($rules->getRules() as $rule) {
|
||||
$cleanedRules[] = $rule->getToolTip();
|
||||
}
|
||||
|
||||
return $cleanedRules;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Validation Rule creation
|
||||
// *
|
||||
// * @param string $type Rule class type
|
||||
// * @param string $operator Rule operator (<, >, =, etc)
|
||||
// * @param array $values Rules values
|
||||
// *
|
||||
// * @return bool
|
||||
// */
|
||||
// protected function validateRulesCreation($type, $operator, $values)
|
||||
// {
|
||||
// /** @var CouponAdapterInterface $adapter */
|
||||
// $adapter = $this->container->get('thelia.adapter');
|
||||
// $validator = new PriceParam()
|
||||
// try {
|
||||
// $rule = new AvailableForTotalAmount($adapter, $validators);
|
||||
// $rule = new $type($adapter, $validators);
|
||||
// } catch (\Exception $e) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
}
|
||||
40
core/lib/Thelia/Controller/Admin/CustomerController.php
Normal file
40
core/lib/Thelia/Controller/Admin/CustomerController.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?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\Controller\Admin;
|
||||
|
||||
|
||||
/**
|
||||
* Class CustomerController
|
||||
* @package Thelia\Controller\Admin
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class CustomerController extends BaseAdminController
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.customers.view")) return $response;
|
||||
|
||||
return $this->render("customers", array("display_customer" => 20));
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,10 @@ namespace Thelia\Controller;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||
|
||||
use Symfony\Component\Routing\Exception\InvalidParameterException;
|
||||
use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
|
||||
use Symfony\Component\Routing\Exception\RouteNotFoundException;
|
||||
use Symfony\Component\Routing\Router;
|
||||
use Thelia\Core\Security\SecurityContext;
|
||||
use Thelia\Tools\URL;
|
||||
use Thelia\Tools\Redirect;
|
||||
@@ -175,7 +179,14 @@ class BaseController extends ContainerAware
|
||||
return $form;
|
||||
}
|
||||
else {
|
||||
throw new FormValidationException(sprintf("Missing or invalid data: %s", $this->getErrorMessages($form)));
|
||||
$errorMessage = null;
|
||||
if ($form->get("error_message")->getData() != null) {
|
||||
$errorMessage = $form->get("error_message")->getData();
|
||||
} else {
|
||||
$errorMessage = sprintf("Missing or invalid data: %s", $this->getErrorMessages($form));
|
||||
}
|
||||
|
||||
throw new FormValidationException($errorMessage);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -216,20 +227,27 @@ class BaseController extends ContainerAware
|
||||
/**
|
||||
* Get a route path from the route id.
|
||||
*
|
||||
* @param $routerName
|
||||
* @param $routeId
|
||||
* @param string $routerName Router name
|
||||
* @param string $routeId The name of the route
|
||||
* @param mixed $parameters An array of parameters
|
||||
* @param Boolean|string $referenceType The type of reference to be generated (one of the constants)
|
||||
*
|
||||
* @return mixed
|
||||
* @throws InvalidArgumentException
|
||||
* @throws RouteNotFoundException If the named route doesn't exist
|
||||
* @throws MissingMandatoryParametersException When some parameters are missing that are mandatory for the route
|
||||
* @throws InvalidParameterException When a parameter value for a placeholder is not correct because
|
||||
* it does not match the requirement
|
||||
* @throws \InvalidArgumentException When the router doesn't exist
|
||||
* @return string The generated URL
|
||||
*/
|
||||
protected function getRouteFromRouter($routerName, $routeId) {
|
||||
$route = $this->container->get($routerName)->getRouteCollection()->get($routeId);
|
||||
protected function getRouteFromRouter($routerName, $routeId, $parameters = array(), $referenceType = Router::ABSOLUTE_PATH) {
|
||||
/** @var Router $router */
|
||||
$router = $this->container->get($routerName);
|
||||
|
||||
if ($route == null) {
|
||||
throw new \InvalidArgumentException(sprintf("Route ID '%s' does not exists.", $routeId));
|
||||
if ($router == null) {
|
||||
throw new \InvalidArgumentException(sprintf("Router '%s' does not exists.", $routerName));
|
||||
}
|
||||
|
||||
return $route->getPath();
|
||||
return $router->generate($routeId, $parameters, $referenceType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -240,4 +258,14 @@ class BaseController extends ContainerAware
|
||||
{
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if environment is in debug mode
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isDebug()
|
||||
{
|
||||
return $this->container->getParameter('kernel.debug');
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Controller\Front;
|
||||
|
||||
use Symfony\Component\Routing\Router;
|
||||
use Thelia\Controller\BaseController;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
@@ -34,8 +35,8 @@ class BaseFrontController extends BaseController
|
||||
*
|
||||
* @see \Thelia\Controller\BaseController::getRouteFromRouter()
|
||||
*/
|
||||
protected function getRoute($routeId) {
|
||||
return $this->getRouteFromRouter('router.front', $routeId);
|
||||
protected function getRoute($routeId, $parameters = array(), $referenceType = Router::ABSOLUTE_PATH) {
|
||||
return $this->getRouteFromRouter('router.front', $routeId, $parameters, $referenceType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,7 +45,7 @@ class BaseFrontController extends BaseController
|
||||
* @param unknown $routeId the route ID, as found in Config/Resources/routing/admin.xml
|
||||
* @param unknown $urlParameters the URL parametrs, as a var/value pair array
|
||||
*/
|
||||
public function redirectToRoute($routeId, $urlParameters = array()) {
|
||||
$this->redirect(URL::getInstance()->absoluteUrl($this->getRoute($routeId), $urlParameters));
|
||||
public function redirectToRoute($routeId, $urlParameters = array(), $referenceType = Router::ABSOLUTE_PATH) {
|
||||
$this->redirect(URL::getInstance()->absoluteUrl($this->getRoute($routeId, array(), $referenceType), $urlParameters));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ use Thelia\Core\Factory\ActionEventFactory;
|
||||
use Thelia\Tools\URL;
|
||||
use Thelia\Log\Tlog;
|
||||
use Thelia\Core\Security\Exception\WrongPasswordException;
|
||||
use Symfony\Component\Routing\Router;
|
||||
|
||||
/**
|
||||
* Class CustomerController
|
||||
@@ -167,16 +168,25 @@ class CustomerController extends BaseFrontController
|
||||
|
||||
}
|
||||
catch (FormValidationException $e) {
|
||||
|
||||
if ($request->request->has("account")) {
|
||||
$account = $request->request->get("account");
|
||||
$form = $customerLoginForm->getForm();
|
||||
if($account == 0 && $form->get("email")->getData() !== null) {
|
||||
$this->redirectToRoute("customer.create.view", array("email" => $form->get("email")->getData()));
|
||||
}
|
||||
}
|
||||
|
||||
$message = sprintf("Please check your input: %s", $e->getMessage());
|
||||
}
|
||||
catch(UsernameNotFoundException $e) {
|
||||
$message = "This customer email was not found.";
|
||||
$message = "Wrong email or password. Please try again";
|
||||
}
|
||||
catch (WrongPasswordException $e) {
|
||||
$message = "Wrong password. Please try again.";
|
||||
$message = "Wrong email or password. Please try again";
|
||||
}
|
||||
catch(AuthenticationException $e) {
|
||||
$message = "Sorry, we failed to authentify you. Please try again.";
|
||||
$message = "Wrong email or password. Please try again";
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$message = sprintf("Sorry, an error occured: %s", $e->getMessage());
|
||||
|
||||
@@ -26,9 +26,11 @@ use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Scope;
|
||||
|
||||
use Thelia\Core\DependencyInjection\Compiler\RegisterCouponPass;
|
||||
use Thelia\Core\DependencyInjection\Compiler\RegisterListenersPass;
|
||||
use Thelia\Core\DependencyInjection\Compiler\RegisterParserPluginPass;
|
||||
use Thelia\Core\DependencyInjection\Compiler\RegisterRouterPass;
|
||||
use Thelia\Core\DependencyInjection\Compiler\RegisterRulePass;
|
||||
|
||||
/**
|
||||
* First Bundle use in Thelia
|
||||
@@ -60,6 +62,8 @@ class TheliaBundle extends Bundle
|
||||
->addCompilerPass(new RegisterListenersPass())
|
||||
->addCompilerPass(new RegisterParserPluginPass())
|
||||
->addCompilerPass(new RegisterRouterPass())
|
||||
->addCompilerPass(new RegisterCouponPass())
|
||||
->addCompilerPass(new RegisterRulePass())
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
69
core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterCouponPass.php
Executable file
69
core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterCouponPass.php
Executable file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Core\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 9/05/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Class RegisterListenersPass
|
||||
* Source code come from Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RegisterKernelListenersPass class
|
||||
*
|
||||
* @package Thelia\Core\DependencyInjection\Compiler
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RegisterCouponPass implements CompilerPassInterface
|
||||
{
|
||||
/**
|
||||
* You can modify the container here before it is dumped to PHP code.
|
||||
*
|
||||
* @param ContainerBuilder $container Container
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasDefinition('thelia.coupon.manager')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$couponManager = $container->getDefinition('thelia.coupon.manager');
|
||||
$services = $container->findTaggedServiceIds("thelia.coupon.addCoupon");
|
||||
|
||||
foreach ($services as $id => $rule) {
|
||||
$couponManager->addMethodCall(
|
||||
'addAvailableCoupon',
|
||||
array(
|
||||
new Reference($id)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
69
core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterRulePass.php
Executable file
69
core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterRulePass.php
Executable file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Core\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 9/05/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Class RegisterListenersPass
|
||||
* Source code come from Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RegisterKernelListenersPass class
|
||||
*
|
||||
* @package Thelia\Core\DependencyInjection\Compiler
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RegisterRulePass implements CompilerPassInterface
|
||||
{
|
||||
/**
|
||||
* You can modify the container here before it is dumped to PHP code.
|
||||
*
|
||||
* @param ContainerBuilder $container Container
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasDefinition('thelia.coupon.manager')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$couponManager = $container->getDefinition('thelia.coupon.manager');
|
||||
$services = $container->findTaggedServiceIds("thelia.coupon.addRule");
|
||||
|
||||
foreach ($services as $id => $rule) {
|
||||
$couponManager->addMethodCall(
|
||||
'addAvailableRule',
|
||||
array(
|
||||
new Reference($id)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
312
core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php
Normal file
312
core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php
Normal file
@@ -0,0 +1,312 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event\Coupon;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
use Thelia\Coupon\CouponRuleCollection;
|
||||
use Thelia\Model\Coupon;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/29/13
|
||||
* Time: 3:45 PM
|
||||
*
|
||||
* Occurring when a Coupon is created
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class CouponCreateOrUpdateEvent extends ActionEvent
|
||||
{
|
||||
/** @var CouponRuleCollection Array of CouponRuleInterface */
|
||||
protected $rules = null;
|
||||
|
||||
/** @var string Coupon code (ex: XMAS) */
|
||||
protected $code = null;
|
||||
|
||||
/** @var string Coupon title (ex: Coupon for XMAS) */
|
||||
protected $title = null;
|
||||
|
||||
/** @var string Coupon short description */
|
||||
protected $shortDescription = null;
|
||||
|
||||
/** @var string Coupon description */
|
||||
protected $description = null;
|
||||
|
||||
/** @var bool if Coupon is enabled */
|
||||
protected $isEnabled = false;
|
||||
|
||||
/** @var \DateTime Coupon expiration date */
|
||||
protected $expirationDate = null;
|
||||
|
||||
/** @var bool if Coupon is cumulative */
|
||||
protected $isCumulative = false;
|
||||
|
||||
/** @var bool if Coupon is removing postage */
|
||||
protected $isRemovingPostage = false;
|
||||
|
||||
/** @var float Amount that will be removed from the Checkout (Coupon Effect) */
|
||||
protected $amount = 0;
|
||||
|
||||
/** @var int Max time a Coupon can be used (-1 = unlimited) */
|
||||
protected $maxUsage = -1;
|
||||
|
||||
/** @var bool if Coupon is available for Products already on special offers */
|
||||
protected $isAvailableOnSpecialOffers = false;
|
||||
|
||||
/** @var Coupon Coupon model */
|
||||
protected $coupon = null;
|
||||
|
||||
/** @var string Coupon effect */
|
||||
protected $effect;
|
||||
|
||||
/** @var string Language code ISO (ex: fr_FR) */
|
||||
protected $locale = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $code Coupon Code
|
||||
* @param string $title Coupon title
|
||||
* @param float $amount Amount removed from the Total Checkout
|
||||
* @param string $effect Coupon effect
|
||||
* @param string $shortDescription Coupon short description
|
||||
* @param string $description Coupon description
|
||||
* @param boolean $isEnabled Enable/Disable
|
||||
* @param \DateTime $expirationDate Coupon expiration date
|
||||
* @param boolean $isAvailableOnSpecialOffers Is available on special offers
|
||||
* @param boolean $isCumulative Is cumulative
|
||||
* @param boolean $isRemovingPostage Is removing Postage
|
||||
* @param int $maxUsage Coupon quantity
|
||||
* @param CouponRuleCollection $rules CouponRuleInterface to add
|
||||
* @param string $locale Coupon Language code ISO (ex: fr_FR)
|
||||
*/
|
||||
function __construct(
|
||||
$code,
|
||||
$title,
|
||||
$amount,
|
||||
$effect,
|
||||
$shortDescription,
|
||||
$description,
|
||||
$isEnabled,
|
||||
\DateTime $expirationDate,
|
||||
$isAvailableOnSpecialOffers,
|
||||
$isCumulative,
|
||||
$isRemovingPostage,
|
||||
$maxUsage,
|
||||
$rules,
|
||||
$locale
|
||||
) {
|
||||
$this->amount = $amount;
|
||||
$this->code = $code;
|
||||
$this->description = $description;
|
||||
$this->expirationDate = $expirationDate;
|
||||
$this->isAvailableOnSpecialOffers = $isAvailableOnSpecialOffers;
|
||||
$this->isCumulative = $isCumulative;
|
||||
$this->isEnabled = $isEnabled;
|
||||
$this->isRemovingPostage = $isRemovingPostage;
|
||||
$this->maxUsage = $maxUsage;
|
||||
$this->rules = $rules;
|
||||
$this->shortDescription = $shortDescription;
|
||||
$this->title = $title;
|
||||
$this->effect = $effect;
|
||||
$this->locale = $locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Coupon code (ex: XMAS)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCode()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Coupon title (ex: Coupon for XMAS)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Coupon short description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getShortDescription()
|
||||
{
|
||||
return $this->shortDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Coupon description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* If Coupon is cumulative or prevent any accumulation
|
||||
* If is cumulative you can sum Coupon effects
|
||||
* If not cancel all other Coupon and take the last given
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isCumulative()
|
||||
{
|
||||
return $this->isCumulative;
|
||||
}
|
||||
|
||||
/**
|
||||
* If Coupon is removing Checkout Postage
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isRemovingPostage()
|
||||
{
|
||||
return $this->isRemovingPostage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return effects generated by the coupon
|
||||
*
|
||||
* @return float Amount removed from the Total Checkout
|
||||
*/
|
||||
public function getAmount()
|
||||
{
|
||||
return $this->amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return condition to validate the Coupon or not
|
||||
*
|
||||
* @return CouponRuleCollection
|
||||
*/
|
||||
public function getRules()
|
||||
{
|
||||
if ($this->rules === null || !is_object($this->rules)) {
|
||||
$rules = $this->rules;
|
||||
} else {
|
||||
$rules = clone $this->rules;
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Coupon expiration date
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getExpirationDate()
|
||||
{
|
||||
return clone $this->expirationDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* If Coupon is available on special offers
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAvailableOnSpecialOffers()
|
||||
{
|
||||
return $this->isAvailableOnSpecialOffers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if Coupon is enabled or not
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isEnabled()
|
||||
{
|
||||
return $this->isEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return how many time the Coupon can be used again
|
||||
* Ex : -1 unlimited
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getMaxUsage()
|
||||
{
|
||||
return $this->maxUsage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Coupon effect
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEffect()
|
||||
{
|
||||
return $this->effect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Coupon Language code ISO (ex: fr_FR)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLocale()
|
||||
{
|
||||
return $this->locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Coupon Model
|
||||
*
|
||||
* @param \Thelia\Model\Coupon $coupon Coupon Model
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setCoupon($coupon)
|
||||
{
|
||||
$this->coupon = $coupon;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Coupon Model
|
||||
*
|
||||
* @return \Thelia\Model\Coupon
|
||||
*/
|
||||
public function getCoupon()
|
||||
{
|
||||
return $this->coupon;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
103
core/lib/Thelia/Core/Event/Coupon/CouponDisableEvent.php
Normal file
103
core/lib/Thelia/Core/Event/Coupon/CouponDisableEvent.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event\Coupon;
|
||||
use Thelia\Model\Coupon;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/29/13
|
||||
* Time: 3:45 PM
|
||||
*
|
||||
* Occurring when a Coupon is disabled
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class CouponDisableEvent extends ActionEvent
|
||||
{
|
||||
/** @var int Coupon id */
|
||||
protected $couponId;
|
||||
|
||||
/** @var Coupon Coupon being disabled */
|
||||
protected $disabledCoupon;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $id Coupon Id
|
||||
*/
|
||||
public function __construct($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Coupon id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Coupon id
|
||||
*
|
||||
* @param int $id Coupon id
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Coupon being disabled
|
||||
*
|
||||
* @return Coupon
|
||||
*/
|
||||
public function getDisabledCoupon()
|
||||
{
|
||||
return $this->disabledCoupon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Coupon to be disabled
|
||||
*
|
||||
* @param Coupon $disabledCoupon Coupon to disable
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDisabledCoupon(Coupon $disabledCoupon)
|
||||
{
|
||||
$this->disabledCoupon = $disabledCoupon;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
103
core/lib/Thelia/Core/Event/Coupon/CouponEnableEvent.php
Normal file
103
core/lib/Thelia/Core/Event/Coupon/CouponEnableEvent.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event\Coupon;
|
||||
use Thelia\Model\Coupon;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/29/13
|
||||
* Time: 3:45 PM
|
||||
*
|
||||
* Occurring when a Coupon is enabled
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class CouponEnableEvent extends ActionEvent
|
||||
{
|
||||
/** @var int Coupon id */
|
||||
protected $couponId;
|
||||
|
||||
/** @var Coupon Coupon being enabled */
|
||||
protected $enabledCoupon;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $id Coupon Id
|
||||
*/
|
||||
public function __construct($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Coupon id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Coupon id
|
||||
*
|
||||
* @param int $id Coupon id
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Coupon being enabled
|
||||
*
|
||||
* @return Coupon
|
||||
*/
|
||||
public function getEnabledCoupon()
|
||||
{
|
||||
return $this->enabledCoupon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Coupon to be enabled
|
||||
*
|
||||
* @param Coupon $enabledCoupon Coupon to enabled
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setEnabledCoupon(Coupon $enabledCoupon)
|
||||
{
|
||||
$this->enabledCoupon = $enabledCoupon;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -204,6 +204,114 @@ final class TheliaEvents
|
||||
*/
|
||||
const IMAGE_CLEAR_CACHE = "action.clearImageCache";
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sent when creating a Coupon
|
||||
*/
|
||||
const COUPON_CREATE = "action.create_coupon";
|
||||
|
||||
/**
|
||||
* Sent just before a successful insert of a new Coupon in the database.
|
||||
*/
|
||||
const BEFORE_CREATE_COUPON = "action.before_create_coupon";
|
||||
|
||||
/**
|
||||
* Sent just after a successful insert of a new Coupon in the database.
|
||||
*/
|
||||
const AFTER_CREATE_COUPON = "action.after_create_coupon";
|
||||
|
||||
/**
|
||||
* Sent when editing a Coupon
|
||||
*/
|
||||
const COUPON_UPDATE = "action.update_coupon";
|
||||
|
||||
/**
|
||||
* Sent just before a successful update of a new Coupon in the database.
|
||||
*/
|
||||
const BEFORE_UPDATE_COUPON = "action.before_update_coupon";
|
||||
|
||||
/**
|
||||
* Sent just after a successful update of a new Coupon in the database.
|
||||
*/
|
||||
const AFTER_UPDATE_COUPON = "action.after_update_coupon";
|
||||
|
||||
/**
|
||||
* Sent when disabling a Coupon
|
||||
*/
|
||||
const COUPON_DISABLE = "action.disable_coupon";
|
||||
|
||||
/**
|
||||
* Sent just before a successful disable of a new Coupon in the database.
|
||||
*/
|
||||
const BEFORE_DISABLE_COUPON = "action.before_disable_coupon";
|
||||
|
||||
/**
|
||||
* Sent just after a successful disable of a new Coupon in the database.
|
||||
*/
|
||||
const AFTER_DISABLE_COUPON = "action.after_disable_coupon";
|
||||
|
||||
/**
|
||||
* Sent when enabling a Coupon
|
||||
*/
|
||||
const COUPON_ENABLE = "action.enable_coupon";
|
||||
|
||||
/**
|
||||
* Sent just before a successful enable of a new Coupon in the database.
|
||||
*/
|
||||
const BEFORE_ENABLE_COUPON = "action.before_enable_coupon";
|
||||
|
||||
/**
|
||||
* Sent just after a successful enable of a new Coupon in the database.
|
||||
*/
|
||||
const AFTER_ENABLE_COUPON = "action.after_enable_coupon";
|
||||
|
||||
/**
|
||||
* Sent when attempting to use a Coupon
|
||||
*/
|
||||
const COUPON_CONSUME = "action.consume_coupon";
|
||||
|
||||
/**
|
||||
* Sent just before an attempt to use a Coupon
|
||||
*/
|
||||
const BEFORE_CONSUME_COUPON = "action.before_consume_coupon";
|
||||
|
||||
/**
|
||||
* Sent just after an attempt to use a Coupon
|
||||
*/
|
||||
const AFTER_CONSUME_COUPON = "action.after_consume_coupon";
|
||||
|
||||
/**
|
||||
* Sent when attempting to update Coupon Rule
|
||||
*/
|
||||
const COUPON_RULE_UPDATE = "action.update_coupon_rule";
|
||||
|
||||
/**
|
||||
* Sent just before an attempt to update a Coupon Rule
|
||||
*/
|
||||
const BEFORE_COUPON_RULE_UPDATE = "action.before_update_coupon_rule";
|
||||
|
||||
/**
|
||||
* Sent just after an attempt to update a Coupon Rule
|
||||
*/
|
||||
const AFTER_COUPON_RULE_UPDATE = "action.after_update_coupon_rule";
|
||||
|
||||
/**
|
||||
* Sent when attempting to delete Coupon Rule
|
||||
*/
|
||||
const COUPON_RULE_DELETE = "action.delete_coupon_rule";
|
||||
|
||||
/**
|
||||
* Sent just before an attempt to delete a Coupon Rule
|
||||
*/
|
||||
const BEFORE_COUPON_RULE_DELETE = "action.before_delete_coupon_rule";
|
||||
|
||||
/**
|
||||
* Sent just after an attempt to delete a Coupon Rule
|
||||
*/
|
||||
const AFTER_COUPON_RULE_DELETE = "action.after_delete_coupon_rule";
|
||||
|
||||
|
||||
// -- Configuration management ---------------------------------------------
|
||||
|
||||
const CONFIG_CREATE = "action.createConfig";
|
||||
|
||||
@@ -28,6 +28,7 @@ use Thelia\Core\Security\User\UserInterface;
|
||||
use Thelia\Exception\InvalidCartException;
|
||||
use Thelia\Model\CartQuery;
|
||||
use Thelia\Model\Cart;
|
||||
use Thelia\Model\Currency;
|
||||
use Thelia\Tools\URL;
|
||||
use Thelia\Model\Lang;
|
||||
|
||||
@@ -44,9 +45,9 @@ class Session extends BaseSession
|
||||
/**
|
||||
* @return \Thelia\Model\Lang|null
|
||||
*/
|
||||
public function getLang()
|
||||
public function getLang($forceDefault = true)
|
||||
{
|
||||
return $this->get("thelia.current.lang", Lang::getDefaultLanguage());
|
||||
return $this->get("thelia.current.lang", $forceDefault ? Lang::getDefaultLanguage():null);
|
||||
}
|
||||
|
||||
public function setLang(Lang $lang)
|
||||
@@ -68,6 +69,16 @@ class Session extends BaseSession
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setCurrency(Currency $currency)
|
||||
{
|
||||
$this->set("thelia.current.currency", $currency);
|
||||
}
|
||||
|
||||
public function getCurrency($forceDefault = true)
|
||||
{
|
||||
return $this->get("thelia.current.currency", $forceDefault ? Currency::getDefaultCurrency():null);
|
||||
}
|
||||
|
||||
// -- Customer user --------------------------------------------------------
|
||||
|
||||
public function setCustomerUser(UserInterface $user)
|
||||
|
||||
@@ -59,11 +59,12 @@ abstract class BaseI18nLoop extends BaseLoop
|
||||
* @param array $columns the i18n columns
|
||||
* @param string $foreignTable the specified table (default to criteria table)
|
||||
* @param string $foreignKey the foreign key in this table (default to criteria table)
|
||||
* @param bool $forceReturn
|
||||
*
|
||||
* @return mixed the locale
|
||||
*/
|
||||
protected function configureI18nProcessing(ModelCriteria $search, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID', $forceReturn = false) {
|
||||
|
||||
protected function configureI18nProcessing(ModelCriteria $search, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID', $forceReturn = false)
|
||||
{
|
||||
/* manage translations */
|
||||
return ModelCriteriaTools::getI18n(
|
||||
$this->getBackend_context(),
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
namespace Thelia\Core\Template\Element;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
@@ -52,6 +53,9 @@ abstract class BaseLoop
|
||||
*/
|
||||
protected $securityContext;
|
||||
|
||||
/** @var ContainerInterface Service Container */
|
||||
protected $container = null;
|
||||
|
||||
protected $args;
|
||||
|
||||
public $countable = true;
|
||||
@@ -61,15 +65,15 @@ abstract class BaseLoop
|
||||
/**
|
||||
* Create a new Loop
|
||||
*
|
||||
* @param Request $request
|
||||
* @param EventDispatcherInterface $dispatcher
|
||||
* @param SecurityContext $securityContext
|
||||
* @param ContainerInterface $container
|
||||
*/
|
||||
public function __construct(Request $request, EventDispatcherInterface $dispatcher, SecurityContext $securityContext)
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->securityContext = $securityContext;
|
||||
$this->container = $container;
|
||||
|
||||
$this->request = $container->get('request');
|
||||
$this->dispatcher = $container->get('event_dispatcher');
|
||||
$this->securityContext = $container->get('thelia.securityContext');
|
||||
|
||||
$this->args = $this->getArgDefinitions()->addArguments($this->getDefaultArgs(), false);
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ class Address extends BaseLoop
|
||||
$customer = $this->getCustomer();
|
||||
|
||||
if ($customer === 'current') {
|
||||
$currentCustomer = $this->request->getSession()->getCustomerUser();
|
||||
$currentCustomer = $this->securityContext->getCustomerUser();
|
||||
if ($currentCustomer === null) {
|
||||
return new LoopResult();
|
||||
} else {
|
||||
|
||||
130
core/lib/Thelia/Core/Template/Loop/Coupon.php
Executable file
130
core/lib/Thelia/Core/Template/Loop/Coupon.php
Executable file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Template\Loop;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Thelia\Constraint\ConstraintFactory;
|
||||
use Thelia\Constraint\Rule\CouponRuleInterface;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\Template\Element\BaseI18nLoop;
|
||||
use Thelia\Core\Template\Element\LoopResult;
|
||||
use Thelia\Core\Template\Element\LoopResultRow;
|
||||
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
|
||||
use Thelia\Model\Base\CategoryQuery;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Model\CouponQuery;
|
||||
use Thelia\Model\Coupon as MCoupon;
|
||||
use Thelia\Model\Map\ProductCategoryTableMap;
|
||||
use Thelia\Type;
|
||||
use Thelia\Type\BooleanOrBothType;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Coupon Loop
|
||||
*
|
||||
* @package Thelia\Core\Template\Loop
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class Coupon extends BaseI18nLoop
|
||||
{
|
||||
/**
|
||||
* @return ArgumentCollection
|
||||
*/
|
||||
protected function getArgDefinitions()
|
||||
{
|
||||
return new ArgumentCollection(
|
||||
Argument::createIntListTypeArgument('id')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $pagination
|
||||
*
|
||||
* @return \Thelia\Core\Template\Element\LoopResult
|
||||
*/
|
||||
public function exec(&$pagination)
|
||||
{
|
||||
$search = CouponQuery::create();
|
||||
|
||||
/* manage translations */
|
||||
$locale = $this->configureI18nProcessing($search, array('TITLE', 'DESCRIPTION', 'SHORT_DESCRIPTION'));
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
if (null !== $id) {
|
||||
$search->filterById($id, Criteria::IN);
|
||||
}
|
||||
|
||||
// Perform search
|
||||
$coupons = $this->search($search, $pagination);
|
||||
|
||||
$loopResult = new LoopResult();
|
||||
/** @var ConstraintFactory $constraintFactory */
|
||||
$constraintFactory = $this->container->get('thelia.constraint.factory');
|
||||
|
||||
/** @var Request $request */
|
||||
$request = $this->container->get('request');
|
||||
/** @var Lang $lang */
|
||||
$lang = $request->getSession()->getLang();
|
||||
|
||||
|
||||
/** @var MCoupon $coupon */
|
||||
foreach ($coupons as $coupon) {
|
||||
$loopResultRow = new LoopResultRow();
|
||||
$rules = $constraintFactory->unserializeCouponRuleCollection(
|
||||
$coupon->getSerializedRules()
|
||||
);
|
||||
|
||||
$cleanedRules = array();
|
||||
/** @var CouponRuleInterface $rule */
|
||||
foreach ($rules->getRules() as $key => $rule) {
|
||||
$cleanedRules[] = $rule->getToolTip();
|
||||
}
|
||||
$loopResultRow->set("ID", $coupon->getId())
|
||||
->set("IS_TRANSLATED", $coupon->getVirtualColumn('IS_TRANSLATED'))
|
||||
->set("LOCALE", $locale)
|
||||
->set("CODE", $coupon->getCode())
|
||||
->set("TITLE", $coupon->getVirtualColumn('i18n_TITLE'))
|
||||
->set("SHORT_DESCRIPTION", $coupon->getVirtualColumn('i18n_SHORT_DESCRIPTION'))
|
||||
->set("DESCRIPTION", $coupon->getVirtualColumn('i18n_DESCRIPTION'))
|
||||
->set("EXPIRATION_DATE", $coupon->getExpirationDate($lang->getDateFormat()))
|
||||
->set("USAGE_LEFT", $coupon->getMaxUsage())
|
||||
->set("IS_CUMULATIVE", $coupon->getIsCumulative())
|
||||
->set("IS_REMOVING_POSTAGE", $coupon->getIsRemovingPostage())
|
||||
->set("IS_ENABLED", $coupon->getIsEnabled())
|
||||
->set("AMOUNT", $coupon->getAmount())
|
||||
->set("APPLICATION_CONDITIONS", $cleanedRules);
|
||||
$loopResult->addRow($loopResultRow);
|
||||
}
|
||||
|
||||
return $loopResult;
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,7 @@ class Customer extends BaseLoop
|
||||
)
|
||||
),
|
||||
Argument::createBooleanTypeArgument('reseller'),
|
||||
Argument::createBooleanTypeArgument('last_order'),
|
||||
Argument::createIntTypeArgument('sponsor')
|
||||
);
|
||||
}
|
||||
@@ -80,7 +81,7 @@ class Customer extends BaseLoop
|
||||
$current = $this->getCurrent();
|
||||
|
||||
if ($current === true) {
|
||||
$currentCustomer = $this->request->getSession()->getCustomerUser();
|
||||
$currentCustomer = $this->securityContext->getCustomerUser();
|
||||
if ($currentCustomer === null) {
|
||||
return new LoopResult();
|
||||
} else {
|
||||
@@ -130,6 +131,20 @@ class Customer extends BaseLoop
|
||||
$loopResultRow->set("SPONSOR", $customer->getSponsor());
|
||||
$loopResultRow->set("DISCOUNT", $customer->getDiscount());
|
||||
|
||||
$lastOrderDate = "";
|
||||
$lastOrderAmount = "";
|
||||
|
||||
if ($this->getLastOrder()) {
|
||||
$order = $customer->getOrders()->getFirst();
|
||||
if ($order) {
|
||||
$lastOrderDate = $order->getCreatedAt();
|
||||
$lastOrderAmount = $order->getTotalAmount();
|
||||
}
|
||||
}
|
||||
|
||||
$loopResultRow->set("LASTORDER_DATE", $lastOrderDate);
|
||||
$loopResultRow->set("LASTORDER_AMOUNT", $lastOrderAmount);
|
||||
|
||||
$loopResult->addRow($loopResultRow);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
use Thelia\Model\CategoryQuery;
|
||||
use Thelia\Model\CountryQuery;
|
||||
use Thelia\Model\Map\FeatureProductTableMap;
|
||||
use Thelia\Model\Map\ProductPriceTableMap;
|
||||
use Thelia\Model\Map\ProductSaleElementsTableMap;
|
||||
@@ -333,10 +334,10 @@ class Product extends BaseI18nLoop
|
||||
foreach($isProductPriceLeftJoinList as $pSE => $isProductPriceLeftJoin) {
|
||||
$booleanMatchedPriceList[] = 'CASE WHEN `' . $pSE . '`.PROMO=1 THEN `' . $isProductPriceLeftJoin . '`.PROMO_PRICE ELSE `' . $isProductPriceLeftJoin . '`.PRICE END';
|
||||
}
|
||||
$search->withColumn('MAX(' . implode(' OR ', $booleanMatchedPromoList) . ')', 'main_product_is_promo');
|
||||
$search->withColumn('MAX(' . implode(' OR ', $booleanMatchedNewnessList) . ')', 'main_product_is_new');
|
||||
$search->withColumn('MAX(' . implode(' OR ', $booleanMatchedPriceList) . ')', 'real_highest_price');
|
||||
$search->withColumn('MIN(' . implode(' OR ', $booleanMatchedPriceList) . ')', 'real_lowest_price');
|
||||
$search->withColumn('ROUND(MAX(' . implode(' OR ', $booleanMatchedPromoList) . '), 2)', 'main_product_is_promo');
|
||||
$search->withColumn('ROUND(MAX(' . implode(' OR ', $booleanMatchedNewnessList) . '), 2)', 'main_product_is_new');
|
||||
$search->withColumn('ROUND(MAX(' . implode(' OR ', $booleanMatchedPriceList) . '), 2)', 'real_highest_price');
|
||||
$search->withColumn('ROUND(MIN(' . implode(' OR ', $booleanMatchedPriceList) . '), 2)', 'real_lowest_price');
|
||||
|
||||
|
||||
$current = $this->getCurrent();
|
||||
@@ -509,6 +510,12 @@ class Product extends BaseI18nLoop
|
||||
foreach ($products as $product) {
|
||||
$loopResultRow = new LoopResultRow($loopResult, $product, $this->versionable, $this->timestampable, $this->countable);
|
||||
|
||||
$price = $product->getRealLowestPrice();
|
||||
$taxedPrice = $product->getTaxedPrice(
|
||||
CountryQuery::create()->findOneById(64) // @TODO : make it magic
|
||||
);
|
||||
|
||||
|
||||
$loopResultRow->set("ID", $product->getId())
|
||||
->set("REF",$product->getRef())
|
||||
->set("IS_TRANSLATED",$product->getVirtualColumn('IS_TRANSLATED'))
|
||||
@@ -518,7 +525,9 @@ class Product extends BaseI18nLoop
|
||||
->set("DESCRIPTION", $product->getVirtualColumn('i18n_DESCRIPTION'))
|
||||
->set("POSTSCRIPTUM", $product->getVirtualColumn('i18n_POSTSCRIPTUM'))
|
||||
->set("URL", $product->getUrl($locale))
|
||||
->set("BEST_PRICE", $product->getVirtualColumn('real_lowest_price'))
|
||||
->set("BEST_PRICE", $price)
|
||||
->set("BEST_PRICE_TAX", $taxedPrice - $price)
|
||||
->set("BEST_TAXED_PRICE", $taxedPrice)
|
||||
->set("IS_PROMO", $product->getVirtualColumn('main_product_is_promo'))
|
||||
->set("IS_NEW", $product->getVirtualColumn('main_product_is_new'))
|
||||
->set("POSITION", $product->getPosition())
|
||||
|
||||
@@ -35,6 +35,7 @@ use Thelia\Log\Tlog;
|
||||
|
||||
use Thelia\Model\Base\ProductSaleElementsQuery;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Model\CountryQuery;
|
||||
use Thelia\Type\TypeCollection;
|
||||
use Thelia\Type;
|
||||
|
||||
@@ -124,6 +125,15 @@ class ProductSaleElements extends BaseLoop
|
||||
foreach ($PSEValues as $PSEValue) {
|
||||
$loopResultRow = new LoopResultRow($loopResult, $PSEValue, $this->versionable, $this->timestampable, $this->countable);
|
||||
|
||||
$price = $PSEValue->getPrice();
|
||||
$taxedPrice = $PSEValue->getTaxedPrice(
|
||||
CountryQuery::create()->findOneById(64) // @TODO : make it magic
|
||||
);
|
||||
$promoPrice = $PSEValue->getPromoPrice();
|
||||
$taxedPromoPrice = $PSEValue->getTaxedPromoPrice(
|
||||
CountryQuery::create()->findOneById(64) // @TODO : make it magic
|
||||
);
|
||||
|
||||
$loopResultRow->set("ID", $PSEValue->getId())
|
||||
->set("QUANTITY", $PSEValue->getQuantity())
|
||||
->set("IS_PROMO", $PSEValue->getPromo() === 1 ? 1 : 0)
|
||||
@@ -131,8 +141,12 @@ class ProductSaleElements extends BaseLoop
|
||||
->set("WEIGHT", $PSEValue->getWeight())
|
||||
|
||||
->set("CURRENCY", $PSEValue->getVirtualColumn('price_CURRENCY_ID'))
|
||||
->set("PRICE", $PSEValue->getVirtualColumn('price_PRICE'))
|
||||
->set("PROMO_PRICE", $PSEValue->getVirtualColumn('price_PROMO_PRICE'));
|
||||
->set("PRICE", $price)
|
||||
->set("PRICE_TAX", $taxedPrice - $price)
|
||||
->set("TAXED_PRICE", $taxedPrice)
|
||||
->set("PROMO_PRICE", $promoPrice)
|
||||
->set("PROMO_PRICE_TAX", $taxedPromoPrice - $promoPrice)
|
||||
->set("TAXED_PROMO_PRICE", $taxedPromoPrice);
|
||||
|
||||
$loopResult->addRow($loopResultRow);
|
||||
}
|
||||
@@ -31,6 +31,7 @@ use Thelia\Core\Template\ParserContext;
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
||||
use Thelia\Model\CategoryQuery;
|
||||
use Thelia\Model\ContentQuery;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Model\FolderQuery;
|
||||
use Thelia\Model\Product;
|
||||
use Thelia\Model\ProductQuery;
|
||||
@@ -132,6 +133,35 @@ class DataAccessFunctions extends AbstractSmartyPlugin
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* currency global data
|
||||
*
|
||||
* @param $params
|
||||
* @param $smarty
|
||||
*/
|
||||
public function currencyDataAccess($params, $smarty)
|
||||
{
|
||||
$currency = $this->request->getSession()->getCurrency();
|
||||
|
||||
if ($currency) {
|
||||
$currencyQuery = CurrencyQuery::create()
|
||||
->filterById($currency->getId());
|
||||
|
||||
return $this->dataAccessWithI18n("Currency", $params, $currencyQuery, array("NAME"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lang global data
|
||||
*
|
||||
* @param $params
|
||||
* @param $smarty
|
||||
*/
|
||||
public function langDataAccess($params, $smarty)
|
||||
{
|
||||
return $this->dataAccess("Lang", $params, $this->request->getSession()->getLang());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $objectLabel
|
||||
* @param $params
|
||||
@@ -231,6 +261,8 @@ class DataAccessFunctions extends AbstractSmartyPlugin
|
||||
new SmartyPluginDescriptor('function', 'category', $this, 'categoryDataAccess'),
|
||||
new SmartyPluginDescriptor('function', 'content', $this, 'contentDataAccess'),
|
||||
new SmartyPluginDescriptor('function', 'folder', $this, 'folderDataAccess'),
|
||||
new SmartyPluginDescriptor('function', 'currency', $this, 'currencyDataAccess'),
|
||||
new SmartyPluginDescriptor('function', 'lang', $this, 'langDataAccess'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,8 +120,15 @@ class Form extends AbstractSmartyPlugin
|
||||
$formFieldView = $this->getFormFieldView($params);
|
||||
|
||||
$template->assign("options", $formFieldView->vars);
|
||||
|
||||
$template->assign("name", $formFieldView->vars["full_name"]);
|
||||
$template->assign("value", $formFieldView->vars["value"]);
|
||||
|
||||
// If Checkbox input type
|
||||
if ($formFieldView->vars['checked'] !== null) {
|
||||
$this->renderFormFieldCheckBox($template, $formFieldView);
|
||||
}
|
||||
|
||||
$template->assign("label", $formFieldView->vars["label"]);
|
||||
$template->assign("label_attr", $formFieldView->vars["label_attr"]);
|
||||
|
||||
@@ -266,4 +273,17 @@ class Form extends AbstractSmartyPlugin
|
||||
new SmartyPluginDescriptor("block", "form_error", $this, "formError")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Smarty_Internal_Template $template
|
||||
* @param $formFieldView
|
||||
*/
|
||||
public function renderFormFieldCheckBox(\Smarty_Internal_Template $template, $formFieldView)
|
||||
{
|
||||
$template->assign("value", 0);
|
||||
if ($formFieldView->vars['checked']) {
|
||||
$template->assign("value", 1);
|
||||
}
|
||||
$template->assign("value", $formFieldView->vars['checked']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,9 +113,15 @@ class Format extends AbstractSmartyPlugin
|
||||
throw new SmartyPluginException("number is a mandatory parameter in format_number function");
|
||||
}
|
||||
|
||||
$number = $params["number"];
|
||||
|
||||
if(empty($number)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
$lang = $this->request->getSession()->getLang();
|
||||
|
||||
$number = $params["number"];
|
||||
|
||||
$decimals = array_key_exists("decimals", $params) ? $params["decimals"] : $lang->getDecimals();
|
||||
$decPoint = array_key_exists("dec_point", $params) ? $params["dec_point"] : $lang->getDecimalSeparator();
|
||||
$thousandsSep = array_key_exists("thousands_sep", $params) ? $params["thousands_sep"] : $lang->getThousandsSeparator();
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
namespace Thelia\Core\Template\Smarty\Plugins;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Thelia\Core\Template\Element\BaseLoop;
|
||||
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
||||
@@ -44,14 +45,22 @@ class TheliaLoop extends AbstractSmartyPlugin
|
||||
protected $dispatcher;
|
||||
protected $securityContext;
|
||||
|
||||
/** @var ContainerInterface Service Container */
|
||||
protected $container = null;
|
||||
|
||||
protected $loopstack = array();
|
||||
protected $varstack = array();
|
||||
|
||||
public function __construct(Request $request, EventDispatcherInterface $dispatcher, SecurityContext $securityContext)
|
||||
/**
|
||||
* @param ContainerInterface $container
|
||||
*/
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->securityContext = $securityContext;
|
||||
$this->container = $container;
|
||||
|
||||
$this->request = $container->get('request');
|
||||
$this->dispatcher = $container->get('event_dispatcher');
|
||||
$this->securityContext = $container->get('thelia.securityContext');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -315,9 +324,7 @@ class TheliaLoop extends AbstractSmartyPlugin
|
||||
}
|
||||
|
||||
$loop = $class->newInstance(
|
||||
$this->request,
|
||||
$this->dispatcher,
|
||||
$this->securityContext
|
||||
$this->container
|
||||
);
|
||||
|
||||
$loop->initializeArgs($smartyParams);
|
||||
|
||||
@@ -65,9 +65,7 @@ class SmartyParser extends Smarty implements ParserInterface
|
||||
$this->setTemplate($template ?: ConfigQuery::read('active-template', 'default'));
|
||||
|
||||
$this->debugging = $debug;
|
||||
|
||||
$this->escape_html = true;
|
||||
|
||||
|
||||
// Prevent smarty ErrorException: Notice: Undefined index bla bla bla...
|
||||
$this->error_reporting = E_ALL ^ E_NOTICE;
|
||||
|
||||
@@ -86,12 +84,13 @@ class SmartyParser extends Smarty implements ParserInterface
|
||||
|
||||
$this->registerFilter('pre', array($this, "preThelia"));
|
||||
$this->registerFilter('output', array($this, "removeBlankLines"));
|
||||
$this->registerFilter('variable', array(__CLASS__, "theliaEscape"));
|
||||
}
|
||||
|
||||
public function preThelia($tpl_source, \Smarty_Internal_Template $template)
|
||||
{
|
||||
$new_source = preg_replace('`{#([a-zA-Z][a-zA-Z0-9\-_]*)(.*)}`', '{\$$1$2}', $tpl_source);
|
||||
$new_source = preg_replace('`#([a-zA-Z][a-zA-Z0-9\-_]*)`', '{\$$1|dieseCanceller:\'#$1\'}', $new_source);
|
||||
$new_source = preg_replace('`{#([a-zA-Z][a-zA-Z0-9_]*)(.*)}`', '{\$$1$2}', $tpl_source);
|
||||
$new_source = preg_replace('`#([a-zA-Z][a-zA-Z0-9_]*)`', '{\$$1|dieseCanceller:\'#$1\'}', $new_source);
|
||||
|
||||
return $new_source;
|
||||
}
|
||||
@@ -101,6 +100,15 @@ class SmartyParser extends Smarty implements ParserInterface
|
||||
return preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $tpl_source);
|
||||
}
|
||||
|
||||
public static function theliaEscape($content, $smarty)
|
||||
{
|
||||
if(is_scalar($content)) {
|
||||
return htmlspecialchars($content ,ENT_QUOTES, Smarty::$_CHARSET);
|
||||
} else {
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
|
||||
public function setTemplate($template_path_from_template_base)
|
||||
{
|
||||
$this->template = $template_path_from_template_base;
|
||||
|
||||
@@ -135,9 +135,26 @@ class TheliaHttpKernel extends HttpKernel
|
||||
if ($lang) {
|
||||
$request->getSession()
|
||||
->setLang($lang)
|
||||
->setLocale($lang->getLocale())
|
||||
;
|
||||
}
|
||||
|
||||
$request->getSession()->setCurrency($this->defineCurrency($request));
|
||||
}
|
||||
|
||||
protected function defineCurrency(Request $request)
|
||||
{
|
||||
$currency = null;
|
||||
if ($request->query->has("currency")) {
|
||||
$currency = Model\CurrencyQuery::create()->findOneByCode($request->query->get("currency"));
|
||||
} else {
|
||||
$currency = $request->getSession()->getCurrency(false);
|
||||
}
|
||||
|
||||
if(null === $currency) {
|
||||
$currency = Model\Currency::getDefaultCurrency();
|
||||
}
|
||||
|
||||
return $currency;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,7 +170,7 @@ class TheliaHttpKernel extends HttpKernel
|
||||
$lang = Model\LangQuery::create()->findOneByCode($request->query->get("lang"));
|
||||
|
||||
if (is_null($lang)) {
|
||||
return;
|
||||
return Model\Lang::getDefaultLanguage();
|
||||
}
|
||||
|
||||
//if each lang had is own domain, we redirect the user to the good one.
|
||||
@@ -175,7 +192,7 @@ class TheliaHttpKernel extends HttpKernel
|
||||
}
|
||||
|
||||
//check if lang is not defined. If not we have to search the good one.
|
||||
if (null === $request->getSession()->getLang()) {
|
||||
if (null === $request->getSession()->getLang(false)) {
|
||||
|
||||
if (Model\ConfigQuery::read("one_domain_foreach_lang", false) == 1) {
|
||||
//find lang with domain
|
||||
@@ -183,7 +200,7 @@ class TheliaHttpKernel extends HttpKernel
|
||||
}
|
||||
|
||||
//find default lang
|
||||
return Model\LangQuery::create()->findOneByByDefault(1);
|
||||
return Model\Lang::getDefaultLanguage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ class Translator extends BaseTranslator
|
||||
* Return this class instance, only once instanciated.
|
||||
*
|
||||
* @throws \RuntimeException if the class has not been instanciated.
|
||||
* @return Thelia\Core\Translation\Translator the instance.
|
||||
* @return \Thelia\Core\Translation\Translator the instance.
|
||||
*/
|
||||
public static function getInstance() {
|
||||
if (self::$instance == null) throw new \RuntimeException("Translator instance is not initialized.");
|
||||
|
||||
158
core/lib/Thelia/Coupon/CouponAdapterInterface.php
Normal file
158
core/lib/Thelia/Coupon/CouponAdapterInterface.php
Normal file
@@ -0,0 +1,158 @@
|
||||
<?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\Coupon;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Translation\Translator;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Thelia\Coupon\Type\CouponInterface;
|
||||
use Thelia\Model\Coupon;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Allow a CouponManager class to be fed with relevant Thelia data
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
interface CouponAdapterInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param ContainerInterface $container Service container
|
||||
*/
|
||||
function __construct(ContainerInterface $container);
|
||||
|
||||
/**
|
||||
* Return a Cart a CouponManager can process
|
||||
*
|
||||
* @return \Thelia\Model\Cart
|
||||
*/
|
||||
public function getCart();
|
||||
|
||||
/**
|
||||
* Return an Address a CouponManager can process
|
||||
*
|
||||
* @return \Thelia\Model\Address
|
||||
*/
|
||||
public function getDeliveryAddress();
|
||||
|
||||
/**
|
||||
* Return an Customer a CouponManager can process
|
||||
*
|
||||
* @return \Thelia\Model\Customer
|
||||
*/
|
||||
public function getCustomer();
|
||||
|
||||
/**
|
||||
* Return Checkout total price
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getCheckoutTotalPrice();
|
||||
|
||||
/**
|
||||
* Return Products total price
|
||||
* CartTotalPrice = Checkout total - discount - postage
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getCartTotalPrice();
|
||||
|
||||
/**
|
||||
* Return the Checkout currency EUR|USD
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCheckoutCurrency();
|
||||
|
||||
/**
|
||||
* Return Checkout total postage (only) price
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getCheckoutPostagePrice();
|
||||
|
||||
/**
|
||||
* Return the number of Products in the Cart
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getNbArticlesInCart();
|
||||
|
||||
/**
|
||||
* Return all Coupon given during the Checkout
|
||||
*
|
||||
* @return array Array of CouponInterface
|
||||
*/
|
||||
public function getCurrentCoupons();
|
||||
|
||||
/**
|
||||
* Find one Coupon in the database from its code
|
||||
*
|
||||
* @param string $code Coupon code
|
||||
*
|
||||
* @return Coupon
|
||||
*/
|
||||
public function findOneCouponByCode($code);
|
||||
|
||||
/**
|
||||
* Save a Coupon in the database
|
||||
*
|
||||
* @param CouponInterface $coupon Coupon
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function saveCoupon(CouponInterface $coupon);
|
||||
|
||||
/**
|
||||
* Return platform Container
|
||||
*
|
||||
* @return Container
|
||||
*/
|
||||
public function getContainer();
|
||||
|
||||
/**
|
||||
* Return platform TranslatorInterface
|
||||
*
|
||||
* @return TranslatorInterface
|
||||
*/
|
||||
public function getTranslator();
|
||||
|
||||
/**
|
||||
* Return the main currency
|
||||
* THe one used to set prices in BackOffice
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMainCurrency();
|
||||
|
||||
}
|
||||
235
core/lib/Thelia/Coupon/CouponBaseAdapter.php
Normal file
235
core/lib/Thelia/Coupon/CouponBaseAdapter.php
Normal file
@@ -0,0 +1,235 @@
|
||||
<?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\Coupon;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Translation\Translator;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Thelia\Coupon\Type\CouponInterface;
|
||||
use Thelia\Model\Coupon;
|
||||
use Thelia\Model\CouponQuery;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
* @todo implements
|
||||
*
|
||||
*/
|
||||
class CouponBaseAdapter implements CouponAdapterInterface
|
||||
{
|
||||
/** @var ContainerInterface Service Container */
|
||||
protected $container = null;
|
||||
|
||||
/** @var Translator Service Translator */
|
||||
protected $translator = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param ContainerInterface $container Service container
|
||||
*/
|
||||
function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a Cart a CouponManager can process
|
||||
*
|
||||
* @return \Thelia\Model\Cart
|
||||
*/
|
||||
public function getCart()
|
||||
{
|
||||
// TODO: Implement getCart() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an Address a CouponManager can process
|
||||
*
|
||||
* @return \Thelia\Model\Address
|
||||
*/
|
||||
public function getDeliveryAddress()
|
||||
{
|
||||
// TODO: Implement getDeliveryAddress() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an Customer a CouponManager can process
|
||||
*
|
||||
* @return \Thelia\Model\Customer
|
||||
*/
|
||||
public function getCustomer()
|
||||
{
|
||||
// TODO: Implement getCustomer() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Checkout total price
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getCheckoutTotalPrice()
|
||||
{
|
||||
// TODO: Implement getCheckoutTotalPrice() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Checkout total postage (only) price
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getCheckoutPostagePrice()
|
||||
{
|
||||
// TODO: Implement getCheckoutPostagePrice() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Products total price
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getCartTotalPrice()
|
||||
{
|
||||
// TODO: Implement getCartTotalPrice() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Checkout currency EUR|USD
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCheckoutCurrency()
|
||||
{
|
||||
// TODO: Implement getCheckoutCurrency() method.
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the number of Products in the Cart
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getNbArticlesInCart()
|
||||
{
|
||||
// TODO: Implement getNbArticlesInCart() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all Coupon given during the Checkout
|
||||
*
|
||||
* @return array Array of CouponInterface
|
||||
*/
|
||||
public function getCurrentCoupons()
|
||||
{
|
||||
$couponFactory = $this->container->get('thelia.coupon.factory');
|
||||
|
||||
// @todo Get from Session
|
||||
$couponCodes = array('XMAS', 'SPRINGBREAK');
|
||||
|
||||
$coupons = array();
|
||||
foreach ($couponCodes as $couponCode) {
|
||||
$coupons[] = $couponFactory->buildCouponFromCode($couponCode);
|
||||
}
|
||||
|
||||
return $coupons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find one Coupon in the database from its code
|
||||
*
|
||||
* @param string $code Coupon code
|
||||
*
|
||||
* @return Coupon
|
||||
*/
|
||||
public function findOneCouponByCode($code)
|
||||
{
|
||||
$couponQuery = CouponQuery::create();
|
||||
|
||||
return $couponQuery->findOneByCode($code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a Coupon in the database
|
||||
*
|
||||
* @param CouponInterface $coupon Coupon
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function saveCoupon(CouponInterface $coupon)
|
||||
{
|
||||
// $couponModel = new Coupon();
|
||||
// $couponModel->setCode($coupon->getCode());
|
||||
// $couponModel->setType(get_class($coupon));
|
||||
// $couponModel->setTitle($coupon->getTitle());
|
||||
// $couponModel->setShortDescription($coupon->getShortDescription());
|
||||
// $couponModel->setDescription($coupon->getDescription());
|
||||
// $couponModel->setAmount($coupon->getDiscount());
|
||||
// $couponModel->setIsUsed(0);
|
||||
// $couponModel->setIsEnabled(1);
|
||||
// $couponModel->set
|
||||
// $couponModel->set
|
||||
// $couponModel->set
|
||||
// $couponModel->set
|
||||
// $couponModel->set
|
||||
// $couponModel->set
|
||||
// $couponModel->set
|
||||
}
|
||||
|
||||
/**
|
||||
* Return plateform Container
|
||||
*
|
||||
* @return Container
|
||||
*/
|
||||
public function getContainer()
|
||||
{
|
||||
// TODO: Implement getContainer() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Return platform TranslatorInterface
|
||||
*
|
||||
* @return TranslatorInterface
|
||||
*/
|
||||
public function getTranslator()
|
||||
{
|
||||
return $this->container->get('thelia.translator');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the main currency
|
||||
* THe one used to set prices in BackOffice
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMainCurrency()
|
||||
{
|
||||
// TODO: Implement getMainCurrency() method.
|
||||
}
|
||||
}
|
||||
146
core/lib/Thelia/Coupon/CouponFactory.php
Normal file
146
core/lib/Thelia/Coupon/CouponFactory.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?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\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;
|
||||
use Thelia\Exception\InvalidRuleException;
|
||||
use Thelia\Model\Coupon;
|
||||
use Symfony\Component\Serializer\Encoder\JsonEncoder;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Generate a CouponInterface
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class CouponFactory
|
||||
{
|
||||
/** @var ContainerInterface Service Container */
|
||||
protected $container = null;
|
||||
|
||||
/** @var CouponAdapterInterface Provide necessary value from Thelia*/
|
||||
protected $adapter;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param ContainerInterface $container Service container
|
||||
*/
|
||||
function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->adapter = $container->get('thelia.adapter');
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a CouponInterface from its database data
|
||||
*
|
||||
* @param string $couponCode Coupon code ex: XMAS
|
||||
*
|
||||
* @throws \Thelia\Exception\CouponExpiredException
|
||||
* @throws \Symfony\Component\Translation\Exception\NotFoundResourceException
|
||||
* @return CouponInterface ready to be processed
|
||||
*/
|
||||
public function buildCouponFromCode($couponCode)
|
||||
{
|
||||
/** @var Coupon $couponModel */
|
||||
$couponModel = $this->adapter->findOneCouponByCode($couponCode);
|
||||
if ($couponModel === null) {
|
||||
throw new NotFoundResourceException(
|
||||
'Coupon ' . $couponCode . ' not found in Database'
|
||||
);
|
||||
}
|
||||
|
||||
if ($couponModel->getExpirationDate() < new \DateTime()) {
|
||||
throw new CouponExpiredException($couponCode);
|
||||
}
|
||||
|
||||
/** @var CouponInterface $couponInterface */
|
||||
$couponInterface = $this->buildCouponInterfacFromModel($couponModel);
|
||||
if ($couponInterface->getRules()->isEmpty()) {
|
||||
throw new InvalidRuleException(
|
||||
get_class($couponInterface)
|
||||
);
|
||||
}
|
||||
|
||||
return $couponInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a CouponInterface from its Model data contained in the DataBase
|
||||
*
|
||||
* @param Coupon $model Database data
|
||||
*
|
||||
* @return CouponInterface ready to use CouponInterface object instance
|
||||
*/
|
||||
protected function buildCouponInterfacFromModel(Coupon $model)
|
||||
{
|
||||
$isCumulative = ($model->getIsCumulative() == 1 ? true : false);
|
||||
$isRemovingPostage = ($model->getIsRemovingPostage() == 1 ? true : false);
|
||||
|
||||
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(),
|
||||
$model->getDescription(),
|
||||
$model->getAmount(),
|
||||
$isCumulative,
|
||||
$isRemovingPostage,
|
||||
$model->getIsAvailableOnSpecialOffers(),
|
||||
$model->getIsEnabled(),
|
||||
$model->getMaxUsage(),
|
||||
$model->getExpirationDate()
|
||||
);
|
||||
|
||||
/** @var ConstraintFactory $constraintFactory */
|
||||
$constraintFactory = $this->container->get('thelia.constraint.factory');
|
||||
$rules = $constraintFactory->unserializeCouponRuleCollection(
|
||||
$model->getSerializedRules()
|
||||
);
|
||||
|
||||
$couponManager->setRules($rules);
|
||||
|
||||
return $couponManager;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
257
core/lib/Thelia/Coupon/CouponManager.php
Normal file
257
core/lib/Thelia/Coupon/CouponManager.php
Normal file
@@ -0,0 +1,257 @@
|
||||
<?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\Coupon;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Thelia\Constraint\Rule\CouponRuleInterface;
|
||||
use Thelia\Coupon\Type\CouponInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Manage how Coupons could interact with a Checkout
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class CouponManager
|
||||
{
|
||||
/** @var CouponAdapterInterface Provides necessary value from Thelia */
|
||||
protected $adapter = null;
|
||||
|
||||
/** @var ContainerInterface Service Container */
|
||||
protected $container = null;
|
||||
|
||||
/** @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
|
||||
*
|
||||
* @param ContainerInterface $container Service container
|
||||
*/
|
||||
function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->adapter = $container->get('thelia.adapter');
|
||||
$this->coupons = $this->adapter->getCurrentCoupons();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Discount for the given Coupons
|
||||
*
|
||||
* @api
|
||||
* @return float checkout discount
|
||||
*/
|
||||
public function getDiscount()
|
||||
{
|
||||
$discount = 0.00;
|
||||
|
||||
if (count($this->coupons) > 0) {
|
||||
$couponsKept = $this->sortCoupons($this->coupons);
|
||||
|
||||
$isRemovingPostage = $this->isCouponRemovingPostage($couponsKept);
|
||||
|
||||
$discount = $this->getEffect($couponsKept);
|
||||
|
||||
if ($isRemovingPostage) {
|
||||
$postage = $this->adapter->getCheckoutPostagePrice();
|
||||
$discount += $postage;
|
||||
}
|
||||
|
||||
// Just In Case test
|
||||
$checkoutTotalPrice = $this->adapter->getCartTotalPrice();
|
||||
if ($discount >= $checkoutTotalPrice) {
|
||||
$discount = $checkoutTotalPrice;
|
||||
}
|
||||
}
|
||||
|
||||
return $discount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there is a Coupon removing Postage
|
||||
*
|
||||
* @param array $couponsKept Array of CouponInterface sorted
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isCouponRemovingPostage(array $couponsKept)
|
||||
{
|
||||
$isRemovingPostage = false;
|
||||
|
||||
/** @var CouponInterface $coupon */
|
||||
foreach ($couponsKept as $coupon) {
|
||||
if ($coupon->isRemovingPostage()) {
|
||||
$isRemovingPostage = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $isRemovingPostage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort Coupon to keep
|
||||
* Coupon not cumulative cancels previous
|
||||
*
|
||||
* @param array $coupons CouponInterface to process
|
||||
*
|
||||
* @return array Array of CouponInterface sorted
|
||||
*/
|
||||
protected function sortCoupons(array $coupons)
|
||||
{
|
||||
$couponsKept = array();
|
||||
|
||||
/** @var CouponInterface $coupon */
|
||||
foreach ($coupons as $coupon) {
|
||||
if (!$coupon->isExpired()) {
|
||||
if ($coupon->isCumulative()) {
|
||||
if (isset($couponsKept[0])) {
|
||||
/** @var CouponInterface $previousCoupon */
|
||||
$previousCoupon = $couponsKept[0];
|
||||
if ($previousCoupon->isCumulative()) {
|
||||
// Add Coupon
|
||||
$couponsKept[] = $coupon;
|
||||
} else {
|
||||
// Reset Coupons, add last
|
||||
$couponsKept = array($coupon);
|
||||
}
|
||||
} else {
|
||||
// Reset Coupons, add last
|
||||
$couponsKept = array($coupon);
|
||||
}
|
||||
} else {
|
||||
// Reset Coupons, add last
|
||||
$couponsKept = array($coupon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$coupons = $couponsKept;
|
||||
$couponsKept = array();
|
||||
|
||||
/** @var CouponInterface $coupon */
|
||||
foreach ($coupons as $coupon) {
|
||||
if ($coupon->isMatching($this->adapter)) {
|
||||
$couponsKept[] = $coupon;
|
||||
}
|
||||
}
|
||||
|
||||
return $couponsKept;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process given Coupon in order to get their cumulative effects
|
||||
*
|
||||
* @param array $coupons CouponInterface to process
|
||||
*
|
||||
* @return float discount
|
||||
*/
|
||||
protected function getEffect(array $coupons)
|
||||
{
|
||||
$discount = 0.00;
|
||||
/** @var CouponInterface $coupon */
|
||||
foreach ($coupons as $coupon) {
|
||||
$discount += $coupon->getDiscount($this->adapter);
|
||||
}
|
||||
|
||||
return $discount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a CouponRuleInterface from data coming from a form
|
||||
*
|
||||
* @param string $ruleServiceId Rule service id you want to instantiate
|
||||
* @param array $operators Rule Operator set by the Admin
|
||||
* @param array $values Rule Values set by the Admin
|
||||
*
|
||||
* @return CouponRuleInterface
|
||||
*/
|
||||
public function buildRuleFromForm($ruleServiceId, array $operators, array $values)
|
||||
{
|
||||
$rule = false;
|
||||
try {
|
||||
|
||||
if ($this->container->has($ruleServiceId)) {
|
||||
/** @var CouponRuleInterface $rule */
|
||||
$rule = $this->container->get($ruleServiceId);
|
||||
$rule->populateFromForm($operators, $values);
|
||||
}
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
105
core/lib/Thelia/Coupon/CouponRuleCollection.php
Normal file
105
core/lib/Thelia/Coupon/CouponRuleCollection.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?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\Coupon;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Thelia\Constraint\Rule\CouponRuleInterface;
|
||||
use Thelia\Constraint\Rule\SerializableRule;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Manage a set of CouponRuleInterface
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class CouponRuleCollection
|
||||
{
|
||||
/** @var array Array of CouponRuleInterface */
|
||||
protected $rules = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Rules
|
||||
*
|
||||
* @return array Array of CouponRuleInterface
|
||||
*/
|
||||
public function getRules()
|
||||
{
|
||||
return $this->rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a CouponRuleInterface to the Collection
|
||||
*
|
||||
* @param CouponRuleInterface $rule Rule
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function add(CouponRuleInterface $rule)
|
||||
{
|
||||
$this->rules[] = $rule;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there is at least one rule in the collection
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
return (empty($this->rules));
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow to compare 2 set of rules
|
||||
*
|
||||
* @return string Jsoned data
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$arrayToSerialize = array();
|
||||
/** @var CouponRuleInterface $rule */
|
||||
foreach ($this->getRules() as $rule) {
|
||||
$arrayToSerialize[] = $rule->getSerializableRule();
|
||||
}
|
||||
|
||||
return json_encode($arrayToSerialize);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
51
core/lib/Thelia/Coupon/RuleOrganizer.php
Normal file
51
core/lib/Thelia/Coupon/RuleOrganizer.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?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\Coupon;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Manage how Coupons could interact with a Checkout
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RuleOrganizer implements RuleOrganizerInterface
|
||||
{
|
||||
/**
|
||||
* Organize CouponRuleInterface
|
||||
*
|
||||
* @param array $rules Array of CouponRuleInterface
|
||||
*
|
||||
* @return array Array of CouponRuleInterface sorted
|
||||
*/
|
||||
public function organize(array $rules)
|
||||
{
|
||||
// TODO: Implement organize() method.
|
||||
}
|
||||
|
||||
}
|
||||
47
core/lib/Thelia/Coupon/RuleOrganizerInterface.php
Normal file
47
core/lib/Thelia/Coupon/RuleOrganizerInterface.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?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\Coupon;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Manage how Coupons could interact with a Checkout
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
interface RuleOrganizerInterface
|
||||
{
|
||||
/**
|
||||
* Organize CouponRuleInterface
|
||||
*
|
||||
* @param array $rules Array of CouponRuleInterface
|
||||
*
|
||||
* @return array Array of CouponRuleInterface sorted
|
||||
*/
|
||||
public function organize(array $rules);
|
||||
}
|
||||
305
core/lib/Thelia/Coupon/Type/CouponAbstract.php
Normal file
305
core/lib/Thelia/Coupon/Type/CouponAbstract.php
Normal file
@@ -0,0 +1,305 @@
|
||||
<?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\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;
|
||||
use Thelia\Exception\InvalidRuleException;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Assist in writing a CouponInterface
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
abstract class CouponAbstract implements CouponInterface
|
||||
{
|
||||
/** @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 ConstraintValidator Constraint validator */
|
||||
protected $constraintValidator = null;
|
||||
|
||||
/** @var string Coupon code (ex: XMAS) */
|
||||
protected $code = null;
|
||||
|
||||
/** @var string Coupon title (ex: Coupon for XMAS) */
|
||||
protected $title = null;
|
||||
|
||||
/** @var string Coupon short description */
|
||||
protected $shortDescription = null;
|
||||
|
||||
/** @var string Coupon description */
|
||||
protected $description = null;
|
||||
|
||||
/** @var bool if Coupon is enabled */
|
||||
protected $isEnabled = false;
|
||||
|
||||
/** @var \DateTime Coupon expiration date */
|
||||
protected $expirationDate = null;
|
||||
|
||||
/** @var bool if Coupon is cumulative */
|
||||
protected $isCumulative = false;
|
||||
|
||||
/** @var bool if Coupon is removing postage */
|
||||
protected $isRemovingPostage = false;
|
||||
|
||||
/** @var float Amount that will be removed from the Checkout (Coupon Effect) */
|
||||
protected $amount = 0;
|
||||
|
||||
/** @var int Max time a Coupon can be used (-1 = unlimited) */
|
||||
protected $maxUsage = -1;
|
||||
|
||||
/** @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
|
||||
*
|
||||
* @param RuleOrganizerInterface $organizer Manage Rule groups (&& and ||)
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setOrganizer($organizer)
|
||||
{
|
||||
$this->organizer = $organizer;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Coupon code (ex: XMAS)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCode()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Coupon title (ex: Coupon for XMAS)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Coupon short description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getShortDescription()
|
||||
{
|
||||
return $this->shortDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Coupon description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* If Coupon is cumulative or prevent any accumulation
|
||||
* If is cumulative you can sum Coupon effects
|
||||
* If not cancel all other Coupon and take the last given
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isCumulative()
|
||||
{
|
||||
return $this->isCumulative;
|
||||
}
|
||||
|
||||
/**
|
||||
* If Coupon is removing Checkout Postage
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isRemovingPostage()
|
||||
{
|
||||
return $this->isRemovingPostage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return effects generated by the coupon
|
||||
* A negative value
|
||||
*
|
||||
* @return float Amount removed from the Total Checkout
|
||||
*/
|
||||
public function getDiscount()
|
||||
{
|
||||
return $this->amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return condition to validate the Coupon or not
|
||||
*
|
||||
* @return CouponRuleCollection
|
||||
*/
|
||||
public function getRules()
|
||||
{
|
||||
return clone $this->rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the existing Rules by those given in parameter
|
||||
* If one Rule is badly implemented, no Rule will be added
|
||||
*
|
||||
* @param CouponRuleCollection $rules CouponRuleInterface to add
|
||||
*
|
||||
* @return $this
|
||||
* @throws \Thelia\Exception\InvalidRuleException
|
||||
*/
|
||||
public function setRules(CouponRuleCollection $rules)
|
||||
{
|
||||
$this->rules = $rules;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current Coupon is matching its conditions (Rules)
|
||||
* Thelia variables are given by the CouponAdapterInterface
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isMatching()
|
||||
{
|
||||
return $this->constraintValidator->test($this->rules);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Coupon expiration date
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getExpirationDate()
|
||||
{
|
||||
return clone $this->expirationDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the Coupon can be used against a
|
||||
* product already with a special offer price
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAvailableOnSpecialOffers()
|
||||
{
|
||||
return $this->isAvailableOnSpecialOffers;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if Coupon has been disabled by admin
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isEnabled()
|
||||
{
|
||||
return $this->isEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return how many time the Coupon can be used again
|
||||
* Ex : -1 unlimited
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getMaxUsage()
|
||||
{
|
||||
return $this->maxUsage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the Coupon is already Expired
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isExpired()
|
||||
{
|
||||
$ret = true;
|
||||
|
||||
$now = new \DateTime();
|
||||
if ($this->expirationDate > $now) {
|
||||
$ret = false;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Coupon Manager service Id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getServiceId()
|
||||
{
|
||||
return $this->serviceId;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
215
core/lib/Thelia/Coupon/Type/CouponInterface.php
Normal file
215
core/lib/Thelia/Coupon/Type/CouponInterface.php
Normal file
@@ -0,0 +1,215 @@
|
||||
<?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\Coupon\Type;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Coupon\CouponRuleCollection;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Represents a Coupon ready to be processed in a Checkout process
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
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)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCode();
|
||||
|
||||
/**
|
||||
* Return Coupon title (ex: Coupon for XMAS)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle();
|
||||
|
||||
/**
|
||||
* Return Coupon short description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getShortDescription();
|
||||
|
||||
/**
|
||||
* Return Coupon description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription();
|
||||
|
||||
/**
|
||||
* If Coupon is cumulative or prevent any accumulation
|
||||
* If is cumulative you can sum Coupon effects
|
||||
* If not cancel all other Coupon and take the last given
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isCumulative();
|
||||
|
||||
/**
|
||||
* If Coupon is removing Checkout Postage
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isRemovingPostage();
|
||||
|
||||
/**
|
||||
* Return effects generated by the coupon
|
||||
* A positive value
|
||||
*
|
||||
* Effects could also affect something else than the final Checkout price
|
||||
* CouponAdapter $adapter could be use to directly pass a Session value
|
||||
* some would wish to modify
|
||||
* Hence affecting a wide variety of Thelia elements
|
||||
*
|
||||
* @return float Amount removed from the Total Checkout
|
||||
*/
|
||||
public function getDiscount();
|
||||
|
||||
/**
|
||||
* Return condition to validate the Coupon or not
|
||||
*
|
||||
* @return CouponRuleCollection A set of CouponRuleInterface
|
||||
*/
|
||||
public function getRules();
|
||||
|
||||
/**
|
||||
* Check if the current Coupon is matching its conditions (Rules)
|
||||
* Thelia variables are given by the CouponAdapterInterface
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isMatching();
|
||||
|
||||
/**
|
||||
* Replace the existing Rules by those given in parameter
|
||||
* If one Rule is badly implemented, no Rule will be added
|
||||
*
|
||||
* @param CouponRuleCollection $rules CouponRuleInterface to add
|
||||
*
|
||||
* @return $this
|
||||
* @throws \Thelia\Exception\InvalidRuleException
|
||||
*/
|
||||
public function setRules(CouponRuleCollection $rules);
|
||||
|
||||
/**
|
||||
* Return Coupon expiration date
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getExpirationDate();
|
||||
|
||||
/**
|
||||
* Check if the Coupon can be used against a
|
||||
* product already with a special offer price
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAvailableOnSpecialOffers();
|
||||
|
||||
|
||||
/**
|
||||
* Check if Coupon has been disabled by admin
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isEnabled();
|
||||
|
||||
/**
|
||||
* Return how many time the Coupon can be used again
|
||||
* Ex : -1 unlimited
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getMaxUsage();
|
||||
|
||||
/**
|
||||
* Check if the Coupon is already Expired
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isExpired();
|
||||
|
||||
/**
|
||||
* Get I18n name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip();
|
||||
|
||||
/**
|
||||
* Get Coupon Manager service Id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getServiceId();
|
||||
|
||||
}
|
||||
123
core/lib/Thelia/Coupon/Type/RemoveXAmountManager.php
Normal file
123
core/lib/Thelia/Coupon/Type/RemoveXAmountManager.php
Normal file
@@ -0,0 +1,123 @@
|
||||
<?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\Coupon\Type;
|
||||
|
||||
use Thelia\Constraint\ConstraintManager;
|
||||
use Thelia\Coupon\Type\CouponAbstract;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Allow to remove an amount from the checkout total
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RemoveXAmountManager extends CouponAbstract
|
||||
{
|
||||
/** @var string Service Id */
|
||||
protected $serviceId = 'thelia.coupon.type.remove_x_amount';
|
||||
|
||||
/**
|
||||
* 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 $amount Coupon amount 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,
|
||||
$amount,
|
||||
$isCumulative,
|
||||
$isRemovingPostage,
|
||||
$isAvailableOnSpecialOffers,
|
||||
$isEnabled,
|
||||
$maxUsage,
|
||||
\DateTime $expirationDate
|
||||
)
|
||||
{
|
||||
$this->code = $code;
|
||||
$this->title = $title;
|
||||
$this->shortDescription = $shortDescription;
|
||||
$this->description = $description;
|
||||
|
||||
$this->isCumulative = $isCumulative;
|
||||
$this->isRemovingPostage = $isRemovingPostage;
|
||||
|
||||
$this->amount = $amount;
|
||||
|
||||
$this->isAvailableOnSpecialOffers = $isAvailableOnSpecialOffers;
|
||||
$this->isEnabled = $isEnabled;
|
||||
$this->maxUsage = $maxUsage;
|
||||
$this->expirationDate = $expirationDate;
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans('Remove X amount to total cart', array(), 'constraint');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
$toolTip = $this->adapter
|
||||
->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.',
|
||||
array(),
|
||||
'constraint'
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
}
|
||||
38
core/lib/Thelia/Coupon/Type/RemoveXPercentForAttributeY.php
Normal file
38
core/lib/Thelia/Coupon/Type/RemoveXPercentForAttributeY.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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\Coupon\Type;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RemoveXPercentForAttributeY extends RemoveXPercent
|
||||
{
|
||||
|
||||
}
|
||||
38
core/lib/Thelia/Coupon/Type/RemoveXPercentForCategoryY.php
Normal file
38
core/lib/Thelia/Coupon/Type/RemoveXPercentForCategoryY.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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\Coupon\Type;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RemoveXPercentForCategoryY extends RemoveXPercent
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?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\Coupon\Type;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RemoveXPercentForProductSaleElementIdY extends RemoveXPercent
|
||||
{
|
||||
|
||||
}
|
||||
38
core/lib/Thelia/Coupon/Type/RemoveXPercentForProductY.php
Normal file
38
core/lib/Thelia/Coupon/Type/RemoveXPercentForProductY.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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\Coupon\Type;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RemoveXPercentForProductY extends RemoveXPercent
|
||||
{
|
||||
|
||||
}
|
||||
146
core/lib/Thelia/Coupon/Type/RemoveXPercentManager.php
Normal file
146
core/lib/Thelia/Coupon/Type/RemoveXPercentManager.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?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\Coupon\Type;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Coupon\Type\CouponAbstract;
|
||||
use Thelia\Exception\MissingAdapterException;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RemoveXPercentManager extends CouponAbstract
|
||||
{
|
||||
/** @var string Service Id */
|
||||
protected $serviceId = 'thelia.coupon.type.remove_x_percent';
|
||||
|
||||
protected $percent = 0;
|
||||
|
||||
/**
|
||||
* 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 $percent Coupon 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,
|
||||
$percent,
|
||||
$isCumulative,
|
||||
$isRemovingPostage,
|
||||
$isAvailableOnSpecialOffers,
|
||||
$isEnabled,
|
||||
$maxUsage,
|
||||
\DateTime $expirationDate)
|
||||
{
|
||||
$this->code = $code;
|
||||
$this->title = $title;
|
||||
$this->shortDescription = $shortDescription;
|
||||
$this->description = $description;
|
||||
|
||||
$this->isCumulative = $isCumulative;
|
||||
$this->isRemovingPostage = $isRemovingPostage;
|
||||
|
||||
$this->percent = $percent;
|
||||
|
||||
$this->isAvailableOnSpecialOffers = $isAvailableOnSpecialOffers;
|
||||
$this->isEnabled = $isEnabled;
|
||||
$this->maxUsage = $maxUsage;
|
||||
$this->expirationDate = $expirationDate;
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return effects generated by the coupon
|
||||
* A negative value
|
||||
*
|
||||
* @throws \Thelia\Exception\MissingAdapterException
|
||||
* @throws \InvalidArgumentException
|
||||
* @return float
|
||||
*/
|
||||
public function getDiscount()
|
||||
{
|
||||
if ($this->percent >= 100) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Percentage must be inferior to 100'
|
||||
);
|
||||
}
|
||||
|
||||
$basePrice = $this->adapter->getCartTotalPrice();
|
||||
|
||||
return $basePrice * (( $this->percent ) / 100);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get I18n name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans('Remove X percent to total cart', array(), 'constraint');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
$toolTip = $this->adapter
|
||||
->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.',
|
||||
array(),
|
||||
'constraint'
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
|
||||
}
|
||||
53
core/lib/Thelia/Exception/CouponExpiredException.php
Normal file
53
core/lib/Thelia/Exception/CouponExpiredException.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?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\Exception;
|
||||
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Thrown when an Expired Coupon is tried
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class CouponExpiredException extends \Exception
|
||||
{
|
||||
/**
|
||||
* CouponExpiredException thrown when a Coupon is expired
|
||||
*
|
||||
* @param string $couponCode Coupon code
|
||||
*/
|
||||
public function __construct($couponCode)
|
||||
{
|
||||
$message = 'Expired Coupon ' . $couponCode . 'attempt';
|
||||
Tlog::getInstance()->addInfo($message);
|
||||
|
||||
parent::__construct($message);
|
||||
}
|
||||
}
|
||||
54
core/lib/Thelia/Exception/InvalidRuleException.php
Normal file
54
core/lib/Thelia/Exception/InvalidRuleException.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?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\Exception;
|
||||
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Thrown when a Rule is badly implemented
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class InvalidRuleException extends \RuntimeException
|
||||
{
|
||||
/**
|
||||
* InvalidRuleOperatorException thrown when a Rule is badly implemented
|
||||
*
|
||||
* @param string $className Class name
|
||||
*/
|
||||
public function __construct($className)
|
||||
{
|
||||
|
||||
$message = 'Invalid Rule given to ' . $className;
|
||||
Tlog::getInstance()->addError($message);
|
||||
|
||||
parent::__construct($message);
|
||||
}
|
||||
}
|
||||
55
core/lib/Thelia/Exception/InvalidRuleOperatorException.php
Normal file
55
core/lib/Thelia/Exception/InvalidRuleOperatorException.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?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\Exception;
|
||||
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Thrown when a Rule receive an invalid Operator
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class InvalidRuleOperatorException extends \RuntimeException
|
||||
{
|
||||
/**
|
||||
* InvalidRuleOperatorException thrown when a Rule is given a bad Operator
|
||||
*
|
||||
* @param string $className Class name
|
||||
* @param string $parameter array key parameter
|
||||
*/
|
||||
public function __construct($className, $parameter)
|
||||
{
|
||||
|
||||
$message = 'Invalid Operator for Rule ' . $className . ' on parameter ' . $parameter;
|
||||
Tlog::getInstance()->addError($message);
|
||||
|
||||
parent::__construct($message);
|
||||
}
|
||||
}
|
||||
55
core/lib/Thelia/Exception/InvalidRuleValueException.php
Normal file
55
core/lib/Thelia/Exception/InvalidRuleValueException.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?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\Exception;
|
||||
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Thrown when a Rule receive an invalid Parameter
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class InvalidRuleValueException extends \RuntimeException
|
||||
{
|
||||
/**
|
||||
* InvalidRuleValueException thrown when a Rule is given a bad Parameter
|
||||
*
|
||||
* @param string $className Class name
|
||||
* @param string $parameter array key parameter
|
||||
*/
|
||||
public function __construct($className, $parameter)
|
||||
{
|
||||
|
||||
$message = 'Invalid Parameter for Rule ' . $className . ' on parameter ' . $parameter;
|
||||
Tlog::getInstance()->addError($message);
|
||||
|
||||
parent::__construct($message);
|
||||
}
|
||||
}
|
||||
50
core/lib/Thelia/Exception/MissingAdapterException.php
Normal file
50
core/lib/Thelia/Exception/MissingAdapterException.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?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\Exception;
|
||||
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Thrown when the Adapter is not set
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class MissingAdapterException extends \RuntimeException
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct($message, $code = null, $previous = null) {
|
||||
|
||||
Tlog::getInstance()->addError($message);
|
||||
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
||||
43
core/lib/Thelia/Exception/NotImplementedException.php
Normal file
43
core/lib/Thelia/Exception/NotImplementedException.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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\Exception;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Exception\BadMethodCallException;
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Thrown when an Abstract method has not been implemented
|
||||
*
|
||||
* @package Exception
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class NotImplementedException extends BadMethodCallException
|
||||
{
|
||||
|
||||
}
|
||||
44
core/lib/Thelia/Exception/TaxEngineException.php
Executable file
44
core/lib/Thelia/Exception/TaxEngineException.php
Executable file
@@ -0,0 +1,44 @@
|
||||
<?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\Exception;
|
||||
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
class TaxEngineException extends \RuntimeException
|
||||
{
|
||||
const UNKNOWN_EXCEPTION = 0;
|
||||
|
||||
const UNDEFINED_PRODUCT = 501;
|
||||
const UNDEFINED_COUNTRY = 502;
|
||||
const UNDEFINED_TAX_RULES_COLLECTION = 503;
|
||||
|
||||
const BAD_AMOUNT_FORMAT = 601;
|
||||
|
||||
public function __construct($message, $code = null, $previous = null) {
|
||||
if($code === null) {
|
||||
$code = self::UNKNOWN_EXCEPTION;
|
||||
}
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
||||
@@ -102,6 +102,10 @@ abstract class BaseForm
|
||||
$this->formBuilder->add("success_url", "text");
|
||||
}
|
||||
|
||||
if (! $this->formBuilder->has('error_message')) {
|
||||
$this->formBuilder->add("error_message", "text");
|
||||
}
|
||||
|
||||
$this->form = $this->formBuilder->getForm();
|
||||
}
|
||||
|
||||
|
||||
160
core/lib/Thelia/Form/CouponCreationForm.php
Executable file
160
core/lib/Thelia/Form/CouponCreationForm.php
Executable file
@@ -0,0 +1,160 @@
|
||||
<?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\Form;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/29/13
|
||||
* Time: 3:45 PM
|
||||
*
|
||||
* Allow to build a form Coupon
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class CouponCreationForm extends BaseForm
|
||||
{
|
||||
/**
|
||||
* Build Coupon form
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function buildForm()
|
||||
{
|
||||
$this->formBuilder
|
||||
->add(
|
||||
'code',
|
||||
'text',
|
||||
array(
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
)
|
||||
->add(
|
||||
'title',
|
||||
'text',
|
||||
array(
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
)
|
||||
->add(
|
||||
'shortDescription',
|
||||
'text',
|
||||
array(
|
||||
'invalid_message' => 'test',
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
)
|
||||
->add(
|
||||
'description',
|
||||
'textarea',
|
||||
array(
|
||||
'invalid_message' => 'test',
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
)
|
||||
->add(
|
||||
'effect',
|
||||
'text',
|
||||
array(
|
||||
'invalid_message' => 'test',
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
)
|
||||
->add(
|
||||
'amount',
|
||||
'money',
|
||||
array()
|
||||
)
|
||||
->add(
|
||||
'isEnabled',
|
||||
'checkbox',
|
||||
array()
|
||||
)
|
||||
->add(
|
||||
'expirationDate',
|
||||
'text',
|
||||
array(
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
)
|
||||
->add(
|
||||
'isCumulative',
|
||||
'checkbox',
|
||||
array()
|
||||
)
|
||||
->add(
|
||||
'isRemovingPostage',
|
||||
'checkbox',
|
||||
array()
|
||||
)
|
||||
->add(
|
||||
'isAvailableOnSpecialOffers',
|
||||
'checkbox',
|
||||
array()
|
||||
)
|
||||
->add(
|
||||
'maxUsage',
|
||||
'text',
|
||||
array(
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
)
|
||||
->add(
|
||||
'locale',
|
||||
'hidden',
|
||||
array(
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get form name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'thelia_coupon_creation';
|
||||
}
|
||||
}
|
||||
@@ -22,24 +22,38 @@
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Form;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\Callback;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Symfony\Component\Validator\Constraints\Email;
|
||||
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
|
||||
class CustomerLogin extends BaseForm
|
||||
{
|
||||
protected function buildForm()
|
||||
{
|
||||
$this->formBuilder
|
||||
->add("email", "text", array(
|
||||
->add("email", "email", array(
|
||||
"constraints" => array(
|
||||
new NotBlank(),
|
||||
new Email()
|
||||
)
|
||||
),
|
||||
"label" => Translator::getInstance()->trans("Please enter your email address"),
|
||||
"label_attr" => array(
|
||||
"for" => "email"
|
||||
),
|
||||
"required" => true
|
||||
))
|
||||
->add("password", "password", array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
)
|
||||
),
|
||||
"label" => Translator::getInstance()->trans("Please enter your password"),
|
||||
"label_attr" => array(
|
||||
"for" => "password"
|
||||
),
|
||||
"required" => true
|
||||
))
|
||||
->add("remember_me", "checkbox")
|
||||
;
|
||||
@@ -49,4 +63,5 @@ class CustomerLogin extends BaseForm
|
||||
{
|
||||
return "thelia_customer_login";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
0
core/lib/Thelia/Model/Base/Accessory.php
Executable file → Normal file
0
core/lib/Thelia/Model/Base/Accessory.php
Executable file → Normal file
0
core/lib/Thelia/Model/Base/AccessoryQuery.php
Executable file → Normal file
0
core/lib/Thelia/Model/Base/AccessoryQuery.php
Executable file → Normal file
0
core/lib/Thelia/Model/Base/Address.php
Executable file → Normal file
0
core/lib/Thelia/Model/Base/Address.php
Executable file → Normal file
0
core/lib/Thelia/Model/Base/AddressQuery.php
Executable file → Normal file
0
core/lib/Thelia/Model/Base/AddressQuery.php
Executable file → Normal file
0
core/lib/Thelia/Model/Base/Admin.php
Executable file → Normal file
0
core/lib/Thelia/Model/Base/Admin.php
Executable file → Normal file
0
core/lib/Thelia/Model/Base/AdminGroup.php
Executable file → Normal file
0
core/lib/Thelia/Model/Base/AdminGroup.php
Executable file → Normal file
0
core/lib/Thelia/Model/Base/AdminGroupQuery.php
Executable file → Normal file
0
core/lib/Thelia/Model/Base/AdminGroupQuery.php
Executable file → Normal file
0
core/lib/Thelia/Model/Base/AdminLog.php
Executable file → Normal file
0
core/lib/Thelia/Model/Base/AdminLog.php
Executable file → Normal file
0
core/lib/Thelia/Model/Base/AdminLogQuery.php
Executable file → Normal file
0
core/lib/Thelia/Model/Base/AdminLogQuery.php
Executable file → Normal file
0
core/lib/Thelia/Model/Base/AdminQuery.php
Executable file → Normal file
0
core/lib/Thelia/Model/Base/AdminQuery.php
Executable file → Normal file
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user