Merge branch 'master' of https://github.com/thelia/thelia
Conflicts: .gitignore
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -23,3 +23,5 @@ web/.htaccess
|
||||
phpdoc*.log
|
||||
php-cs
|
||||
xhprof/
|
||||
phpunit.phar
|
||||
.DS_Store
|
||||
@@ -9,7 +9,6 @@
|
||||
},
|
||||
"require":{
|
||||
"php": ">=5.4",
|
||||
"ezyang/htmlpurifier": "dev-master",
|
||||
"ircmaxell/password-compat": "dev-master",
|
||||
"propel/propel": "dev-master",
|
||||
"psr/log" : "1.0",
|
||||
@@ -37,11 +36,13 @@
|
||||
"simplepie/simplepie": "dev-master",
|
||||
|
||||
"imagine/imagine": "dev-master",
|
||||
"symfony/serializer": "dev-master",
|
||||
"symfony/icu": "1.0"
|
||||
},
|
||||
"require-dev" : {
|
||||
"phpunit/phpunit": "3.7.*",
|
||||
"fzaninotto/faker": "dev-master"
|
||||
"fzaninotto/faker": "dev-master",
|
||||
"maximebf/debugbar": "1.*"
|
||||
},
|
||||
"minimum-stability": "stable",
|
||||
"config" : {
|
||||
|
||||
97
composer.lock
generated
97
composer.lock
generated
@@ -3,52 +3,9 @@
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
|
||||
],
|
||||
"hash": "db69990b239a4056558bfd694115d01b",
|
||||
"hash": "ba2f3e0943f00c7c3bf0c086bc611b0f",
|
||||
|
||||
"packages": [
|
||||
{
|
||||
"name": "ezyang/htmlpurifier",
|
||||
"version": "dev-master",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/ezyang/htmlpurifier.git",
|
||||
"reference": "fac747bdbdba6aeaba4bed91ef49b2378c1798e4"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/ezyang/htmlpurifier/zipball/fac747bdbdba6aeaba4bed91ef49b2378c1798e4",
|
||||
"reference": "fac747bdbdba6aeaba4bed91ef49b2378c1798e4",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.2"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"HTMLPurifier": "library/"
|
||||
},
|
||||
"files": [
|
||||
"library/HTMLPurifier.composer.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"LGPL"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Edward Z. Yang",
|
||||
"email": "admin@htmlpurifier.org",
|
||||
"homepage": "http://ezyang.com"
|
||||
}
|
||||
],
|
||||
"description": "Standards compliant HTML filter written in PHP",
|
||||
"homepage": "http://htmlpurifier.org/",
|
||||
"keywords": [
|
||||
"html"
|
||||
],
|
||||
"time": "2013-08-18 02:27:26"
|
||||
},
|
||||
{
|
||||
"name": "imagine/imagine",
|
||||
"version": "dev-master",
|
||||
@@ -1662,6 +1619,55 @@
|
||||
],
|
||||
"time": "2013-08-29 19:11:59"
|
||||
},
|
||||
{
|
||||
"name": "maximebf/debugbar",
|
||||
"version": "1.5.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/maximebf/php-debugbar.git",
|
||||
"reference": "37dccc40da52bf9f85571c30cf302da696db0d05"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/37dccc40da52bf9f85571c30cf302da696db0d05",
|
||||
"reference": "37dccc40da52bf9f85571c30cf302da696db0d05",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.0",
|
||||
"psr/log": "~1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"suggest": {
|
||||
"kriswallsmith/assetic": "The best way to manage assets",
|
||||
"monolog/monolog": "Log using Monolog"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"DebugBar": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Maxime Bouroumeau-Fuseau",
|
||||
"email": "maxime.bouroumeau@gmail.com",
|
||||
"homepage": "http://maximebf.com"
|
||||
}
|
||||
],
|
||||
"description": "Debug bar in the browser for php application",
|
||||
"homepage": "https://github.com/maximebf/php-debugbar",
|
||||
"keywords": [
|
||||
"debug"
|
||||
],
|
||||
"time": "2013-08-17 02:02:49"
|
||||
},
|
||||
{
|
||||
"name": "phpunit/php-code-coverage",
|
||||
"version": "1.2.12",
|
||||
@@ -2035,7 +2041,6 @@
|
||||
],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": {
|
||||
"ezyang/htmlpurifier": 20,
|
||||
"ircmaxell/password-compat": 20,
|
||||
"propel/propel": 20,
|
||||
"kriswallsmith/assetic": 20,
|
||||
|
||||
@@ -51,6 +51,8 @@ class Category extends BaseAction implements EventSubscriberInterface
|
||||
$event->getParent(),
|
||||
$event->getLocale()
|
||||
);
|
||||
|
||||
$event->setCategory($category);
|
||||
}
|
||||
|
||||
public function update(CategoryChangeEvent $event)
|
||||
|
||||
180
core/lib/Thelia/Action/Coupon.php
Executable file
180
core/lib/Thelia/Action/Coupon.php
Executable file
@@ -0,0 +1,180 @@
|
||||
<?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_CREATE => array("createRule", 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ namespace %%NAMESPACE%%;
|
||||
|
||||
use Thelia\Module\BaseModule;
|
||||
|
||||
class Class extends BaseModule
|
||||
class %%CLASSNAME%% extends BaseModule
|
||||
{
|
||||
/**
|
||||
* YOU HAVE TO IMPLEMENT HERE ABSTRACT METHODD FROM BaseModule Class
|
||||
|
||||
@@ -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,7 +33,9 @@
|
||||
<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>
|
||||
|
||||
<forms>
|
||||
@@ -47,7 +49,10 @@
|
||||
<form name="thelia.address.update" class="Thelia\Form\AddressUpdateForm" />
|
||||
|
||||
<form name="thelia.admin.category.creation" class="Thelia\Form\CategoryCreationForm"/>
|
||||
<form name="thelia.admin.category.deletion" class="Thelia\Form\CategoryDeletionForm"/>
|
||||
<form name="thelia.admin.category.deletion" class="Thelia\Form\CategoryModificationForm"/>
|
||||
|
||||
<form name="thelia.admin.product.creation" class="Thelia\Form\ProductCreationForm"/>
|
||||
<form name="thelia.admin.product.deletion" class="Thelia\Form\ProductModificationForm"/>
|
||||
|
||||
<form name="thelia.cart.add" class="Thelia\Form\CartAdd"/>
|
||||
|
||||
@@ -59,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>
|
||||
|
||||
|
||||
@@ -79,7 +86,6 @@
|
||||
|
||||
<service id="thelia.url.manager" class="Thelia\Tools\URL">
|
||||
<argument type="service" id="service_container" />
|
||||
<argument >%kernel.environment%</argument>
|
||||
</service>
|
||||
|
||||
<service id="event_dispatcher" class="Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher">
|
||||
@@ -98,7 +104,7 @@
|
||||
<!-- Translation and internationalisation -->
|
||||
|
||||
<service id="thelia.translator" class="Thelia\Core\Translation\Translator">
|
||||
<argument type="string" id="en_US"></argument>
|
||||
<argument type="string" id="en_UK"></argument>
|
||||
</service>
|
||||
|
||||
<!-- Security context for front and back office -->
|
||||
@@ -143,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>
|
||||
@@ -207,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>
|
||||
|
||||
@@ -25,16 +25,82 @@
|
||||
</route>
|
||||
|
||||
|
||||
<!-- Route to the catalog controller (process category browsing) -->
|
||||
<!-- Route to the catalog controller -->
|
||||
|
||||
<route id="admin.catalog" path="/admin/catalog">
|
||||
<default key="_controller">Thelia\Controller\Admin\CategoryController::indexAction</default>
|
||||
<default key="_controller">Thelia\Controller\Admin\CategoryController::defaultAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.category" path="/admin/catalog/category">
|
||||
<default key="_controller">Thelia\Controller\Admin\CategoryController::processAction</default>
|
||||
<!-- 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">
|
||||
<default key="_controller">Thelia\Controller\Admin\CategoryController::defaultAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.categories.create" path="/admin/categories/create">
|
||||
<default key="_controller">Thelia\Controller\Admin\CategoryController::createAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.categories.update" path="/admin/categories/update">
|
||||
<default key="_controller">Thelia\Controller\Admin\CategoryController::changeAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.categories.save" path="/admin/categories/save">
|
||||
<default key="_controller">Thelia\Controller\Admin\CategoryController::saveChangeAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.categories.set-default" path="/admin/categories/toggle-online">
|
||||
<default key="_controller">Thelia\Controller\Admin\CategoryController::toggleOnlineAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.categories.delete" path="/admin/categories/delete">
|
||||
<default key="_controller">Thelia\Controller\Admin\CategoryController::deleteAction</default>
|
||||
</route>
|
||||
|
||||
<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>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- Routes to the Config (system variables) controller -->
|
||||
|
||||
<route id="admin.configuration.variables.default" path="/admin/configuration/variables">
|
||||
@@ -105,6 +171,10 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\CurrencyController::setDefaultAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.currencies.update-position" path="/admin/configuration/currencies/update-position">
|
||||
<default key="_controller">Thelia\Controller\Admin\CurrencyController::updatePositionAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.currencies.update-rates" path="/admin/configuration/currencies/update-rates">
|
||||
<default key="_controller">Thelia\Controller\Admin\CurrencyController::updateRatesAction</default>
|
||||
</route>
|
||||
@@ -118,8 +188,7 @@
|
||||
</route>
|
||||
|
||||
<!-- attribute and feature routes management -->
|
||||
|
||||
|
||||
|
||||
<route id="admin.configuration.attribute" path="/admin/configuration/product_attributes">
|
||||
<default key="_controller">Thelia\Controller\Admin\AttributeController::defaultAction</default>
|
||||
</route>
|
||||
@@ -128,7 +197,6 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\AttributeController::updateAction</default>
|
||||
</route>
|
||||
|
||||
|
||||
<!-- end attribute and feature routes management -->
|
||||
|
||||
<!-- The default route, to display a template -->
|
||||
|
||||
@@ -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 -->
|
||||
@@ -60,4 +72,11 @@
|
||||
<default key="_view">cart</default>
|
||||
</route>
|
||||
|
||||
<!-- order management process -->
|
||||
<route id="order.delivery.add" path="/delivery/choose/{delivery_id}">
|
||||
<default key="_controller">Thelia\Controller\Front\DeliveryController::select</default>
|
||||
<requirement key="delivery_id">\d+</requirement>
|
||||
</route>
|
||||
<!-- end order management process -->
|
||||
|
||||
</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' => ''
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
262
core/lib/Thelia/Constraint/Rule/CouponRuleAbstract.php
Normal file
262
core/lib/Thelia/Constraint/Rule/CouponRuleAbstract.php
Normal file
@@ -0,0 +1,262 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
return $translatedInputs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate inputs ready to be drawn
|
||||
*
|
||||
* @throws \Thelia\Exception\NotImplementedException
|
||||
* @return array
|
||||
*/
|
||||
protected function generateInputs()
|
||||
{
|
||||
throw new \Thelia\Exception\NotImplementedException(
|
||||
'The generateInputs method must be implemented in ' . get_class()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
@@ -34,6 +37,9 @@ use Thelia\Core\Security\SecurityContext;
|
||||
use Thelia\Model\AdminLog;
|
||||
use Thelia\Model\Lang;
|
||||
use Thelia\Model\LangQuery;
|
||||
use Thelia\Form\BaseForm;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
class BaseAdminController extends BaseController
|
||||
{
|
||||
@@ -66,7 +72,7 @@ class BaseAdminController extends BaseController
|
||||
}
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
return new Response($this->errorPage($ex->getMessage()));
|
||||
return $this->errorPage($ex->getMessage());
|
||||
}
|
||||
|
||||
return $this->pageNotFound();
|
||||
@@ -92,7 +98,7 @@ class BaseAdminController extends BaseController
|
||||
protected function errorPage($message)
|
||||
{
|
||||
if ($message instanceof \Exception) {
|
||||
$message = sprintf("Sorry, an error occured: %s", $message->getMessage());
|
||||
$message = sprintf($this->getTranslator()->trans("Sorry, an error occured: %msg"), array('msg' => $message->getMessage()));
|
||||
}
|
||||
|
||||
return $this->render('general_error', array(
|
||||
@@ -123,7 +129,56 @@ class BaseAdminController extends BaseController
|
||||
// Generate the proper response
|
||||
$response = new Response();
|
||||
|
||||
return $response->setContent($this->errorPage("Sorry, you're not allowed to perform this action"));
|
||||
return $this->errorPage($this->getTranslator()->trans("Sorry, you're not allowed to perform this action"));
|
||||
}
|
||||
|
||||
/*
|
||||
* Create the standard message displayed to the user when the form cannot be validated.
|
||||
*/
|
||||
protected function createStandardFormValidationErrorMessage(FormValidationException $exception) {
|
||||
return $this->getTranslator()->trans(
|
||||
"Please check your input: %error",
|
||||
array(
|
||||
'%error' => $exception->getMessage()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the error context when an error occurs in a action method.
|
||||
*
|
||||
* @param string $action the action that caused the error (category modification, variable creation, currency update, etc.)
|
||||
* @param BaseForm $form the form where the error occured, or null if no form was involved
|
||||
* @param string $error_message the error message
|
||||
* @param Exception $exception the exception or null if no exception
|
||||
*/
|
||||
protected function setupFormErrorContext($action, $error_message, BaseForm $form = null, \Exception $exception = null) {
|
||||
|
||||
if ($error_message !== false) {
|
||||
|
||||
// Log the error message
|
||||
Tlog::getInstance()->error(
|
||||
$this->getTranslator()->trans(
|
||||
"Error during %action process : %error. Exception was %exc",
|
||||
array(
|
||||
'%action' => $action,
|
||||
'%error' => $error_message,
|
||||
'%exc' => $exception != null ? $exception->getMessage() : 'no exception'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
if ($form != null) {
|
||||
// Mark the form as errored
|
||||
$form->setErrorMessage($error_message);
|
||||
|
||||
// Pass it to the parser context
|
||||
$this->getParserContext()->addForm($form);
|
||||
}
|
||||
|
||||
// Pass the error message to the parser.
|
||||
$this->getParserContext()->setGeneralError($error_message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,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
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -261,7 +330,7 @@ class BaseAdminController extends BaseController
|
||||
}
|
||||
catch (AuthorizationException $ex) {
|
||||
// User is not allowed to perform the required action. Return the error page instead of the requested page.
|
||||
return $this->errorPage("Sorry, you are not allowed to perform this action.");
|
||||
return $this->errorPage($this->getTranslator()->trans("Sorry, you are not allowed to perform this action."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,226 +34,305 @@ use Thelia\Core\Event\CategoryToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\CategoryChangePositionEvent;
|
||||
use Thelia\Form\CategoryDeletionForm;
|
||||
use Thelia\Model\Lang;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Core\Event\CategoryUpdatePositionEvent;
|
||||
use Thelia\Model\CategoryQuery;
|
||||
use Thelia\Form\CategoryModificationForm;
|
||||
|
||||
class CategoryController extends BaseAdminController
|
||||
{
|
||||
protected function createNewCategory($args)
|
||||
{
|
||||
try {
|
||||
$categoryCreationForm = new CategoryCreationForm($this->getRequest());
|
||||
|
||||
$form = $this->validateForm($categoryCreationForm, "POST");
|
||||
|
||||
$data = $form->getData();
|
||||
|
||||
$categoryCreateEvent = new CategoryCreateEvent(
|
||||
$data["title"],
|
||||
$data["parent"],
|
||||
$data["locale"]
|
||||
);
|
||||
|
||||
$this->dispatch(TheliaEvents::CATEGORY_CREATE, $categoryCreateEvent);
|
||||
|
||||
$category = $categoryCreateEvent->getCreatedCategory();
|
||||
|
||||
$this->adminLogAppend(sprintf("Category %s (ID %s) created", $category->getTitle(), $category->getId()));
|
||||
|
||||
// Substitute _ID_ in the URL with the ID of the created category
|
||||
$successUrl = str_replace('_ID_', $category->getId(), $categoryCreationForm->getSuccessUrl());
|
||||
|
||||
// Redirect to the success URL
|
||||
$this->redirect($successUrl);
|
||||
}
|
||||
catch (FormValidationException $e) {
|
||||
$categoryCreationForm->setErrorMessage($e->getMessage());
|
||||
$this->getParserContext()->addForm($categoryCreationForm);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
Tlog::getInstance()->error(sprintf("Failed to create category: %s", $e->getMessage()));
|
||||
$this->getParserContext()->setGeneralError($e->getMessage());
|
||||
}
|
||||
|
||||
// At this point, the form has error, and should be redisplayed.
|
||||
return $this->render('categories', $args);
|
||||
/**
|
||||
* Render the categories list, ensuring the sort order is set.
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
*/
|
||||
protected function renderList() {
|
||||
return $this->render('categories', $this->getTemplateArgs());
|
||||
}
|
||||
|
||||
protected function editCategory($args)
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.category.edit")) return $response;
|
||||
|
||||
return $this->render('edit_category', $args);
|
||||
}
|
||||
|
||||
protected function deleteCategory($args)
|
||||
{
|
||||
try {
|
||||
$categoryDeletionForm = new CategoryDeletionForm($this->getRequest());
|
||||
|
||||
$data = $this->validateForm($categoryDeletionForm, "POST")->getData();
|
||||
|
||||
$categoryDeleteEvent = new CategoryDeleteEvent($data['category_id']);
|
||||
|
||||
$this->dispatch(TheliaEvents::CATEGORY_DELETE, $categoryDeleteEvent);
|
||||
|
||||
$category = $categoryDeleteEvent->getDeletedCategory();
|
||||
|
||||
$this->adminLogAppend(sprintf("Category %s (ID %s) deleted", $category->getTitle(), $category->getId()));
|
||||
|
||||
// Substitute _ID_ in the URL with the ID of the created category
|
||||
$successUrl = str_replace('_ID_', $categoryDeleteEvent->getDeletedCategory()->getParent(), $categoryDeletionForm->getSuccessUrl());
|
||||
|
||||
// Redirect to the success URL
|
||||
$this->redirect($successUrl);
|
||||
}
|
||||
catch (FormValidationException $e) {
|
||||
$categoryDeletionForm->setErrorMessage($e->getMessage());
|
||||
$this->getParserContext()->addForm($categoryDeletionForm);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
Tlog::getInstance()->error(sprintf("Failed to delete category: %s", $e->getMessage()));
|
||||
$this->getParserContext()->setGeneralError($e->getMessage());
|
||||
}
|
||||
|
||||
// At this point, something was wrong, category was not deleted. Display parent category list
|
||||
return $this->render('categories', $args);
|
||||
}
|
||||
|
||||
protected function browseCategory($args)
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.catalog.view")) return $response;
|
||||
|
||||
return $this->render('categories', $args);
|
||||
}
|
||||
|
||||
protected function visibilityToggle($args)
|
||||
{
|
||||
$event = new CategoryToggleVisibilityEvent($this->getRequest()->get('category_id', 0));
|
||||
|
||||
$this->dispatch(TheliaEvents::CATEGORY_TOGGLE_VISIBILITY, $event);
|
||||
|
||||
return $this->nullResponse();
|
||||
}
|
||||
|
||||
protected function changePosition($args)
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
||||
$event = new CategoryChangePositionEvent(
|
||||
$request->get('category_id', 0),
|
||||
CategoryChangePositionEvent::POSITION_ABSOLUTE,
|
||||
$request->get('position', null)
|
||||
);
|
||||
|
||||
$this->dispatch(TheliaEvents::CATEGORY_CHANGE_POSITION, $event);
|
||||
|
||||
return $this->render('categories', $args);
|
||||
}
|
||||
|
||||
protected function positionDown($args)
|
||||
{
|
||||
$event = new CategoryChangePositionEvent(
|
||||
$this->getRequest()->get('category_id', 0),
|
||||
CategoryChangePositionEvent::POSITION_DOWN
|
||||
);
|
||||
|
||||
$this->dispatch(TheliaEvents::CATEGORY_CHANGE_POSITION, $event);
|
||||
|
||||
return $this->render('categories', $args);
|
||||
}
|
||||
|
||||
protected function positionUp($args)
|
||||
{
|
||||
$event = new CategoryChangePositionEvent(
|
||||
$this->getRequest()->get('category_id', 0),
|
||||
CategoryChangePositionEvent::POSITION_UP
|
||||
);
|
||||
|
||||
$this->dispatch(TheliaEvents::CATEGORY_CHANGE_POSITION, $event);
|
||||
|
||||
return $this->render('categories', $args);
|
||||
}
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
return $this->processAction();
|
||||
}
|
||||
|
||||
public function processAction()
|
||||
{
|
||||
// Get the current action
|
||||
$action = $this->getRequest()->get('action', 'browse');
|
||||
protected function getTemplateArgs() {
|
||||
|
||||
// Get the category ID
|
||||
$id = $this->getRequest()->get('id', 0);
|
||||
$category_id = $this->getRequest()->get('category_id', 0);
|
||||
|
||||
// Find the current order
|
||||
// Find the current category order
|
||||
$category_order = $this->getRequest()->get(
|
||||
'order',
|
||||
$this->getSession()->get('admin.category_order', 'manual')
|
||||
);
|
||||
|
||||
// Find the current edit language ID
|
||||
$edition_language = $this->getRequest()->get(
|
||||
'edition_language',
|
||||
$this->getSession()->get('admin.edition_language', Lang::getDefaultLanguage()->getId())
|
||||
);
|
||||
|
||||
$args = array(
|
||||
'action' => $action,
|
||||
'current_category_id' => $id,
|
||||
'current_category_id' => $category_id,
|
||||
'category_order' => $category_order,
|
||||
'edition_language' => $edition_language,
|
||||
);
|
||||
|
||||
// Store the current sort order in session
|
||||
$this->getSession()->set('admin.category_order', $category_order);
|
||||
|
||||
// Store the current edition language in session
|
||||
$this->getSession()->set('admin.edition_language', $edition_language);
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* The default action is displaying the categories list.
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
*/
|
||||
public function defaultAction() {
|
||||
|
||||
if (null !== $response = $this->checkAuth("admin.categories.view")) return $response;
|
||||
|
||||
return $this->renderList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new category object
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
*/
|
||||
public function createAction() {
|
||||
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.categories.create")) return $response;
|
||||
|
||||
$error_msg = false;
|
||||
|
||||
// Create the Creation Form
|
||||
$creationForm = new CategoryCreationForm($this->getRequest());
|
||||
|
||||
try {
|
||||
switch ($action) {
|
||||
case 'browse' : // Browse categories
|
||||
|
||||
return $this->browseCategory($args);
|
||||
// Validate the form, create the CategoryCreation event and dispatch it.
|
||||
$form = $this->validateForm($creationForm, "POST");
|
||||
|
||||
case 'create' : // Create a new category
|
||||
$data = $form->getData();
|
||||
|
||||
return $this->createNewCategory($args);
|
||||
$createEvent = new CategoryCreateEvent(
|
||||
$data["title"],
|
||||
$data["parent"],
|
||||
$data["locale"]
|
||||
);
|
||||
|
||||
case 'edit' : // Edit an existing category
|
||||
$this->dispatch(TheliaEvents::CATEGORY_CREATE, $createEvent);
|
||||
|
||||
return $this->editCategory($args);
|
||||
if (! $createEvent->hasCategory()) throw new \LogicException($this->getTranslator()->trans("No category was created."));
|
||||
|
||||
case 'delete' : // Delete an existing category
|
||||
$createdObject = $createEvent->getCategory();
|
||||
|
||||
return $this->deleteCategory($args);
|
||||
// Log category creation
|
||||
$this->adminLogAppend(sprintf("Category %s (ID %s) created", $createdObject->getTitle(), $createdObject->getId()));
|
||||
|
||||
case 'visibilityToggle' : // Toggle visibility
|
||||
// Substitute _ID_ in the URL with the ID of the created object
|
||||
$successUrl = str_replace('_ID_', $createdObject->getId(), $creationForm->getSuccessUrl());
|
||||
|
||||
return $this->visibilityToggle($id);
|
||||
|
||||
case 'changePosition' : // Change position
|
||||
|
||||
return $this->changePosition($args);
|
||||
|
||||
case 'positionUp' : // Move up category
|
||||
|
||||
return $this->positionUp($args);
|
||||
|
||||
case 'positionDown' : // Move down category
|
||||
|
||||
return $this->positionDown($args);
|
||||
}
|
||||
// Redirect to the success URL
|
||||
$this->redirect($successUrl);
|
||||
}
|
||||
catch (AuthorizationException $ex) {
|
||||
return $this->errorPage($ex->getMessage());
|
||||
catch (FormValidationException $ex) {
|
||||
// Form cannot be validated
|
||||
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
|
||||
}
|
||||
catch (AuthenticationException $ex) {
|
||||
return $this->errorPage($ex->getMessage());
|
||||
catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$error_msg = $ex->getMessage();
|
||||
}
|
||||
|
||||
// We did not recognized the action -> return a 404 page
|
||||
return $this->pageNotFound();
|
||||
$this->setupFormErrorContext("category creation", $error_msg, $creationForm, $ex);
|
||||
|
||||
// At this point, the form has error, and should be redisplayed.
|
||||
return $this->renderList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a category object for modification, and display the edit template.
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
*/
|
||||
public function changeAction() {
|
||||
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.categories.update")) return $response;
|
||||
|
||||
// Load the category object
|
||||
$category = CategoryQuery::create()
|
||||
->joinWithI18n($this->getCurrentEditionLocale())
|
||||
->findOneById($this->getRequest()->get('category_id'));
|
||||
|
||||
if ($category != null) {
|
||||
|
||||
// Prepare the data that will hydrate the form
|
||||
$data = array(
|
||||
'id' => $category->getId(),
|
||||
'locale' => $category->getLocale(),
|
||||
'title' => $category->getTitle(),
|
||||
'chapo' => $category->getChapo(),
|
||||
'description' => $category->getDescription(),
|
||||
'postscriptum' => $category->getPostscriptum(),
|
||||
'parent' => $category->getParent(),
|
||||
'visible' => $category->getVisible() ? true : false,
|
||||
'url' => $category->getUrl($this->getCurrentEditionLocale())
|
||||
// tbc !!!
|
||||
);
|
||||
|
||||
// Setup the object form
|
||||
$changeForm = new CategoryModificationForm($this->getRequest(), "form", $data);
|
||||
|
||||
// Pass it to the parser
|
||||
$this->getParserContext()->addForm($changeForm);
|
||||
}
|
||||
|
||||
// Render the edition template.
|
||||
return $this->render('category-edit', $this->getTemplateArgs());
|
||||
}
|
||||
|
||||
/**
|
||||
* Save changes on a modified category object, and either go back to the category list, or stay on the edition page.
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
*/
|
||||
public function saveChangeAction() {
|
||||
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.categories.update")) return $response;
|
||||
|
||||
$error_msg = false;
|
||||
|
||||
// Create the form from the request
|
||||
$changeForm = new CategoryModificationForm($this->getRequest());
|
||||
|
||||
// Get the category ID
|
||||
$category_id = $this->getRequest()->get('category_id');
|
||||
|
||||
try {
|
||||
|
||||
// Check the form against constraints violations
|
||||
$form = $this->validateForm($changeForm, "POST");
|
||||
|
||||
// Get the form field values
|
||||
$data = $form->getData();
|
||||
|
||||
$changeEvent = new CategoryUpdateEvent($data['id']);
|
||||
|
||||
// Create and dispatch the change event
|
||||
$changeEvent
|
||||
->setCategoryName($data['name'])
|
||||
->setLocale($data["locale"])
|
||||
->setSymbol($data['symbol'])
|
||||
->setCode($data['code'])
|
||||
->setRate($data['rate'])
|
||||
;
|
||||
|
||||
$this->dispatch(TheliaEvents::CATEGORY_UPDATE, $changeEvent);
|
||||
|
||||
if (! $createEvent->hasCategory()) throw new \LogicException($this->getTranslator()->trans("No category was updated."));
|
||||
|
||||
// Log category modification
|
||||
$changedObject = $changeEvent->getCategory();
|
||||
|
||||
$this->adminLogAppend(sprintf("Category %s (ID %s) modified", $changedObject->getTitle(), $changedObject->getId()));
|
||||
|
||||
// If we have to stay on the same page, do not redirect to the succesUrl,
|
||||
// just redirect to the edit page again.
|
||||
if ($this->getRequest()->get('save_mode') == 'stay') {
|
||||
$this->redirectToRoute(
|
||||
"admin.categories.update",
|
||||
array('category_id' => $category_id)
|
||||
);
|
||||
}
|
||||
|
||||
// Redirect to the success URL
|
||||
$this->redirect($changeForm->getSuccessUrl());
|
||||
}
|
||||
catch (FormValidationException $ex) {
|
||||
// Form cannot be validated
|
||||
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$error_msg = $ex->getMessage();
|
||||
}
|
||||
|
||||
$this->setupFormErrorContext("category modification", $error_msg, $changeForm, $ex);
|
||||
|
||||
// At this point, the form has errors, and should be redisplayed.
|
||||
return $this->render('category-edit', array('category_id' => $category_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Online status toggle category
|
||||
*/
|
||||
public function setToggleVisibilityAction() {
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.categories.update")) return $response;
|
||||
|
||||
$changeEvent = new CategoryUpdateEvent($this->getRequest()->get('category_id', 0));
|
||||
|
||||
// Create and dispatch the change event
|
||||
$changeEvent->setIsDefault(true);
|
||||
|
||||
try {
|
||||
$this->dispatch(TheliaEvents::CATEGORY_SET_DEFAULT, $changeEvent);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
|
||||
$this->redirectToRoute('admin.categories.default');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update categoryposition
|
||||
*/
|
||||
public function updatePositionAction() {
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.categories.update")) return $response;
|
||||
|
||||
try {
|
||||
$mode = $this->getRequest()->get('mode', null);
|
||||
|
||||
if ($mode == 'up')
|
||||
$mode = CategoryUpdatePositionEvent::POSITION_UP;
|
||||
else if ($mode == 'down')
|
||||
$mode = CategoryUpdatePositionEvent::POSITION_DOWN;
|
||||
else
|
||||
$mode = CategoryUpdatePositionEvent::POSITION_ABSOLUTE;
|
||||
|
||||
$position = $this->getRequest()->get('position', null);
|
||||
|
||||
$event = new CategoryUpdatePositionEvent(
|
||||
$this->getRequest()->get('category_id', null),
|
||||
$mode,
|
||||
$this->getRequest()->get('position', null)
|
||||
);
|
||||
|
||||
$this->dispatch(TheliaEvents::CATEGORY_UPDATE_POSITION, $event);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
|
||||
$this->redirectToRoute('admin.categories.default');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a category object
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
*/
|
||||
public function deleteAction() {
|
||||
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.categories.delete")) return $response;
|
||||
|
||||
// Get the category id, and dispatch the deleted request
|
||||
$event = new CategoryDeleteEvent($this->getRequest()->get('category_id'));
|
||||
|
||||
$this->dispatch(TheliaEvents::CATEGORY_DELETE, $event);
|
||||
|
||||
if ($event->hasCategory())
|
||||
$this->adminLogAppend(sprintf("Category %s (ID %s) deleted", $event->getCategory()->getTitle(), $event->getCategory()->getId()));
|
||||
|
||||
$this->redirectToRoute('admin.categories.default');
|
||||
}
|
||||
}
|
||||
@@ -108,6 +108,8 @@ class ConfigController extends BaseAdminController
|
||||
|
||||
$this->dispatch(TheliaEvents::CONFIG_CREATE, $createEvent);
|
||||
|
||||
if (! $createEvent->hasConfig()) throw new \LogicException($this->getTranslator()->trans("No variable was created."));
|
||||
|
||||
$createdObject = $createEvent->getConfig();
|
||||
|
||||
// Log config creation
|
||||
@@ -121,26 +123,14 @@ class ConfigController extends BaseAdminController
|
||||
}
|
||||
catch (FormValidationException $ex) {
|
||||
// Form cannot be validated
|
||||
$message = sprintf("Please check your input: %s", $ex->getMessage());
|
||||
$message = $this->createStandardFormValidationErrorMessage($ex);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$message = sprintf("Sorry, an error occured: %s", $ex->getMessage());
|
||||
$message = $ex->getMessage();
|
||||
}
|
||||
|
||||
if ($message !== false) {
|
||||
// An error has been detected: log it
|
||||
Tlog::getInstance()->error(sprintf("Error during variable creation process : %s. Exception was %s", $message, $ex->getMessage()));
|
||||
|
||||
// Mark the form as errored
|
||||
$creationForm->setErrorMessage($message);
|
||||
|
||||
// Pass it to the parser, along with the error message
|
||||
$this->getParserContext()
|
||||
->addForm($creationForm)
|
||||
->setGeneralError($message)
|
||||
;
|
||||
}
|
||||
$this->setupFormErrorContext("variable creation", $message, $creationForm, $ex);
|
||||
|
||||
// At this point, the form has error, and should be redisplayed.
|
||||
return $this->renderList();
|
||||
@@ -231,6 +221,8 @@ class ConfigController extends BaseAdminController
|
||||
|
||||
$this->dispatch(TheliaEvents::CONFIG_UPDATE, $changeEvent);
|
||||
|
||||
if (! $changeEvent->hasConfig()) throw new \LogicException($this->getTranslator()->trans("No variable was updated."));
|
||||
|
||||
// Log config modification
|
||||
$changedObject = $changeEvent->getConfig();
|
||||
|
||||
@@ -250,27 +242,15 @@ class ConfigController extends BaseAdminController
|
||||
$this->redirect($changeForm->getSuccessUrl());
|
||||
}
|
||||
catch (FormValidationException $ex) {
|
||||
// Invalid data entered
|
||||
$message = sprintf("Please check your input: %s", $ex->getMessage());
|
||||
// Form cannot be validated
|
||||
$message = $this->createStandardFormValidationErrorMessage($ex);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$message = sprintf("Sorry, an error occured: %s", $ex->getMessage());
|
||||
$message = $ex->getMessage();
|
||||
}
|
||||
|
||||
if ($message !== false) {
|
||||
// Log error message
|
||||
Tlog::getInstance()->error(sprintf("Error during variable modification process : %s. Exception was %s", $message, $ex->getMessage()));
|
||||
|
||||
// Mark the form as errored
|
||||
$changeForm->setErrorMessage($message);
|
||||
|
||||
// Pas the form and the error to the parser
|
||||
$this->getParserContext()
|
||||
->addForm($changeForm)
|
||||
->setGeneralError($message)
|
||||
;
|
||||
}
|
||||
$this->setupFormErrorContext("variable edition", $message, $changeForm, $ex);
|
||||
|
||||
// At this point, the form has errors, and should be redisplayed.
|
||||
return $this->render('variable-edit', array('variable_id' => $variable_id));
|
||||
@@ -314,6 +294,9 @@ class ConfigController extends BaseAdminController
|
||||
|
||||
$this->dispatch(TheliaEvents::CONFIG_DELETE, $event);
|
||||
|
||||
if ($event->hasConfig())
|
||||
$this->adminLogAppend(sprintf("Variable %s (ID %s) modified", $event->getConfig()->getName(), $event->getConfig()->getId()));
|
||||
|
||||
$this->redirectToRoute('admin.configuration.variables.default');
|
||||
}
|
||||
}
|
||||
581
core/lib/Thelia/Controller/Admin/CouponController.php
Executable file
581
core/lib/Thelia/Controller/Admin/CouponController.php
Executable file
@@ -0,0 +1,581 @@
|
||||
<?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 as $rule) {
|
||||
$args['rulesObject'][] = array(
|
||||
'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->getRouteFromRouter(
|
||||
'router.admin',
|
||||
'admin.coupon.rule.input',
|
||||
array('ruleId' => 'ruleId'),
|
||||
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()
|
||||
);
|
||||
}
|
||||
|
||||
// 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->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
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 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;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -108,10 +108,12 @@ class CurrencyController extends BaseAdminController
|
||||
|
||||
$this->dispatch(TheliaEvents::CURRENCY_CREATE, $createEvent);
|
||||
|
||||
if (! $createEvent->hasCurrency()) throw new \LogicException($this->getTranslator()->trans("No currency was created."));
|
||||
|
||||
$createdObject = $createEvent->getCurrency();
|
||||
|
||||
// Log currency creation
|
||||
$this->adminLogAppend(sprintf("Variable %s (ID %s) created", $createdObject->getName(), $createdObject->getId()));
|
||||
$this->adminLogAppend(sprintf("Currency %s (ID %s) created", $createdObject->getName(), $createdObject->getId()));
|
||||
|
||||
// Substitute _ID_ in the URL with the ID of the created object
|
||||
$successUrl = str_replace('_ID_', $createdObject->getId(), $creationForm->getSuccessUrl());
|
||||
@@ -121,26 +123,14 @@ class CurrencyController extends BaseAdminController
|
||||
}
|
||||
catch (FormValidationException $ex) {
|
||||
// Form cannot be validated
|
||||
$error_msg = sprintf("Please check your input: %s", $ex->getMessage());
|
||||
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$error_msg = $ex;
|
||||
$error_msg = $ex->getMessage();
|
||||
}
|
||||
|
||||
if ($error_msg !== false) {
|
||||
// An error has been detected: log it
|
||||
Tlog::getInstance()->error(sprintf("Error during currency creation process : %s. Exception was %s", $error_msg, $ex->getMessage()));
|
||||
|
||||
// Mark the form as errored
|
||||
$creationForm->setErrorMessage($error_msg);
|
||||
|
||||
// Pass it to the parser, along with the error currency
|
||||
$this->getParserContext()
|
||||
->addForm($creationForm)
|
||||
->setGeneralError($error_msg)
|
||||
;
|
||||
}
|
||||
$this->setupFormErrorContext("currency creation", $error_msg, $creationForm, $ex);
|
||||
|
||||
// At this point, the form has error, and should be redisplayed.
|
||||
return $this->renderList();
|
||||
@@ -223,10 +213,12 @@ class CurrencyController extends BaseAdminController
|
||||
|
||||
$this->dispatch(TheliaEvents::CURRENCY_UPDATE, $changeEvent);
|
||||
|
||||
if (! $changeEvent->hasCurrency()) throw new \LogicException($this->getTranslator()->trans("No currency was updated."));
|
||||
|
||||
// Log currency modification
|
||||
$changedObject = $changeEvent->getCurrency();
|
||||
|
||||
$this->adminLogAppend(sprintf("Variable %s (ID %s) modified", $changedObject->getName(), $changedObject->getId()));
|
||||
$this->adminLogAppend(sprintf("Currency %s (ID %s) modified", $changedObject->getName(), $changedObject->getId()));
|
||||
|
||||
// If we have to stay on the same page, do not redirect to the succesUrl,
|
||||
// just redirect to the edit page again.
|
||||
@@ -241,27 +233,15 @@ class CurrencyController extends BaseAdminController
|
||||
$this->redirect($changeForm->getSuccessUrl());
|
||||
}
|
||||
catch (FormValidationException $ex) {
|
||||
// Invalid data entered
|
||||
$error_msg = sprintf("Please check your input: %s", $ex->getMessage());
|
||||
// Form cannot be validated
|
||||
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$error_msg = $ex;
|
||||
$error_msg = $ex->getMessage();
|
||||
}
|
||||
|
||||
if ($error_msg !== false) {
|
||||
// Log error currency
|
||||
Tlog::getInstance()->error(sprintf("Error during currency modification process : %s. Exception was %s", $error_msg, $ex->getMessage()));
|
||||
|
||||
// Mark the form as errored
|
||||
$changeForm->setErrorMessage($error_msg);
|
||||
|
||||
// Pas the form and the error to the parser
|
||||
$this->getParserContext()
|
||||
->addForm($changeForm)
|
||||
->setGeneralError($error_msg)
|
||||
;
|
||||
}
|
||||
$this->setupFormErrorContext("currency modification", $error_msg, $changeForm, $ex);
|
||||
|
||||
// At this point, the form has errors, and should be redisplayed.
|
||||
return $this->render('currency-edit', array('currency_id' => $currency_id));
|
||||
@@ -359,6 +339,9 @@ class CurrencyController extends BaseAdminController
|
||||
|
||||
$this->dispatch(TheliaEvents::CURRENCY_DELETE, $event);
|
||||
|
||||
if ($event->hasCurrency())
|
||||
$this->adminLogAppend(sprintf("Currency %s (ID %s) modified", $event->getCurrency()->getName(), $event->getCurrency()->getId()));
|
||||
|
||||
$this->redirectToRoute('admin.configuration.currencies.default');
|
||||
}
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,15 @@ use Thelia\Form\MessageCreationForm;
|
||||
*/
|
||||
class MessageController extends BaseAdminController
|
||||
{
|
||||
/**
|
||||
* Render the messages list
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
*/
|
||||
protected function renderList() {
|
||||
return $this->render('messages');
|
||||
}
|
||||
|
||||
/**
|
||||
* The default action is displaying the messages list.
|
||||
*
|
||||
@@ -51,7 +60,7 @@ class MessageController extends BaseAdminController
|
||||
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.messages.view")) return $response;
|
||||
|
||||
return $this->render('messages');
|
||||
return $this->renderList();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +75,7 @@ class MessageController extends BaseAdminController
|
||||
|
||||
$message = false;
|
||||
|
||||
// Create the Creation Form
|
||||
// Create the creation Form
|
||||
$creationForm = new MessageCreationForm($this->getRequest());
|
||||
|
||||
try {
|
||||
@@ -87,10 +96,11 @@ class MessageController extends BaseAdminController
|
||||
|
||||
$this->dispatch(TheliaEvents::MESSAGE_CREATE, $createEvent);
|
||||
|
||||
if (! $createEvent->hasMessage()) throw new \LogicException($this->getTranslator()->trans("No message was created."));
|
||||
|
||||
$createdObject = $createEvent->getMessage();
|
||||
|
||||
// Log message creation
|
||||
$this->adminLogAppend(sprintf("Variable %s (ID %s) created", $createdObject->getName(), $createdObject->getId()));
|
||||
$this->adminLogAppend(sprintf("Message %s (ID %s) created", $createdObject->getName(), $createdObject->getId()));
|
||||
|
||||
// Substitute _ID_ in the URL with the ID of the created object
|
||||
$successUrl = str_replace('_ID_', $createdObject->getId(), $creationForm->getSuccessUrl());
|
||||
@@ -100,26 +110,14 @@ class MessageController extends BaseAdminController
|
||||
}
|
||||
catch (FormValidationException $ex) {
|
||||
// Form cannot be validated
|
||||
$message = sprintf("Please check your input: %s", $ex->getMessage());
|
||||
$message = $this->createStandardFormValidationErrorMessage($ex);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$message = sprintf("Sorry, an error occured: %s", $ex->getMessage());
|
||||
$message = $ex->getMessage();
|
||||
}
|
||||
|
||||
if ($message !== false) {
|
||||
// An error has been detected: log it
|
||||
Tlog::getInstance()->error(sprintf("Error during message creation process : %s. Exception was %s", $message, $ex->getMessage()));
|
||||
|
||||
// Mark the form as errored
|
||||
$creationForm->setErrorMessage($message);
|
||||
|
||||
// Pass it to the parser, along with the error message
|
||||
$this->getParserContext()
|
||||
->addForm($creationForm)
|
||||
->setGeneralError($message)
|
||||
;
|
||||
}
|
||||
$this->setupFormErrorContext("message modification", $message, $creationForm, $ex);
|
||||
|
||||
// At this point, the form has error, and should be redisplayed.
|
||||
return $this->render('messages');
|
||||
@@ -206,7 +204,8 @@ class MessageController extends BaseAdminController
|
||||
|
||||
$this->dispatch(TheliaEvents::MESSAGE_UPDATE, $changeEvent);
|
||||
|
||||
// Log message modification
|
||||
if (! $changeEvent->hasMessage()) throw new \LogicException($this->getTranslator()->trans("No message was updated."));
|
||||
|
||||
$changedObject = $changeEvent->getMessage();
|
||||
|
||||
$this->adminLogAppend(sprintf("Variable %s (ID %s) modified", $changedObject->getName(), $changedObject->getId()));
|
||||
@@ -224,27 +223,15 @@ class MessageController extends BaseAdminController
|
||||
$this->redirect($changeForm->getSuccessUrl());
|
||||
}
|
||||
catch (FormValidationException $ex) {
|
||||
// Invalid data entered
|
||||
$message = sprintf("Please check your input: %s", $ex->getMessage());
|
||||
// Form cannot be validated
|
||||
$message = $this->createStandardFormValidationErrorMessage($ex);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$message = sprintf("Sorry, an error occured: %s", $ex->getMessage());
|
||||
$message = $ex->getMessage();
|
||||
}
|
||||
|
||||
if ($message !== false) {
|
||||
// Log error message
|
||||
Tlog::getInstance()->error(sprintf("Error during message modification process : %s. Exception was %s", $message, $ex->getMessage()));
|
||||
|
||||
// Mark the form as errored
|
||||
$changeForm->setErrorMessage($message);
|
||||
|
||||
// Pas the form and the error to the parser
|
||||
$this->getParserContext()
|
||||
->addForm($changeForm)
|
||||
->setGeneralError($message)
|
||||
;
|
||||
}
|
||||
$this->setupFormErrorContext("message modification", $message, $changeForm, $ex);
|
||||
|
||||
// At this point, the form has errors, and should be redisplayed.
|
||||
return $this->render('message-edit', array('message_id' => $message_id));
|
||||
@@ -265,6 +252,9 @@ class MessageController extends BaseAdminController
|
||||
|
||||
$this->dispatch(TheliaEvents::MESSAGE_DELETE, $event);
|
||||
|
||||
$this->redirect(URL::getInstance()->adminViewUrl('messages'));
|
||||
if ($event->hasMessage())
|
||||
$this->adminLogAppend(sprintf("Message %s (ID %s) modified", $event->getMessage()->getName(), $event->getMessage()->getId()));
|
||||
|
||||
$this->redirectToRoute('admin.configuration.messages.default');
|
||||
}
|
||||
}
|
||||
@@ -73,32 +73,34 @@ class SessionController extends BaseAdminController
|
||||
|
||||
// Redirect to the success URL
|
||||
return Redirect::exec($adminLoginForm->getSuccessUrl());
|
||||
} catch (ValidatorException $ex) {
|
||||
|
||||
}
|
||||
catch (FormValidationException $ex) {
|
||||
|
||||
// Validation problem
|
||||
$message = "Missing or invalid information. Please check your input.";
|
||||
} catch (AuthenticationException $ex) {
|
||||
$message = $this->createStandardFormValidationErrorMessage($ex);
|
||||
}
|
||||
catch (AuthenticationException $ex) {
|
||||
|
||||
// Log authentication failure
|
||||
AdminLog::append(sprintf("Authentication failure for username '%s'", $authenticator->getUsername()), $request);
|
||||
|
||||
$message = "Login failed. Please check your username and password.";
|
||||
} catch (\Exception $ex) {
|
||||
$message = $this->getTranslator()->trans("Login failed. Please check your username and password.");
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
|
||||
// Log authentication failure
|
||||
AdminLog::append(sprintf("Undefined error: %s", $ex->getMessage()), $request);
|
||||
|
||||
$message = "Unable to process your request. Please try again.".$ex->getMessage();
|
||||
$message = $this->getTranslator()->trans(
|
||||
"Unable to process your request. Please try again (%err).",
|
||||
array("%err" => $ex->getMessage())
|
||||
);
|
||||
}
|
||||
|
||||
// Store error information in the form
|
||||
$adminLoginForm->setError(true);
|
||||
$adminLoginForm->setErrorMessage($message);
|
||||
|
||||
// Store the form name in session (see Form Smarty plugin to find usage of this parameter)
|
||||
$this->getParserContext()->addForm($adminLoginForm);
|
||||
$this->setupFormErrorContext("Login process", $message, $adminLoginForm, $ex);
|
||||
|
||||
// Display the login form again
|
||||
return $this->render("login");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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());
|
||||
|
||||
56
core/lib/Thelia/Controller/Front/DeliveryController.php
Normal file
56
core/lib/Thelia/Controller/Front/DeliveryController.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?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\Front;
|
||||
use Thelia\Model\ModuleQuery;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
|
||||
/**
|
||||
* Class DeliveryController
|
||||
* @package Thelia\Controller\Front
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class DeliveryController extends BaseFrontController
|
||||
{
|
||||
public function select($delivery_id)
|
||||
{
|
||||
if ($this->getSecurityContext()->hasCustomerUser() === false) {
|
||||
$this->redirect(URL::getInstance()->getIndexPage());
|
||||
}
|
||||
|
||||
$request = $this->getRequest();
|
||||
|
||||
$deliveryModule = ModuleQuery::create()
|
||||
->filterById($delivery_id)
|
||||
->filterByActivate(1)
|
||||
->findOne()
|
||||
;
|
||||
|
||||
if ($deliveryModule) {
|
||||
$request->getSession()->setDelivery($delivery_id);
|
||||
} else {
|
||||
$this->pageNotFound();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
48
core/lib/Thelia/Core/Event/BaseToggleVisibilityEvent.php
Normal file
48
core/lib/Thelia/Core/Event/BaseToggleVisibilityEvent.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?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;
|
||||
|
||||
|
||||
class BaseToggleVisibilityEvent extends ActionEvent
|
||||
{
|
||||
protected $object_id;
|
||||
|
||||
protected $object;
|
||||
|
||||
public function __construct($object_id)
|
||||
{
|
||||
$this->object_id = $object_id;
|
||||
}
|
||||
|
||||
public function getObjectId()
|
||||
{
|
||||
return $this->object_id;
|
||||
}
|
||||
|
||||
public function setObjectId($object_id)
|
||||
{
|
||||
$this->object_id = $object_id;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -25,12 +25,11 @@ namespace Thelia\Core\Event;
|
||||
|
||||
use Thelia\Model\Category;
|
||||
|
||||
class CategoryCreateEvent extends ActionEvent
|
||||
class CategoryCreateEvent extends CategoryEvent
|
||||
{
|
||||
protected $title;
|
||||
protected $parent;
|
||||
protected $locale;
|
||||
protected $created_category;
|
||||
|
||||
public function __construct($title, $parent, $locale)
|
||||
{
|
||||
@@ -47,6 +46,7 @@ class CategoryCreateEvent extends ActionEvent
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getParent()
|
||||
@@ -57,6 +57,7 @@ class CategoryCreateEvent extends ActionEvent
|
||||
public function setParent($parent)
|
||||
{
|
||||
$this->parent = $parent;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLocale()
|
||||
@@ -67,15 +68,6 @@ class CategoryCreateEvent extends ActionEvent
|
||||
public function setLocale($locale)
|
||||
{
|
||||
$this->locale = $locale;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCreatedCategory()
|
||||
{
|
||||
return $this->created_category;
|
||||
}
|
||||
|
||||
public function setCreatedCategory(Category $created_category)
|
||||
{
|
||||
$this->created_category = $created_category;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,13 +22,11 @@
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event;
|
||||
|
||||
use Thelia\Model\Category;
|
||||
|
||||
class CategoryDeleteEvent extends ActionEvent
|
||||
class CategoryDeleteEvent extends CategoryEvent
|
||||
{
|
||||
protected $category_id;
|
||||
protected $deleted_category;
|
||||
|
||||
public function __construct($category_id)
|
||||
{
|
||||
$this->category_id = $category_id;
|
||||
@@ -42,15 +40,6 @@ class CategoryDeleteEvent extends ActionEvent
|
||||
public function setCategoryId($category_id)
|
||||
{
|
||||
$this->category_id = $category_id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDeletedCategory()
|
||||
{
|
||||
return $this->deleted_category;
|
||||
}
|
||||
|
||||
public function setDeletedCategory(Category $deleted_category)
|
||||
{
|
||||
$this->deleted_category = $deleted_category;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,20 +28,26 @@ use Thelia\Core\Event\ActionEvent;
|
||||
|
||||
class CategoryEvent extends ActionEvent
|
||||
{
|
||||
public $category;
|
||||
public $category = null;
|
||||
|
||||
public function __construct(Category $category)
|
||||
public function __construct(Category $category = null)
|
||||
{
|
||||
$this->category = $category;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\Model\Category
|
||||
*/
|
||||
public function hasCategory() {
|
||||
return ! is_null($this->category);
|
||||
}
|
||||
|
||||
public function getCategory()
|
||||
{
|
||||
return $this->category;
|
||||
}
|
||||
|
||||
public function setCategory(Category $category)
|
||||
{
|
||||
$this->category = $category;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,35 +22,7 @@
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event;
|
||||
use Thelia\Model\Category;
|
||||
|
||||
class CategoryToggleVisibilityEvent extends ActionEvent
|
||||
class CategoryToggleVisibilityEvent extends BaseToggleVisibilityEvent
|
||||
{
|
||||
protected $category_id;
|
||||
protected $category;
|
||||
|
||||
public function __construct($category_id)
|
||||
{
|
||||
$this->category_id = $category_id;
|
||||
}
|
||||
|
||||
public function getCategoryId()
|
||||
{
|
||||
return $this->category_id;
|
||||
}
|
||||
|
||||
public function setCategoryId($category_id)
|
||||
{
|
||||
$this->category_id = $category_id;
|
||||
}
|
||||
|
||||
public function getCategory()
|
||||
{
|
||||
return $this->category;
|
||||
}
|
||||
|
||||
public function setCategory(Category $category)
|
||||
{
|
||||
$this->category = $category;
|
||||
}
|
||||
}
|
||||
@@ -22,17 +22,16 @@
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event;
|
||||
|
||||
use Thelia\Model\Category;
|
||||
|
||||
class CategoryUpdateEvent extends ActionEvent
|
||||
class CategoryUpdateEvent extends CategoryCreateEvent
|
||||
{
|
||||
protected $category_id;
|
||||
protected $locale;
|
||||
protected $title;
|
||||
|
||||
protected $chapo;
|
||||
protected $description;
|
||||
protected $postscriptum;
|
||||
|
||||
protected $url;
|
||||
protected $visibility;
|
||||
protected $parent;
|
||||
@@ -41,4 +40,81 @@ class CategoryUpdateEvent extends ActionEvent
|
||||
{
|
||||
$this->category_id = $category_id;
|
||||
}
|
||||
|
||||
public function getCategoryId()
|
||||
{
|
||||
return $this->category_id;
|
||||
}
|
||||
|
||||
public function setCategoryId($category_id)
|
||||
{
|
||||
$this->category_id = $category_id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getChapo()
|
||||
{
|
||||
return $this->chapo;
|
||||
}
|
||||
|
||||
public function setChapo($chapo)
|
||||
{
|
||||
$this->chapo = $chapo;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function setDescription($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPostscriptum()
|
||||
{
|
||||
return $this->postscriptum;
|
||||
}
|
||||
|
||||
public function setPostscriptum($postscriptum)
|
||||
{
|
||||
$this->postscriptum = $postscriptum;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUrl()
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
public function setUrl($url)
|
||||
{
|
||||
$this->url = $url;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getVisibility()
|
||||
{
|
||||
return $this->visibility;
|
||||
}
|
||||
|
||||
public function setVisibility($visibility)
|
||||
{
|
||||
$this->visibility = $visibility;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
public function setParent($parent)
|
||||
{
|
||||
$this->parent = $parent;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,6 @@
|
||||
|
||||
namespace Thelia\Core\Event;
|
||||
|
||||
class CurrencyUpdatePositionEvent extends BaseUpdatePositionEvent
|
||||
class CategoryUpdatePositionEvent extends BaseUpdatePositionEvent
|
||||
{
|
||||
}
|
||||
@@ -26,13 +26,17 @@ use Thelia\Model\Config;
|
||||
|
||||
class ConfigEvent extends ActionEvent
|
||||
{
|
||||
protected $config;
|
||||
protected $config = null;
|
||||
|
||||
public function __construct(Config $config = null)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function hasConfig() {
|
||||
return ! is_null($this->config);
|
||||
}
|
||||
|
||||
public function getConfig()
|
||||
{
|
||||
return $this->config;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -26,13 +26,17 @@ use Thelia\Model\Currency;
|
||||
|
||||
class CurrencyEvent extends ActionEvent
|
||||
{
|
||||
protected $currency;
|
||||
protected $currency = null;
|
||||
|
||||
public function __construct(Currency $currency = null)
|
||||
{
|
||||
$this->currency = $currency;
|
||||
}
|
||||
|
||||
public function hasCurrency() {
|
||||
return ! is_null($this->currency);
|
||||
}
|
||||
|
||||
public function getCurrency()
|
||||
{
|
||||
return $this->currency;
|
||||
|
||||
@@ -26,13 +26,17 @@ use Thelia\Model\Message;
|
||||
|
||||
class MessageEvent extends ActionEvent
|
||||
{
|
||||
protected $message;
|
||||
protected $message = null;
|
||||
|
||||
public function __construct(Message $message = null)
|
||||
{
|
||||
$this->message = $message;
|
||||
}
|
||||
|
||||
public function hasMessage() {
|
||||
return ! is_null($this->message);
|
||||
}
|
||||
|
||||
public function getMessage()
|
||||
{
|
||||
return $this->message;
|
||||
|
||||
@@ -33,6 +33,11 @@ namespace Thelia\Core\Event;
|
||||
final class TheliaEvents
|
||||
{
|
||||
|
||||
/**
|
||||
* sent at the beginning
|
||||
*/
|
||||
const BOOT = "thelia.boot";
|
||||
|
||||
/**
|
||||
* ACTION event
|
||||
*
|
||||
@@ -199,6 +204,130 @@ 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 create Coupon Rule
|
||||
*/
|
||||
const COUPON_RULE_CREATE = "action.create_coupon_rule";
|
||||
|
||||
/**
|
||||
* Sent just before an attempt to create a Coupon Rule
|
||||
*/
|
||||
const BEFORE_COUPON_RULE_CREATE = "action.before_create_coupon_rule";
|
||||
|
||||
/**
|
||||
* Sent just after an attempt to create a Coupon Rule
|
||||
*/
|
||||
const AFTER_COUPON_RULE_CREATE = "action.after_create_coupon_rule";
|
||||
|
||||
/**
|
||||
* 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)
|
||||
@@ -164,10 +175,28 @@ class Session extends BaseSession
|
||||
* assign cart id in session
|
||||
*
|
||||
* @param $cart_id
|
||||
* @return $this
|
||||
*/
|
||||
public function setCart($cart_id)
|
||||
{
|
||||
$this->set("thelia.cart_id", $cart_id);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* assign delivery id in session
|
||||
*
|
||||
* @param $delivery_id
|
||||
* @return $this
|
||||
*/
|
||||
public function setDelivery($delivery_id)
|
||||
{
|
||||
$this->set("thelia.delivery_id", $delivery_id);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDelivery()
|
||||
{
|
||||
return $this->get("thelia.delivery_id");
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -243,23 +247,9 @@ abstract class BaseLoop
|
||||
*
|
||||
* this function have to be implement in your own loop class.
|
||||
*
|
||||
* All your parameters are defined in defineArgs() and can be accessible like a class property.
|
||||
* All loops parameters can be accessible via getter.
|
||||
*
|
||||
* example :
|
||||
*
|
||||
* public function defineArgs()
|
||||
* {
|
||||
* return array (
|
||||
* "ref",
|
||||
* "id" => "optional",
|
||||
* "stock" => array(
|
||||
* "optional",
|
||||
* "default" => 10
|
||||
* )
|
||||
* );
|
||||
* }
|
||||
*
|
||||
* you can retrieve ref value using $this->ref
|
||||
* for example, ref parameter is accessible through getRef method
|
||||
*
|
||||
* @param $pagination
|
||||
*
|
||||
@@ -271,18 +261,31 @@ abstract class BaseLoop
|
||||
*
|
||||
* define all args used in your loop
|
||||
*
|
||||
* array key is your arg name.
|
||||
*
|
||||
* example :
|
||||
*
|
||||
* return array (
|
||||
* "ref",
|
||||
* "id" => "optional",
|
||||
* "stock" => array(
|
||||
* "optional",
|
||||
* "default" => 10
|
||||
* )
|
||||
* );
|
||||
* public function getArgDefinitions()
|
||||
* {
|
||||
* return new ArgumentCollection(
|
||||
* Argument::createIntListTypeArgument('id'),
|
||||
* new Argument(
|
||||
* 'ref',
|
||||
* new TypeCollection(
|
||||
* new Type\AlphaNumStringListType()
|
||||
* )
|
||||
* ),
|
||||
* Argument::createIntListTypeArgument('category'),
|
||||
* Argument::createBooleanTypeArgument('new'),
|
||||
* Argument::createBooleanTypeArgument('promo'),
|
||||
* Argument::createFloatTypeArgument('min_price'),
|
||||
* Argument::createFloatTypeArgument('max_price'),
|
||||
* Argument::createIntTypeArgument('min_stock'),
|
||||
* Argument::createFloatTypeArgument('min_weight'),
|
||||
* Argument::createFloatTypeArgument('max_weight'),
|
||||
* Argument::createBooleanTypeArgument('current'),
|
||||
*
|
||||
* );
|
||||
* }
|
||||
*
|
||||
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection
|
||||
*/
|
||||
|
||||
@@ -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 {
|
||||
|
||||
109
core/lib/Thelia/Core/Template/Loop/BaseSpecificModule.php
Normal file
109
core/lib/Thelia/Core/Template/Loop/BaseSpecificModule.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?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\Core\Template\Element\BaseI18nLoop;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Model\ModuleQuery;
|
||||
|
||||
|
||||
/**
|
||||
* Class Delivery
|
||||
* @package Thelia\Core\Template\Loop
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class BaseSpecificModule extends BaseI18nLoop {
|
||||
public $timestampable = true;
|
||||
|
||||
/**
|
||||
*
|
||||
* define all args used in your loop
|
||||
*
|
||||
*
|
||||
* example :
|
||||
*
|
||||
* public function getArgDefinitions()
|
||||
* {
|
||||
* return new ArgumentCollection(
|
||||
* Argument::createIntListTypeArgument('id'),
|
||||
* new Argument(
|
||||
* 'ref',
|
||||
* new TypeCollection(
|
||||
* new Type\AlphaNumStringListType()
|
||||
* )
|
||||
* ),
|
||||
* Argument::createIntListTypeArgument('category'),
|
||||
* Argument::createBooleanTypeArgument('new'),
|
||||
* Argument::createBooleanTypeArgument('promo'),
|
||||
* Argument::createFloatTypeArgument('min_price'),
|
||||
* Argument::createFloatTypeArgument('max_price'),
|
||||
* Argument::createIntTypeArgument('min_stock'),
|
||||
* Argument::createFloatTypeArgument('min_weight'),
|
||||
* Argument::createFloatTypeArgument('max_weight'),
|
||||
* Argument::createBooleanTypeArgument('current'),
|
||||
*
|
||||
* );
|
||||
* }
|
||||
*
|
||||
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection
|
||||
*/
|
||||
protected function getArgDefinitions()
|
||||
{
|
||||
return new ArgumentCollection(
|
||||
Argument::createIntTypeArgument('id'),
|
||||
Argument::createIntListTypeArgument('exclude')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* this function have to be implement in your own loop class.
|
||||
*
|
||||
* All loops parameters can be accesible via getter.
|
||||
*
|
||||
* for example, ref parameter is accessible through getRef method
|
||||
*
|
||||
* @param $pagination
|
||||
*
|
||||
* @return \Thelia\Model\ModuleQuery
|
||||
*/
|
||||
public function exec(&$pagination)
|
||||
{
|
||||
$search = ModuleQuery::create();
|
||||
|
||||
if(null !== $id = $this->getId())
|
||||
{
|
||||
$search->filterById($id);
|
||||
}
|
||||
|
||||
|
||||
if (null !== $exclude = $this->getExclude()) {
|
||||
$search->filterById($exclude, Criteria::NOT_IN);
|
||||
}
|
||||
|
||||
return $search;
|
||||
}
|
||||
|
||||
}
|
||||
110
core/lib/Thelia/Core/Template/Loop/Coupon.php
Executable file
110
core/lib/Thelia/Core/Template/Loop/Coupon.php
Executable file
@@ -0,0 +1,110 @@
|
||||
<?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\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 MCoupon $coupon */
|
||||
foreach ($coupons as $coupon) {
|
||||
$loopResultRow = new LoopResultRow();
|
||||
$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())
|
||||
->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", $coupon->getRules());
|
||||
$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);
|
||||
}
|
||||
|
||||
|
||||
85
core/lib/Thelia/Core/Template/Loop/Delivery.php
Normal file
85
core/lib/Thelia/Core/Template/Loop/Delivery.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?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 Thelia\Core\Template\Element\LoopResult;
|
||||
use Thelia\Core\Template\Element\LoopResultRow;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
|
||||
|
||||
/**
|
||||
* Class Delivery
|
||||
* @package Thelia\Core\Template\Loop
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class Delivery extends BaseSpecificModule
|
||||
{
|
||||
|
||||
public function getArgDefinitions()
|
||||
{
|
||||
$collection = parent::getArgDefinitions();
|
||||
|
||||
$collection->addArgument(
|
||||
Argument::createIntTypeArgument("country")
|
||||
);
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
public function exec(&$pagination)
|
||||
{
|
||||
$search = parent::exec($pagination);
|
||||
/* manage translations */
|
||||
$locale = $this->configureI18nProcessing($search);
|
||||
/* perform search */
|
||||
$deliveryModules = $this->search($search, $pagination);
|
||||
|
||||
$loopResult = new LoopResult($deliveryModules);
|
||||
|
||||
foreach ($deliveryModules as $deliveryModule) {
|
||||
$loopResultRow = new LoopResultRow($loopResult, $deliveryModule, $this->versionable, $this->timestampable, $this->countable);
|
||||
|
||||
$moduleReflection = new \ReflectionClass($deliveryModule->getFullNamespace());
|
||||
if($moduleReflection->isSubclassOf("Thelia\Module\DeliveryModuleInterface") === false) {
|
||||
throw new \RuntimeException(sprintf("delivery module %s is not a Thelia\Module\DeliveryModuleInterface", $deliveryModule->getCode()));
|
||||
}
|
||||
$moduleInstance = $moduleReflection->newInstance();
|
||||
|
||||
$moduleInstance->setRequest($this->request);
|
||||
$moduleInstance->setDispatcher($this->dispatcher);
|
||||
|
||||
$loopResultRow
|
||||
->set('ID', $deliveryModule->getId())
|
||||
->set('TITLE', $deliveryModule->getVirtualColumn('i18n_TITLE'))
|
||||
->set('CHAPO', $deliveryModule->getVirtualColumn('i18n_CHAPO'))
|
||||
->set('DESCRIPTION', $deliveryModule->getVirtualColumn('i18n_DESCRIPTION'))
|
||||
->set('POSTSCRIPTUM', $deliveryModule->getVirtualColumn('i18n_POSTSCRIPTUM'))
|
||||
->set('PRICE', $moduleInstance->calculate($this->getCountry()))
|
||||
;
|
||||
|
||||
$loopResult->addRow($loopResultRow);
|
||||
}
|
||||
|
||||
return $loopResult;
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -293,13 +302,11 @@ class TheliaLoop extends AbstractSmartyPlugin
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $smartyParams
|
||||
*
|
||||
* find the loop class with his name and construct an instance of this class
|
||||
*
|
||||
* @param string $name
|
||||
* @return \Thelia\Core\Template\Element\BaseLoop
|
||||
* @throws InvalidElementException
|
||||
* @throws ElementNotFoundException
|
||||
* @return object
|
||||
* @throws \Thelia\Core\Template\Element\Exception\InvalidElementException
|
||||
* @throws \Thelia\Core\Template\Element\Exception\ElementNotFoundException
|
||||
*/
|
||||
protected function createLoopInstance($smartyParams)
|
||||
{
|
||||
@@ -317,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_object($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;
|
||||
|
||||
@@ -33,12 +33,15 @@ namespace Thelia\Core;
|
||||
*/
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\HttpKernel\Kernel;
|
||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||
use Symfony\Component\Validator\Tests\Fixtures\Reference;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||
|
||||
use Thelia\Core\Bundle;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Log\Tlog;
|
||||
use Thelia\Config\DatabaseConfiguration;
|
||||
use Thelia\Config\DefinePropel;
|
||||
@@ -73,7 +76,6 @@ class Thelia extends Kernel
|
||||
|
||||
$definePropel = new DefinePropel(new DatabaseConfiguration(),
|
||||
Yaml::parse(THELIA_ROOT . '/local/config/database.yml'));
|
||||
$propelConfig = $definePropel->getConfig();
|
||||
$serviceContainer = Propel::getServiceContainer();
|
||||
$serviceContainer->setAdapterClass('thelia', 'mysql');
|
||||
$manager = new ConnectionManagerSingle();
|
||||
@@ -81,13 +83,21 @@ class Thelia extends Kernel
|
||||
$serviceContainer->setConnectionManager('thelia', $manager);
|
||||
|
||||
if ($this->isDebug()) {
|
||||
$serviceContainer->setLogger('defaultLogger', Tlog::getInstance());
|
||||
|
||||
$con = Propel::getConnection(\Thelia\Model\Map\ProductTableMap::DATABASE_NAME);
|
||||
$con->useDebug(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* dispatch an event when application is boot
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
$this->getContainer()->get("event_dispatcher")->dispatch(TheliaEvents::BOOT);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Load some configuration
|
||||
@@ -107,6 +117,16 @@ class Thelia extends Kernel
|
||||
foreach ($modules as $module) {
|
||||
|
||||
try {
|
||||
|
||||
$defintion = new Definition();
|
||||
$defintion->setClass($module->getFullNamespace());
|
||||
$defintion->addMethodCall("setContainer", array('service_container'));
|
||||
|
||||
$container->setDefinition(
|
||||
"module.".$module->getCode(),
|
||||
$defintion
|
||||
);
|
||||
|
||||
$loader = new XmlFileLoader($container, new FileLocator(THELIA_MODULE_DIR . "/" . ucfirst($module->getCode()) . "/Config"));
|
||||
$loader->load("config.xml");
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
|
||||
@@ -127,14 +127,34 @@ class TheliaHttpKernel extends HttpKernel
|
||||
// See Thelia\Tools\URL class.
|
||||
$this->container->get('thelia.url.manager');
|
||||
|
||||
// Same thing for the Translator service.
|
||||
$this->container->get('thelia.translator');
|
||||
|
||||
$lang = $this->detectLang($request);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,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.
|
||||
@@ -172,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
|
||||
@@ -180,7 +200,7 @@ class TheliaHttpKernel extends HttpKernel
|
||||
}
|
||||
|
||||
//find default lang
|
||||
return Model\LangQuery::create()->findOneByByDefault(1);
|
||||
return Model\Lang::getDefaultLanguage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,29 @@ use Symfony\Component\Translation\Translator as BaseTranslator;
|
||||
|
||||
class Translator extends BaseTranslator
|
||||
{
|
||||
|
||||
protected static $instance = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// Allow singleton style calls once intanciated.
|
||||
// For this to work, the Translator service has to be instanciated very early. This is done manually
|
||||
// in TheliaHttpKernel, by calling $this->container->get('thelia.translator');
|
||||
self::$instance = $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this class instance, only once instanciated.
|
||||
*
|
||||
* @throws \RuntimeException if the class has not been instanciated.
|
||||
* @return \Thelia\Core\Translation\Translator the instance.
|
||||
*/
|
||||
public static function getInstance() {
|
||||
if (self::$instance == null) throw new \RuntimeException("Translator instance is not initialized.");
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
@@ -21,7 +44,7 @@ class Translator extends BaseTranslator
|
||||
}
|
||||
|
||||
if ($this->catalogues[$locale]->has((string) $id, $domain))
|
||||
return parent::trans($id, $parameters, $domain = 'messages', $locale = null);
|
||||
return parent::trans($id, $parameters, $domain, $locale);
|
||||
else
|
||||
return strtr($id, $parameters);
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user