Merge branch 'master' into catalog
This commit is contained in:
@@ -13,3 +13,5 @@ before_script:
|
||||
- sh -c "mysql -u$DB_USER -e 'SET FOREIGN_KEY_CHECKS = 0; DROP DATABASE IF EXISTS thelia;SET FOREIGN_KEY_CHECKS = 1;'; fi"
|
||||
- php Thelia thelia:install --db_host=localhost --db_username=$DB_USER --db_name=thelia
|
||||
- php install/faker.php
|
||||
- php Thelia module:activate Colissimo
|
||||
- php Thelia module:activate Cheque
|
||||
@@ -5,10 +5,10 @@ Thelia
|
||||
------
|
||||
[](https://travis-ci.org/thelia/thelia)
|
||||
|
||||
Thelia is an open source tool for creating e-business websites and managing online content. This software is published under GPL.
|
||||
[Thelia](http://thelia.net) is an open source tool for creating e-business websites and managing online content. This software is published under GPL.
|
||||
|
||||
Here is the current developping next major version. You can download this version for testing or see the code.
|
||||
Here is the most recent developed code for the next major version (v2). You can download this version for testing or having a look on the code (or anything you wish, respecting GPL).
|
||||
Here is the most recent developed code for the next major version (v2). You can download this version for testing or having a look on the code (or anything you wish, respecting GPL). See http://thelia.net/v2 web site for more information.
|
||||
|
||||
Most part of the code can possibly change, a large part will be refactor soon, graphical setup does not exist yet.
|
||||
|
||||
|
||||
36
composer.lock
generated
36
composer.lock
generated
@@ -214,12 +214,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/propelorm/Propel2.git",
|
||||
"reference": "58a25ded43c3d04313cad2b738342d307988b1b5"
|
||||
"reference": "fb9a10939abdd6efea7a066f0ef28f82ad06e435"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/propelorm/Propel2/zipball/58a25ded43c3d04313cad2b738342d307988b1b5",
|
||||
"reference": "58a25ded43c3d04313cad2b738342d307988b1b5",
|
||||
"url": "https://api.github.com/repos/propelorm/Propel2/zipball/fb9a10939abdd6efea7a066f0ef28f82ad06e435",
|
||||
"reference": "fb9a10939abdd6efea7a066f0ef28f82ad06e435",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -266,7 +266,7 @@
|
||||
"orm",
|
||||
"persistence"
|
||||
],
|
||||
"time": "2013-09-01 13:29:51"
|
||||
"time": "2013-09-30 08:26:26"
|
||||
},
|
||||
{
|
||||
"name": "psr/log",
|
||||
@@ -845,17 +845,17 @@
|
||||
},
|
||||
{
|
||||
"name": "symfony/finder",
|
||||
"version": "v2.3.4",
|
||||
"version": "v2.3.5",
|
||||
"target-dir": "Symfony/Component/Finder",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/Finder.git",
|
||||
"reference": "4a0fee5b86f5bbd9dfdc11ec124eba2915737ce1"
|
||||
"reference": "a175521f680b178e63c5d0ab87c6b046c0990c3f"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/Finder/zipball/4a0fee5b86f5bbd9dfdc11ec124eba2915737ce1",
|
||||
"reference": "4a0fee5b86f5bbd9dfdc11ec124eba2915737ce1",
|
||||
"url": "https://api.github.com/repos/symfony/Finder/zipball/a175521f680b178e63c5d0ab87c6b046c0990c3f",
|
||||
"reference": "a175521f680b178e63c5d0ab87c6b046c0990c3f",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -888,7 +888,7 @@
|
||||
],
|
||||
"description": "Symfony Finder Component",
|
||||
"homepage": "http://symfony.com",
|
||||
"time": "2013-08-13 20:18:00"
|
||||
"time": "2013-09-19 09:45:20"
|
||||
},
|
||||
{
|
||||
"name": "symfony/form",
|
||||
@@ -1769,12 +1769,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
|
||||
"reference": "0e9958c459d675fb497d8dc5001c91d335734e48"
|
||||
"reference": "1.2.12"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/0e9958c459d675fb497d8dc5001c91d335734e48",
|
||||
"reference": "0e9958c459d675fb497d8dc5001c91d335734e48",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/1.2.12",
|
||||
"reference": "1.2.12",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -1963,12 +1963,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/sebastianbergmann/php-token-stream.git",
|
||||
"reference": "31babf400e5b5868573bf49a000a3519d3978233"
|
||||
"reference": "1.2.0"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/31babf400e5b5868573bf49a000a3519d3978233",
|
||||
"reference": "31babf400e5b5868573bf49a000a3519d3978233",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/1.2.0",
|
||||
"reference": "1.2.0",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -2013,12 +2013,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/sebastianbergmann/phpunit.git",
|
||||
"reference": "af7b77ccb5c64458bdfca95665d29558d1df7d08"
|
||||
"reference": "3.7.24"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/af7b77ccb5c64458bdfca95665d29558d1df7d08",
|
||||
"reference": "af7b77ccb5c64458bdfca95665d29558d1df7d08",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3.7.24",
|
||||
"reference": "3.7.24",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
||||
@@ -25,8 +25,8 @@ namespace Thelia\Action;
|
||||
use Propel\Runtime\Exception\PropelException;
|
||||
use Propel\Runtime\Propel;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Core\Event\AddressCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\AddressEvent;
|
||||
use Thelia\Core\Event\Address\AddressCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\Address\AddressEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Model\Address as AddressModel;
|
||||
use Thelia\Model\Map\AddressTableMap;
|
||||
@@ -86,14 +86,14 @@ class Address extends BaseAction implements EventSubscriberInterface
|
||||
->save()
|
||||
;
|
||||
|
||||
if($event->getIsDefault()) {
|
||||
if ($event->getIsDefault()) {
|
||||
$addressModel->makeItDefault();
|
||||
}
|
||||
|
||||
$event->setAddress($addressModel);
|
||||
$con->commit();
|
||||
|
||||
} catch(PropelException $e) {
|
||||
} catch (PropelException $e) {
|
||||
$con->rollback();
|
||||
throw $e;
|
||||
}
|
||||
|
||||
@@ -30,15 +30,11 @@ use Thelia\Model\Attribute as AttributeModel;
|
||||
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
|
||||
use Thelia\Core\Event\AttributeUpdateEvent;
|
||||
use Thelia\Core\Event\AttributeCreateEvent;
|
||||
use Thelia\Core\Event\AttributeDeleteEvent;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Model\AttributeAv;
|
||||
use Thelia\Model\AttributeAvQuery;
|
||||
use Thelia\Core\Event\Attribute\AttributeUpdateEvent;
|
||||
use Thelia\Core\Event\Attribute\AttributeCreateEvent;
|
||||
use Thelia\Core\Event\Attribute\AttributeDeleteEvent;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Core\Event\CategoryEvent;
|
||||
use Thelia\Core\Event\AttributeEvent;
|
||||
use Thelia\Core\Event\Attribute\AttributeEvent;
|
||||
use Thelia\Model\AttributeTemplate;
|
||||
use Thelia\Model\AttributeTemplateQuery;
|
||||
use Thelia\Model\TemplateQuery;
|
||||
@@ -130,7 +126,7 @@ class Attribute extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
$templates = TemplateQuery::create()->find();
|
||||
|
||||
foreach($templates as $template) {
|
||||
foreach ($templates as $template) {
|
||||
|
||||
$attribute_template = new AttributeTemplate();
|
||||
|
||||
@@ -171,4 +167,4 @@ class Attribute extends BaseAction implements EventSubscriberInterface
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,10 +30,9 @@ use Thelia\Model\AttributeAv as AttributeAvModel;
|
||||
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
|
||||
use Thelia\Core\Event\AttributeAvUpdateEvent;
|
||||
use Thelia\Core\Event\AttributeAvCreateEvent;
|
||||
use Thelia\Core\Event\AttributeAvDeleteEvent;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Core\Event\Attribute\AttributeAvUpdateEvent;
|
||||
use Thelia\Core\Event\Attribute\AttributeAvCreateEvent;
|
||||
use Thelia\Core\Event\Attribute\AttributeAvDeleteEvent;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
|
||||
class AttributeAv extends BaseAction implements EventSubscriberInterface
|
||||
@@ -63,7 +62,7 @@ class AttributeAv extends BaseAction implements EventSubscriberInterface
|
||||
/**
|
||||
* Change a product attribute
|
||||
*
|
||||
* @param AttributeAvUpdateEvent $event
|
||||
* @param \Thelia\Core\Event\Attribute\AttributeAvUpdateEvent $event
|
||||
*/
|
||||
public function update(AttributeAvUpdateEvent $event)
|
||||
{
|
||||
@@ -115,7 +114,6 @@ class AttributeAv extends BaseAction implements EventSubscriberInterface
|
||||
return $this->genericUpdatePosition(AttributeAvQuery::create(), $event);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -128,4 +126,4 @@ class AttributeAv extends BaseAction implements EventSubscriberInterface
|
||||
TheliaEvents::ATTRIBUTE_AV_UPDATE_POSITION => array("updatePosition", 128),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ namespace Thelia\Action;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Thelia\Model\AdminLog;
|
||||
use Propel\Runtime\ActiveQuery\PropelQuery;
|
||||
use Propel\Runtime\ActiveQuery\ModelCriteria;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
|
||||
@@ -50,7 +49,6 @@ class BaseAction
|
||||
return $this->container->get('event_dispatcher');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Changes object position, selecting absolute ou relative change.
|
||||
*
|
||||
|
||||
@@ -23,10 +23,7 @@
|
||||
|
||||
namespace Thelia\Action;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
use Thelia\Core\Event\CachedFileEvent;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
/**
|
||||
@@ -50,7 +47,7 @@ abstract class BaseCachedFile extends BaseAction
|
||||
/**
|
||||
* @return string root of the file cache directory in web space
|
||||
*/
|
||||
protected abstract function getCacheDirFromWebRoot();
|
||||
abstract protected function getCacheDirFromWebRoot();
|
||||
|
||||
/**
|
||||
* Clear the file cache. Is a subdirectory is specified, only this directory is cleared.
|
||||
@@ -104,9 +101,9 @@ abstract class BaseCachedFile extends BaseAction
|
||||
/**
|
||||
* Return the full path of the cached file
|
||||
*
|
||||
* @param string $subdir the subdirectory related to cache base
|
||||
* @param string $filename the filename
|
||||
* @param string $hashed_options a hash of transformation options, or null if no transformations have been applied
|
||||
* @param string $subdir the subdirectory related to cache base
|
||||
* @param string $filename the filename
|
||||
* @param string $hashed_options a hash of transformation options, or null if no transformations have been applied
|
||||
* @param boolean $forceOriginalDocument if true, the original file path in the cache dir is returned.
|
||||
* @return string the cache directory path relative to Web Root
|
||||
*/
|
||||
@@ -175,4 +172,4 @@ abstract class BaseCachedFile extends BaseAction
|
||||
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Thelia\Action;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Core\Event\CartEvent;
|
||||
use Thelia\Core\Event\Cart\CartEvent;
|
||||
use Thelia\Model\ProductPrice;
|
||||
use Thelia\Model\ProductPriceQuery;
|
||||
use Thelia\Model\CartItem;
|
||||
@@ -45,7 +45,7 @@ class Cart extends BaseAction implements EventSubscriberInterface
|
||||
/**
|
||||
*
|
||||
* add an article in the current cart
|
||||
* @param \Thelia\Core\Event\CartEvent $event
|
||||
* @param \Thelia\Core\Event\Cart\CartEvent $event
|
||||
*/
|
||||
public function addItem(CartEvent $event)
|
||||
{
|
||||
@@ -77,7 +77,7 @@ class Cart extends BaseAction implements EventSubscriberInterface
|
||||
*
|
||||
* Delete specify article present into cart
|
||||
*
|
||||
* @param \Thelia\Core\Event\CartEvent $event
|
||||
* @param \Thelia\Core\Event\Cart\CartEvent $event
|
||||
*/
|
||||
public function deleteItem(CartEvent $event)
|
||||
{
|
||||
@@ -97,7 +97,7 @@ class Cart extends BaseAction implements EventSubscriberInterface
|
||||
*
|
||||
* don't use Form here just test the Request.
|
||||
*
|
||||
* @param \Thelia\Core\Event\CartEvent $event
|
||||
* @param \Thelia\Core\Event\Cart\CartEvent $event
|
||||
*/
|
||||
public function changeItem(CartEvent $event)
|
||||
{
|
||||
|
||||
@@ -30,14 +30,13 @@ use Thelia\Model\Category as CategoryModel;
|
||||
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
|
||||
use Thelia\Core\Event\CategoryUpdateEvent;
|
||||
use Thelia\Core\Event\CategoryCreateEvent;
|
||||
use Thelia\Core\Event\CategoryDeleteEvent;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Core\Event\Category\CategoryUpdateEvent;
|
||||
use Thelia\Core\Event\Category\CategoryCreateEvent;
|
||||
use Thelia\Core\Event\Category\CategoryDeleteEvent;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Core\Event\CategoryToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\CategoryAddContentEvent;
|
||||
use Thelia\Core\Event\CategoryDeleteContentEvent;
|
||||
use Thelia\Core\Event\Category\CategoryToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\Category\CategoryAddContentEvent;
|
||||
use Thelia\Core\Event\Category\CategoryDeleteContentEvent;
|
||||
use Thelia\Model\CategoryAssociatedContent;
|
||||
use Thelia\Model\CategoryAssociatedContentQuery;
|
||||
|
||||
@@ -46,7 +45,7 @@ class Category extends BaseAction implements EventSubscriberInterface
|
||||
/**
|
||||
* Create a new category entry
|
||||
*
|
||||
* @param CategoryCreateEvent $event
|
||||
* @param \Thelia\Core\Event\Category\CategoryCreateEvent $event
|
||||
*/
|
||||
public function create(CategoryCreateEvent $event)
|
||||
{
|
||||
@@ -69,7 +68,7 @@ class Category extends BaseAction implements EventSubscriberInterface
|
||||
/**
|
||||
* Change a category
|
||||
*
|
||||
* @param CategoryUpdateEvent $event
|
||||
* @param \Thelia\Core\Event\Category\CategoryUpdateEvent $event
|
||||
*/
|
||||
public function update(CategoryUpdateEvent $event)
|
||||
{
|
||||
@@ -98,7 +97,7 @@ class Category extends BaseAction implements EventSubscriberInterface
|
||||
/**
|
||||
* Delete a category entry
|
||||
*
|
||||
* @param CategoryDeleteEvent $event
|
||||
* @param \Thelia\Core\Event\Category\CategoryDeleteEvent $event
|
||||
*/
|
||||
public function delete(CategoryDeleteEvent $event)
|
||||
{
|
||||
@@ -139,8 +138,8 @@ class Category extends BaseAction implements EventSubscriberInterface
|
||||
return $this->genericUpdatePosition(CategoryQuery::create(), $event);
|
||||
}
|
||||
|
||||
public function addContent(CategoryAddContentEvent $event) {
|
||||
|
||||
public function addContent(CategoryAddContentEvent $event)
|
||||
{
|
||||
if (CategoryAssociatedContentQuery::create()
|
||||
->filterByContentId($event->getContentId())
|
||||
->filterByCategory($event->getCategory())->count() <= 0) {
|
||||
@@ -156,8 +155,8 @@ class Category extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function removeContent(CategoryDeleteContentEvent $event) {
|
||||
|
||||
public function removeContent(CategoryDeleteContentEvent $event)
|
||||
{
|
||||
$content = CategoryAssociatedContentQuery::create()
|
||||
->filterByContentId($event->getContentId())
|
||||
->filterByCategory($event->getCategory())->findOne()
|
||||
@@ -170,7 +169,6 @@ class Category extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
||||
@@ -29,16 +29,16 @@ use Thelia\Model\Config as ConfigModel;
|
||||
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
|
||||
use Thelia\Core\Event\ConfigUpdateEvent;
|
||||
use Thelia\Core\Event\ConfigCreateEvent;
|
||||
use Thelia\Core\Event\ConfigDeleteEvent;
|
||||
use Thelia\Core\Event\Config\ConfigUpdateEvent;
|
||||
use Thelia\Core\Event\Config\ConfigCreateEvent;
|
||||
use Thelia\Core\Event\Config\ConfigDeleteEvent;
|
||||
|
||||
class Config extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* Create a new configuration entry
|
||||
*
|
||||
* @param ConfigCreateEvent $event
|
||||
* @param \Thelia\Core\Event\Config\ConfigCreateEvent $event
|
||||
*/
|
||||
public function create(ConfigCreateEvent $event)
|
||||
{
|
||||
@@ -54,7 +54,7 @@ class Config extends BaseAction implements EventSubscriberInterface
|
||||
/**
|
||||
* Change a configuration entry value
|
||||
*
|
||||
* @param ConfigUpdateEvent $event
|
||||
* @param \Thelia\Core\Event\Config\ConfigUpdateEvent $event
|
||||
*/
|
||||
public function setValue(ConfigUpdateEvent $event)
|
||||
{
|
||||
@@ -74,7 +74,7 @@ class Config extends BaseAction implements EventSubscriberInterface
|
||||
/**
|
||||
* Change a configuration entry
|
||||
*
|
||||
* @param ConfigUpdateEvent $event
|
||||
* @param \Thelia\Core\Event\Config\ConfigUpdateEvent $event
|
||||
*/
|
||||
public function modify(ConfigUpdateEvent $event)
|
||||
{
|
||||
@@ -94,7 +94,7 @@ class Config extends BaseAction implements EventSubscriberInterface
|
||||
/**
|
||||
* Delete a configuration entry
|
||||
*
|
||||
* @param ConfigDeleteEvent $event
|
||||
* @param \Thelia\Core\Event\Config\ConfigDeleteEvent $event
|
||||
*/
|
||||
public function delete(ConfigDeleteEvent $event)
|
||||
{
|
||||
|
||||
@@ -22,14 +22,20 @@
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Action;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Core\Event\Content\ContentAddFolderEvent;
|
||||
use Thelia\Core\Event\Content\ContentCreateEvent;
|
||||
use Thelia\Core\Event\Content\ContentDeleteEvent;
|
||||
use Thelia\Core\Event\Content\ContentRemoveFolderEvent;
|
||||
use Thelia\Core\Event\Content\ContentToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\Content\ContentUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Model\ContentFolder;
|
||||
use Thelia\Model\ContentFolderQuery;
|
||||
use Thelia\Model\ContentQuery;
|
||||
use Thelia\Model\Content as ContentModel;
|
||||
use Thelia\Model\FolderQuery;
|
||||
|
||||
|
||||
/**
|
||||
* Class Content
|
||||
@@ -73,10 +79,92 @@ class Content extends BaseAction implements EventSubscriberInterface
|
||||
->save()
|
||||
;
|
||||
|
||||
$content->updateDefaultFolder($event->getDefaultFolder());
|
||||
|
||||
$event->setContent($content);
|
||||
}
|
||||
}
|
||||
|
||||
public function updatePosition(UpdatePositionEvent $event)
|
||||
{
|
||||
if (null !== $content = ContentQuery::create()->findPk($event->getObjectId())) {
|
||||
$content->setDispatcher($this->getDispatcher());
|
||||
|
||||
switch ($event->getMode()) {
|
||||
case UpdatePositionEvent::POSITION_ABSOLUTE:
|
||||
$content->changeAbsolutePosition($event->getPosition());
|
||||
break;
|
||||
case UpdatePositionEvent::POSITION_DOWN:
|
||||
$content->movePositionDown();
|
||||
break;
|
||||
case UpdatePositionEvent::POSITION_UP:
|
||||
$content->movePositionUp();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function toggleVisibility(ContentToggleVisibilityEvent $event)
|
||||
{
|
||||
$content = $event->getContent();
|
||||
|
||||
$content
|
||||
->setDispatcher($this->getDispatcher())
|
||||
->setVisible(!$content->getVisible())
|
||||
->save();
|
||||
|
||||
$event->setContent($content);
|
||||
|
||||
}
|
||||
|
||||
public function delete(ContentDeleteEvent $event)
|
||||
{
|
||||
if (null !== $content = ContentQuery::create()->findPk($event->getContentId())) {
|
||||
$defaultFolderId = $content->getDefaultFolderId();
|
||||
|
||||
$content->setDispatcher($this->getDispatcher())
|
||||
->delete();
|
||||
|
||||
$event->setDefaultFolderId($defaultFolderId);
|
||||
$event->setContent($content);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* associate a folder to a content if the association already does not exists
|
||||
*
|
||||
* @param ContentAddFolderEvent $event
|
||||
*/
|
||||
public function addFolder(ContentAddFolderEvent $event)
|
||||
{
|
||||
if(ContentFolderQuery::create()
|
||||
->filterByContent($event->getContent())
|
||||
->filterByFolderId($event->getFolderId())
|
||||
->count() <= 0
|
||||
) {
|
||||
$contentFolder = new ContentFolder();
|
||||
|
||||
$contentFolder
|
||||
->setFolderId($event->getFolderId())
|
||||
->setContent($event->getContent())
|
||||
->setDefaultFolder(false)
|
||||
->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function removeFolder(ContentRemoveFolderEvent $event)
|
||||
{
|
||||
$contentFolder = ContentFolderQuery::create()
|
||||
->filterByContent($event->getContent())
|
||||
->filterByFolderId($event->getFolderId())
|
||||
->findOne();
|
||||
|
||||
if(null !== $contentFolder) {
|
||||
$contentFolder->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of event names this subscriber wants to listen to.
|
||||
*
|
||||
@@ -100,13 +188,16 @@ class Content extends BaseAction implements EventSubscriberInterface
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
TheliaEvents::CONTENT_CREATE => array("create", 128),
|
||||
TheliaEvents::CONTENT_UPDATE => array("update", 128),
|
||||
TheliaEvents::CONTENT_DELETE => array("delete", 128),
|
||||
TheliaEvents::CONTENT_TOGGLE_VISIBILITY => array("toggleVisibility", 128),
|
||||
TheliaEvents::CONTENT_CREATE => array('create', 128),
|
||||
TheliaEvents::CONTENT_UPDATE => array('update', 128),
|
||||
TheliaEvents::CONTENT_DELETE => array('delete', 128),
|
||||
TheliaEvents::CONTENT_TOGGLE_VISIBILITY => array('toggleVisibility', 128),
|
||||
|
||||
TheliaEvents::CONTENT_UPDATE_POSITION => array("updatePosition", 128),
|
||||
TheliaEvents::CONTENT_UPDATE_POSITION => array('updatePosition', 128),
|
||||
|
||||
TheliaEvents::CONTENT_ADD_FOLDER => array('addFolder', 128),
|
||||
TheliaEvents::CONTENT_REMOVE_FOLDER => array('removeFolder', 128),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,15 +23,16 @@
|
||||
|
||||
namespace Thelia\Action;
|
||||
|
||||
use Symfony\Component\Config\Definition\Exception\Exception;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Constraint\ConstraintFactory;
|
||||
use Thelia\Condition\ConditionFactory;
|
||||
use Thelia\Condition\ConditionManagerInterface;
|
||||
use Thelia\Core\Event\Coupon\CouponConsumeEvent;
|
||||
use Thelia\Core\Event\Coupon\CouponCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Coupon\CouponFactory;
|
||||
use Thelia\Coupon\CouponManager;
|
||||
use Thelia\Coupon\ConditionCollection;
|
||||
use Thelia\Coupon\Type\CouponInterface;
|
||||
use Thelia\Model\Coupon as CouponModel;
|
||||
|
||||
@@ -73,19 +74,19 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Occurring when a Coupon rule is about to be updated
|
||||
* Occurring when a Coupon condition is about to be updated
|
||||
*
|
||||
* @param CouponCreateOrUpdateEvent $event Event creation or update Coupon Rule
|
||||
*/
|
||||
public function updateRule(CouponCreateOrUpdateEvent $event)
|
||||
public function updateCondition(CouponCreateOrUpdateEvent $event)
|
||||
{
|
||||
$coupon = $event->getCoupon();
|
||||
|
||||
$this->createOrUpdateRule($coupon, $event);
|
||||
$this->createOrUpdateCondition($coupon, $event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Occurring when a Coupon rule is about to be consumed
|
||||
* Occurring when a Coupon condition is about to be consumed
|
||||
*
|
||||
* @param CouponConsumeEvent $event Event consuming Coupon
|
||||
*/
|
||||
@@ -137,11 +138,22 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
$coupon->setDispatcher($this->getDispatcher());
|
||||
|
||||
// Set default condition if none found
|
||||
/** @var ConditionManagerInterface $noConditionRule */
|
||||
$noConditionRule = $this->container->get('thelia.condition.match_for_everyone');
|
||||
/** @var ConditionFactory $conditionFactory */
|
||||
$conditionFactory = $this->container->get('thelia.condition.factory');
|
||||
$couponRuleCollection = new ConditionCollection();
|
||||
$couponRuleCollection->add($noConditionRule);
|
||||
$defaultSerializedRule = $conditionFactory->serializeConditionCollection(
|
||||
$couponRuleCollection
|
||||
);
|
||||
|
||||
$coupon->createOrUpdate(
|
||||
$event->getCode(),
|
||||
$event->getTitle(),
|
||||
$event->getAmount(),
|
||||
$event->getEffect(),
|
||||
$event->getType(),
|
||||
$event->isRemovingPostage(),
|
||||
$event->getShortDescription(),
|
||||
$event->getDescription(),
|
||||
@@ -150,6 +162,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
||||
$event->isAvailableOnSpecialOffers(),
|
||||
$event->isCumulative(),
|
||||
$event->getMaxUsage(),
|
||||
$defaultSerializedRule,
|
||||
$event->getLocale()
|
||||
);
|
||||
|
||||
@@ -163,15 +176,15 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
||||
* @param CouponModel $coupon Model to save
|
||||
* @param CouponCreateOrUpdateEvent $event Event containing data
|
||||
*/
|
||||
protected function createOrUpdateRule(CouponModel $coupon, CouponCreateOrUpdateEvent $event)
|
||||
protected function createOrUpdateCondition(CouponModel $coupon, CouponCreateOrUpdateEvent $event)
|
||||
{
|
||||
$coupon->setDispatcher($this->getDispatcher());
|
||||
|
||||
/** @var ConstraintFactory $constraintFactory */
|
||||
$constraintFactory = $this->container->get('thelia.constraint.factory');
|
||||
/** @var ConditionFactory $conditionFactory */
|
||||
$conditionFactory = $this->container->get('thelia.condition.factory');
|
||||
|
||||
$coupon->createOrUpdateRules(
|
||||
$constraintFactory->serializeCouponRuleCollection($event->getRules()),
|
||||
$coupon->createOrUpdateConditions(
|
||||
$conditionFactory->serializeConditionCollection($event->getConditions()),
|
||||
$event->getLocale()
|
||||
);
|
||||
|
||||
@@ -204,7 +217,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
||||
TheliaEvents::COUPON_CREATE => array("create", 128),
|
||||
TheliaEvents::COUPON_UPDATE => array("update", 128),
|
||||
TheliaEvents::COUPON_CONSUME => array("consume", 128),
|
||||
TheliaEvents::COUPON_RULE_UPDATE => array("updateRule", 128)
|
||||
TheliaEvents::COUPON_CONDITION_UPDATE => array("updateCondition", 128)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,9 +30,9 @@ use Thelia\Model\Currency as CurrencyModel;
|
||||
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
|
||||
use Thelia\Core\Event\CurrencyUpdateEvent;
|
||||
use Thelia\Core\Event\CurrencyCreateEvent;
|
||||
use Thelia\Core\Event\CurrencyDeleteEvent;
|
||||
use Thelia\Core\Event\Currency\CurrencyUpdateEvent;
|
||||
use Thelia\Core\Event\Currency\CurrencyCreateEvent;
|
||||
use Thelia\Core\Event\Currency\CurrencyDeleteEvent;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
|
||||
@@ -41,7 +41,7 @@ class Currency extends BaseAction implements EventSubscriberInterface
|
||||
/**
|
||||
* Create a new currencyuration entry
|
||||
*
|
||||
* @param CurrencyCreateEvent $event
|
||||
* @param \Thelia\Core\Event\Currency\CurrencyCreateEvent $event
|
||||
*/
|
||||
public function create(CurrencyCreateEvent $event)
|
||||
{
|
||||
@@ -65,7 +65,7 @@ class Currency extends BaseAction implements EventSubscriberInterface
|
||||
/**
|
||||
* Change a currency
|
||||
*
|
||||
* @param CurrencyUpdateEvent $event
|
||||
* @param \Thelia\Core\Event\Currency\CurrencyUpdateEvent $event
|
||||
*/
|
||||
public function update(CurrencyUpdateEvent $event)
|
||||
{
|
||||
@@ -118,7 +118,7 @@ class Currency extends BaseAction implements EventSubscriberInterface
|
||||
/**
|
||||
* Delete a currencyuration entry
|
||||
*
|
||||
* @param CurrencyDeleteEvent $event
|
||||
* @param \Thelia\Core\Event\Currency\CurrencyDeleteEvent $event
|
||||
*/
|
||||
public function delete(CurrencyDeleteEvent $event)
|
||||
{
|
||||
|
||||
@@ -25,11 +25,11 @@ namespace Thelia\Action;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
use Thelia\Core\Event\CustomerCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\CustomerEvent;
|
||||
use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\Customer\CustomerEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Model\Customer as CustomerModel;
|
||||
use Thelia\Core\Event\CustomerLoginEvent;
|
||||
use Thelia\Core\Event\Customer\CustomerLoginEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -25,19 +25,15 @@ namespace Thelia\Action;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
use Thelia\Core\Event\DocumentCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\DocumentDeleteEvent;
|
||||
use Thelia\Core\Event\DocumentEvent;
|
||||
use Thelia\Core\Event\Document\DocumentCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\Document\DocumentDeleteEvent;
|
||||
use Thelia\Core\Event\Document\DocumentEvent;
|
||||
use Thelia\Exception\ImageException;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Tools\FileManager;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
use Imagine\Document\ImagineInterface;
|
||||
use Imagine\Document\DocumentInterface;
|
||||
use Imagine\Document\Box;
|
||||
use Imagine\Document\Color;
|
||||
use Imagine\Document\Point;
|
||||
use Thelia\Exception\DocumentException;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
|
||||
@@ -80,7 +76,8 @@ class Document extends BaseCachedFile implements EventSubscriberInterface
|
||||
/**
|
||||
* @return string root of the document cache directory in web space
|
||||
*/
|
||||
protected function getCacheDirFromWebRoot() {
|
||||
protected function getCacheDirFromWebRoot()
|
||||
{
|
||||
return ConfigQuery::read('document_cache_dir_from_web_root', 'cache');
|
||||
}
|
||||
|
||||
@@ -95,7 +92,7 @@ class Document extends BaseCachedFile implements EventSubscriberInterface
|
||||
* @param DocumentEvent $event Event
|
||||
*
|
||||
* @throws \Thelia\Exception\DocumentException
|
||||
* @throws \InvalidArgumentException , DocumentException
|
||||
* @throws \InvalidArgumentException , DocumentException
|
||||
*/
|
||||
public function processDocument(DocumentEvent $event)
|
||||
{
|
||||
@@ -139,7 +136,7 @@ class Document extends BaseCachedFile implements EventSubscriberInterface
|
||||
/**
|
||||
* Take care of saving document in the database and file storage
|
||||
*
|
||||
* @param DocumentCreateOrUpdateEvent $event Document event
|
||||
* @param \Thelia\Core\Event\Document\DocumentCreateOrUpdateEvent $event Document event
|
||||
*
|
||||
* @throws \Thelia\Exception\ImageException
|
||||
* @todo refactor make all documents using propel inheritance and factorise image behaviour into one single clean action
|
||||
@@ -183,7 +180,7 @@ class Document extends BaseCachedFile implements EventSubscriberInterface
|
||||
/**
|
||||
* Take care of updating document in the database and file storage
|
||||
*
|
||||
* @param DocumentCreateOrUpdateEvent $event Document event
|
||||
* @param \Thelia\Core\Event\Document\DocumentCreateOrUpdateEvent $event Document event
|
||||
*
|
||||
* @throws \Thelia\Exception\ImageException
|
||||
* @todo refactor make all documents using propel inheritance and factorise image behaviour into one single clean action
|
||||
@@ -225,7 +222,7 @@ class Document extends BaseCachedFile implements EventSubscriberInterface
|
||||
/**
|
||||
* Take care of deleting document in the database and file storage
|
||||
*
|
||||
* @param DocumentDeleteEvent $event Image event
|
||||
* @param \Thelia\Core\Event\Document\DocumentDeleteEvent $event Image event
|
||||
*
|
||||
* @throws \Exception
|
||||
* @todo refactor make all documents using propel inheritance and factorise image behaviour into one single clean action
|
||||
@@ -247,7 +244,7 @@ class Document extends BaseCachedFile implements EventSubscriberInterface
|
||||
'document'
|
||||
)
|
||||
);
|
||||
} catch(\Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->adminLogAppend(
|
||||
$this->container->get('thelia.translator')->trans(
|
||||
'Fail to delete document for %id% with parent id %parentId% (Exception : %e%)',
|
||||
|
||||
@@ -30,15 +30,11 @@ use Thelia\Model\Feature as FeatureModel;
|
||||
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
|
||||
use Thelia\Core\Event\FeatureUpdateEvent;
|
||||
use Thelia\Core\Event\FeatureCreateEvent;
|
||||
use Thelia\Core\Event\FeatureDeleteEvent;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Model\FeatureAv;
|
||||
use Thelia\Model\FeatureAvQuery;
|
||||
use Thelia\Core\Event\Feature\FeatureUpdateEvent;
|
||||
use Thelia\Core\Event\Feature\FeatureCreateEvent;
|
||||
use Thelia\Core\Event\Feature\FeatureDeleteEvent;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Core\Event\CategoryEvent;
|
||||
use Thelia\Core\Event\FeatureEvent;
|
||||
use Thelia\Core\Event\Feature\FeatureEvent;
|
||||
use Thelia\Model\FeatureTemplate;
|
||||
use Thelia\Model\FeatureTemplateQuery;
|
||||
use Thelia\Model\TemplateQuery;
|
||||
@@ -48,7 +44,7 @@ class Feature extends BaseAction implements EventSubscriberInterface
|
||||
/**
|
||||
* Create a new feature entry
|
||||
*
|
||||
* @param FeatureCreateEvent $event
|
||||
* @param \Thelia\Core\Event\Feature\FeatureCreateEvent $event
|
||||
*/
|
||||
public function create(FeatureCreateEvent $event)
|
||||
{
|
||||
@@ -74,7 +70,7 @@ class Feature extends BaseAction implements EventSubscriberInterface
|
||||
/**
|
||||
* Change a product feature
|
||||
*
|
||||
* @param FeatureUpdateEvent $event
|
||||
* @param \Thelia\Core\Event\Feature\FeatureUpdateEvent $event
|
||||
*/
|
||||
public function update(FeatureUpdateEvent $event)
|
||||
{
|
||||
@@ -130,7 +126,7 @@ class Feature extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
$templates = TemplateQuery::create()->find();
|
||||
|
||||
foreach($templates as $template) {
|
||||
foreach ($templates as $template) {
|
||||
|
||||
$feature_template = new FeatureTemplate();
|
||||
|
||||
@@ -171,4 +167,4 @@ class Feature extends BaseAction implements EventSubscriberInterface
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,10 +30,9 @@ use Thelia\Model\FeatureAv as FeatureAvModel;
|
||||
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
|
||||
use Thelia\Core\Event\FeatureAvUpdateEvent;
|
||||
use Thelia\Core\Event\FeatureAvCreateEvent;
|
||||
use Thelia\Core\Event\FeatureAvDeleteEvent;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Core\Event\Feature\FeatureAvUpdateEvent;
|
||||
use Thelia\Core\Event\Feature\FeatureAvCreateEvent;
|
||||
use Thelia\Core\Event\Feature\FeatureAvDeleteEvent;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
|
||||
class FeatureAv extends BaseAction implements EventSubscriberInterface
|
||||
@@ -115,7 +114,6 @@ class FeatureAv extends BaseAction implements EventSubscriberInterface
|
||||
return $this->genericUpdatePosition(FeatureAvQuery::create(), $event);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -128,4 +126,4 @@ class FeatureAv extends BaseAction implements EventSubscriberInterface
|
||||
TheliaEvents::FEATURE_AV_UPDATE_POSITION => array("updatePosition", 128),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,24 +23,22 @@
|
||||
|
||||
namespace Thelia\Action;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Core\Event\FolderCreateEvent;
|
||||
use Thelia\Core\Event\FolderDeleteEvent;
|
||||
use Thelia\Core\Event\FolderToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\FolderUpdateEvent;
|
||||
use Thelia\Core\Event\Folder\FolderCreateEvent;
|
||||
use Thelia\Core\Event\Folder\FolderDeleteEvent;
|
||||
use Thelia\Core\Event\Folder\FolderToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\Folder\FolderUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Model\FolderQuery;
|
||||
use Thelia\Model\Folder as FolderModel;
|
||||
|
||||
|
||||
/**
|
||||
* Class Folder
|
||||
* @package Thelia\Action
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class Folder extends BaseAction implements EventSubscriberInterface {
|
||||
|
||||
|
||||
class Folder extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
public function update(FolderUpdateEvent $event)
|
||||
{
|
||||
|
||||
@@ -99,15 +97,16 @@ class Folder extends BaseAction implements EventSubscriberInterface {
|
||||
->setVisible(!$folder->getVisible())
|
||||
->save();
|
||||
|
||||
$event->setFolder($folder);
|
||||
|
||||
}
|
||||
|
||||
public function updatePosition(UpdatePositionEvent $event)
|
||||
{
|
||||
if(null !== $folder = FolderQuery::create()->findPk($event->getObjectId())) {
|
||||
if (null !== $folder = FolderQuery::create()->findPk($event->getObjectId())) {
|
||||
$folder->setDispatcher($this->getDispatcher());
|
||||
|
||||
switch($event->getMode())
|
||||
{
|
||||
switch ($event->getMode()) {
|
||||
case UpdatePositionEvent::POSITION_ABSOLUTE:
|
||||
$folder->changeAbsolutePosition($event->getPosition());
|
||||
break;
|
||||
@@ -152,4 +151,4 @@ class Folder extends BaseAction implements EventSubscriberInterface {
|
||||
TheliaEvents::FOLDER_UPDATE_POSITION => array("updatePosition", 128),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class HttpException extends BaseAction implements EventSubscriberInterface
|
||||
$this->display404($event);
|
||||
}
|
||||
|
||||
if($event->getException() instanceof AccessDeniedHttpException) {
|
||||
if ($event->getException() instanceof AccessDeniedHttpException) {
|
||||
$this->display403($event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,19 +23,12 @@
|
||||
|
||||
namespace Thelia\Action;
|
||||
|
||||
use Propel\Runtime\ActiveRecord\ActiveRecordInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
use Thelia\Core\Event\ImageCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\ImagesCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\ImageDeleteEvent;
|
||||
use Thelia\Core\Event\ImageEvent;
|
||||
use Thelia\Model\CategoryImage;
|
||||
use Thelia\Core\Event\Image\ImageCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\Image\ImageDeleteEvent;
|
||||
use Thelia\Core\Event\Image\ImageEvent;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Model\ContentImage;
|
||||
use Thelia\Model\FolderImage;
|
||||
use Thelia\Model\ProductImage;
|
||||
use Thelia\Tools\FileManager;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
@@ -88,12 +81,11 @@ class Image extends BaseCachedFile implements EventSubscriberInterface
|
||||
const EXACT_RATIO_WITH_CROP = 2;
|
||||
const KEEP_IMAGE_RATIO = 3;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return string root of the image cache directory in web space
|
||||
*/
|
||||
protected function getCacheDirFromWebRoot() {
|
||||
protected function getCacheDirFromWebRoot()
|
||||
{
|
||||
return ConfigQuery::read('image_cache_dir_from_web_root', 'cache');
|
||||
}
|
||||
|
||||
@@ -106,8 +98,8 @@ class Image extends BaseCachedFile implements EventSubscriberInterface
|
||||
*
|
||||
* This method updates the cache_file_path and file_url attributes of the event
|
||||
*
|
||||
* @param ImageEvent $event
|
||||
* @throws \InvalidArgumentException, ImageException
|
||||
* @param \Thelia\Core\Event\Image\ImageEvent $event
|
||||
* @throws \InvalidArgumentException, ImageException
|
||||
*/
|
||||
public function processImage(ImageEvent $event)
|
||||
{
|
||||
@@ -241,7 +233,7 @@ class Image extends BaseCachedFile implements EventSubscriberInterface
|
||||
// Compute the image URL
|
||||
$processed_image_url = $this->getCacheFileURL($subdir, basename($cacheFilePath));
|
||||
|
||||
// compute the full resulution image path in cache
|
||||
// compute the full resolution image path in cache
|
||||
$original_image_url = $this->getCacheFileURL($subdir, basename($originalImagePathInCache));
|
||||
|
||||
// Update the event with file path and file URL
|
||||
@@ -255,7 +247,7 @@ class Image extends BaseCachedFile implements EventSubscriberInterface
|
||||
/**
|
||||
* Take care of saving image in the database and file storage
|
||||
*
|
||||
* @param ImageCreateOrUpdateEvent $event Image event
|
||||
* @param \Thelia\Core\Event\Image\ImageCreateOrUpdateEvent $event Image event
|
||||
*
|
||||
* @throws \Thelia\Exception\ImageException
|
||||
* @todo refactor make all pictures using propel inheritance and factorise image behaviour into one single clean action
|
||||
@@ -358,7 +350,7 @@ class Image extends BaseCachedFile implements EventSubscriberInterface
|
||||
'image'
|
||||
)
|
||||
);
|
||||
} catch(\Exception $e){
|
||||
} catch (\Exception $e) {
|
||||
$this->adminLogAppend(
|
||||
$this->container->get('thelia.translator')->trans(
|
||||
'Fail to delete image for %id% with parent id %parentId% (Exception : %e%)',
|
||||
|
||||
@@ -30,16 +30,16 @@ use Thelia\Model\Message as MessageModel;
|
||||
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
|
||||
use Thelia\Core\Event\MessageUpdateEvent;
|
||||
use Thelia\Core\Event\MessageCreateEvent;
|
||||
use Thelia\Core\Event\MessageDeleteEvent;
|
||||
use Thelia\Core\Event\Message\MessageUpdateEvent;
|
||||
use Thelia\Core\Event\Message\MessageCreateEvent;
|
||||
use Thelia\Core\Event\Message\MessageDeleteEvent;
|
||||
|
||||
class Message extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* Create a new messageuration entry
|
||||
*
|
||||
* @param MessageCreateEvent $event
|
||||
* @param \Thelia\Core\Event\Message\MessageCreateEvent $event
|
||||
*/
|
||||
public function create(MessageCreateEvent $event)
|
||||
{
|
||||
@@ -64,7 +64,7 @@ class Message extends BaseAction implements EventSubscriberInterface
|
||||
/**
|
||||
* Change a message
|
||||
*
|
||||
* @param MessageUpdateEvent $event
|
||||
* @param \Thelia\Core\Event\Message\MessageUpdateEvent $event
|
||||
*/
|
||||
public function modify(MessageUpdateEvent $event)
|
||||
{
|
||||
@@ -94,7 +94,7 @@ class Message extends BaseAction implements EventSubscriberInterface
|
||||
/**
|
||||
* Delete a messageuration entry
|
||||
*
|
||||
* @param MessageDeleteEvent $event
|
||||
* @param \Thelia\Core\Event\Message\MessageDeleteEvent $event
|
||||
*/
|
||||
public function delete(MessageDeleteEvent $event)
|
||||
{
|
||||
|
||||
@@ -23,12 +23,11 @@
|
||||
|
||||
namespace Thelia\Action;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\ModelCriteria;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Core\Event\OrderEvent;
|
||||
use Thelia\Core\Event\Order\OrderAddressEvent;
|
||||
use Thelia\Core\Event\Order\OrderEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Exception\OrderException;
|
||||
use Thelia\Exception\TheliaProcessException;
|
||||
use Thelia\Model\AddressQuery;
|
||||
use Thelia\Model\OrderProductAttributeCombination;
|
||||
@@ -38,7 +37,6 @@ use Thelia\Model\OrderStatus;
|
||||
use Thelia\Model\Map\OrderTableMap;
|
||||
use Thelia\Model\OrderAddress;
|
||||
use Thelia\Model\OrderStatusQuery;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Tools\I18n;
|
||||
|
||||
/**
|
||||
@@ -50,7 +48,7 @@ use Thelia\Tools\I18n;
|
||||
class Order extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* @param \Thelia\Core\Event\OrderEvent $event
|
||||
* @param \Thelia\Core\Event\Order\OrderEvent $event
|
||||
*/
|
||||
public function setDeliveryAddress(OrderEvent $event)
|
||||
{
|
||||
@@ -62,7 +60,7 @@ class Order extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Thelia\Core\Event\OrderEvent $event
|
||||
* @param \Thelia\Core\Event\Order\OrderEvent $event
|
||||
*/
|
||||
public function setDeliveryModule(OrderEvent $event)
|
||||
{
|
||||
@@ -75,7 +73,7 @@ class Order extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Thelia\Core\Event\OrderEvent $event
|
||||
* @param \Thelia\Core\Event\Order\OrderEvent $event
|
||||
*/
|
||||
public function setInvoiceAddress(OrderEvent $event)
|
||||
{
|
||||
@@ -87,7 +85,7 @@ class Order extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Thelia\Core\Event\OrderEvent $event
|
||||
* @param \Thelia\Core\Event\Order\OrderEvent $event
|
||||
*/
|
||||
public function setPaymentModule(OrderEvent $event)
|
||||
{
|
||||
@@ -99,7 +97,7 @@ class Order extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Thelia\Core\Event\OrderEvent $event
|
||||
* @param \Thelia\Core\Event\Order\OrderEvent $event
|
||||
*/
|
||||
public function create(OrderEvent $event)
|
||||
{
|
||||
@@ -144,6 +142,7 @@ class Order extends BaseAction implements EventSubscriberInterface
|
||||
->setAddress3($deliveryAddress->getAddress3())
|
||||
->setZipcode($deliveryAddress->getZipcode())
|
||||
->setCity($deliveryAddress->getCity())
|
||||
->setPhone($deliveryAddress->getPhone())
|
||||
->setCountryId($deliveryAddress->getCountryId())
|
||||
->save($con)
|
||||
;
|
||||
@@ -159,6 +158,7 @@ class Order extends BaseAction implements EventSubscriberInterface
|
||||
->setAddress3($invoiceAddress->getAddress3())
|
||||
->setZipcode($invoiceAddress->getZipcode())
|
||||
->setCity($invoiceAddress->getCity())
|
||||
->setPhone($invoiceAddress->getPhone())
|
||||
->setCountryId($invoiceAddress->getCountryId())
|
||||
->save($con)
|
||||
;
|
||||
@@ -174,7 +174,7 @@ class Order extends BaseAction implements EventSubscriberInterface
|
||||
|
||||
/* fulfill order_products and decrease stock */
|
||||
|
||||
foreach($cartItems as $cartItem) {
|
||||
foreach ($cartItems as $cartItem) {
|
||||
$product = $cartItem->getProduct();
|
||||
|
||||
/* get translation */
|
||||
@@ -183,7 +183,7 @@ class Order extends BaseAction implements EventSubscriberInterface
|
||||
$pse = $cartItem->getProductSaleElements();
|
||||
|
||||
/* check still in stock */
|
||||
if($cartItem->getQuantity() > $pse->getQuantity()) {
|
||||
if ($cartItem->getQuantity() > $pse->getQuantity()) {
|
||||
throw new TheliaProcessException("Not enough stock", TheliaProcessException::CART_ITEM_NOT_ENOUGH_STOCK, $cartItem);
|
||||
}
|
||||
|
||||
@@ -198,7 +198,8 @@ class Order extends BaseAction implements EventSubscriberInterface
|
||||
|
||||
$taxDetail = $product->getTaxRule()->getTaxDetail(
|
||||
$taxCountry,
|
||||
$cartItem->getPromo() == 1 ? $cartItem->getPromoPrice() : $cartItem->getPrice(),
|
||||
$cartItem->getPrice(),
|
||||
$cartItem->getPromoPrice(),
|
||||
$this->getSession()->getLang()->getLocale()
|
||||
);
|
||||
|
||||
@@ -224,13 +225,13 @@ class Order extends BaseAction implements EventSubscriberInterface
|
||||
$orderProduct->save($con);
|
||||
|
||||
/* fulfill order_product_tax */
|
||||
foreach($taxDetail as $tax) {
|
||||
foreach ($taxDetail as $tax) {
|
||||
$tax->setOrderProductId($orderProduct->getId());
|
||||
$tax->save($con);
|
||||
}
|
||||
|
||||
/* fulfill order_attribute_combination and decrease stock */
|
||||
foreach($pse->getAttributeCombinations() as $attributeCombination) {
|
||||
foreach ($pse->getAttributeCombinations() as $attributeCombination) {
|
||||
$attribute = I18n::forceI18nRetrieving($this->getSession()->getLang()->getLocale(), 'Attribute', $attributeCombination->getAttributeId());
|
||||
$attributeAv = I18n::forceI18nRetrieving($this->getSession()->getLang()->getLocale(), 'AttributeAv', $attributeCombination->getAttributeAvId());
|
||||
|
||||
@@ -240,7 +241,7 @@ class Order extends BaseAction implements EventSubscriberInterface
|
||||
->setAttributeTitle($attribute->getTitle())
|
||||
->setAttributeChapo($attribute->getChapo())
|
||||
->setAttributeDescription($attribute->getDescription())
|
||||
->setAttributePostscriptumn($attribute->getPostscriptum())
|
||||
->setAttributePostscriptum($attribute->getPostscriptum())
|
||||
->setAttributeAvTitle($attributeAv->getTitle())
|
||||
->setAttributeAvChapo($attributeAv->getChapo())
|
||||
->setAttributeAvDescription($attributeAv->getDescription())
|
||||
@@ -277,7 +278,7 @@ class Order extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Thelia\Core\Event\OrderEvent $event
|
||||
* @param \Thelia\Core\Event\Order\OrderEvent $event
|
||||
*/
|
||||
public function sendOrderEmail(OrderEvent $event)
|
||||
{
|
||||
@@ -285,17 +286,54 @@ class Order extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Thelia\Core\Event\OrderEvent $event
|
||||
* @param OrderEvent $event
|
||||
*/
|
||||
public function setReference(OrderEvent $event)
|
||||
public function updateStatus(OrderEvent $event)
|
||||
{
|
||||
$event->getOrder()->setRef($this->generateRef());
|
||||
$order = $event->getOrder();
|
||||
|
||||
$order->setStatusId($event->getStatus());
|
||||
$order->save();
|
||||
|
||||
$event->setOrder($order);
|
||||
}
|
||||
|
||||
public function generateRef()
|
||||
/**
|
||||
* @param OrderEvent $event
|
||||
*/
|
||||
public function updateDeliveryRef(OrderEvent $event)
|
||||
{
|
||||
/* order addresses are unique */
|
||||
return uniqid('ORD', true);
|
||||
$order = $event->getOrder();
|
||||
|
||||
$order->setDeliveryRef($event->getDeliveryRef());
|
||||
$order->save();
|
||||
|
||||
$event->setOrder($order);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OrderAddressEvent $event
|
||||
*/
|
||||
public function updateAddress(OrderAddressEvent $event)
|
||||
{
|
||||
$orderAddress = $event->getOrderAddress();
|
||||
|
||||
$orderAddress
|
||||
->setCustomerTitleId($event->getTitle())
|
||||
->setCompany($event->getCompany())
|
||||
->setFirstname($event->getFirstname())
|
||||
->setLastname($event->getLastname())
|
||||
->setAddress1($event->getAddress1())
|
||||
->setAddress2($event->getAddress2())
|
||||
->setAddress3($event->getAddress3())
|
||||
->setZipcode($event->getZipcode())
|
||||
->setCity($event->getCity())
|
||||
->setCountryId($event->getCountry())
|
||||
->setPhone($event->getPhone())
|
||||
;
|
||||
$orderAddress->save();
|
||||
|
||||
$event->setOrderAddress($orderAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -326,8 +364,10 @@ class Order extends BaseAction implements EventSubscriberInterface
|
||||
TheliaEvents::ORDER_SET_INVOICE_ADDRESS => array("setInvoiceAddress", 128),
|
||||
TheliaEvents::ORDER_SET_PAYMENT_MODULE => array("setPaymentModule", 128),
|
||||
TheliaEvents::ORDER_PAY => array("create", 128),
|
||||
TheliaEvents::ORDER_BEFORE_CREATE => array("setReference", 128),
|
||||
TheliaEvents::ORDER_BEFORE_PAYMENT => array("sendOrderEmail", 128),
|
||||
TheliaEvents::ORDER_UPDATE_STATUS => array("updateStatus", 128),
|
||||
TheliaEvents::ORDER_UPDATE_DELIVERY_REF => array("updateDeliveryRef", 128),
|
||||
TheliaEvents::ORDER_UPDATE_ADDRESS => array("updateAddress", 128),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,51 +30,45 @@ use Thelia\Model\Product as ProductModel;
|
||||
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
|
||||
use Thelia\Core\Event\ProductUpdateEvent;
|
||||
use Thelia\Core\Event\ProductCreateEvent;
|
||||
use Thelia\Core\Event\ProductDeleteEvent;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Core\Event\Product\ProductUpdateEvent;
|
||||
use Thelia\Core\Event\Product\ProductCreateEvent;
|
||||
use Thelia\Core\Event\Product\ProductDeleteEvent;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Core\Event\ProductToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\ProductAddContentEvent;
|
||||
use Thelia\Core\Event\ProductDeleteContentEvent;
|
||||
use Thelia\Core\Event\Product\ProductToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\Product\ProductAddContentEvent;
|
||||
use Thelia\Core\Event\Product\ProductDeleteContentEvent;
|
||||
use Thelia\Model\ProductAssociatedContent;
|
||||
use Thelia\Model\ProductAssociatedContentQuery;
|
||||
use Thelia\Model\ProductCategory;
|
||||
use Thelia\Model\TaxRule;
|
||||
use Thelia\Model\TaxRuleQuery;
|
||||
use Thelia\Model\TaxQuery;
|
||||
use Thelia\Model\AccessoryQuery;
|
||||
use Thelia\Model\Accessory;
|
||||
use Thelia\Core\Event\ProductAddAccessoryEvent;
|
||||
use Thelia\Core\Event\ProductDeleteAccessoryEvent;
|
||||
use Thelia\Core\Event\FeatureProductUpdateEvent;
|
||||
use Thelia\Core\Event\FeatureProduct\FeatureProductUpdateEvent;
|
||||
use Thelia\Model\FeatureProduct;
|
||||
use Thelia\Model\FeatureQuery;
|
||||
use Thelia\Core\Event\FeatureProductDeleteEvent;
|
||||
use Thelia\Core\Event\FeatureProduct\FeatureProductDeleteEvent;
|
||||
use Thelia\Model\FeatureProductQuery;
|
||||
use Thelia\Model\ProductCategoryQuery;
|
||||
use Thelia\Core\Event\ProductSetTemplateEvent;
|
||||
use Thelia\Model\AttributeCombinationQuery;
|
||||
use Thelia\Core\Event\Product\ProductSetTemplateEvent;
|
||||
use Thelia\Model\ProductSaleElementsQuery;
|
||||
use Propel\Runtime\ActiveQuery\PropelQuery;
|
||||
use Thelia\Core\Event\ProductDeleteCategoryEvent;
|
||||
use Thelia\Core\Event\ProductAddCategoryEvent;
|
||||
use Thelia\Core\Event\Product\ProductDeleteCategoryEvent;
|
||||
use Thelia\Core\Event\Product\ProductAddCategoryEvent;
|
||||
use Thelia\Model\AttributeAvQuery;
|
||||
use Thelia\Model\AttributeCombination;
|
||||
use Thelia\Core\Event\ProductCreateCombinationEvent;
|
||||
use Thelia\Core\Event\Product\ProductCreateCombinationEvent;
|
||||
use Propel\Runtime\Propel;
|
||||
use Thelia\Model\Map\ProductTableMap;
|
||||
use Thelia\Core\Event\ProductDeleteCombinationEvent;
|
||||
use Thelia\Core\Event\Product\ProductDeleteCombinationEvent;
|
||||
use Thelia\Model\ProductPrice;
|
||||
use Thelia\Model\ProductSaleElements;
|
||||
use Thelia\Core\Event\Product\ProductAddAccessoryEvent;
|
||||
use Thelia\Core\Event\Product\ProductDeleteAccessoryEvent;
|
||||
|
||||
class Product extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* Create a new product entry
|
||||
*
|
||||
* @param ProductCreateEvent $event
|
||||
* @param \Thelia\Core\Event\Product\ProductCreateEvent $event
|
||||
*/
|
||||
public function create(ProductCreateEvent $event)
|
||||
{
|
||||
@@ -108,7 +102,7 @@ class Product extends BaseAction implements EventSubscriberInterface
|
||||
/**
|
||||
* Change a product
|
||||
*
|
||||
* @param ProductUpdateEvent $event
|
||||
* @param \Thelia\Core\Event\Product\ProductUpdateEvent $event
|
||||
*/
|
||||
public function update(ProductUpdateEvent $event)
|
||||
{
|
||||
@@ -140,7 +134,7 @@ class Product extends BaseAction implements EventSubscriberInterface
|
||||
/**
|
||||
* Delete a product entry
|
||||
*
|
||||
* @param ProductDeleteEvent $event
|
||||
* @param \Thelia\Core\Event\Product\ProductDeleteEvent $event
|
||||
*/
|
||||
public function delete(ProductDeleteEvent $event)
|
||||
{
|
||||
@@ -181,8 +175,8 @@ class Product extends BaseAction implements EventSubscriberInterface
|
||||
return $this->genericUpdatePosition(ProductQuery::create(), $event);
|
||||
}
|
||||
|
||||
public function addContent(ProductAddContentEvent $event) {
|
||||
|
||||
public function addContent(ProductAddContentEvent $event)
|
||||
{
|
||||
if (ProductAssociatedContentQuery::create()
|
||||
->filterByContentId($event->getContentId())
|
||||
->filterByProduct($event->getProduct())->count() <= 0) {
|
||||
@@ -198,8 +192,8 @@ class Product extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function removeContent(ProductDeleteContentEvent $event) {
|
||||
|
||||
public function removeContent(ProductDeleteContentEvent $event)
|
||||
{
|
||||
$content = ProductAssociatedContentQuery::create()
|
||||
->filterByContentId($event->getContentId())
|
||||
->filterByProduct($event->getProduct())->findOne()
|
||||
@@ -212,8 +206,8 @@ class Product extends BaseAction implements EventSubscriberInterface
|
||||
;
|
||||
}
|
||||
|
||||
public function addCategory(ProductAddCategoryEvent $event) {
|
||||
|
||||
public function addCategory(ProductAddCategoryEvent $event)
|
||||
{
|
||||
if (ProductCategoryQuery::create()
|
||||
->filterByProduct($event->getProduct())
|
||||
->filterByCategoryId($event->getCategoryId())
|
||||
@@ -230,8 +224,8 @@ class Product extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function removeCategory(ProductDeleteCategoryEvent $event) {
|
||||
|
||||
public function removeCategory(ProductDeleteCategoryEvent $event)
|
||||
{
|
||||
$productCategory = ProductCategoryQuery::create()
|
||||
->filterByProduct($event->getProduct())
|
||||
->filterByCategoryId($event->getCategoryId())
|
||||
@@ -240,8 +234,8 @@ class Product extends BaseAction implements EventSubscriberInterface
|
||||
if ($productCategory != null) $productCategory->delete();
|
||||
}
|
||||
|
||||
public function addAccessory(ProductAddAccessoryEvent $event) {
|
||||
|
||||
public function addAccessory(ProductAddAccessoryEvent $event)
|
||||
{
|
||||
if (AccessoryQuery::create()
|
||||
->filterByAccessory($event->getAccessoryId())
|
||||
->filterByProductId($event->getProduct()->getId())->count() <= 0) {
|
||||
@@ -257,8 +251,8 @@ class Product extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function removeAccessory(ProductDeleteAccessoryEvent $event) {
|
||||
|
||||
public function removeAccessory(ProductDeleteAccessoryEvent $event)
|
||||
{
|
||||
$accessory = AccessoryQuery::create()
|
||||
->filterByAccessory($event->getAccessoryId())
|
||||
->filterByProductId($event->getProduct()->getId())->findOne()
|
||||
@@ -271,8 +265,8 @@ class Product extends BaseAction implements EventSubscriberInterface
|
||||
;
|
||||
}
|
||||
|
||||
public function setProductTemplate(ProductSetTemplateEvent $event) {
|
||||
|
||||
public function setProductTemplate(ProductSetTemplateEvent $event)
|
||||
{
|
||||
$product = $event->getProduct();
|
||||
|
||||
// Delete all product feature relations
|
||||
@@ -310,8 +304,8 @@ class Product extends BaseAction implements EventSubscriberInterface
|
||||
return $this->genericUpdatePosition(ProductAssociatedContentQuery::create(), $event);
|
||||
}
|
||||
|
||||
public function updateFeatureProductValue(FeatureProductUpdateEvent $event) {
|
||||
|
||||
public function updateFeatureProductValue(FeatureProductUpdateEvent $event)
|
||||
{
|
||||
// If the feature is not free text, it may have one ore more values.
|
||||
// If the value exists, we do not change it
|
||||
// If the value does not exists, we create it.
|
||||
@@ -343,8 +337,7 @@ class Product extends BaseAction implements EventSubscriberInterface
|
||||
|
||||
if ($event->getIsTextValue() == true) {
|
||||
$featureProduct->setFreeTextValue($event->getFeatureValue());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$featureProduct->setFeatureAvId($event->getFeatureValue());
|
||||
}
|
||||
|
||||
@@ -353,8 +346,8 @@ class Product extends BaseAction implements EventSubscriberInterface
|
||||
$event->setFeatureProduct($featureProduct);
|
||||
}
|
||||
|
||||
public function deleteFeatureProductValue(FeatureProductDeleteEvent $event) {
|
||||
|
||||
public function deleteFeatureProductValue(FeatureProductDeleteEvent $event)
|
||||
{
|
||||
$featureProduct = FeatureProductQuery::create()
|
||||
->filterByProductId($event->getProductId())
|
||||
->filterByFeatureId($event->getFeatureId())
|
||||
@@ -362,8 +355,8 @@ class Product extends BaseAction implements EventSubscriberInterface
|
||||
;
|
||||
}
|
||||
|
||||
public function createProductCombination(ProductCreateCombinationEvent $event) {
|
||||
|
||||
public function createProductCombination(ProductCreateCombinationEvent $event)
|
||||
{
|
||||
$con = Propel::getWriteConnection(ProductTableMap::DATABASE_NAME);
|
||||
|
||||
$con->beginTransaction();
|
||||
@@ -399,7 +392,7 @@ class Product extends BaseAction implements EventSubscriberInterface
|
||||
|
||||
if (count($combinationAttributes) > 0) {
|
||||
|
||||
foreach($combinationAttributes as $attributeAvId) {
|
||||
foreach ($combinationAttributes as $attributeAvId) {
|
||||
|
||||
$attributeAv = AttributeAvQuery::create()->findPk($attributeAvId);
|
||||
|
||||
@@ -417,8 +410,7 @@ class Product extends BaseAction implements EventSubscriberInterface
|
||||
|
||||
// Store all the stuff !
|
||||
$con->commit();
|
||||
}
|
||||
catch(\Exception $ex) {
|
||||
} catch (\Exception $ex) {
|
||||
|
||||
$con->rollback();
|
||||
|
||||
@@ -426,8 +418,8 @@ class Product extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteProductCombination(ProductDeleteCombinationEvent $event) {
|
||||
|
||||
public function deleteProductCombination(ProductDeleteCombinationEvent $event)
|
||||
{
|
||||
if (null !== $pse = ProductSaleElementsQuery::create()->findPk($event->getProductSaleElementId())) {
|
||||
$pse->delete();
|
||||
}
|
||||
|
||||
@@ -30,24 +30,17 @@ use Thelia\Model\Template as TemplateModel;
|
||||
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
|
||||
use Thelia\Core\Event\TemplateUpdateEvent;
|
||||
use Thelia\Core\Event\TemplateCreateEvent;
|
||||
use Thelia\Core\Event\TemplateDeleteEvent;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Model\TemplateAv;
|
||||
use Thelia\Model\TemplateAvQuery;
|
||||
use Thelia\Core\Event\Template\TemplateUpdateEvent;
|
||||
use Thelia\Core\Event\Template\TemplateCreateEvent;
|
||||
use Thelia\Core\Event\Template\TemplateDeleteEvent;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Core\Event\CategoryEvent;
|
||||
use Thelia\Core\Event\TemplateEvent;
|
||||
use Thelia\Model\TemplateTemplate;
|
||||
use Thelia\Model\TemplateTemplateQuery;
|
||||
use Thelia\Model\ProductQuery;
|
||||
use Thelia\Core\Event\TemplateAddAttributeEvent;
|
||||
use Thelia\Core\Event\TemplateDeleteAttributeEvent;
|
||||
use Thelia\Core\Event\Template\TemplateAddAttributeEvent;
|
||||
use Thelia\Core\Event\Template\TemplateDeleteAttributeEvent;
|
||||
use Thelia\Model\AttributeTemplateQuery;
|
||||
use Thelia\Model\AttributeTemplate;
|
||||
use Thelia\Core\Event\TemplateDeleteFeatureEvent;
|
||||
use Thelia\Core\Event\TemplateAddFeatureEvent;
|
||||
use Thelia\Core\Event\Template\TemplateDeleteFeatureEvent;
|
||||
use Thelia\Core\Event\Template\TemplateAddFeatureEvent;
|
||||
use Thelia\Model\FeatureTemplateQuery;
|
||||
use Thelia\Model\FeatureTemplate;
|
||||
|
||||
@@ -56,7 +49,7 @@ class Template extends BaseAction implements EventSubscriberInterface
|
||||
/**
|
||||
* Create a new template entry
|
||||
*
|
||||
* @param TemplateCreateEvent $event
|
||||
* @param \Thelia\Core\Event\Template\TemplateCreateEvent $event
|
||||
*/
|
||||
public function create(TemplateCreateEvent $event)
|
||||
{
|
||||
@@ -77,7 +70,7 @@ class Template extends BaseAction implements EventSubscriberInterface
|
||||
/**
|
||||
* Change a product template
|
||||
*
|
||||
* @param TemplateUpdateEvent $event
|
||||
* @param \Thelia\Core\Event\Template\TemplateUpdateEvent $event
|
||||
*/
|
||||
public function update(TemplateUpdateEvent $event)
|
||||
{
|
||||
@@ -99,7 +92,7 @@ class Template extends BaseAction implements EventSubscriberInterface
|
||||
/**
|
||||
* Delete a product template entry
|
||||
*
|
||||
* @param TemplateDeleteEvent $event
|
||||
* @param \Thelia\Core\Event\Template\TemplateDeleteEvent $event
|
||||
*/
|
||||
public function delete(TemplateDeleteEvent $event)
|
||||
{
|
||||
@@ -121,8 +114,8 @@ class Template extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function addAttribute(TemplateAddAttributeEvent $event) {
|
||||
|
||||
public function addAttribute(TemplateAddAttributeEvent $event)
|
||||
{
|
||||
if (null === AttributeTemplateQuery::create()->filterByAttributeId($event->getAttributeId())->filterByTemplate($event->getTemplate())->findOne()) {
|
||||
|
||||
$attribute_template = new AttributeTemplate();
|
||||
@@ -155,8 +148,8 @@ class Template extends BaseAction implements EventSubscriberInterface
|
||||
return $this->genericUpdatePosition(FeatureTemplateQuery::create(), $event);
|
||||
}
|
||||
|
||||
public function deleteAttribute(TemplateDeleteAttributeEvent $event) {
|
||||
|
||||
public function deleteAttribute(TemplateDeleteAttributeEvent $event)
|
||||
{
|
||||
$attribute_template = AttributeTemplateQuery::create()
|
||||
->filterByAttributeId($event->getAttributeId())
|
||||
->filterByTemplate($event->getTemplate())->findOne()
|
||||
@@ -165,8 +158,8 @@ class Template extends BaseAction implements EventSubscriberInterface
|
||||
if ($attribute_template !== null) $attribute_template->delete();
|
||||
}
|
||||
|
||||
public function addFeature(TemplateAddFeatureEvent $event) {
|
||||
|
||||
public function addFeature(TemplateAddFeatureEvent $event)
|
||||
{
|
||||
if (null === FeatureTemplateQuery::create()->filterByFeatureId($event->getFeatureId())->filterByTemplate($event->getTemplate())->findOne()) {
|
||||
|
||||
$feature_template = new FeatureTemplate();
|
||||
@@ -179,8 +172,8 @@ class Template extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteFeature(TemplateDeleteFeatureEvent $event) {
|
||||
|
||||
public function deleteFeature(TemplateDeleteFeatureEvent $event)
|
||||
{
|
||||
$feature_template = FeatureTemplateQuery::create()
|
||||
->filterByFeatureId($event->getFeatureId())
|
||||
->filterByTemplate($event->getTemplate())->findOne()
|
||||
@@ -210,4 +203,4 @@ class Template extends BaseAction implements EventSubscriberInterface
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ use Thelia\Model\Customer;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Session\Session;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\CartEvent;
|
||||
use Thelia\Core\Event\Cart\CartEvent;
|
||||
|
||||
/**
|
||||
* managed cart
|
||||
|
||||
@@ -73,10 +73,11 @@ class CacheClear extends ContainerAwareCommand
|
||||
|
||||
try {
|
||||
$directoryBrowser = new \DirectoryIterator($dir);
|
||||
} catch(\UnexpectedValueException $e) {
|
||||
} catch (\UnexpectedValueException $e) {
|
||||
// throws same exception code for does not exist and permission denied ...
|
||||
if(!file_exists($dir)) {
|
||||
if (!file_exists($dir)) {
|
||||
$output->writeln(sprintf("<info>%s cache dir already clear</info>", $dir));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ use Thelia\Command\ContainerAwareCommand;
|
||||
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Thelia\Core\Event\ImageEvent;
|
||||
use Thelia\Core\Event\Image\ImageEvent;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
|
||||
@@ -25,12 +25,9 @@ namespace Thelia\Command;
|
||||
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Filesystem\Exception\IOException;
|
||||
|
||||
use Thelia\Command\ContainerAwareCommand;
|
||||
use Thelia\Model\ModuleQuery;
|
||||
|
||||
/**
|
||||
@@ -62,7 +59,7 @@ class ModuleActivateCommand extends BaseModuleGenerate
|
||||
|
||||
$module = ModuleQuery::create()->findOneByCode($moduleCode);
|
||||
|
||||
if(null === $module) {
|
||||
if (null === $module) {
|
||||
throw new \RuntimeException(sprintf("module %s not found", $moduleCode));
|
||||
}
|
||||
|
||||
@@ -74,7 +71,7 @@ class ModuleActivateCommand extends BaseModuleGenerate
|
||||
$moduleInstance = $moduleReflection->newInstance();
|
||||
|
||||
$moduleInstance->activate();
|
||||
} catch(\Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
throw new \RuntimeException(sprintf("Activation fail with Exception : [%d] %s", $e->getCode(), $e->getMessage()));
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ class ReloadDatabaseCommand extends BaseModuleGenerate
|
||||
|
||||
$tables = $connection->query("SHOW TABLES");
|
||||
$connection->query("SET FOREIGN_KEY_CHECKS = 0");
|
||||
foreach($tables as $table) {
|
||||
foreach ($tables as $table) {
|
||||
$connection->query(sprintf("DROP TABLE `%s`", $table[0]));
|
||||
}
|
||||
$connection->query("SET FOREIGN_KEY_CHECKS = 1");
|
||||
|
||||
144
core/lib/Thelia/Condition/ConditionEvaluator.php
Normal file
144
core/lib/Thelia/Condition/ConditionEvaluator.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?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\Condition;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Coupon\ConditionCollection;
|
||||
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Validate Conditions
|
||||
*
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ConditionEvaluator
|
||||
{
|
||||
/**
|
||||
* Check if an Event matches SerializableCondition
|
||||
*
|
||||
* @param ConditionCollection $conditions Conditions to check against the Event
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isMatching(ConditionCollection $conditions)
|
||||
{
|
||||
$isMatching = true;
|
||||
/** @var ConditionManagerInterface $condition */
|
||||
foreach ($conditions->getConditions() as $condition) {
|
||||
if (!$condition->isMatching()) {
|
||||
$isMatching = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $isMatching;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Do variable comparison
|
||||
*
|
||||
* @param mixed $v1 Variable 1
|
||||
* @param string $o Operator ex : Operators::DIFFERENT
|
||||
* @param mixed $v2 Variable 2
|
||||
*
|
||||
* @throws \Exception
|
||||
* @return bool
|
||||
*/
|
||||
public function variableOpComparison($v1, $o, $v2)
|
||||
{
|
||||
if ($o == Operators::DIFFERENT) {
|
||||
return ($v1 != $v2);
|
||||
}
|
||||
|
||||
switch ($o) {
|
||||
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:
|
||||
// in
|
||||
if (in_array($v1, $v2)) {
|
||||
return true;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case Operators::OUT:
|
||||
// not in
|
||||
if (!in_array($v1, $v2)) {
|
||||
return true;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new \Exception('Unrecognized operator ' . $o);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
169
core/lib/Thelia/Condition/ConditionFactory.php
Normal file
169
core/lib/Thelia/Condition/ConditionFactory.php
Normal file
@@ -0,0 +1,169 @@
|
||||
<?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\Condition;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Thelia\Coupon\AdapterInterface;
|
||||
use Thelia\Coupon\ConditionCollection;
|
||||
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Manage how Condition could interact with the current application state (Thelia)
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ConditionFactory
|
||||
{
|
||||
/** @var ContainerInterface Service Container */
|
||||
protected $container = null;
|
||||
|
||||
/** @var AdapterInterface Provide necessary value from Thelia */
|
||||
protected $adapter;
|
||||
|
||||
/** @var array ConditionCollection to process*/
|
||||
protected $conditions = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param ContainerInterface $container Service container
|
||||
*/
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->adapter = $container->get('thelia.adapter');
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a collection of conditions
|
||||
*
|
||||
* @param ConditionCollection $collection A collection of conditions
|
||||
*
|
||||
* @return string A ready to be stored Condition collection
|
||||
*/
|
||||
public function serializeConditionCollection(ConditionCollection $collection)
|
||||
{
|
||||
if ($collection->isEmpty()) {
|
||||
/** @var ConditionManagerInterface $conditionNone */
|
||||
$conditionNone = $this->container->get(
|
||||
'thelia.condition.match_for_everyone'
|
||||
);
|
||||
$collection->add($conditionNone);
|
||||
}
|
||||
$serializableConditions = array();
|
||||
$conditions = $collection->getConditions();
|
||||
if ($conditions !== null) {
|
||||
/** @var $condition ConditionManagerInterface */
|
||||
foreach ($conditions as $condition) {
|
||||
// Remove all condition if the "no condition" condition is found
|
||||
// if ($condition->getServiceId() == 'thelia.condition.match_for_everyone') {
|
||||
// return base64_encode(json_encode(array($condition->getSerializableRule())));
|
||||
// }
|
||||
$serializableConditions[] = $condition->getSerializableCondition();
|
||||
}
|
||||
}
|
||||
|
||||
return base64_encode(json_encode($serializableConditions));
|
||||
}
|
||||
|
||||
/**
|
||||
* Unserialize a collection of conditions
|
||||
*
|
||||
* @param string $serializedConditions Serialized Conditions
|
||||
*
|
||||
* @return ConditionCollection Conditions ready to be processed
|
||||
*/
|
||||
public function unserializeConditionCollection($serializedConditions)
|
||||
{
|
||||
$unserializedConditions = json_decode(base64_decode($serializedConditions));
|
||||
|
||||
$collection = new ConditionCollection();
|
||||
|
||||
if (!empty($unserializedConditions) && !empty($unserializedConditions)) {
|
||||
/** @var SerializableCondition $condition */
|
||||
foreach ($unserializedConditions as $condition) {
|
||||
if ($this->container->has($condition->conditionServiceId)) {
|
||||
/** @var ConditionManagerInterface $conditionManager */
|
||||
$conditionManager = $this->build(
|
||||
$condition->conditionServiceId,
|
||||
(array) $condition->operators,
|
||||
(array) $condition->values
|
||||
);
|
||||
$collection->add(clone $conditionManager);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build a Condition from form
|
||||
*
|
||||
* @param string $conditionServiceId Condition class name
|
||||
* @param array $operators Condition Operator (<, >, = )
|
||||
* @param array $values Values setting this Condition
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return ConditionManagerInterface Ready to use Condition or false
|
||||
*/
|
||||
public function build($conditionServiceId, array $operators, array $values)
|
||||
{
|
||||
if (!$this->container->has($conditionServiceId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var ConditionManagerInterface $condition */
|
||||
$condition = $this->container->get($conditionServiceId);
|
||||
$condition->setValidatorsFromForm($operators, $values);
|
||||
|
||||
return $condition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Condition inputs from serviceId
|
||||
*
|
||||
* @param string $conditionServiceId ConditionManager class name
|
||||
*
|
||||
* @return array Ready to be drawn condition inputs
|
||||
*/
|
||||
public function getInputs($conditionServiceId)
|
||||
{
|
||||
if (!$this->container->has($conditionServiceId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var ConditionManagerInterface $condition */
|
||||
$condition = $this->container->get($conditionServiceId);
|
||||
|
||||
return $condition->getValidators();
|
||||
}
|
||||
}
|
||||
@@ -21,16 +21,14 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Rule;
|
||||
namespace Thelia\Condition;
|
||||
|
||||
use Symfony\Component\Intl\Exception\NotImplementedException;
|
||||
use Thelia\Constraint\ConstraintValidator;
|
||||
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;
|
||||
use Thelia\Coupon\AdapterInterface;
|
||||
use Thelia\Exception\InvalidConditionValueException;
|
||||
use Thelia\Model\Currency;
|
||||
use Thelia\Type\FloatType;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -43,7 +41,7 @@ use Thelia\Exception\InvalidRuleOperatorException;
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
abstract class ConditionManagerAbstract implements ConditionManagerInterface
|
||||
{
|
||||
// /** Operator key in $validators */
|
||||
// CONST OPERATOR = 'operator';
|
||||
@@ -62,7 +60,7 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
// /** @var array Parameters to be validated */
|
||||
// protected $paramsToValidate = array();
|
||||
|
||||
/** @var CouponAdapterInterface Provide necessary value from Thelia */
|
||||
/** @var AdapterInterface Provide necessary value from Thelia */
|
||||
protected $adapter = null;
|
||||
|
||||
/** @var Translator Service Translator */
|
||||
@@ -74,19 +72,19 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
/** @var array Values set by Admin in BackOffice */
|
||||
protected $values = array();
|
||||
|
||||
/** @var ConstraintValidator Constaints validator */
|
||||
protected $constraintValidator = null;
|
||||
/** @var ConditionEvaluator Conditions validator */
|
||||
protected $conditionValidator = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Service adapter
|
||||
* @param AdapterInterface $adapter Service adapter
|
||||
*/
|
||||
function __construct(CouponAdapterInterface $adapter)
|
||||
public function __construct(AdapterInterface $adapter)
|
||||
{
|
||||
$this->adapter = $adapter;
|
||||
$this->translator = $adapter->getTranslator();
|
||||
$this->constraintValidator = $adapter->getConstraintValidator();
|
||||
$this->conditionValidator = $adapter->getConditionEvaluator();
|
||||
}
|
||||
|
||||
// /**
|
||||
@@ -96,16 +94,16 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
// * validating $paramsToValidate against
|
||||
// *
|
||||
// * @return $this
|
||||
// * @throws InvalidRuleException
|
||||
// * @throws InvalidConditionException
|
||||
// */
|
||||
// protected function setValidators(array $validators)
|
||||
// {
|
||||
// foreach ($validators as $validator) {
|
||||
// if (!$validator instanceof RuleValidator) {
|
||||
// throw new InvalidRuleException(get_class());
|
||||
// throw new InvalidConditionException(get_class());
|
||||
// }
|
||||
// if (!in_array($validator->getOperator(), $this->availableOperators)) {
|
||||
// throw new InvalidRuleOperatorException(
|
||||
// throw new InvalidConditionOperatorException(
|
||||
// get_class(),
|
||||
// $validator->getOperator()
|
||||
// );
|
||||
@@ -146,7 +144,7 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
// }
|
||||
|
||||
/**
|
||||
* Return all available Operators for this Rule
|
||||
* Return all available Operators for this Condition
|
||||
*
|
||||
* @return array Operators::CONST
|
||||
*/
|
||||
@@ -158,7 +156,7 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
// /**
|
||||
// * Check if Operators set for this Rule in the BackOffice are legit
|
||||
// *
|
||||
// * @throws InvalidRuleOperatorException if Operator is not allowed
|
||||
// * @throws InvalidConditionOperatorException if Operator is not allowed
|
||||
// * @return bool
|
||||
// */
|
||||
// protected function checkBackOfficeInputsOperators()
|
||||
@@ -169,7 +167,7 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
// if (!isset($operator)
|
||||
// ||!in_array($operator, $this->availableOperators)
|
||||
// ) {
|
||||
// throw new InvalidRuleOperatorException(get_class(), $key);
|
||||
// throw new InvalidConditionOperatorException(get_class(), $key);
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
@@ -230,7 +228,7 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Rule Service id
|
||||
* Get ConditionManager Service id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -240,7 +238,7 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate if Operator given is available for this Coupon
|
||||
* Validate if Operator given is available for this Condition
|
||||
*
|
||||
* @param string $operator Operator to validate ex <
|
||||
* @param array $availableOperators Available operators
|
||||
@@ -253,19 +251,67 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a serializable Rule
|
||||
* Return a serializable Condition
|
||||
*
|
||||
* @return SerializableRule
|
||||
* @return SerializableCondition
|
||||
*/
|
||||
public function getSerializableRule()
|
||||
public function getSerializableCondition()
|
||||
{
|
||||
$serializableRule = new SerializableRule();
|
||||
$serializableRule->ruleServiceId = $this->serviceId;
|
||||
$serializableRule->operators = $this->operators;
|
||||
$serializableCondition = new SerializableCondition();
|
||||
$serializableCondition->conditionServiceId = $this->serviceId;
|
||||
$serializableCondition->operators = $this->operators;
|
||||
|
||||
$serializableRule->values = $this->values;
|
||||
$serializableCondition->values = $this->values;
|
||||
|
||||
return $serializableRule;
|
||||
return $serializableCondition;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if currency if valid or not
|
||||
*
|
||||
* @param string $currencyValue Currency EUR|USD|..
|
||||
*
|
||||
* @return bool
|
||||
* @throws \Thelia\Exception\InvalidConditionValueException
|
||||
*/
|
||||
protected function IsCurrencyValid($currencyValue)
|
||||
{
|
||||
$availableCurrencies = $this->adapter->getAvailableCurrencies();
|
||||
/** @var Currency $currency */
|
||||
$currencyFound = false;
|
||||
foreach ($availableCurrencies as $currency) {
|
||||
if ($currencyValue == $currency->getCode()) {
|
||||
$currencyFound = true;
|
||||
}
|
||||
}
|
||||
if (!$currencyFound) {
|
||||
throw new InvalidConditionValueException(
|
||||
get_class(), 'currency'
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if price is valid
|
||||
*
|
||||
* @param float $priceValue Price value to check
|
||||
*
|
||||
* @return bool
|
||||
* @throws \Thelia\Exception\InvalidConditionValueException
|
||||
*/
|
||||
protected function isPriceValid($priceValue)
|
||||
{
|
||||
$floatType = new FloatType();
|
||||
if (!$floatType->isValid($priceValue) || $priceValue <= 0) {
|
||||
throw new InvalidConditionValueException(
|
||||
get_class(), 'price'
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,30 +21,30 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Rule;
|
||||
namespace Thelia\Condition;
|
||||
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Coupon\AdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Represents a condition of whether the Rule is applied or not
|
||||
* Manage how the application checks its state in order to check if it matches the implemented condition
|
||||
*
|
||||
* @package Constraint
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
interface CouponRuleInterface
|
||||
interface ConditionManagerInterface
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Service adapter
|
||||
* @param AdapterInterface $adapter Service adapter
|
||||
*/
|
||||
function __construct(CouponAdapterInterface $adapter);
|
||||
function __construct(AdapterInterface $adapter);
|
||||
|
||||
/**
|
||||
* Get Rule Service id
|
||||
@@ -86,14 +86,14 @@ interface CouponRuleInterface
|
||||
// public function isMatching();
|
||||
|
||||
/**
|
||||
* Test if Customer meets conditions
|
||||
* Test if the current application state matches conditions
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isMatching();
|
||||
|
||||
/**
|
||||
* Return all available Operators for this Rule
|
||||
* Return all available Operators for this condition
|
||||
*
|
||||
* @return array Operators::CONST
|
||||
*/
|
||||
@@ -122,10 +122,10 @@ interface CouponRuleInterface
|
||||
public function getValidators();
|
||||
|
||||
// /**
|
||||
// * Populate a Rule from a form admin
|
||||
// * Populate a Condition from a form admin
|
||||
// *
|
||||
// * @param array $operators Rule Operator set by the Admin
|
||||
// * @param array $values Rule Values set by the Admin
|
||||
// * @param array $operators Condition Operator set by the Admin
|
||||
// * @param array $values Condition Values set by the Admin
|
||||
// *
|
||||
// * @return bool
|
||||
// */
|
||||
@@ -133,14 +133,10 @@ interface CouponRuleInterface
|
||||
|
||||
|
||||
/**
|
||||
* Return a serializable Rule
|
||||
* Return a serializable Condition
|
||||
*
|
||||
* @return SerializableRule
|
||||
* @return SerializableCondition
|
||||
*/
|
||||
public function getSerializableRule();
|
||||
|
||||
|
||||
|
||||
|
||||
public function getSerializableCondition();
|
||||
|
||||
}
|
||||
@@ -21,17 +21,10 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Rule;
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
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;
|
||||
use Thelia\Condition\ConditionManagerAbstract;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -40,14 +33,14 @@ use Thelia\Type\FloatType;
|
||||
*
|
||||
* Allow every one, perform no check
|
||||
*
|
||||
* @package Constraint
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AvailableForEveryoneManager extends CouponRuleAbstract
|
||||
class MatchForEveryoneManager extends ConditionManagerAbstract
|
||||
{
|
||||
/** @var string Service Id from Resources/config.xml */
|
||||
protected $serviceId = 'thelia.constraint.rule.available_for_everyone';
|
||||
protected $serviceId = 'thelia.condition.match_for_everyone';
|
||||
|
||||
/** @var array Available Operators (Operators::CONST) */
|
||||
protected $availableOperators = array();
|
||||
@@ -102,7 +95,7 @@ class AvailableForEveryoneManager extends CouponRuleAbstract
|
||||
return $this->translator->trans(
|
||||
'Everybody can use it (no condition)',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -116,7 +109,7 @@ class AvailableForEveryoneManager extends CouponRuleAbstract
|
||||
$toolTip = $this->translator->trans(
|
||||
'Will return always true',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
@@ -21,42 +21,37 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Rule;
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Symfony\Component\Intl\Exception\NotImplementedException;
|
||||
use Symfony\Component\Translation\Translator;
|
||||
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\Condition\ConditionManagerAbstract;
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Exception\InvalidConditionOperatorException;
|
||||
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
|
||||
* Condition AvailableForTotalAmount
|
||||
* Check if a Checkout total amount match criteria
|
||||
*
|
||||
* @package Constraint
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AvailableForTotalAmountManager extends CouponRuleAbstract
|
||||
class MatchForTotalAmountManager extends ConditionManagerAbstract
|
||||
{
|
||||
/** Rule 1st parameter : price */
|
||||
/** Condition 1st parameter : price */
|
||||
CONST INPUT1 = 'price';
|
||||
|
||||
/** Rule 1st parameter : currency */
|
||||
/** Condition 1st parameter : currency */
|
||||
CONST INPUT2 = 'currency';
|
||||
|
||||
/** @var string Service Id from Resources/config.xml */
|
||||
protected $serviceId = 'thelia.constraint.rule.available_for_total_amount';
|
||||
protected $serviceId = 'thelia.condition.match_for_total_amount';
|
||||
|
||||
/** @var array Available Operators (Operators::CONST) */
|
||||
protected $availableOperators = array(
|
||||
@@ -101,7 +96,7 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract
|
||||
* @param string $currencyOperator Currency Operator ex =
|
||||
* @param string $currencyValue Currency set to meet condition
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \Thelia\Exception\InvalidConditionOperatorException
|
||||
* @return $this
|
||||
*/
|
||||
protected function setValidators($priceOperator, $priceValue, $currencyOperator, $currencyValue)
|
||||
@@ -111,8 +106,8 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract
|
||||
$this->availableOperators[self::INPUT1]
|
||||
);
|
||||
if (!$isOperator1Legit) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Operator for price field is not legit'
|
||||
throw new InvalidConditionOperatorException(
|
||||
get_class(), 'price'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -121,19 +116,16 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract
|
||||
$this->availableOperators[self::INPUT2]
|
||||
);
|
||||
if (!$isOperator1Legit) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Operator for currency field is not legit'
|
||||
throw new InvalidConditionOperatorException(
|
||||
get_class(), 'price'
|
||||
);
|
||||
}
|
||||
|
||||
$floatType = new FloatType();
|
||||
if (!$floatType->isValid($priceValue) || $priceValue <= 0) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Value for price field is not legit'
|
||||
);
|
||||
}
|
||||
$this->isPriceValid($priceValue);
|
||||
|
||||
|
||||
$this->IsCurrencyValid($currencyValue);
|
||||
|
||||
// @todo check currency is legit or not
|
||||
|
||||
$this->operators = array(
|
||||
self::INPUT1 => $priceOperator,
|
||||
@@ -167,19 +159,20 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract
|
||||
return false;
|
||||
}
|
||||
|
||||
$constraint1 = $this->constraintValidator->variableOpComparison(
|
||||
$condition1 = $this->conditionValidator->variableOpComparison(
|
||||
$this->adapter->getCartTotalPrice(),
|
||||
$this->operators[self::INPUT1],
|
||||
$this->values[self::INPUT1]
|
||||
);
|
||||
$constraint2 = $this->constraintValidator->variableOpComparison(
|
||||
$condition2 = $this->conditionValidator->variableOpComparison(
|
||||
$this->adapter->getCheckoutCurrency(),
|
||||
$this->operators[self::INPUT2],
|
||||
$this->values[self::INPUT2]
|
||||
);
|
||||
if ($constraint1 && $constraint2) {
|
||||
if ($condition1 && $condition2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -193,7 +186,7 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract
|
||||
return $this->translator->trans(
|
||||
'Cart total amount',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -215,7 +208,7 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract
|
||||
'%amount%' => $this->values[self::INPUT1],
|
||||
'%currency%' => $this->values[self::INPUT2]
|
||||
),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
@@ -238,12 +231,12 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract
|
||||
$name1 = $this->translator->trans(
|
||||
'Price',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
$name2 = $this->translator->trans(
|
||||
'Currency',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
|
||||
return array(
|
||||
@@ -21,17 +21,13 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Rule;
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
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;
|
||||
use Thelia\Condition\ConditionManagerAbstract;
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Exception\InvalidConditionOperatorException;
|
||||
use Thelia\Exception\InvalidConditionValueException;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -40,17 +36,17 @@ use Thelia\Type\FloatType;
|
||||
*
|
||||
* Check a Checkout against its Product number
|
||||
*
|
||||
* @package Constraint
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AvailableForXArticlesManager extends CouponRuleAbstract
|
||||
class MatchForXArticlesManager extends ConditionManagerAbstract
|
||||
{
|
||||
/** Rule 1st parameter : quantity */
|
||||
/** Condition 1st parameter : quantity */
|
||||
CONST INPUT1 = 'quantity';
|
||||
|
||||
/** @var string Service Id from Resources/config.xml */
|
||||
protected $serviceId = 'thelia.constraint.rule.available_for_x_articles';
|
||||
protected $serviceId = 'thelia.condition.match_for_x_articles';
|
||||
|
||||
/** @var array Available Operators (Operators::CONST) */
|
||||
protected $availableOperators = array(
|
||||
@@ -88,7 +84,8 @@ class AvailableForXArticlesManager extends CouponRuleAbstract
|
||||
* @param string $quantityOperator Quantity Operator ex <
|
||||
* @param int $quantityValue Quantity set to meet condition
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \Thelia\Exception\InvalidConditionValueException
|
||||
* @throws \Thelia\Exception\InvalidConditionOperatorException
|
||||
* @return $this
|
||||
*/
|
||||
protected function setValidators($quantityOperator, $quantityValue)
|
||||
@@ -98,14 +95,14 @@ class AvailableForXArticlesManager extends CouponRuleAbstract
|
||||
$this->availableOperators[self::INPUT1]
|
||||
);
|
||||
if (!$isOperator1Legit) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Operator for quantity field is not legit'
|
||||
throw new InvalidConditionOperatorException(
|
||||
get_class(), 'quantity'
|
||||
);
|
||||
}
|
||||
|
||||
if ((int) $quantityValue <= 0) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Value for quantity field is not legit'
|
||||
throw new InvalidConditionValueException(
|
||||
get_class(), 'quantity'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -126,15 +123,16 @@ class AvailableForXArticlesManager extends CouponRuleAbstract
|
||||
*/
|
||||
public function isMatching()
|
||||
{
|
||||
$constraint1 = $this->constraintValidator->variableOpComparison(
|
||||
$condition1 = $this->conditionValidator->variableOpComparison(
|
||||
$this->adapter->getNbArticlesInCart(),
|
||||
$this->operators[self::INPUT1],
|
||||
$this->values[self::INPUT1]
|
||||
);
|
||||
|
||||
if ($constraint1) {
|
||||
if ($condition1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -148,7 +146,7 @@ class AvailableForXArticlesManager extends CouponRuleAbstract
|
||||
return $this->translator->trans(
|
||||
'Number of articles in cart',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -169,7 +167,7 @@ class AvailableForXArticlesManager extends CouponRuleAbstract
|
||||
'%operator%' => $i18nOperator,
|
||||
'%quantity%' => $this->values[self::INPUT1]
|
||||
),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
@@ -185,7 +183,7 @@ class AvailableForXArticlesManager extends CouponRuleAbstract
|
||||
$name1 = $this->translator->trans(
|
||||
'Quantity',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
|
||||
return array(
|
||||
@@ -199,5 +197,4 @@ class AvailableForXArticlesManager extends CouponRuleAbstract
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -21,17 +21,16 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Rule;
|
||||
namespace Thelia\Condition;
|
||||
|
||||
use Symfony\Component\Translation\Translator;
|
||||
use Thelia\Constraint\Validator\ComparableInterface;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Represent available Operations in rule checking
|
||||
* Represent available Operations in condition checking
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
@@ -56,62 +55,6 @@ abstract class Operators
|
||||
/** 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
|
||||
*
|
||||
@@ -128,56 +71,56 @@ abstract class Operators
|
||||
$ret = $translator->trans(
|
||||
'inferior to',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
break;
|
||||
case self::INFERIOR_OR_EQUAL:
|
||||
$ret = $translator->trans(
|
||||
'inferior or equal to',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
break;
|
||||
case self::EQUAL:
|
||||
$ret = $translator->trans(
|
||||
'equal to',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
break;
|
||||
case self::SUPERIOR_OR_EQUAL:
|
||||
$ret = $translator->trans(
|
||||
'superior or equal to',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
break;
|
||||
case self::SUPERIOR:
|
||||
$ret = $translator->trans(
|
||||
'superior to',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
break;
|
||||
case self::DIFFERENT:
|
||||
$ret = $translator->trans(
|
||||
'different from',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
break;
|
||||
case self::IN:
|
||||
$ret = $translator->trans(
|
||||
'in',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
break;
|
||||
case self::OUT:
|
||||
$ret = $translator->trans(
|
||||
'not in',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
break;
|
||||
default:
|
||||
@@ -21,50 +21,57 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
namespace Thelia\Condition;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Unit Test RemoveXPercentForCategoryY Class
|
||||
* A condition set by an admin ready to be serialized and stored in DataBase
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RemoveXPercentForCategoryYTest extends \PHPUnit_Framework_TestCase
|
||||
class SerializableCondition
|
||||
{
|
||||
public function testSomething()
|
||||
{
|
||||
// Stop here and mark this test as incomplete.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
/** @var string Condition Service id */
|
||||
public $conditionServiceId = null;
|
||||
|
||||
/** @var array Operators set by Admin for this Condition */
|
||||
public $operators = array();
|
||||
|
||||
/** @var array Values set by Admin for this Condition */
|
||||
public $values = array();
|
||||
|
||||
// /**
|
||||
// * Sets up the fixture, for example, opens a network connection.
|
||||
// * This method is called before a test is executed.
|
||||
// * Get Operators set by Admin for this Condition
|
||||
// *
|
||||
// * @return array
|
||||
// */
|
||||
// protected function setUp()
|
||||
// public function getOperators()
|
||||
// {
|
||||
// }
|
||||
//
|
||||
// public function incompleteTest()
|
||||
// {
|
||||
// $this->markTestIncomplete(
|
||||
// 'This test has not been implemented yet.'
|
||||
// );
|
||||
// return $this->operators;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Tears down the fixture, for example, closes a network connection.
|
||||
// * This method is called after a test is executed.
|
||||
// * Get Condition Service id
|
||||
// *
|
||||
// * @return string
|
||||
// */
|
||||
// protected function tearDown()
|
||||
// public function getConditionServiceId()
|
||||
// {
|
||||
// return $this->conditionServiceId;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Get Values set by Admin for this Condition
|
||||
// *
|
||||
// * @return array
|
||||
// */
|
||||
// public function getValues()
|
||||
// {
|
||||
// return $this->values;
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -60,7 +60,7 @@ class DatabaseConfiguration implements ConfigurationInterface
|
||||
->cannotBeEmpty()
|
||||
->end()
|
||||
->scalarNode("classname")
|
||||
->defaultValue("\Propel\Runtime\Connection\PropelPDO")
|
||||
->defaultValue("\Propel\Runtime\Connection\ConnectionWrapper")
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
|
||||
@@ -21,8 +21,12 @@
|
||||
<loop class="Thelia\Core\Template\Loop\FeatureAvailability" name="feature-availability"/>
|
||||
<loop class="Thelia\Core\Template\Loop\FeatureValue" name="feature_value"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Folder" name="folder"/>
|
||||
<loop class="Thelia\Core\Template\Loop\FolderPath" name="folder-path"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Module" name="module"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Order" name="order"/>
|
||||
<loop class="Thelia\Core\Template\Loop\OrderAddress" name="order_address"/>
|
||||
<loop class="Thelia\Core\Template\Loop\OrderProduct" name="order_product"/>
|
||||
<loop class="Thelia\Core\Template\Loop\OrderProductAttributeCombination" name="order_product_attribute_combination"/>
|
||||
<loop class="Thelia\Core\Template\Loop\OrderStatus" name="order-status"/>
|
||||
<loop class="Thelia\Core\Template\Loop\CategoryPath" name="category-path"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Payment" name="payment"/>
|
||||
@@ -84,6 +88,7 @@
|
||||
|
||||
<form name="thelia.order.delivery" class="Thelia\Form\OrderDelivery"/>
|
||||
<form name="thelia.order.payment" class="Thelia\Form\OrderPayment"/>
|
||||
<form name="thelia.order.update.address" class="Thelia\Form\OrderUpdateAddress"/>
|
||||
|
||||
<form name="thelia.admin.config.creation" class="Thelia\Form\ConfigCreationForm"/>
|
||||
<form name="thelia.admin.config.modification" class="Thelia\Form\ConfigModificationForm"/>
|
||||
@@ -204,6 +209,10 @@
|
||||
</call>
|
||||
</service>
|
||||
|
||||
<service id="smarty.plugin.type" class="Thelia\Core\Template\Smarty\Plugins\Type" scope="request">
|
||||
<tag name="thelia.parser.register_plugin"/>
|
||||
</service>
|
||||
|
||||
<service id="smart.plugin.form" class="Thelia\Core\Template\Smarty\Plugins\Form" scope="request">
|
||||
<tag name="thelia.parser.register_plugin"/>
|
||||
|
||||
@@ -267,7 +276,7 @@
|
||||
<service id="kernel" synthetic="true" />
|
||||
|
||||
<!-- Coupon module -->
|
||||
<service id="thelia.adapter" class="Thelia\Coupon\CouponBaseAdapter">
|
||||
<service id="thelia.adapter" class="Thelia\Coupon\BaseAdapter">
|
||||
<argument type="service" id="service_container" />
|
||||
</service>
|
||||
<service id="thelia.coupon.manager" class="Thelia\Coupon\CouponManager">
|
||||
@@ -277,24 +286,6 @@
|
||||
<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.validator" class="Thelia\Constraint\ConstraintValidator">
|
||||
</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"/>
|
||||
@@ -304,6 +295,26 @@
|
||||
<tag name="thelia.coupon.addCoupon"/>
|
||||
</service>
|
||||
|
||||
|
||||
<!-- Condition module -->
|
||||
<service id="thelia.condition.factory" class="Thelia\Condition\ConditionFactory">
|
||||
<argument type="service" id="service_container" />
|
||||
</service>
|
||||
<service id="thelia.condition.validator" class="Thelia\Condition\ConditionEvaluator">
|
||||
</service>
|
||||
<service id="thelia.condition.match_for_everyone" class="Thelia\Condition\Implementation\MatchForEveryoneManager">
|
||||
<argument type="service" id="thelia.adapter" />
|
||||
<tag name="thelia.coupon.addCondition"/>
|
||||
</service>
|
||||
<service id="thelia.condition.match_for_x_articles" class="Thelia\Condition\Implementation\MatchForXArticlesManager">
|
||||
<argument type="service" id="thelia.adapter" />
|
||||
<tag name="thelia.coupon.addCondition"/>
|
||||
</service>
|
||||
<service id="thelia.condition.match_for_total_amount" class="Thelia\Condition\Implementation\MatchForTotalAmountManager">
|
||||
<argument type="service" id="thelia.adapter" />
|
||||
<tag name="thelia.coupon.addCondition"/>
|
||||
</service>
|
||||
|
||||
<service id="mailer" class="Thelia\Mailer\MailerFactory">
|
||||
<argument type="service" id="event_dispatcher"/>
|
||||
</service>
|
||||
|
||||
@@ -123,9 +123,9 @@
|
||||
|
||||
<!-- end Customer rule management -->
|
||||
|
||||
<!-- Order rule management -->
|
||||
<!-- order management -->
|
||||
|
||||
<route id="admin.order" path="/admin/order">
|
||||
<route id="admin.order.list" path="/admin/orders">
|
||||
<default key="_controller">Thelia\Controller\Admin\OrderController::indexAction</default>
|
||||
</route>
|
||||
|
||||
@@ -134,7 +134,23 @@
|
||||
<requirement key="order_id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<!-- end Customer rule management -->
|
||||
<route id="admin.order.list.update.status" path="/admin/order/update/status">
|
||||
<default key="_controller">Thelia\Controller\Admin\OrderController::updateStatus</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.order.update.status" path="/admin/order/update/{order_id}/status">
|
||||
<default key="_controller">Thelia\Controller\Admin\OrderController::updateStatus</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.order.update.deliveryRef" path="/admin/order/update/{order_id}/delivery-ref">
|
||||
<default key="_controller">Thelia\Controller\Admin\OrderController::updateDeliveryRef</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.order.update.address" path="/admin/order/update/{order_id}/address">
|
||||
<default key="_controller">Thelia\Controller\Admin\OrderController::updateAddress</default>
|
||||
</route>
|
||||
|
||||
<!-- end order management -->
|
||||
|
||||
<!-- Categories management -->
|
||||
|
||||
@@ -367,29 +383,54 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\ContentController::processUpdateAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.content.update-position" path="/admin/content/update-position">
|
||||
<default key="_controller">Thelia\Controller\Admin\ContentController::updatePositionAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.content.toggle-online" path="/admin/content/toggle-online">
|
||||
<default key="_controller">Thelia\Controller\Admin\ContentController::setToggleVisibilityAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.content.delete" path="/admin/content/delete">
|
||||
<default key="_controller">Thelia\Controller\Admin\ContentController::deleteAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.content.additional-folder.add" path="/admin/content/folder/add">
|
||||
<default key="_controller">Thelia\Controller\Admin\ContentController::addAdditionalFolderAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.content.additional-folder.delete" path="/admin/content/folder/delete">
|
||||
<default key="_controller">Thelia\Controller\Admin\ContentController::removeAdditionalFolderAction</default>
|
||||
</route>
|
||||
|
||||
|
||||
<!-- Route to the Coupon controller (process Coupon browsing) -->
|
||||
|
||||
<route id="admin.coupon.list" path="/admin/coupon/">
|
||||
<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/">
|
||||
<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}/">
|
||||
<route id="admin.coupon.update" path="/admin/coupon/update/{couponId}">
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::updateAction</default>
|
||||
<requirement key="couponId">\d+</requirement>
|
||||
</route>
|
||||
<route id="admin.coupon.read" path="/admin/coupon/read/{couponId}/">
|
||||
<route id="admin.coupon.read" path="/admin/coupon/read/{couponId}">
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::readAction</default>
|
||||
<requirement key="couponId">\d+</requirement>
|
||||
</route>
|
||||
<route id="admin.coupon.rule.input" path="/admin/coupon/rule/{ruleId}/">
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::getRuleInputAction</default>
|
||||
<route id="admin.coupon.condition.input" path="/admin/coupon/condition/{conditionId}">
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::getConditionInputAction</default>
|
||||
<requirement key="conditionId">.*</requirement>
|
||||
</route>
|
||||
<route id="admin.coupon.rule.update" path="/admin/coupon/{couponId}/rule/update/">
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::updateRulesAction</default>
|
||||
<route id="admin.coupon.condition.update" path="/admin/coupon/{couponId}/condition/update">
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::updateConditionsAction</default>
|
||||
<requirement key="couponId">\d+</requirement>
|
||||
</route>
|
||||
<route id="admin.coupon.consume" path="/admin/coupon/consume/{couponCode}/">
|
||||
<route id="admin.coupon.consume" path="/admin/coupon/consume/{couponCode}">
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::consumeAction</default>
|
||||
<requirement key="couponCode">.*</requirement>
|
||||
</route>
|
||||
|
||||
<!-- Routes to the Config (system variables) controller -->
|
||||
|
||||
@@ -117,22 +117,22 @@
|
||||
<!-- order management process -->
|
||||
<route id="order.delivery.process" path="/order/delivery" methods="post">
|
||||
<default key="_controller">Thelia\Controller\Front\OrderController::deliver</default>
|
||||
<default key="_view">order_delivery</default>
|
||||
<default key="_view">order-delivery</default>
|
||||
</route>
|
||||
|
||||
<route id="order.delivery" path="/order/delivery">
|
||||
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
|
||||
<default key="_view">order_delivery</default>
|
||||
<default key="_view">order-delivery</default>
|
||||
</route>
|
||||
|
||||
<route id="order.invoice.process" path="/order/invoice" methods="post">
|
||||
<default key="_controller">Thelia\Controller\Front\OrderController::invoice</default>
|
||||
<default key="_view">order_invoice</default>
|
||||
<default key="_view">order-invoice</default>
|
||||
</route>
|
||||
|
||||
<route id="order.invoice" path="/order/invoice">
|
||||
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
|
||||
<default key="_view">order_invoice</default>
|
||||
<default key="_view">order-invoice</default>
|
||||
</route>
|
||||
|
||||
<route id="order.payment.process" path="/order/pay">
|
||||
@@ -141,7 +141,7 @@
|
||||
|
||||
<route id="order.placed" path="/order/placed/{order_id}">
|
||||
<default key="_controller">Thelia\Controller\Front\OrderController::orderPlaced</default>
|
||||
<default key="_view">order_placed</default>
|
||||
<default key="_view">order-placed</default>
|
||||
</route>
|
||||
<!-- end order management process -->
|
||||
|
||||
|
||||
@@ -1,174 +0,0 @@
|
||||
<?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\AvailableForEveryoneManager;
|
||||
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)
|
||||
{
|
||||
if ($collection->isEmpty()) {
|
||||
/** @var CouponRuleInterface $ruleNoCondition */
|
||||
$ruleNoCondition = $this->container->get(
|
||||
'thelia.constraint.rule.available_for_everyone'
|
||||
);
|
||||
$collection->add($ruleNoCondition);
|
||||
}
|
||||
$serializableRules = array();
|
||||
$rules = $collection->getRules();
|
||||
if ($rules !== null) {
|
||||
/** @var $rule CouponRuleInterface */
|
||||
foreach ($rules as $rule) {
|
||||
// Remove all rule if the "no condition" rule is found
|
||||
// if ($rule->getServiceId() == 'thelia.constraint.rule.available_for_everyone') {
|
||||
// return base64_encode(json_encode(array($rule->getSerializableRule())));
|
||||
// }
|
||||
$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();
|
||||
}
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
<?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 isMatching(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;
|
||||
}
|
||||
}
|
||||
@@ -1,178 +0,0 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
<?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.
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
<?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.
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
<?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);
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
<?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'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
<?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');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
<?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');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,165 +0,0 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
<?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'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
<?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'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
||||
@@ -1,297 +0,0 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,7 +25,6 @@ namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Core\Event\ToggleVisibilityEvent;
|
||||
|
||||
/**
|
||||
* An abstract CRUD controller for Thelia ADMIN, to manage basic CRUD operations on a givent object.
|
||||
@@ -53,14 +52,13 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
protected $visibilityToggleEventIdentifier;
|
||||
protected $changePositionEventIdentifier;
|
||||
|
||||
|
||||
/**
|
||||
* @param string $objectName the lower case object name. Example. "message"
|
||||
*
|
||||
* @param string $defaultListOrder the default object list order, or null if list is not sortable. Example: manual
|
||||
* @param string $defaultListOrder the default object list order, or null if list is not sortable. Example: manual
|
||||
* @param string $orderRequestParameterName Name of the request parameter that set the list order (null if list is not sortable)
|
||||
*
|
||||
* @param string $viewPermissionIdentifier the 'view' permission identifier. Example: "admin.configuration.message.view"
|
||||
* @param string $viewPermissionIdentifier the 'view' permission identifier. Example: "admin.configuration.message.view"
|
||||
* @param string $createPermissionIdentifier the 'create' permission identifier. Example: "admin.configuration.message.create"
|
||||
* @param string $updatePermissionIdentifier the 'update' permission identifier. Example: "admin.configuration.message.update"
|
||||
* @param string $deletePermissionIdentifier the 'delete' permission identifier. Example: "admin.configuration.message.delete"
|
||||
@@ -70,7 +68,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
* @param string $deleteEventIdentifier the dispatched delete TheliaEvent identifier. Example: TheliaEvents::MESSAGE_DELETE
|
||||
*
|
||||
* @param string $visibilityToggleEventIdentifier the dispatched visibility toggle TheliaEvent identifier, or null if the object has no visible options. Example: TheliaEvents::MESSAGE_TOGGLE_VISIBILITY
|
||||
* @param string $changePositionEventIdentifier the dispatched position change TheliaEvent identifier, or null if the object has no position. Example: TheliaEvents::MESSAGE_UPDATE_POSITION
|
||||
* @param string $changePositionEventIdentifier the dispatched position change TheliaEvent identifier, or null if the object has no position. Example: TheliaEvents::MESSAGE_UPDATE_POSITION
|
||||
*/
|
||||
public function __construct(
|
||||
$objectName,
|
||||
@@ -109,94 +107,93 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
/**
|
||||
* Return the creation form for this object
|
||||
*/
|
||||
protected abstract function getCreationForm();
|
||||
abstract protected function getCreationForm();
|
||||
|
||||
/**
|
||||
* Return the update form for this object
|
||||
*/
|
||||
protected abstract function getUpdateForm();
|
||||
abstract protected function getUpdateForm();
|
||||
|
||||
/**
|
||||
* Hydrate the update form for this object, before passing it to the update template
|
||||
*
|
||||
* @param unknown $object
|
||||
*/
|
||||
protected abstract function hydrateObjectForm($object);
|
||||
abstract protected function hydrateObjectForm($object);
|
||||
|
||||
/**
|
||||
* Creates the creation event with the provided form data
|
||||
*
|
||||
* @param unknown $formData
|
||||
*/
|
||||
protected abstract function getCreationEvent($formData);
|
||||
abstract protected function getCreationEvent($formData);
|
||||
|
||||
/**
|
||||
* Creates the update event with the provided form data
|
||||
*
|
||||
* @param unknown $formData
|
||||
*/
|
||||
protected abstract function getUpdateEvent($formData);
|
||||
abstract protected function getUpdateEvent($formData);
|
||||
|
||||
/**
|
||||
* Creates the delete event with the provided form data
|
||||
*/
|
||||
protected abstract function getDeleteEvent();
|
||||
abstract protected function getDeleteEvent();
|
||||
|
||||
/**
|
||||
* Return true if the event contains the object, e.g. the action has updated the object in the event.
|
||||
*
|
||||
* @param unknown $event
|
||||
*/
|
||||
protected abstract function eventContainsObject($event);
|
||||
abstract protected function eventContainsObject($event);
|
||||
|
||||
/**
|
||||
* Get the created object from an event.
|
||||
*
|
||||
* @param unknown $createEvent
|
||||
*/
|
||||
protected abstract function getObjectFromEvent($event);
|
||||
abstract protected function getObjectFromEvent($event);
|
||||
|
||||
/**
|
||||
* Load an existing object from the database
|
||||
*/
|
||||
protected abstract function getExistingObject();
|
||||
abstract protected function getExistingObject();
|
||||
|
||||
/**
|
||||
* Returns the object label form the object event (name, title, etc.)
|
||||
*
|
||||
* @param unknown $object
|
||||
*/
|
||||
protected abstract function getObjectLabel($object);
|
||||
abstract protected function getObjectLabel($object);
|
||||
|
||||
/**
|
||||
* Returns the object ID from the object
|
||||
*
|
||||
* @param unknown $object
|
||||
*/
|
||||
protected abstract function getObjectId($object);
|
||||
abstract protected function getObjectId($object);
|
||||
|
||||
/**
|
||||
* Render the main list template
|
||||
*
|
||||
* @param unknown $currentOrder, if any, null otherwise.
|
||||
*/
|
||||
protected abstract function renderListTemplate($currentOrder);
|
||||
abstract protected function renderListTemplate($currentOrder);
|
||||
|
||||
/**
|
||||
* Render the edition template
|
||||
*/
|
||||
protected abstract function renderEditionTemplate();
|
||||
abstract protected function renderEditionTemplate();
|
||||
|
||||
/**
|
||||
* Redirect to the edition template
|
||||
*/
|
||||
protected abstract function redirectToEditionTemplate();
|
||||
abstract protected function redirectToEditionTemplate();
|
||||
|
||||
/**
|
||||
* Redirect to the list template
|
||||
*/
|
||||
protected abstract function redirectToListTemplate();
|
||||
|
||||
abstract protected function redirectToListTemplate();
|
||||
|
||||
protected function createUpdatePositionEvent($positionChangeMode, $positionValue)
|
||||
{
|
||||
@@ -211,7 +208,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
/**
|
||||
* Put in this method post object creation processing if required.
|
||||
*
|
||||
* @param unknown $createEvent the create event
|
||||
* @param unknown $createEvent the create event
|
||||
* @return Response a response, or null to continue normal processing
|
||||
*/
|
||||
protected function performAdditionalCreateAction($createEvent)
|
||||
@@ -222,7 +219,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
/**
|
||||
* Put in this method post object update processing if required.
|
||||
*
|
||||
* @param unknown $updateEvent the update event
|
||||
* @param unknown $updateEvent the update event
|
||||
* @return Response a response, or null to continue normal processing
|
||||
*/
|
||||
protected function performAdditionalUpdateAction($updateEvent)
|
||||
@@ -233,7 +230,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
/**
|
||||
* Put in this method post object delete processing if required.
|
||||
*
|
||||
* @param unknown $deleteEvent the delete event
|
||||
* @param unknown $deleteEvent the delete event
|
||||
* @return Response a response, or null to continue normal processing
|
||||
*/
|
||||
protected function performAdditionalDeleteAction($deleteEvent)
|
||||
@@ -244,7 +241,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
/**
|
||||
* Put in this method post object position change processing if required.
|
||||
*
|
||||
* @param unknown $deleteEvent the delete event
|
||||
* @param unknown $deleteEvent the delete event
|
||||
* @return Response a response, or null to continue normal processing
|
||||
*/
|
||||
protected function performAdditionalUpdatePositionAction($positionChangeEvent)
|
||||
@@ -282,7 +279,6 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
public function defaultAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth($this->viewPermissionIdentifier)) return $response;
|
||||
|
||||
return $this->renderList();
|
||||
}
|
||||
|
||||
@@ -323,22 +319,19 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
|
||||
$response = $this->performAdditionalCreateAction($createEvent);
|
||||
|
||||
if ($response == null) {
|
||||
if ($response == null) {
|
||||
// Substitute _ID_ in the URL with the ID of the created object
|
||||
$successUrl = str_replace('_ID_', $this->getObjectId($createdObject), $creationForm->getSuccessUrl());
|
||||
|
||||
// Redirect to the success URL
|
||||
$this->redirect($successUrl);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
catch (FormValidationException $ex) {
|
||||
} catch (FormValidationException $ex) {
|
||||
// Form cannot be validated
|
||||
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
} catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$error_msg = $ex->getMessage();
|
||||
}
|
||||
@@ -423,16 +416,13 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
|
||||
// Redirect to the success URL
|
||||
$this->redirect($changeForm->getSuccessUrl());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
catch (FormValidationException $ex) {
|
||||
} catch (FormValidationException $ex) {
|
||||
// Form cannot be validated
|
||||
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
} catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$error_msg = $ex->getMessage();
|
||||
}
|
||||
@@ -469,8 +459,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
$event = $this->createUpdatePositionEvent($mode, $position);
|
||||
|
||||
$this->dispatch($this->changePositionEventIdentifier, $event);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
} catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
@@ -479,14 +468,13 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
|
||||
if ($response == null) {
|
||||
$this->redirectToListTemplate();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
protected function genericUpdatePositionAction($object, $eventName, $doFinalRedirect = true) {
|
||||
|
||||
protected function genericUpdatePositionAction($object, $eventName, $doFinalRedirect = true)
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response;
|
||||
|
||||
@@ -507,8 +495,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
$event = new UpdatePositionEvent($object->getId(), $mode, $position);
|
||||
|
||||
$this->dispatch($eventName, $event);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
} catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
|
||||
@@ -23,10 +23,6 @@
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Security\Authentication\AdminTokenAuthenticator;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Core\Security\Exception\TokenAuthenticationException;
|
||||
|
||||
class AdminController extends BaseAdminController
|
||||
{
|
||||
public function indexAction()
|
||||
@@ -36,6 +32,6 @@ class AdminController extends BaseAdminController
|
||||
|
||||
public function updateAction()
|
||||
{
|
||||
return $this->render("profile-edit");
|
||||
return $this->render("profile-edit");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,10 +23,10 @@
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Event\AttributeAvDeleteEvent;
|
||||
use Thelia\Core\Event\Attribute\AttributeAvDeleteEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\AttributeAvUpdateEvent;
|
||||
use Thelia\Core\Event\AttributeAvCreateEvent;
|
||||
use Thelia\Core\Event\Attribute\AttributeAvUpdateEvent;
|
||||
use Thelia\Core\Event\Attribute\AttributeAvCreateEvent;
|
||||
use Thelia\Model\AttributeAvQuery;
|
||||
use Thelia\Form\AttributeAvModificationForm;
|
||||
use Thelia\Form\AttributeAvCreationForm;
|
||||
@@ -193,4 +193,4 @@ class AttributeAvController extends AbstractCrudController
|
||||
$this->getViewArguments()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,18 +23,18 @@
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Event\AttributeDeleteEvent;
|
||||
use Thelia\Core\Event\Attribute\AttributeDeleteEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\AttributeUpdateEvent;
|
||||
use Thelia\Core\Event\AttributeCreateEvent;
|
||||
use Thelia\Core\Event\Attribute\AttributeUpdateEvent;
|
||||
use Thelia\Core\Event\Attribute\AttributeCreateEvent;
|
||||
use Thelia\Model\AttributeQuery;
|
||||
use Thelia\Form\AttributeModificationForm;
|
||||
use Thelia\Form\AttributeCreationForm;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Model\AttributeAv;
|
||||
use Thelia\Model\AttributeAvQuery;
|
||||
use Thelia\Core\Event\AttributeAvUpdateEvent;
|
||||
use Thelia\Core\Event\AttributeEvent;
|
||||
use Thelia\Core\Event\Attribute\AttributeAvUpdateEvent;
|
||||
use Thelia\Core\Event\Attribute\AttributeEvent;
|
||||
|
||||
/**
|
||||
* Manages attributes
|
||||
@@ -113,7 +113,7 @@ class AttributeController extends AbstractCrudController
|
||||
|
||||
if ($attr_values !== null) {
|
||||
|
||||
foreach($attr_values as $id => $value) {
|
||||
foreach ($attr_values as $id => $value) {
|
||||
|
||||
$event = new AttributeAvUpdateEvent($id);
|
||||
|
||||
@@ -168,7 +168,7 @@ class AttributeController extends AbstractCrudController
|
||||
|
||||
$attr_array = array();
|
||||
|
||||
foreach($attr_av_list as $attr_av) {
|
||||
foreach ($attr_av_list as $attr_av) {
|
||||
$attr_array[$attr_av->getId()] = $attr_av->getTitle();
|
||||
}
|
||||
|
||||
@@ -262,8 +262,7 @@ class AttributeController extends AbstractCrudController
|
||||
|
||||
$this->dispatch($eventType, $event);
|
||||
}
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
} catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
@@ -286,4 +285,4 @@ class AttributeController extends AbstractCrudController
|
||||
{
|
||||
return $this->addRemoveFromAllTemplates(TheliaEvents::ATTRIBUTE_ADD_TO_ALL_TEMPLATES);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,20 +293,19 @@ class BaseAdminController extends BaseController
|
||||
return $this->getCurrentEditionLang()->getLocale();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the current list order identifier for a given object name,
|
||||
* updating in using the current request.
|
||||
*
|
||||
* @param unknown $objectName the object name (e.g. 'attribute', 'message')
|
||||
* @param unknown $objectName the object name (e.g. 'attribute', 'message')
|
||||
* @param unknown $requestParameterName the name of the request parameter that defines the list order
|
||||
* @param unknown $defaultListOrder the default order to use, if none is defined
|
||||
* @param string $updateSession if true, the session will be updated with the current order.
|
||||
* @param unknown $defaultListOrder the default order to use, if none is defined
|
||||
* @param string $updateSession if true, the session will be updated with the current order.
|
||||
*
|
||||
* @return String the current liste order.
|
||||
*/
|
||||
protected function getListOrderFromSession($objectName, $requestParameterName, $defaultListOrder, $updateSession = true) {
|
||||
|
||||
protected function getListOrderFromSession($objectName, $requestParameterName, $defaultListOrder, $updateSession = true)
|
||||
{
|
||||
$order = $defaultListOrder;
|
||||
|
||||
$orderSessionIdentifier = sprintf("admin.%s.currentListOrder", $objectName);
|
||||
@@ -318,7 +317,6 @@ class BaseAdminController extends BaseController
|
||||
);
|
||||
|
||||
if ($updateSession) $this->getSession()->set($orderSessionIdentifier, $order);
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
@@ -353,8 +351,8 @@ class BaseAdminController extends BaseController
|
||||
/** Clear the remember me cookie.
|
||||
*
|
||||
*/
|
||||
protected function clearRememberMeCookie() {
|
||||
|
||||
protected function clearRememberMeCookie()
|
||||
{
|
||||
$ctp = new CookieTokenProvider();
|
||||
|
||||
$cookieName = ConfigQuery::read('admin_remember_me_cookie_name', 'armcn');
|
||||
|
||||
@@ -24,19 +24,17 @@
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Thelia\Core\Event\CategoryDeleteEvent;
|
||||
use Thelia\Core\Event\ImageCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\Category\CategoryDeleteEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\CategoryUpdateEvent;
|
||||
use Thelia\Core\Event\CategoryCreateEvent;
|
||||
use Thelia\Log\Tlog;
|
||||
use Thelia\Core\Event\Category\CategoryUpdateEvent;
|
||||
use Thelia\Core\Event\Category\CategoryCreateEvent;
|
||||
use Thelia\Model\CategoryQuery;
|
||||
use Thelia\Form\CategoryModificationForm;
|
||||
use Thelia\Form\CategoryCreationForm;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Core\Event\CategoryToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\CategoryDeleteContentEvent;
|
||||
use Thelia\Core\Event\CategoryAddContentEvent;
|
||||
use Thelia\Core\Event\Category\CategoryToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\Category\CategoryDeleteContentEvent;
|
||||
use Thelia\Core\Event\Category\CategoryAddContentEvent;
|
||||
use Thelia\Model\FolderQuery;
|
||||
use Thelia\Model\ContentQuery;
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
@@ -49,7 +47,8 @@ use Thelia\Model\CategoryAssociatedContentQuery;
|
||||
*/
|
||||
class CategoryController extends AbstractCrudController
|
||||
{
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
'category',
|
||||
'manual',
|
||||
@@ -68,15 +67,18 @@ class CategoryController extends AbstractCrudController
|
||||
);
|
||||
}
|
||||
|
||||
protected function getCreationForm() {
|
||||
protected function getCreationForm()
|
||||
{
|
||||
return new CategoryCreationForm($this->getRequest());
|
||||
}
|
||||
|
||||
protected function getUpdateForm() {
|
||||
protected function getUpdateForm()
|
||||
{
|
||||
return new CategoryModificationForm($this->getRequest());
|
||||
}
|
||||
|
||||
protected function getCreationEvent($formData) {
|
||||
protected function getCreationEvent($formData)
|
||||
{
|
||||
$createEvent = new CategoryCreateEvent();
|
||||
|
||||
$createEvent
|
||||
@@ -89,7 +91,8 @@ class CategoryController extends AbstractCrudController
|
||||
return $createEvent;
|
||||
}
|
||||
|
||||
protected function getUpdateEvent($formData) {
|
||||
protected function getUpdateEvent($formData)
|
||||
{
|
||||
$changeEvent = new CategoryUpdateEvent($formData['id']);
|
||||
|
||||
// Create and dispatch the change event
|
||||
@@ -107,8 +110,8 @@ class CategoryController extends AbstractCrudController
|
||||
return $changeEvent;
|
||||
}
|
||||
|
||||
protected function createUpdatePositionEvent($positionChangeMode, $positionValue) {
|
||||
|
||||
protected function createUpdatePositionEvent($positionChangeMode, $positionValue)
|
||||
{
|
||||
return new UpdatePositionEvent(
|
||||
$this->getRequest()->get('category_id', null),
|
||||
$positionChangeMode,
|
||||
@@ -116,16 +119,18 @@ class CategoryController extends AbstractCrudController
|
||||
);
|
||||
}
|
||||
|
||||
protected function getDeleteEvent() {
|
||||
protected function getDeleteEvent()
|
||||
{
|
||||
return new CategoryDeleteEvent($this->getRequest()->get('category_id', 0));
|
||||
}
|
||||
|
||||
protected function eventContainsObject($event) {
|
||||
protected function eventContainsObject($event)
|
||||
{
|
||||
return $event->hasCategory();
|
||||
}
|
||||
|
||||
protected function hydrateObjectForm($object) {
|
||||
|
||||
protected function hydrateObjectForm($object)
|
||||
{
|
||||
// Prepare the data that will hydrate the form
|
||||
$data = array(
|
||||
'id' => $object->getId(),
|
||||
@@ -143,21 +148,25 @@ class CategoryController extends AbstractCrudController
|
||||
return new CategoryModificationForm($this->getRequest(), "form", $data);
|
||||
}
|
||||
|
||||
protected function getObjectFromEvent($event) {
|
||||
protected function getObjectFromEvent($event)
|
||||
{
|
||||
return $event->hasCategory() ? $event->getCategory() : null;
|
||||
}
|
||||
|
||||
protected function getExistingObject() {
|
||||
protected function getExistingObject()
|
||||
{
|
||||
return CategoryQuery::create()
|
||||
->joinWithI18n($this->getCurrentEditionLocale())
|
||||
->findOneById($this->getRequest()->get('category_id', 0));
|
||||
}
|
||||
|
||||
protected function getObjectLabel($object) {
|
||||
protected function getObjectLabel($object)
|
||||
{
|
||||
return $object->getTitle();
|
||||
}
|
||||
|
||||
protected function getObjectId($object) {
|
||||
protected function getObjectId($object)
|
||||
{
|
||||
return $object->getId();
|
||||
}
|
||||
|
||||
@@ -170,8 +179,8 @@ class CategoryController extends AbstractCrudController
|
||||
);
|
||||
}
|
||||
|
||||
protected function renderListTemplate($currentOrder) {
|
||||
|
||||
protected function renderListTemplate($currentOrder)
|
||||
{
|
||||
// Get product order
|
||||
$product_order = $this->getListOrderFromSession('product', 'product_order', 'manual');
|
||||
|
||||
@@ -183,19 +192,21 @@ class CategoryController extends AbstractCrudController
|
||||
));
|
||||
}
|
||||
|
||||
protected function redirectToListTemplate() {
|
||||
protected function redirectToListTemplate()
|
||||
{
|
||||
$this->redirectToRoute(
|
||||
'admin.categories.default',
|
||||
array('category_id' => $this->getRequest()->get('category_id', 0))
|
||||
);
|
||||
}
|
||||
|
||||
protected function renderEditionTemplate() {
|
||||
|
||||
protected function renderEditionTemplate()
|
||||
{
|
||||
return $this->render('category-edit', $this->getEditionArguments());
|
||||
}
|
||||
|
||||
protected function redirectToEditionTemplate() {
|
||||
protected function redirectToEditionTemplate()
|
||||
{
|
||||
$this->redirectToRoute("admin.categories.update", $this->getEditionArguments());
|
||||
}
|
||||
|
||||
@@ -257,8 +268,8 @@ class CategoryController extends AbstractCrudController
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getAvailableRelatedContentAction($categoryId, $folderId) {
|
||||
|
||||
public function getAvailableRelatedContentAction($categoryId, $folderId)
|
||||
{
|
||||
$result = array();
|
||||
|
||||
$folders = FolderQuery::create()->filterById($folderId)->find();
|
||||
@@ -273,7 +284,7 @@ class CategoryController extends AbstractCrudController
|
||||
;
|
||||
|
||||
if ($list !== null) {
|
||||
foreach($list as $item) {
|
||||
foreach ($list as $item) {
|
||||
$result[] = array('id' => $item->getId(), 'title' => $item->getTitle());
|
||||
}
|
||||
}
|
||||
@@ -282,8 +293,8 @@ class CategoryController extends AbstractCrudController
|
||||
return $this->jsonResponse(json_encode($result));
|
||||
}
|
||||
|
||||
public function addRelatedContentAction() {
|
||||
|
||||
public function addRelatedContentAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.categories.update")) return $response;
|
||||
|
||||
@@ -298,8 +309,7 @@ class CategoryController extends AbstractCrudController
|
||||
|
||||
try {
|
||||
$this->dispatch(TheliaEvents::CATEGORY_ADD_CONTENT, $event);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
} catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
@@ -341,8 +351,8 @@ class CategoryController extends AbstractCrudController
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
|
||||
public function deleteRelatedContentAction() {
|
||||
|
||||
public function deleteRelatedContentAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.categories.update")) return $response;
|
||||
|
||||
@@ -357,8 +367,7 @@ class CategoryController extends AbstractCrudController
|
||||
|
||||
try {
|
||||
$this->dispatch(TheliaEvents::CATEGORY_REMOVE_CONTENT, $event);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
} catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
|
||||
@@ -23,14 +23,13 @@
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Event\ConfigDeleteEvent;
|
||||
use Thelia\Core\Event\Config\ConfigDeleteEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\ConfigUpdateEvent;
|
||||
use Thelia\Core\Event\ConfigCreateEvent;
|
||||
use Thelia\Core\Event\Config\ConfigUpdateEvent;
|
||||
use Thelia\Core\Event\Config\ConfigCreateEvent;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Form\ConfigModificationForm;
|
||||
use Thelia\Form\ConfigCreationForm;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
|
||||
/**
|
||||
* Manages variables
|
||||
@@ -39,7 +38,8 @@ use Thelia\Core\Event\UpdatePositionEvent;
|
||||
*/
|
||||
class ConfigController extends AbstractCrudController
|
||||
{
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
'variable',
|
||||
'name',
|
||||
@@ -58,15 +58,18 @@ class ConfigController extends AbstractCrudController
|
||||
);
|
||||
}
|
||||
|
||||
protected function getCreationForm() {
|
||||
protected function getCreationForm()
|
||||
{
|
||||
return new ConfigCreationForm($this->getRequest());
|
||||
}
|
||||
|
||||
protected function getUpdateForm() {
|
||||
protected function getUpdateForm()
|
||||
{
|
||||
return new ConfigModificationForm($this->getRequest());
|
||||
}
|
||||
|
||||
protected function getCreationEvent($data) {
|
||||
protected function getCreationEvent($data)
|
||||
{
|
||||
$createEvent = new ConfigCreateEvent();
|
||||
|
||||
$createEvent
|
||||
@@ -78,11 +81,11 @@ class ConfigController extends AbstractCrudController
|
||||
->setSecured($data['secured'])
|
||||
;
|
||||
|
||||
|
||||
return $createEvent;
|
||||
}
|
||||
|
||||
protected function getUpdateEvent($data) {
|
||||
protected function getUpdateEvent($data)
|
||||
{
|
||||
$changeEvent = new ConfigUpdateEvent($data['id']);
|
||||
|
||||
// Create and dispatch the change event
|
||||
@@ -101,16 +104,18 @@ class ConfigController extends AbstractCrudController
|
||||
return $changeEvent;
|
||||
}
|
||||
|
||||
protected function getDeleteEvent() {
|
||||
protected function getDeleteEvent()
|
||||
{
|
||||
return new ConfigDeleteEvent($this->getRequest()->get('variable_id'));
|
||||
}
|
||||
|
||||
protected function eventContainsObject($event) {
|
||||
protected function eventContainsObject($event)
|
||||
{
|
||||
return $event->hasConfig();
|
||||
}
|
||||
|
||||
protected function hydrateObjectForm($object) {
|
||||
|
||||
protected function hydrateObjectForm($object)
|
||||
{
|
||||
// Prepare the data that will hydrate the form
|
||||
$data = array(
|
||||
'id' => $object->getId(),
|
||||
@@ -129,40 +134,48 @@ class ConfigController extends AbstractCrudController
|
||||
return new ConfigModificationForm($this->getRequest(), "form", $data);
|
||||
}
|
||||
|
||||
protected function getObjectFromEvent($event) {
|
||||
protected function getObjectFromEvent($event)
|
||||
{
|
||||
return $event->hasConfig() ? $event->getConfig() : null;
|
||||
}
|
||||
|
||||
protected function getExistingObject() {
|
||||
protected function getExistingObject()
|
||||
{
|
||||
return ConfigQuery::create()
|
||||
->joinWithI18n($this->getCurrentEditionLocale())
|
||||
->findOneById($this->getRequest()->get('variable_id'));
|
||||
}
|
||||
|
||||
protected function getObjectLabel($object) {
|
||||
protected function getObjectLabel($object)
|
||||
{
|
||||
return $object->getName();
|
||||
}
|
||||
|
||||
protected function getObjectId($object) {
|
||||
protected function getObjectId($object)
|
||||
{
|
||||
return $object->getId();
|
||||
}
|
||||
|
||||
protected function renderListTemplate($currentOrder) {
|
||||
protected function renderListTemplate($currentOrder)
|
||||
{
|
||||
return $this->render('variables', array('order' => $currentOrder));
|
||||
}
|
||||
|
||||
protected function renderEditionTemplate() {
|
||||
protected function renderEditionTemplate()
|
||||
{
|
||||
return $this->render('variable-edit', array('variable_id' => $this->getRequest()->get('variable_id')));
|
||||
}
|
||||
|
||||
protected function redirectToEditionTemplate() {
|
||||
protected function redirectToEditionTemplate()
|
||||
{
|
||||
$this->redirectToRoute(
|
||||
"admin.configuration.variables.update",
|
||||
array('variable_id' => $this->getRequest()->get('variable_id'))
|
||||
);
|
||||
}
|
||||
|
||||
protected function redirectToListTemplate() {
|
||||
protected function redirectToListTemplate()
|
||||
{
|
||||
$this->redirectToRoute('admin.configuration.variables.default');
|
||||
}
|
||||
|
||||
@@ -188,4 +201,4 @@ class ConfigController extends AbstractCrudController
|
||||
|
||||
$this->redirectToRoute('admin.configuration.variables.default');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,14 +22,18 @@
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
use Thelia\Core\Event\Content\ContentAddFolderEvent;
|
||||
use Thelia\Core\Event\Content\ContentCreateEvent;
|
||||
use Thelia\Core\Event\Content\ContentDeleteEvent;
|
||||
use Thelia\Core\Event\Content\ContentRemoveFolderEvent;
|
||||
use Thelia\Core\Event\Content\ContentToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\Content\ContentUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Form\ContentCreationForm;
|
||||
use Thelia\Form\ContentModificationForm;
|
||||
use Thelia\Model\ContentQuery;
|
||||
|
||||
|
||||
/**
|
||||
* Class ContentController
|
||||
* @package Thelia\Controller\Admin
|
||||
@@ -58,6 +62,62 @@ class ContentController extends AbstractCrudController
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* controller adding content to additional folder
|
||||
*
|
||||
* @return mixed|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function addAdditionalFolderAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth('admin.content.update')) return $response;
|
||||
|
||||
$folder_id = intval($this->getRequest()->request->get('additional_folder_id'));
|
||||
|
||||
if ($folder_id > 0) {
|
||||
$event = new ContentAddFolderEvent(
|
||||
$this->getExistingObject(),
|
||||
$folder_id
|
||||
);
|
||||
|
||||
try {
|
||||
$this->dispatch(TheliaEvents::CONTENT_ADD_FOLDER, $event);
|
||||
} catch (\Exception $e) {
|
||||
return $this->errorPage($e);
|
||||
}
|
||||
}
|
||||
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* controller removing additional folder to a content
|
||||
*
|
||||
* @return mixed|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function removeAdditionalFolderAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth('admin.content.update')) return $response;
|
||||
|
||||
$folder_id = intval($this->getRequest()->request->get('additional_folder_id'));
|
||||
|
||||
if ($folder_id > 0) {
|
||||
$event = new ContentRemoveFolderEvent(
|
||||
$this->getExistingObject(),
|
||||
$folder_id
|
||||
);
|
||||
|
||||
try {
|
||||
$this->dispatch(TheliaEvents::CONTENT_REMOVE_FOLDER, $event);
|
||||
} catch (\Exception $e) {
|
||||
return $this->errorPage($e);
|
||||
}
|
||||
}
|
||||
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the creation form for this object
|
||||
*/
|
||||
@@ -143,7 +203,7 @@ class ContentController extends AbstractCrudController
|
||||
*/
|
||||
protected function getDeleteEvent()
|
||||
{
|
||||
// TODO: Implement getDeleteEvent() method.
|
||||
return new ContentDeleteEvent($this->getRequest()->get('content_id'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,10 +269,10 @@ class ContentController extends AbstractCrudController
|
||||
{
|
||||
$folderId = $this->getRequest()->get('folder_id', null);
|
||||
|
||||
if(null === $folderId) {
|
||||
if (null === $folderId) {
|
||||
$content = $this->getExistingObject();
|
||||
|
||||
if($content) {
|
||||
if ($content) {
|
||||
$folderId = $content->getDefaultFolderId();
|
||||
}
|
||||
}
|
||||
@@ -240,7 +300,8 @@ class ContentController extends AbstractCrudController
|
||||
{
|
||||
return array(
|
||||
'content_id' => $this->getRequest()->get('content_id', 0),
|
||||
'current_tab' => $this->getRequest()->get('current_tab', 'general')
|
||||
'current_tab' => $this->getRequest()->get('current_tab', 'general'),
|
||||
'folder_id' => $this->getFolderId(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -272,7 +333,7 @@ class ContentController extends AbstractCrudController
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Thelia\Core\Event\Content\ContentUpdateEvent $updateEvent
|
||||
* @param \Thelia\Core\Event\Content\ContentUpdateEvent $updateEvent
|
||||
* @return Response|void
|
||||
*/
|
||||
protected function performAdditionalUpdateAction($updateEvent)
|
||||
@@ -286,4 +347,59 @@ class ContentController extends AbstractCrudController
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Put in this method post object delete processing if required.
|
||||
*
|
||||
* @param \Thelia\Core\Event\Content\ContentDeleteEvent $deleteEvent the delete event
|
||||
* @return Response a response, or null to continue normal processing
|
||||
*/
|
||||
protected function performAdditionalDeleteAction($deleteEvent)
|
||||
{
|
||||
// Redirect to parent category list
|
||||
$this->redirectToRoute(
|
||||
'admin.folders.default',
|
||||
array('parent' => $deleteEvent->getDefaultFolderId())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $event \Thelia\Core\Event\UpdatePositionEvent
|
||||
* @return null|Response
|
||||
*/
|
||||
protected function performAdditionalUpdatePositionAction($event)
|
||||
{
|
||||
|
||||
if (null !== $content = ContentQuery::create()->findPk($event->getObjectId())) {
|
||||
// Redirect to parent category list
|
||||
$this->redirectToRoute(
|
||||
'admin.folders.default',
|
||||
array('parent' => $content->getDefaultFolderId())
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $positionChangeMode
|
||||
* @param $positionValue
|
||||
* @return UpdatePositionEvent|void
|
||||
*/
|
||||
protected function createUpdatePositionEvent($positionChangeMode, $positionValue)
|
||||
{
|
||||
return new UpdatePositionEvent(
|
||||
$this->getRequest()->get('content_id', null),
|
||||
$positionChangeMode,
|
||||
$positionValue
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ContentToggleVisibilityEvent|void
|
||||
*/
|
||||
protected function createToggleVisibilityEvent()
|
||||
{
|
||||
return new ContentToggleVisibilityEvent($this->getExistingObject());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,10 +43,10 @@ class CountryController extends BaseAdminController
|
||||
* @return mixed|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function updateAction($country_id)
|
||||
{
|
||||
{
|
||||
return $this->render("country-edit", array(
|
||||
"country_id" => $country_id
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,24 +25,14 @@ 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\Condition\ConditionFactory;
|
||||
use Thelia\Condition\ConditionManagerInterface;
|
||||
use Thelia\Core\Event\Condition\ConditionCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\Coupon\CouponConsumeEvent;
|
||||
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\CouponFactory;
|
||||
use Thelia\Coupon\CouponManager;
|
||||
use Thelia\Coupon\CouponRuleCollection;
|
||||
use Thelia\Coupon\ConditionCollection;
|
||||
use Thelia\Coupon\Type\CouponInterface;
|
||||
use Thelia\Form\CouponCreationForm;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
@@ -76,13 +66,13 @@ class CouponController extends BaseAdminController
|
||||
|
||||
$args['urlReadCoupon'] = $this->getRoute(
|
||||
'admin.coupon.read',
|
||||
array('couponId' => 'couponId'),
|
||||
array('couponId' => 0),
|
||||
Router::ABSOLUTE_URL
|
||||
);
|
||||
|
||||
$args['urlEditCoupon'] = $this->getRoute(
|
||||
'admin.coupon.update',
|
||||
array('couponId' => 'couponId'),
|
||||
array('couponId' => 0),
|
||||
Router::ABSOLUTE_URL
|
||||
);
|
||||
|
||||
@@ -162,7 +152,7 @@ class CouponController extends BaseAdminController
|
||||
|
||||
$args['dateFormat'] = $this->getSession()->getLang()->getDateFormat();
|
||||
$args['availableCoupons'] = $this->getAvailableCoupons();
|
||||
$args['formAction'] = 'admin/coupon/create/';
|
||||
$args['formAction'] = 'admin/coupon/create';
|
||||
|
||||
return $this->render(
|
||||
'coupon-create',
|
||||
@@ -187,8 +177,9 @@ class CouponController extends BaseAdminController
|
||||
|
||||
/** @var Coupon $coupon */
|
||||
$coupon = CouponQuery::create()->findPk($couponId);
|
||||
if (!$coupon) {
|
||||
$this->pageNotFound();
|
||||
if (null === $coupon) {
|
||||
return $this->pageNotFound();
|
||||
|
||||
}
|
||||
|
||||
// Parameters given to the template
|
||||
@@ -199,7 +190,7 @@ class CouponController extends BaseAdminController
|
||||
$lang = $this->getSession()->getLang();
|
||||
$eventToDispatch = TheliaEvents::COUPON_UPDATE;
|
||||
|
||||
// Create
|
||||
// Update
|
||||
if ($this->getRequest()->isMethod('POST')) {
|
||||
$this->validateCreateOrUpdateForm(
|
||||
$i18n,
|
||||
@@ -208,20 +199,23 @@ class CouponController extends BaseAdminController
|
||||
'updated',
|
||||
'update'
|
||||
);
|
||||
} else { // Update
|
||||
|
||||
} else {
|
||||
// Display
|
||||
// Prepare the data that will hydrate the form
|
||||
/** @var ConstraintFactory $constraintFactory */
|
||||
$constraintFactory = $this->container->get('thelia.constraint.factory');
|
||||
$rules = $constraintFactory->unserializeCouponRuleCollection(
|
||||
$coupon->getSerializedRules()
|
||||
/** @var ConditionFactory $conditionFactory */
|
||||
$conditionFactory = $this->container->get('thelia.condition.factory');
|
||||
$conditions = $conditionFactory->unserializeConditionCollection(
|
||||
$coupon->getSerializedConditions()
|
||||
);
|
||||
|
||||
var_dump($coupon->getIsEnabled());;
|
||||
var_dump($coupon->getIsAvailableOnSpecialOffers());;
|
||||
var_dump($coupon->getIsCumulative());;
|
||||
var_dump($coupon->getIsRemovingPostage());;
|
||||
$data = array(
|
||||
'code' => $coupon->getCode(),
|
||||
'title' => $coupon->getTitle(),
|
||||
'amount' => $coupon->getAmount(),
|
||||
'effect' => $coupon->getType(),
|
||||
'type' => $coupon->getType(),
|
||||
'shortDescription' => $coupon->getShortDescription(),
|
||||
'description' => $coupon->getDescription(),
|
||||
'isEnabled' => ($coupon->getIsEnabled() == 1),
|
||||
@@ -230,23 +224,23 @@ class CouponController extends BaseAdminController
|
||||
'isCumulative' => ($coupon->getIsCumulative() == 1),
|
||||
'isRemovingPostage' => ($coupon->getIsRemovingPostage() == 1),
|
||||
'maxUsage' => $coupon->getMaxUsage(),
|
||||
'rules' => $rules,
|
||||
'conditions' => $conditions,
|
||||
'locale' => $coupon->getLocale(),
|
||||
);
|
||||
|
||||
$args['rulesObject'] = array();
|
||||
$args['conditionsObject'] = array();
|
||||
|
||||
/** @var CouponRuleInterface $rule */
|
||||
foreach ($rules->getRules() as $rule) {
|
||||
$args['rulesObject'][] = array(
|
||||
'serviceId' => $rule->getServiceId(),
|
||||
'name' => $rule->getName(),
|
||||
'tooltip' => $rule->getToolTip(),
|
||||
'validators' => $rule->getValidators()
|
||||
/** @var ConditionManagerInterface $condition */
|
||||
foreach ($conditions->getConditions() as $condition) {
|
||||
$args['conditionsObject'][] = array(
|
||||
'serviceId' => $condition->getServiceId(),
|
||||
'name' => $condition->getName(),
|
||||
'tooltip' => $condition->getToolTip(),
|
||||
'validators' => $condition->getValidators()
|
||||
);
|
||||
}
|
||||
|
||||
$args['rules'] = $this->cleanRuleForTemplate($rules);
|
||||
$args['conditions'] = $this->cleanConditionForTemplate($conditions);
|
||||
|
||||
// Setup the object form
|
||||
$changeForm = new CouponCreationForm($this->getRequest(), 'form', $data);
|
||||
@@ -256,20 +250,20 @@ class CouponController extends BaseAdminController
|
||||
}
|
||||
$args['couponCode'] = $coupon->getCode();
|
||||
$args['availableCoupons'] = $this->getAvailableCoupons();
|
||||
$args['availableRules'] = $this->getAvailableRules();
|
||||
$args['urlAjaxGetRuleInput'] = $this->getRoute(
|
||||
'admin.coupon.rule.input',
|
||||
array('ruleId' => 'ruleId'),
|
||||
$args['availableConditions'] = $this->getAvailableConditions();
|
||||
$args['urlAjaxGetConditionInput'] = $this->getRoute(
|
||||
'admin.coupon.condition.input',
|
||||
array('conditionId' => 'conditionId'),
|
||||
Router::ABSOLUTE_URL
|
||||
);
|
||||
|
||||
$args['urlAjaxUpdateRules'] = $this->getRoute(
|
||||
'admin.coupon.rule.update',
|
||||
$args['urlAjaxUpdateConditions'] = $this->getRoute(
|
||||
'admin.coupon.condition.update',
|
||||
array('couponId' => $couponId),
|
||||
Router::ABSOLUTE_URL
|
||||
);
|
||||
|
||||
$args['formAction'] = 'admin/coupon/update/' . $couponId;
|
||||
$args['formAction'] = 'admin/coupon/update' . $couponId;
|
||||
|
||||
return $this->render('coupon-update', $args);
|
||||
}
|
||||
@@ -277,34 +271,33 @@ class CouponController extends BaseAdminController
|
||||
/**
|
||||
* Manage Coupons read display
|
||||
*
|
||||
* @param string $ruleId Rule service id
|
||||
* @param string $conditionId Condition service id
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function getRuleInputAction($ruleId)
|
||||
public function getConditionInputAction($conditionId)
|
||||
{
|
||||
$this->checkAuth('ADMIN', 'admin.coupon.read');
|
||||
|
||||
$this->checkXmlHttpRequest();
|
||||
|
||||
/** @var ConstraintFactory $constraintFactory */
|
||||
$constraintFactory = $this->container->get('thelia.constraint.factory');
|
||||
$inputs = $constraintFactory->getInputs($ruleId);
|
||||
/** @var ConditionFactory $conditionFactory */
|
||||
$conditionFactory = $this->container->get('thelia.condition.factory');
|
||||
$inputs = $conditionFactory->getInputs($conditionId);
|
||||
|
||||
if ($inputs === null) {
|
||||
return $this->pageNotFound();
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'coupon/rule-input-ajax',
|
||||
'coupon/condition-input-ajax',
|
||||
array(
|
||||
'ruleId' => $ruleId,
|
||||
'conditionId' => $conditionId,
|
||||
'inputs' => $inputs
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Manage Coupons read display
|
||||
*
|
||||
@@ -312,7 +305,7 @@ class CouponController extends BaseAdminController
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function updateRulesAction($couponId)
|
||||
public function updateConditionsAction($couponId)
|
||||
{
|
||||
$this->checkAuth('ADMIN', 'admin.coupon.read');
|
||||
|
||||
@@ -326,64 +319,51 @@ class CouponController extends BaseAdminController
|
||||
return $this->pageNotFound();
|
||||
}
|
||||
|
||||
$rules = new CouponRuleCollection();
|
||||
$conditions = new ConditionCollection();
|
||||
|
||||
/** @var ConstraintFactory $constraintFactory */
|
||||
$constraintFactory = $this->container->get('thelia.constraint.factory');
|
||||
$rulesReceived = json_decode($this->getRequest()->get('rules'));
|
||||
foreach ($rulesReceived as $ruleReceived) {
|
||||
$rule = $constraintFactory->build(
|
||||
$ruleReceived->serviceId,
|
||||
(array) $ruleReceived->operators,
|
||||
(array) $ruleReceived->values
|
||||
/** @var ConditionFactory $conditionFactory */
|
||||
$conditionFactory = $this->container->get('thelia.condition.factory');
|
||||
$conditionsReceived = json_decode($this->getRequest()->get('conditions'));
|
||||
foreach ($conditionsReceived as $conditionReceived) {
|
||||
$condition = $conditionFactory->build(
|
||||
$conditionReceived->serviceId,
|
||||
(array) $conditionReceived->operators,
|
||||
(array) $conditionReceived->values
|
||||
);
|
||||
$rules->add(clone $rule);
|
||||
$conditions->add(clone $condition);
|
||||
}
|
||||
|
||||
$coupon->setSerializedRules(
|
||||
$constraintFactory->serializeCouponRuleCollection($rules)
|
||||
);
|
||||
// $coupon->setSerializedConditions(
|
||||
// $conditionFactory->serializeCouponConditionCollection($conditions)
|
||||
// );
|
||||
|
||||
$couponEvent = new CouponCreateOrUpdateEvent(
|
||||
$coupon->getCode(),
|
||||
$coupon->getTitle(),
|
||||
$coupon->getAmount(),
|
||||
$coupon->getType(),
|
||||
$coupon->getShortDescription(),
|
||||
$coupon->getDescription(),
|
||||
$coupon->getIsEnabled(),
|
||||
$coupon->getExpirationDate(),
|
||||
$coupon->getIsAvailableOnSpecialOffers(),
|
||||
$coupon->getIsCumulative(),
|
||||
$coupon->getIsRemovingPostage(),
|
||||
$coupon->getMaxUsage(),
|
||||
$rules,
|
||||
$coupon->getLocale()
|
||||
$conditionEvent = new ConditionCreateOrUpdateEvent(
|
||||
$conditions
|
||||
);
|
||||
$couponEvent->setCoupon($coupon);
|
||||
$conditionEvent->setCouponModel($coupon);
|
||||
|
||||
$eventToDispatch = TheliaEvents::COUPON_RULE_UPDATE;
|
||||
$eventToDispatch = TheliaEvents::COUPON_CONDITION_UPDATE;
|
||||
// Dispatch Event to the Action
|
||||
$this->dispatch(
|
||||
$eventToDispatch,
|
||||
$couponEvent
|
||||
$conditionEvent
|
||||
);
|
||||
|
||||
$this->adminLogAppend(
|
||||
sprintf(
|
||||
'Coupon %s (ID %s) rules updated',
|
||||
$couponEvent->getTitle(),
|
||||
$couponEvent->getCoupon()->getId()
|
||||
'Coupon %s (ID %s) conditions updated',
|
||||
$conditionEvent->getCouponModel()->getTitle(),
|
||||
$conditionEvent->getCouponModel()->getServiceId()
|
||||
)
|
||||
);
|
||||
|
||||
$cleanedRules = $this->cleanRuleForTemplate($rules);
|
||||
$cleanedConditions = $this->cleanConditionForTemplate($conditions);
|
||||
|
||||
return $this->render(
|
||||
'coupon/rules',
|
||||
'coupon/conditions',
|
||||
array(
|
||||
'couponId' => $couponId,
|
||||
'rules' => $cleanedRules,
|
||||
'conditions' => $cleanedConditions,
|
||||
'urlEdit' => $couponId,
|
||||
'urlDelete' => $couponId
|
||||
)
|
||||
@@ -395,6 +375,8 @@ class CouponController extends BaseAdminController
|
||||
*
|
||||
* @param string $couponCode Coupon code
|
||||
*
|
||||
* @todo remove (event dispatcher testing purpose)
|
||||
*
|
||||
*/
|
||||
public function consumeAction($couponCode)
|
||||
{
|
||||
@@ -431,8 +413,8 @@ class CouponController extends BaseAdminController
|
||||
$couponBeingCreated->setAmount($data['amount']);
|
||||
$couponBeingCreated->setIsEnabled($data['isEnabled']);
|
||||
$couponBeingCreated->setExpirationDate($data['expirationDate']);
|
||||
$couponBeingCreated->setSerializedRules(
|
||||
new CouponRuleCollection(
|
||||
$couponBeingCreated->setSerializedConditions(
|
||||
new ConditionCollection(
|
||||
array()
|
||||
)
|
||||
);
|
||||
@@ -488,26 +470,14 @@ class CouponController extends BaseAdminController
|
||||
|
||||
$message = false;
|
||||
try {
|
||||
// Check the form against constraints violations
|
||||
// Check the form against conditions 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'],
|
||||
\DateTime::createFromFormat('Y-m-d', $data['expirationDate']),
|
||||
$data['isAvailableOnSpecialOffers'],
|
||||
$data['isCumulative'],
|
||||
$data['isRemovingPostage'],
|
||||
$data['maxUsage'],
|
||||
new CouponRuleCollection(array()),
|
||||
$data['locale']
|
||||
$data['code'], $data['title'], $data['amount'], $data['type'], $data['shortDescription'], $data['description'], $data['isEnabled'], \DateTime::createFromFormat('Y-m-d', $data['expirationDate']), $data['isAvailableOnSpecialOffers'], $data['isCumulative'], $data['isRemovingPostage'], $data['maxUsage'], $data['locale']
|
||||
);
|
||||
|
||||
// Dispatch Event to the Action
|
||||
@@ -535,7 +505,6 @@ class CouponController extends BaseAdminController
|
||||
} catch (FormValidationException $e) {
|
||||
// Invalid data entered
|
||||
$message = 'Please check your input:';
|
||||
$this->logError($action, $message, $e);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// Any other error
|
||||
@@ -557,26 +526,26 @@ class CouponController extends BaseAdminController
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all available rules
|
||||
* Get all available conditions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getAvailableRules()
|
||||
protected function getAvailableConditions()
|
||||
{
|
||||
/** @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;
|
||||
$availableConditions = $couponManager->getAvailableConditions();
|
||||
$cleanedConditions = array();
|
||||
/** @var ConditionManagerInterface $availableCondition */
|
||||
foreach ($availableConditions as $availableCondition) {
|
||||
$condition = array();
|
||||
$condition['serviceId'] = $availableCondition->getServiceId();
|
||||
$condition['name'] = $availableCondition->getName();
|
||||
$condition['toolTip'] = $availableCondition->getToolTip();
|
||||
$cleanedConditions[] = $condition;
|
||||
}
|
||||
|
||||
return $cleanedRules;
|
||||
return $cleanedConditions;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -592,53 +561,54 @@ class CouponController extends BaseAdminController
|
||||
$cleanedCoupons = array();
|
||||
/** @var CouponInterface $availableCoupon */
|
||||
foreach ($availableCoupons as $availableCoupon) {
|
||||
$rule = array();
|
||||
$rule['serviceId'] = $availableCoupon->getServiceId();
|
||||
$rule['name'] = $availableCoupon->getName();
|
||||
$rule['toolTip'] = $availableCoupon->getToolTip();
|
||||
$cleanedCoupons[] = $rule;
|
||||
$condition = array();
|
||||
$condition['serviceId'] = $availableCoupon->getServiceId();
|
||||
$condition['name'] = $availableCoupon->getName();
|
||||
$condition['toolTip'] = $availableCoupon->getToolTip();
|
||||
$cleanedCoupons[] = $condition;
|
||||
}
|
||||
|
||||
return $cleanedCoupons;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $rules
|
||||
* Clean condition for template
|
||||
*
|
||||
* @param ConditionCollection $conditions Condition collection
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function cleanRuleForTemplate($rules)
|
||||
protected function cleanConditionForTemplate(ConditionCollection $conditions)
|
||||
{
|
||||
$cleanedRules = array();
|
||||
/** @var $rule CouponRuleInterface */
|
||||
foreach ($rules->getRules() as $rule) {
|
||||
$cleanedRules[] = $rule->getToolTip();
|
||||
$cleanedConditions = array();
|
||||
/** @var $condition ConditionManagerInterface */
|
||||
foreach ($conditions->getConditions() as $condition) {
|
||||
$cleanedConditions[] = $condition->getToolTip();
|
||||
}
|
||||
|
||||
return $cleanedRules;
|
||||
return $cleanedConditions;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Validation Rule creation
|
||||
// * Validation Condition creation
|
||||
// *
|
||||
// * @param string $type Rule class type
|
||||
// * @param string $operator Rule operator (<, >, =, etc)
|
||||
// * @param array $values Rules values
|
||||
// * @param string $type Condition class type
|
||||
// * @param string $operator Condition operator (<, >, =, etc)
|
||||
// * @param array $values Condition values
|
||||
// *
|
||||
// * @return bool
|
||||
// */
|
||||
// protected function validateRulesCreation($type, $operator, $values)
|
||||
// protected function validateConditionsCreation($type, $operator, $values)
|
||||
// {
|
||||
// /** @var CouponAdapterInterface $adapter */
|
||||
// /** @var AdapterInterface $adapter */
|
||||
// $adapter = $this->container->get('thelia.adapter');
|
||||
// $validator = new PriceParam()
|
||||
// try {
|
||||
// $rule = new AvailableForTotalAmount($adapter, $validators);
|
||||
// $rule = new $type($adapter, $validators);
|
||||
// $condition = new AvailableForTotalAmount($adapter, $validators);
|
||||
// $condition = new $type($adapter, $validators);
|
||||
// } catch (\Exception $e) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -23,10 +23,10 @@
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Event\CurrencyDeleteEvent;
|
||||
use Thelia\Core\Event\Currency\CurrencyDeleteEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\CurrencyUpdateEvent;
|
||||
use Thelia\Core\Event\CurrencyCreateEvent;
|
||||
use Thelia\Core\Event\Currency\CurrencyUpdateEvent;
|
||||
use Thelia\Core\Event\Currency\CurrencyCreateEvent;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Form\CurrencyModificationForm;
|
||||
use Thelia\Form\CurrencyCreationForm;
|
||||
@@ -39,7 +39,8 @@ use Thelia\Core\Event\UpdatePositionEvent;
|
||||
*/
|
||||
class CurrencyController extends AbstractCrudController
|
||||
{
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
'currency',
|
||||
'manual',
|
||||
@@ -58,15 +59,18 @@ class CurrencyController extends AbstractCrudController
|
||||
);
|
||||
}
|
||||
|
||||
protected function getCreationForm() {
|
||||
protected function getCreationForm()
|
||||
{
|
||||
return new CurrencyCreationForm($this->getRequest());
|
||||
}
|
||||
|
||||
protected function getUpdateForm() {
|
||||
protected function getUpdateForm()
|
||||
{
|
||||
return new CurrencyModificationForm($this->getRequest());
|
||||
}
|
||||
|
||||
protected function getCreationEvent($formData) {
|
||||
protected function getCreationEvent($formData)
|
||||
{
|
||||
$createEvent = new CurrencyCreateEvent();
|
||||
|
||||
$createEvent
|
||||
@@ -80,7 +84,8 @@ class CurrencyController extends AbstractCrudController
|
||||
return $createEvent;
|
||||
}
|
||||
|
||||
protected function getUpdateEvent($formData) {
|
||||
protected function getUpdateEvent($formData)
|
||||
{
|
||||
$changeEvent = new CurrencyUpdateEvent($formData['id']);
|
||||
|
||||
// Create and dispatch the change event
|
||||
@@ -95,8 +100,8 @@ class CurrencyController extends AbstractCrudController
|
||||
return $changeEvent;
|
||||
}
|
||||
|
||||
protected function createUpdatePositionEvent($positionChangeMode, $positionValue) {
|
||||
|
||||
protected function createUpdatePositionEvent($positionChangeMode, $positionValue)
|
||||
{
|
||||
return new UpdatePositionEvent(
|
||||
$this->getRequest()->get('currency_id', null),
|
||||
$positionChangeMode,
|
||||
@@ -104,16 +109,18 @@ class CurrencyController extends AbstractCrudController
|
||||
);
|
||||
}
|
||||
|
||||
protected function getDeleteEvent() {
|
||||
protected function getDeleteEvent()
|
||||
{
|
||||
return new CurrencyDeleteEvent($this->getRequest()->get('currency_id'));
|
||||
}
|
||||
|
||||
protected function eventContainsObject($event) {
|
||||
protected function eventContainsObject($event)
|
||||
{
|
||||
return $event->hasCurrency();
|
||||
}
|
||||
|
||||
protected function hydrateObjectForm($object) {
|
||||
|
||||
protected function hydrateObjectForm($object)
|
||||
{
|
||||
// Prepare the data that will hydrate the form
|
||||
$data = array(
|
||||
'id' => $object->getId(),
|
||||
@@ -128,44 +135,51 @@ class CurrencyController extends AbstractCrudController
|
||||
return new CurrencyModificationForm($this->getRequest(), "form", $data);
|
||||
}
|
||||
|
||||
protected function getObjectFromEvent($event) {
|
||||
protected function getObjectFromEvent($event)
|
||||
{
|
||||
return $event->hasCurrency() ? $event->getCurrency() : null;
|
||||
}
|
||||
|
||||
protected function getExistingObject() {
|
||||
protected function getExistingObject()
|
||||
{
|
||||
return CurrencyQuery::create()
|
||||
->joinWithI18n($this->getCurrentEditionLocale())
|
||||
->findOneById($this->getRequest()->get('currency_id'));
|
||||
}
|
||||
|
||||
protected function getObjectLabel($object) {
|
||||
protected function getObjectLabel($object)
|
||||
{
|
||||
return $object->getName();
|
||||
}
|
||||
|
||||
protected function getObjectId($object) {
|
||||
protected function getObjectId($object)
|
||||
{
|
||||
return $object->getId();
|
||||
}
|
||||
|
||||
protected function renderListTemplate($currentOrder) {
|
||||
protected function renderListTemplate($currentOrder)
|
||||
{
|
||||
return $this->render('currencies', array('order' => $currentOrder));
|
||||
}
|
||||
|
||||
protected function renderEditionTemplate() {
|
||||
protected function renderEditionTemplate()
|
||||
{
|
||||
return $this->render('currency-edit', array('currency_id' => $this->getRequest()->get('currency_id')));
|
||||
}
|
||||
|
||||
protected function redirectToEditionTemplate() {
|
||||
protected function redirectToEditionTemplate()
|
||||
{
|
||||
$this->redirectToRoute(
|
||||
"admin.configuration.currencies.update",
|
||||
array('currency_id' => $this->getRequest()->get('currency_id'))
|
||||
);
|
||||
}
|
||||
|
||||
protected function redirectToListTemplate() {
|
||||
protected function redirectToListTemplate()
|
||||
{
|
||||
$this->redirectToRoute('admin.configuration.currencies.default');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update currencies rates
|
||||
*/
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
namespace Thelia\Controller\Admin;
|
||||
use Propel\Runtime\Exception\PropelException;
|
||||
use Symfony\Component\Form\Form;
|
||||
use Thelia\Core\Event\CustomerCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\CustomerEvent;
|
||||
use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\Customer\CustomerEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Form\CustomerModification;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
@@ -48,10 +48,9 @@ class CustomerController extends BaseAdminController
|
||||
public function viewAction($customer_id)
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.customer.view")) return $response;
|
||||
|
||||
return $this->render("customer-edit", array(
|
||||
"customer_id" => $customer_id
|
||||
));
|
||||
return $this->render("customer-edit", array(
|
||||
"customer_id" => $customer_id
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,8 +70,8 @@ class CustomerController extends BaseAdminController
|
||||
try {
|
||||
$customer = CustomerQuery::create()->findPk($customer_id);
|
||||
|
||||
if(null === $customer) {
|
||||
throw new \InvalidArgumentException(sprintf("%d customer id does not exists", $customer_id));
|
||||
if (null === $customer) {
|
||||
throw new \InvalidArgumentException(sprintf("%d customer id does not exist", $customer_id));
|
||||
}
|
||||
|
||||
$form = $this->validateForm($customerModification);
|
||||
@@ -86,7 +85,7 @@ class CustomerController extends BaseAdminController
|
||||
|
||||
$this->adminLogAppend(sprintf("Customer with Ref %s (ID %d) modified", $customerUpdated->getRef() , $customerUpdated->getId()));
|
||||
|
||||
if($this->getRequest()->get("save_mode") == "close") {
|
||||
if ($this->getRequest()->get("save_mode") == "close") {
|
||||
$this->redirectToRoute("admin.customers");
|
||||
} else {
|
||||
$this->redirectSuccess($customerModification);
|
||||
@@ -126,14 +125,14 @@ class CustomerController extends BaseAdminController
|
||||
$customer_id = $this->getRequest()->get("customer_id");
|
||||
$customer = CustomerQuery::create()->findPk($customer_id);
|
||||
|
||||
if(null === $customer) {
|
||||
throw new \InvalidArgumentException(Translator::getInstance("The customer you want to delete does not exists"));
|
||||
if (null === $customer) {
|
||||
throw new \InvalidArgumentException(Translator::getInstance("The customer you want to delete does not exist"));
|
||||
}
|
||||
|
||||
$event = new CustomerEvent($customer);
|
||||
|
||||
$this->dispatch(TheliaEvents::CUSTOMER_DELETEACCOUNT, $event);
|
||||
} catch(\Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$message = $e->getMessage();
|
||||
}
|
||||
|
||||
@@ -151,7 +150,7 @@ class CustomerController extends BaseAdminController
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return CustomerCreateOrUpdateEvent
|
||||
* @return \Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent
|
||||
*/
|
||||
private function createEventInstance($data)
|
||||
{
|
||||
@@ -178,4 +177,4 @@ class CustomerController extends BaseAdminController
|
||||
|
||||
return $customerCreateEvent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,10 +23,10 @@
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Event\FeatureAvDeleteEvent;
|
||||
use Thelia\Core\Event\Feature\FeatureAvDeleteEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\FeatureAvUpdateEvent;
|
||||
use Thelia\Core\Event\FeatureAvCreateEvent;
|
||||
use Thelia\Core\Event\Feature\FeatureAvUpdateEvent;
|
||||
use Thelia\Core\Event\Feature\FeatureAvCreateEvent;
|
||||
use Thelia\Model\FeatureAvQuery;
|
||||
use Thelia\Form\FeatureAvModificationForm;
|
||||
use Thelia\Form\FeatureAvCreationForm;
|
||||
@@ -193,4 +193,4 @@ class FeatureAvController extends AbstractCrudController
|
||||
$this->getViewArguments()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,18 +23,18 @@
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Event\FeatureDeleteEvent;
|
||||
use Thelia\Core\Event\Feature\FeatureDeleteEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\FeatureUpdateEvent;
|
||||
use Thelia\Core\Event\FeatureCreateEvent;
|
||||
use Thelia\Core\Event\Feature\FeatureUpdateEvent;
|
||||
use Thelia\Core\Event\Feature\FeatureCreateEvent;
|
||||
use Thelia\Model\FeatureQuery;
|
||||
use Thelia\Form\FeatureModificationForm;
|
||||
use Thelia\Form\FeatureCreationForm;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Model\FeatureAv;
|
||||
use Thelia\Model\FeatureAvQuery;
|
||||
use Thelia\Core\Event\FeatureAvUpdateEvent;
|
||||
use Thelia\Core\Event\FeatureEvent;
|
||||
use Thelia\Core\Event\Feature\FeatureAvUpdateEvent;
|
||||
use Thelia\Core\Event\Feature\FeatureEvent;
|
||||
|
||||
/**
|
||||
* Manages features
|
||||
@@ -113,7 +113,7 @@ class FeatureController extends AbstractCrudController
|
||||
|
||||
if ($attr_values !== null) {
|
||||
|
||||
foreach($attr_values as $id => $value) {
|
||||
foreach ($attr_values as $id => $value) {
|
||||
|
||||
$event = new FeatureAvUpdateEvent($id);
|
||||
|
||||
@@ -168,7 +168,7 @@ class FeatureController extends AbstractCrudController
|
||||
|
||||
$attr_array = array();
|
||||
|
||||
foreach($attr_av_list as $attr_av) {
|
||||
foreach ($attr_av_list as $attr_av) {
|
||||
$attr_array[$attr_av->getId()] = $attr_av->getTitle();
|
||||
}
|
||||
|
||||
@@ -262,8 +262,7 @@ class FeatureController extends AbstractCrudController
|
||||
|
||||
$this->dispatch($eventType, $event);
|
||||
}
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
} catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
@@ -286,4 +285,4 @@ class FeatureController extends AbstractCrudController
|
||||
{
|
||||
return $this->addRemoveFromAllTemplates(TheliaEvents::FEATURE_ADD_TO_ALL_TEMPLATES);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,15 +25,12 @@ namespace Thelia\Controller\Admin;
|
||||
|
||||
use Propel\Runtime\Exception\PropelException;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Router;
|
||||
use Thelia\Core\Event\DocumentCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\DocumentDeleteEvent;
|
||||
use Thelia\Core\Event\ImageCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\ImageDeleteEvent;
|
||||
use Thelia\Core\Event\Document\DocumentCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\Document\DocumentDeleteEvent;
|
||||
use Thelia\Core\Event\Image\ImageCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\Image\ImageDeleteEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Log\Tlog;
|
||||
use Thelia\Model\CategoryDocument;
|
||||
@@ -62,7 +59,6 @@ use Thelia\Tools\Rest\ResponseRest;
|
||||
class FileController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Manage how a image collection has to be saved
|
||||
*
|
||||
@@ -126,14 +122,12 @@ class FileController extends BaseAdminController
|
||||
$imageCreateOrUpdateEvent->setUploadedFile($fileBeingUploaded);
|
||||
$imageCreateOrUpdateEvent->setParentName($parentModel->getTitle());
|
||||
|
||||
|
||||
// Dispatch Event to the Action
|
||||
$this->dispatch(
|
||||
TheliaEvents::IMAGE_SAVE,
|
||||
$imageCreateOrUpdateEvent
|
||||
);
|
||||
|
||||
|
||||
return new ResponseRest(array('status' => true, 'message' => ''));
|
||||
}
|
||||
}
|
||||
@@ -192,14 +186,12 @@ class FileController extends BaseAdminController
|
||||
$documentCreateOrUpdateEvent->setUploadedFile($fileBeingUploaded);
|
||||
$documentCreateOrUpdateEvent->setParentName($parentModel->getTitle());
|
||||
|
||||
|
||||
// Dispatch Event to the Action
|
||||
$this->dispatch(
|
||||
TheliaEvents::DOCUMENT_SAVE,
|
||||
$documentCreateOrUpdateEvent
|
||||
);
|
||||
|
||||
|
||||
return new ResponseRest(array('status' => true, 'message' => ''));
|
||||
}
|
||||
}
|
||||
@@ -676,5 +668,4 @@ class FileController extends BaseAdminController
|
||||
return $documentCreateEvent;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -22,10 +22,10 @@
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
use Thelia\Core\Event\FolderCreateEvent;
|
||||
use Thelia\Core\Event\FolderDeleteEvent;
|
||||
use Thelia\Core\Event\FolderToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\FolderUpdateEvent;
|
||||
use Thelia\Core\Event\Folder\FolderCreateEvent;
|
||||
use Thelia\Core\Event\Folder\FolderDeleteEvent;
|
||||
use Thelia\Core\Event\Folder\FolderToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\Folder\FolderUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Form\FolderCreationForm;
|
||||
@@ -81,8 +81,8 @@ class FolderController extends AbstractCrudController
|
||||
*
|
||||
* @param \Thelia\Model\Folder $object
|
||||
*/
|
||||
protected function hydrateObjectForm($object) {
|
||||
|
||||
protected function hydrateObjectForm($object)
|
||||
{
|
||||
// Prepare the data that will hydrate the form
|
||||
$data = array(
|
||||
'id' => $object->getId(),
|
||||
@@ -150,7 +150,7 @@ class FolderController extends AbstractCrudController
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FolderToggleVisibilityEvent|void
|
||||
* @return \Thelia\Core\Event\Folder\FolderToggleVisibilityEvent|void
|
||||
*/
|
||||
protected function createToggleVisibilityEvent()
|
||||
{
|
||||
@@ -162,8 +162,8 @@ class FolderController extends AbstractCrudController
|
||||
* @param $positionValue
|
||||
* @return UpdatePositionEvent|void
|
||||
*/
|
||||
protected function createUpdatePositionEvent($positionChangeMode, $positionValue) {
|
||||
|
||||
protected function createUpdatePositionEvent($positionChangeMode, $positionValue)
|
||||
{
|
||||
return new UpdatePositionEvent(
|
||||
$this->getRequest()->get('folder_id', null),
|
||||
$positionChangeMode,
|
||||
@@ -174,7 +174,7 @@ class FolderController extends AbstractCrudController
|
||||
/**
|
||||
* Return true if the event contains the object, e.g. the action has updated the object in the event.
|
||||
*
|
||||
* @param \Thelia\Core\Event\FolderEvent $event
|
||||
* @param \Thelia\Core\Event\Folder\FolderEvent $event
|
||||
*/
|
||||
protected function eventContainsObject($event)
|
||||
{
|
||||
@@ -184,7 +184,7 @@ class FolderController extends AbstractCrudController
|
||||
/**
|
||||
* Get the created object from an event.
|
||||
*
|
||||
* @param $event \Thelia\Core\Event\FolderEvent $event
|
||||
* @param $event \Thelia\Core\Event\Folder\FolderEvent $event
|
||||
*
|
||||
* @return null|\Thelia\Model\Folder
|
||||
*/
|
||||
@@ -196,7 +196,8 @@ class FolderController extends AbstractCrudController
|
||||
/**
|
||||
* Load an existing object from the database
|
||||
*/
|
||||
protected function getExistingObject() {
|
||||
protected function getExistingObject()
|
||||
{
|
||||
return FolderQuery::create()
|
||||
->joinWithI18n($this->getCurrentEditionLocale())
|
||||
->findOneById($this->getRequest()->get('folder_id', 0));
|
||||
@@ -207,7 +208,8 @@ class FolderController extends AbstractCrudController
|
||||
*
|
||||
* @param unknown $object
|
||||
*/
|
||||
protected function getObjectLabel($object) {
|
||||
protected function getObjectLabel($object)
|
||||
{
|
||||
return $object->getTitle();
|
||||
}
|
||||
|
||||
@@ -226,8 +228,8 @@ class FolderController extends AbstractCrudController
|
||||
*
|
||||
* @param unknown $currentOrder, if any, null otherwise.
|
||||
*/
|
||||
protected function renderListTemplate($currentOrder) {
|
||||
|
||||
protected function renderListTemplate($currentOrder)
|
||||
{
|
||||
// Get content order
|
||||
$content_order = $this->getListOrderFromSession('content', 'content_order', 'manual');
|
||||
|
||||
@@ -239,12 +241,11 @@ class FolderController extends AbstractCrudController
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render the edition template
|
||||
*/
|
||||
protected function renderEditionTemplate() {
|
||||
|
||||
protected function renderEditionTemplate()
|
||||
{
|
||||
return $this->render('folder-edit', $this->getEditionArguments());
|
||||
}
|
||||
|
||||
@@ -257,7 +258,7 @@ class FolderController extends AbstractCrudController
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Thelia\Core\Event\FolderUpdateEvent $updateEvent
|
||||
* @param \Thelia\Core\Event\Folder\FolderUpdateEvent $updateEvent
|
||||
* @return Response|void
|
||||
*/
|
||||
protected function performAdditionalUpdateAction($updateEvent)
|
||||
@@ -275,8 +276,8 @@ class FolderController extends AbstractCrudController
|
||||
/**
|
||||
* Put in this method post object delete processing if required.
|
||||
*
|
||||
* @param \Thelia\Core\Event\FolderDeleteEvent $deleteEvent the delete event
|
||||
* @return Response a response, or null to continue normal processing
|
||||
* @param \Thelia\Core\Event\Folder\FolderDeleteEvent $deleteEvent the delete event
|
||||
* @return Response a response, or null to continue normal processing
|
||||
*/
|
||||
protected function performAdditionalDeleteAction($deleteEvent)
|
||||
{
|
||||
@@ -325,4 +326,4 @@ class FolderController extends AbstractCrudController
|
||||
array('parent' => $this->getRequest()->get('parent', 0))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Event\MessageDeleteEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;use Thelia\Core\Event\MessageUpdateEvent;
|
||||
use Thelia\Core\Event\MessageCreateEvent;
|
||||
use Thelia\Core\Event\Message\MessageDeleteEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;use Thelia\Core\Event\Message\MessageUpdateEvent;
|
||||
use Thelia\Core\Event\Message\MessageCreateEvent;
|
||||
use Thelia\Model\MessageQuery;
|
||||
use Thelia\Form\MessageModificationForm;
|
||||
use Thelia\Form\MessageCreationForm;
|
||||
|
||||
@@ -35,12 +35,11 @@ class ModuleController extends BaseAdminController
|
||||
if (null !== $response = $this->checkAuth("admin.module.view")) return $response;
|
||||
return $this->render("modules", array("display_module" => 20));
|
||||
}
|
||||
|
||||
|
||||
public function updateAction($module_id)
|
||||
{
|
||||
|
||||
return $this->render("module-edit", array(
|
||||
"module_id" => $module_id
|
||||
));
|
||||
return $this->render("module-edit", array(
|
||||
"module_id" => $module_id
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,15 @@
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Event\Order\OrderAddressEvent;
|
||||
use Thelia\Core\Event\Order\OrderEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Form\OrderUpdateAddress;
|
||||
use Thelia\Model\Base\OrderAddressQuery;
|
||||
use Thelia\Model\OrderQuery;
|
||||
use Thelia\Model\OrderStatusQuery;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
/**
|
||||
* Class OrderController
|
||||
* @package Thelia\Controller\Admin
|
||||
@@ -38,10 +47,150 @@ class OrderController extends BaseAdminController
|
||||
|
||||
public function viewAction($order_id)
|
||||
{
|
||||
|
||||
return $this->render("order-edit", array(
|
||||
"order_id" => $order_id
|
||||
));
|
||||
return $this->render("order-edit", array(
|
||||
"order_id" => $order_id
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
public function updateStatus($order_id = null)
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.order.update")) return $response;
|
||||
|
||||
$message = null;
|
||||
|
||||
try {
|
||||
if ($order_id !== null) {
|
||||
$order_id = $order_id;
|
||||
} else {
|
||||
$order_id = $this->getRequest()->get("order_id");
|
||||
}
|
||||
|
||||
$order = OrderQuery::create()->findPk($order_id);
|
||||
|
||||
$statusId = $this->getRequest()->request->get("status_id");
|
||||
$status = OrderStatusQuery::create()->findPk($statusId);
|
||||
|
||||
if (null === $order) {
|
||||
throw new \InvalidArgumentException("The order you want to update status does not exist");
|
||||
}
|
||||
if (null === $status) {
|
||||
throw new \InvalidArgumentException("The status you want to set to the order does not exist");
|
||||
}
|
||||
|
||||
$event = new OrderEvent($order);
|
||||
$event->setStatus($statusId);
|
||||
|
||||
$this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
|
||||
} catch (\Exception $e) {
|
||||
$message = $e->getMessage();
|
||||
}
|
||||
|
||||
$params = array();
|
||||
|
||||
if ($message) {
|
||||
$params["update_status_error_message"] = $message;
|
||||
}
|
||||
|
||||
$browsedPage = $this->getRequest()->get("order_page");
|
||||
|
||||
if ($browsedPage) {
|
||||
$params["order_page"] = $browsedPage;
|
||||
$this->redirectToRoute("admin.order.list", $params);
|
||||
} else {
|
||||
$params["order_id"] = $order_id;
|
||||
$params["tab"] = $this->getRequest()->get("tab", 'cart');
|
||||
$this->redirect(URL::getInstance()->absoluteUrl($this->getRoute("admin.order.update.view", $params)));
|
||||
}
|
||||
}
|
||||
|
||||
public function updateDeliveryRef($order_id)
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.order.update")) return $response;
|
||||
|
||||
$message = null;
|
||||
|
||||
try {
|
||||
$order = OrderQuery::create()->findPk($order_id);
|
||||
|
||||
$deliveryRef = $this->getRequest()->get("delivery_ref");
|
||||
|
||||
if (null === $order) {
|
||||
throw new \InvalidArgumentException("The order you want to update status does not exist");
|
||||
}
|
||||
|
||||
$event = new OrderEvent($order);
|
||||
$event->setDeliveryRef($deliveryRef);
|
||||
|
||||
$this->dispatch(TheliaEvents::ORDER_UPDATE_DELIVERY_REF, $event);
|
||||
} catch (\Exception $e) {
|
||||
$message = $e->getMessage();
|
||||
}
|
||||
|
||||
$params = array();
|
||||
|
||||
if ($message) {
|
||||
$params["update_status_error_message"] = $message;
|
||||
}
|
||||
|
||||
$params["order_id"] = $order_id;
|
||||
$params["tab"] = $this->getRequest()->get("tab", 'bill');
|
||||
|
||||
$this->redirect(URL::getInstance()->absoluteUrl($this->getRoute("admin.order.update.view", $params)));
|
||||
}
|
||||
|
||||
public function updateAddress($order_id)
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.order.update")) return $response;
|
||||
|
||||
$message = null;
|
||||
|
||||
$orderUpdateAddress = new OrderUpdateAddress($this->getRequest());
|
||||
|
||||
try {
|
||||
$order = OrderQuery::create()->findPk($order_id);
|
||||
|
||||
if (null === $order) {
|
||||
throw new \InvalidArgumentException("The order you want to update does not exist");
|
||||
}
|
||||
|
||||
$form = $this->validateForm($orderUpdateAddress, "post");
|
||||
|
||||
$orderAddress = OrderAddressQuery::create()->findPk($form->get("id")->getData());
|
||||
|
||||
if ($orderAddress->getId() !== $order->getInvoiceOrderAddressId() && $orderAddress->getId() !== $order->getDeliveryOrderAddressId()) {
|
||||
throw new \InvalidArgumentException("The order address you want to update does not belong to the current order not exist");
|
||||
}
|
||||
|
||||
$event = new OrderAddressEvent(
|
||||
$form->get("title")->getData(),
|
||||
$form->get("firstname")->getData(),
|
||||
$form->get("lastname")->getData(),
|
||||
$form->get("address1")->getData(),
|
||||
$form->get("address2")->getData(),
|
||||
$form->get("address3")->getData(),
|
||||
$form->get("zipcode")->getData(),
|
||||
$form->get("city")->getData(),
|
||||
$form->get("country")->getData(),
|
||||
$form->get("phone")->getData(),
|
||||
$form->get("company")->getData()
|
||||
);
|
||||
$event->setOrderAddress($orderAddress);
|
||||
$event->setOrder($order);
|
||||
|
||||
$this->dispatch(TheliaEvents::ORDER_UPDATE_ADDRESS, $event);
|
||||
} catch (\Exception $e) {
|
||||
$message = $e->getMessage();
|
||||
}
|
||||
|
||||
$params = array();
|
||||
|
||||
if ($message) {
|
||||
$params["update_status_error_message"] = $message;
|
||||
}
|
||||
|
||||
$params["order_id"] = $order_id;
|
||||
$params["tab"] = $this->getRequest()->get("tab", 'bill');
|
||||
|
||||
$this->redirect(URL::getInstance()->absoluteUrl($this->getRoute("admin.order.update.view", $params)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,40 +23,29 @@
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Event\ProductDeleteEvent;
|
||||
use Thelia\Core\Event\Product\ProductAddCategoryEvent;
|
||||
use Thelia\Core\Event\Product\ProductDeleteCategoryEvent;
|
||||
use Thelia\Core\Event\Product\ProductDeleteEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\ProductUpdateEvent;
|
||||
use Thelia\Core\Event\ProductCreateEvent;
|
||||
use Thelia\Core\Event\Product\ProductUpdateEvent;
|
||||
use Thelia\Core\Event\Product\ProductCreateEvent;
|
||||
use Thelia\Model\ProductQuery;
|
||||
use Thelia\Form\ProductModificationForm;
|
||||
use Thelia\Form\ProductCreationForm;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Core\Event\ProductToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\ProductDeleteContentEvent;
|
||||
use Thelia\Core\Event\ProductAddContentEvent;
|
||||
use Thelia\Model\ProductAssociatedContent;
|
||||
use Thelia\Core\Event\Product\ProductToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\Product\ProductDeleteContentEvent;
|
||||
use Thelia\Core\Event\Product\ProductAddContentEvent;
|
||||
use Thelia\Model\FolderQuery;
|
||||
use Thelia\Model\ContentQuery;
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Thelia\Model\ProductAssociatedContentQuery;
|
||||
use Thelia\Model\AccessoryQuery;
|
||||
use Thelia\Model\CategoryQuery;
|
||||
use Thelia\Core\Event\ProductAddAccessoryEvent;
|
||||
use Thelia\Core\Event\ProductDeleteAccessoryEvent;
|
||||
use Thelia\Core\Event\FeatureProductUpdateEvent;
|
||||
use Thelia\Model\FeatureQuery;
|
||||
use Thelia\Core\Event\FeatureProductDeleteEvent;
|
||||
use Thelia\Model\FeatureTemplateQuery;
|
||||
use Thelia\Core\Event\ProductSetTemplateEvent;
|
||||
use Thelia\Core\Event\ProductAddCategoryEvent;
|
||||
use Thelia\Core\Event\ProductDeleteCategoryEvent;
|
||||
use Thelia\Model\AttributeQuery;
|
||||
use Thelia\Model\AttributeAvQuery;
|
||||
|
||||
use Thelia\Core\Event\Product\ProductAddAccessoryEvent;
|
||||
use Thelia\Core\Event\Product\ProductDeleteAccessoryEvent;
|
||||
use Thelia\Model\ProductSaleElementsQuery;
|
||||
use Thelia\Model\AttributeCombination;
|
||||
use Thelia\Model\AttributeAv;
|
||||
use Thelia\Core\Event\ProductCreateCombinationEvent;
|
||||
use Thelia\Core\Event\ProductDeleteCombinationEvent;
|
||||
|
||||
/**
|
||||
* Manages products
|
||||
@@ -89,8 +78,8 @@ class ProductController extends AbstractCrudController
|
||||
/**
|
||||
* Attributes ajax tab loading
|
||||
*/
|
||||
public function loadAttributesAjaxTabAction() {
|
||||
|
||||
public function loadAttributesAjaxTabAction()
|
||||
{
|
||||
return $this->render(
|
||||
'ajax/product-attributes-tab',
|
||||
array(
|
||||
@@ -102,8 +91,8 @@ class ProductController extends AbstractCrudController
|
||||
/**
|
||||
* Related information ajax tab loading
|
||||
*/
|
||||
public function loadRelatedAjaxTabAction() {
|
||||
|
||||
public function loadRelatedAjaxTabAction()
|
||||
{
|
||||
return $this->render(
|
||||
'ajax/product-related-tab',
|
||||
array(
|
||||
@@ -242,7 +231,8 @@ class ProductController extends AbstractCrudController
|
||||
);
|
||||
}
|
||||
|
||||
protected function getCategoryId() {
|
||||
protected function getCategoryId()
|
||||
{
|
||||
// Trouver le category_id, soit depuis la reques, souit depuis le produit courant
|
||||
$category_id = $this->getRequest()->get('category_id', null);
|
||||
|
||||
@@ -353,7 +343,7 @@ class ProductController extends AbstractCrudController
|
||||
;
|
||||
|
||||
if ($list !== null) {
|
||||
foreach($list as $item) {
|
||||
foreach ($list as $item) {
|
||||
$result[] = array('id' => $item->getId(), 'title' => $item->getTitle());
|
||||
}
|
||||
}
|
||||
@@ -379,8 +369,7 @@ class ProductController extends AbstractCrudController
|
||||
|
||||
try {
|
||||
$this->dispatch(TheliaEvents::PRODUCT_ADD_CONTENT, $event);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
} catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
@@ -406,8 +395,7 @@ class ProductController extends AbstractCrudController
|
||||
|
||||
try {
|
||||
$this->dispatch(TheliaEvents::PRODUCT_REMOVE_CONTENT, $event);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
} catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
@@ -416,7 +404,6 @@ class ProductController extends AbstractCrudController
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
|
||||
|
||||
// -- Accessories management ----------------------------------------------
|
||||
|
||||
public function getAvailableAccessoriesAction($productId, $categoryId)
|
||||
@@ -435,7 +422,7 @@ class ProductController extends AbstractCrudController
|
||||
;
|
||||
|
||||
if ($list !== null) {
|
||||
foreach($list as $item) {
|
||||
foreach ($list as $item) {
|
||||
$result[] = array('id' => $item->getId(), 'title' => $item->getTitle());
|
||||
}
|
||||
}
|
||||
@@ -460,8 +447,7 @@ class ProductController extends AbstractCrudController
|
||||
|
||||
try {
|
||||
$this->dispatch(TheliaEvents::PRODUCT_ADD_ACCESSORY, $event);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
} catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
@@ -486,8 +472,7 @@ class ProductController extends AbstractCrudController
|
||||
|
||||
try {
|
||||
$this->dispatch(TheliaEvents::PRODUCT_REMOVE_ACCESSORY, $event);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
} catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
@@ -527,7 +512,8 @@ class ProductController extends AbstractCrudController
|
||||
*
|
||||
* @param unknown $productId
|
||||
*/
|
||||
public function setProductTemplateAction($productId) {
|
||||
public function setProductTemplateAction($productId)
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth('admin.products.update')) return $response;
|
||||
|
||||
@@ -549,8 +535,8 @@ class ProductController extends AbstractCrudController
|
||||
/**
|
||||
* Update product attributes and features
|
||||
*/
|
||||
public function updateAttributesAndFeaturesAction($productId) {
|
||||
|
||||
public function updateAttributesAndFeaturesAction($productId)
|
||||
{
|
||||
$product = ProductQuery::create()->findPk($productId);
|
||||
|
||||
if ($product != null) {
|
||||
@@ -569,7 +555,7 @@ class ProductController extends AbstractCrudController
|
||||
// Update all features values, starting with feature av. values
|
||||
$featureValues = $this->getRequest()->get('feature_value', array());
|
||||
|
||||
foreach($featureValues as $featureId => $featureValueList) {
|
||||
foreach ($featureValues as $featureId => $featureValueList) {
|
||||
|
||||
// Delete all features av. for this feature.
|
||||
$event = new FeatureProductDeleteEvent($productId, $featureId);
|
||||
@@ -577,7 +563,7 @@ class ProductController extends AbstractCrudController
|
||||
$this->dispatch(TheliaEvents::PRODUCT_FEATURE_DELETE_VALUE, $event);
|
||||
|
||||
// Add then all selected values
|
||||
foreach($featureValueList as $featureValue) {
|
||||
foreach ($featureValueList as $featureValue) {
|
||||
$event = new FeatureProductUpdateEvent($productId, $featureId, $featureValue);
|
||||
|
||||
$this->dispatch(TheliaEvents::PRODUCT_FEATURE_UPDATE_VALUE, $event);
|
||||
@@ -589,7 +575,7 @@ class ProductController extends AbstractCrudController
|
||||
// Update then features text values
|
||||
$featureTextValues = $this->getRequest()->get('feature_text_value', array());
|
||||
|
||||
foreach($featureTextValues as $featureId => $featureValue) {
|
||||
foreach ($featureTextValues as $featureId => $featureValue) {
|
||||
|
||||
// considere empty text as empty feature value (e.g., we will delete it)
|
||||
if (empty($featureValue)) continue;
|
||||
@@ -602,7 +588,7 @@ class ProductController extends AbstractCrudController
|
||||
}
|
||||
|
||||
// Delete features which don't have any values
|
||||
foreach($allFeatures as $feature) {
|
||||
foreach ($allFeatures as $feature) {
|
||||
|
||||
if (! in_array($feature->getId(), $updatedFeatures)) {
|
||||
$event = new FeatureProductDeleteEvent($productId, $feature->getId());
|
||||
@@ -623,12 +609,12 @@ class ProductController extends AbstractCrudController
|
||||
$this->redirectToListTemplate();
|
||||
}
|
||||
|
||||
public function addAdditionalCategoryAction() {
|
||||
|
||||
public function addAdditionalCategoryAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.products.update")) return $response;
|
||||
|
||||
$category_id = intval($this->getRequest()->get('additional_category_id'));
|
||||
$category_id = intval($this->getRequest()->request->get('additional_category_id'));
|
||||
|
||||
if ($category_id > 0) {
|
||||
|
||||
@@ -639,8 +625,7 @@ class ProductController extends AbstractCrudController
|
||||
|
||||
try {
|
||||
$this->dispatch(TheliaEvents::PRODUCT_ADD_CATEGORY, $event);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
} catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
@@ -649,8 +634,8 @@ class ProductController extends AbstractCrudController
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
|
||||
public function deleteAdditionalCategoryAction() {
|
||||
|
||||
public function deleteAdditionalCategoryAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.products.update")) return $response;
|
||||
|
||||
@@ -665,8 +650,7 @@ class ProductController extends AbstractCrudController
|
||||
|
||||
try {
|
||||
$this->dispatch(TheliaEvents::PRODUCT_REMOVE_CATEGORY, $event);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
} catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
@@ -677,8 +661,8 @@ class ProductController extends AbstractCrudController
|
||||
|
||||
// -- Product combination management ---------------------------------------
|
||||
|
||||
public function getAttributeValuesAction($productId, $attributeId) {
|
||||
|
||||
public function getAttributeValuesAction($productId, $attributeId)
|
||||
{
|
||||
$result = array();
|
||||
|
||||
// Get attribute for this product
|
||||
@@ -693,7 +677,7 @@ class ProductController extends AbstractCrudController
|
||||
;
|
||||
|
||||
if ($values !== null) {
|
||||
foreach($values as $value) {
|
||||
foreach ($values as $value) {
|
||||
$result[] = array('id' => $value->getId(), 'title' => $value->getTitle());
|
||||
}
|
||||
}
|
||||
@@ -702,8 +686,8 @@ class ProductController extends AbstractCrudController
|
||||
return $this->jsonResponse(json_encode($result));
|
||||
}
|
||||
|
||||
public function addAttributeValueToCombinationAction($productId, $attributeAvId, $combination) {
|
||||
|
||||
public function addAttributeValueToCombinationAction($productId, $attributeAvId, $combination)
|
||||
{
|
||||
$result = array();
|
||||
|
||||
// Get attribute for this product
|
||||
@@ -747,8 +731,8 @@ class ProductController extends AbstractCrudController
|
||||
/**
|
||||
* A a new combination to a product
|
||||
*/
|
||||
public function addCombinationAction() {
|
||||
|
||||
public function addCombinationAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.products.update")) return $response;
|
||||
|
||||
@@ -760,8 +744,7 @@ class ProductController extends AbstractCrudController
|
||||
|
||||
try {
|
||||
$this->dispatch(TheliaEvents::PRODUCT_ADD_COMBINATION, $event);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
} catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
@@ -773,8 +756,8 @@ class ProductController extends AbstractCrudController
|
||||
/**
|
||||
* A a new combination to a product
|
||||
*/
|
||||
public function deleteCombinationAction() {
|
||||
|
||||
public function deleteCombinationAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.products.update")) return $response;
|
||||
|
||||
@@ -785,8 +768,7 @@ class ProductController extends AbstractCrudController
|
||||
|
||||
try {
|
||||
$this->dispatch(TheliaEvents::PRODUCT_DELETE_COMBINATION, $event);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
} catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
|
||||
@@ -31,9 +31,7 @@ use Thelia\Tools\URL;
|
||||
use Thelia\Tools\Redirect;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Security\Authentication\AdminTokenAuthenticator;
|
||||
use Thelia\Core\Security\UserProvider\TokenProvider;
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
use Thelia\Core\Security\UserProvider\CookieTokenProvider;
|
||||
use Thelia\Core\Security\Exception\TokenAuthenticationException;
|
||||
|
||||
class SessionController extends BaseAdminController
|
||||
@@ -59,8 +57,7 @@ class SessionController extends BaseAdminController
|
||||
|
||||
// Render the home page
|
||||
return $this->render("home");
|
||||
}
|
||||
catch (TokenAuthenticationException $ex) {
|
||||
} catch (TokenAuthenticationException $ex) {
|
||||
$this->adminLogAppend("Token based authentication failed.");
|
||||
|
||||
// Clear the cookie
|
||||
|
||||
@@ -35,12 +35,11 @@ class ShippingConfigurationController extends BaseAdminController
|
||||
if (null !== $response = $this->checkAuth("admin.shipping-configuration.view")) return $response;
|
||||
return $this->render("shipping-configuration", array("display_shipping_configuration" => 20));
|
||||
}
|
||||
|
||||
|
||||
public function updateAction($shipping_configuration_id)
|
||||
{
|
||||
|
||||
return $this->render("shipping-configuration-edit", array(
|
||||
"shipping_configuration_id" => $shipping_configuration_id
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,12 +35,11 @@ class ShippingZoneController extends BaseAdminController
|
||||
if (null !== $response = $this->checkAuth("admin.shipping-zones.view")) return $response;
|
||||
return $this->render("shipping-zones", array("display_shipping_zone" => 20));
|
||||
}
|
||||
|
||||
|
||||
public function updateAction($shipping_zones_id)
|
||||
{
|
||||
|
||||
return $this->render("shipping-zones-edit", array(
|
||||
"shipping_zones_id" => $shipping_zones_id
|
||||
));
|
||||
return $this->render("shipping-zones-edit", array(
|
||||
"shipping_zones_id" => $shipping_zones_id
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,22 +23,17 @@
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Event\TemplateDeleteEvent;
|
||||
use Thelia\Core\Event\Template\TemplateDeleteEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\TemplateUpdateEvent;
|
||||
use Thelia\Core\Event\TemplateCreateEvent;
|
||||
use Thelia\Core\Event\Template\TemplateUpdateEvent;
|
||||
use Thelia\Core\Event\Template\TemplateCreateEvent;
|
||||
use Thelia\Model\TemplateQuery;
|
||||
use Thelia\Form\TemplateModificationForm;
|
||||
use Thelia\Form\TemplateCreationForm;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Model\TemplateAv;
|
||||
use Thelia\Model\TemplateAvQuery;
|
||||
use Thelia\Core\Event\TemplateAvUpdateEvent;
|
||||
use Thelia\Core\Event\TemplateEvent;
|
||||
use Thelia\Core\Event\TemplateDeleteAttributeEvent;
|
||||
use Thelia\Core\Event\TemplateAddAttributeEvent;
|
||||
use Thelia\Core\Event\TemplateAddFeatureEvent;
|
||||
use Thelia\Core\Event\TemplateDeleteFeatureEvent;
|
||||
use Thelia\Core\Event\Template\TemplateDeleteAttributeEvent;
|
||||
use Thelia\Core\Event\Template\TemplateAddAttributeEvent;
|
||||
use Thelia\Core\Event\Template\TemplateAddFeatureEvent;
|
||||
use Thelia\Core\Event\Template\TemplateDeleteFeatureEvent;
|
||||
use Thelia\Model\FeatureTemplateQuery;
|
||||
use Thelia\Model\AttributeTemplateQuery;
|
||||
|
||||
@@ -102,7 +97,6 @@ class TemplateController extends AbstractCrudController
|
||||
;
|
||||
|
||||
// Add feature and attributes list
|
||||
|
||||
return $changeEvent;
|
||||
}
|
||||
|
||||
@@ -199,22 +193,24 @@ class TemplateController extends AbstractCrudController
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getAjaxFeaturesAction() {
|
||||
public function getAjaxFeaturesAction()
|
||||
{
|
||||
return $this->render(
|
||||
'ajax/template-feature-list',
|
||||
array('template_id' => $this->getRequest()->get('template_id'))
|
||||
);
|
||||
}
|
||||
|
||||
public function getAjaxAttributesAction() {
|
||||
public function getAjaxAttributesAction()
|
||||
{
|
||||
return $this->render(
|
||||
'ajax/template-attribute-list',
|
||||
array('template_id' => $this->getRequest()->get('template_id'))
|
||||
);
|
||||
}
|
||||
|
||||
public function addAttributeAction() {
|
||||
|
||||
public function addAttributeAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.template.attribute.add")) return $response;
|
||||
|
||||
@@ -237,8 +233,8 @@ class TemplateController extends AbstractCrudController
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
|
||||
public function deleteAttributeAction() {
|
||||
|
||||
public function deleteAttributeAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.template.attribute.delete")) return $response;
|
||||
|
||||
@@ -257,8 +253,8 @@ class TemplateController extends AbstractCrudController
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
|
||||
public function updateAttributePositionAction() {
|
||||
|
||||
public function updateAttributePositionAction()
|
||||
{
|
||||
// Find attribute_template
|
||||
$attributeTemplate = AttributeTemplateQuery::create()
|
||||
->filterByTemplateId($this->getRequest()->get('template_id', null))
|
||||
@@ -272,8 +268,8 @@ class TemplateController extends AbstractCrudController
|
||||
);
|
||||
}
|
||||
|
||||
public function addFeatureAction() {
|
||||
|
||||
public function addFeatureAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.template.feature.add")) return $response;
|
||||
|
||||
@@ -296,8 +292,8 @@ class TemplateController extends AbstractCrudController
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
|
||||
public function deleteFeatureAction() {
|
||||
|
||||
public function deleteFeatureAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.template.feature.delete")) return $response;
|
||||
|
||||
@@ -316,8 +312,8 @@ class TemplateController extends AbstractCrudController
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
|
||||
public function updateFeaturePositionAction() {
|
||||
|
||||
public function updateFeaturePositionAction()
|
||||
{
|
||||
// Find feature_template
|
||||
$featureTemplate = FeatureTemplateQuery::create()
|
||||
->filterByTemplateId($this->getRequest()->get('template_id', null))
|
||||
@@ -330,4 +326,4 @@ class TemplateController extends AbstractCrudController
|
||||
TheliaEvents::TEMPLATE_CHANGE_FEATURE_POSITION
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ class BaseController extends ContainerAware
|
||||
*/
|
||||
protected function checkXmlHttpRequest()
|
||||
{
|
||||
if(false === $this->getRequest()->isXmlHttpRequest() && false === $this->isDebug()) {
|
||||
if (false === $this->getRequest()->isXmlHttpRequest() && false === $this->isDebug()) {
|
||||
$this->accessDenied();
|
||||
}
|
||||
}
|
||||
@@ -300,6 +300,7 @@ class BaseController extends ContainerAware
|
||||
public function getMailer()
|
||||
{
|
||||
$mailer = $this->container->get('mailer');
|
||||
|
||||
return $mailer->getSwiftMailer();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,15 +22,14 @@
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Front;
|
||||
use Thelia\Core\Event\AddressCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\AddressEvent;
|
||||
use Thelia\Core\Event\Address\AddressCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\Address\AddressEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Form\AddressCreateForm;
|
||||
use Thelia\Form\AddressUpdateForm;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Model\AddressQuery;
|
||||
use Thelia\Model\Customer;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
/**
|
||||
* Class AddressController
|
||||
@@ -51,10 +50,8 @@ class AddressController extends BaseFrontController
|
||||
$this->checkAuth();
|
||||
$this->checkXmlHttpRequest();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create controller.
|
||||
* Check if customer is logged in
|
||||
@@ -103,7 +100,7 @@ class AddressController extends BaseFrontController
|
||||
$customer = $this->getSecurityContext()->getCustomerUser();
|
||||
$address = AddressQuery::create()->findPk($address_id);
|
||||
|
||||
if(!$address || $customer->getId() != $address->getCustomerId()) {
|
||||
if (!$address || $customer->getId() != $address->getCustomerId()) {
|
||||
$this->redirectToRoute("home");
|
||||
}
|
||||
|
||||
@@ -117,7 +114,6 @@ class AddressController extends BaseFrontController
|
||||
|
||||
$addressUpdate = new AddressUpdateForm($request);
|
||||
|
||||
|
||||
try {
|
||||
$customer = $this->getSecurityContext()->getCustomerUser();
|
||||
|
||||
@@ -164,7 +160,7 @@ class AddressController extends BaseFrontController
|
||||
$customer = $this->getSecurityContext()->getCustomerUser();
|
||||
$address = AddressQuery::create()->findPk($address_id);
|
||||
|
||||
if(!$address || $customer->getId() != $address->getCustomerId()) {
|
||||
if (!$address || $customer->getId() != $address->getCustomerId()) {
|
||||
$this->redirectToRoute("home");
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ class BaseFrontController extends BaseController
|
||||
|
||||
public function checkAuth()
|
||||
{
|
||||
if($this->getSecurityContext()->hasCustomerUser() === false) {
|
||||
if ($this->getSecurityContext()->hasCustomerUser() === false) {
|
||||
$this->redirectToRoute("customer.login.view");
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ class BaseFrontController extends BaseController
|
||||
protected function checkCartNotEmpty()
|
||||
{
|
||||
$cart = $this->getSession()->getCart();
|
||||
if($cart===null || $cart->countCartItems() == 0) {
|
||||
if ($cart===null || $cart->countCartItems() == 0) {
|
||||
$this->redirectToRoute("cart.view");
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,7 @@ class BaseFrontController extends BaseController
|
||||
protected function checkValidDelivery()
|
||||
{
|
||||
$order = $this->getSession()->getOrder();
|
||||
if(null === $order || null === $order->chosenDeliveryAddress || null === $order->getDeliveryModuleId() || null === AddressQuery::create()->findPk($order->chosenDeliveryAddress) || null === ModuleQuery::create()->findPk($order->getDeliveryModuleId())) {
|
||||
if (null === $order || null === $order->chosenDeliveryAddress || null === $order->getDeliveryModuleId() || null === AddressQuery::create()->findPk($order->chosenDeliveryAddress) || null === ModuleQuery::create()->findPk($order->getDeliveryModuleId())) {
|
||||
$this->redirectToRoute("order.delivery");
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ class BaseFrontController extends BaseController
|
||||
protected function checkValidInvoice()
|
||||
{
|
||||
$order = $this->getSession()->getOrder();
|
||||
if(null === $order || null === $order->chosenInvoiceAddress || null === $order->getPaymentModuleId() || null === AddressQuery::create()->findPk($order->chosenInvoiceAddress) || null === ModuleQuery::create()->findPk($order->getPaymentModuleId())) {
|
||||
if (null === $order || null === $order->chosenInvoiceAddress || null === $order->getPaymentModuleId() || null === AddressQuery::create()->findPk($order->chosenInvoiceAddress) || null === ModuleQuery::create()->findPk($order->getPaymentModuleId())) {
|
||||
$this->redirectToRoute("order.invoice");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Thelia\Controller\Front;
|
||||
|
||||
use Propel\Runtime\Exception\PropelException;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Core\Event\CartEvent;
|
||||
use Thelia\Core\Event\Cart\CartEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Thelia\Form\CartAdd;
|
||||
@@ -102,7 +102,7 @@ class CartController extends BaseFrontController
|
||||
/**
|
||||
* use Thelia\Cart\CartTrait for searching current cart or create a new one
|
||||
*
|
||||
* @return CartEvent
|
||||
* @return \Thelia\Core\Event\Cart\CartEvent
|
||||
*/
|
||||
protected function getCartEvent()
|
||||
{
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Controller\Front;
|
||||
|
||||
use Thelia\Core\Event\CustomerCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\CustomerLoginEvent;
|
||||
use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\Customer\CustomerLoginEvent;
|
||||
use Thelia\Core\Event\LostPasswordEvent;
|
||||
use Thelia\Core\Security\Authentication\CustomerUsernamePasswordFormAuthenticator;
|
||||
use Thelia\Core\Security\Exception\AuthenticationException;
|
||||
@@ -104,7 +104,7 @@ class CustomerController extends BaseFrontController
|
||||
$this->processLogin($customerCreateEvent->getCustomer());
|
||||
|
||||
$cart = $this->getCart($this->getRequest());
|
||||
if($cart->getCartItems()->count() > 0) {
|
||||
if ($cart->getCartItems()->count() > 0) {
|
||||
$this->redirectToRoute("cart.view");
|
||||
} else {
|
||||
$this->redirectSuccess($customerCreation);
|
||||
@@ -257,7 +257,7 @@ class CustomerController extends BaseFrontController
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return CustomerCreateOrUpdateEvent
|
||||
* @return \Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent
|
||||
*/
|
||||
private function createEventInstance($data)
|
||||
{
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Thelia\Controller\Front;
|
||||
use Propel\Runtime\Exception\PropelException;
|
||||
use Thelia\Exception\TheliaProcessException;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Core\Event\OrderEvent;
|
||||
use Thelia\Core\Event\Order\OrderEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Thelia\Form\OrderDelivery;
|
||||
@@ -34,7 +34,6 @@ use Thelia\Log\Tlog;
|
||||
use Thelia\Model\AddressQuery;
|
||||
use Thelia\Model\AreaDeliveryModuleQuery;
|
||||
use Thelia\Model\Base\OrderQuery;
|
||||
use Thelia\Model\CountryQuery;
|
||||
use Thelia\Model\ModuleQuery;
|
||||
use Thelia\Model\Order;
|
||||
use Thelia\Tools\URL;
|
||||
@@ -69,7 +68,7 @@ class OrderController extends BaseFrontController
|
||||
|
||||
/* check that the delivery address belongs to the current customer */
|
||||
$deliveryAddress = AddressQuery::create()->findPk($deliveryAddressId);
|
||||
if($deliveryAddress->getCustomerId() !== $this->getSecurityContext()->getCustomerUser()->getId()) {
|
||||
if ($deliveryAddress->getCustomerId() !== $this->getSecurityContext()->getCustomerUser()->getId()) {
|
||||
throw new \Exception("Delivery address does not belong to the current customer");
|
||||
}
|
||||
|
||||
@@ -139,7 +138,7 @@ class OrderController extends BaseFrontController
|
||||
|
||||
/* check that the invoice address belongs to the current customer */
|
||||
$invoiceAddress = AddressQuery::create()->findPk($invoiceAddressId);
|
||||
if($invoiceAddress->getCustomerId() !== $this->getSecurityContext()->getCustomerUser()->getId()) {
|
||||
if ($invoiceAddress->getCustomerId() !== $this->getSecurityContext()->getCustomerUser()->getId()) {
|
||||
throw new \Exception("Invoice address does not belong to the current customer");
|
||||
}
|
||||
|
||||
@@ -193,7 +192,7 @@ class OrderController extends BaseFrontController
|
||||
|
||||
$placedOrder = $orderEvent->getPlacedOrder();
|
||||
|
||||
if(null !== $placedOrder && null !== $placedOrder->getId()) {
|
||||
if (null !== $placedOrder && null !== $placedOrder->getId()) {
|
||||
/* order has been placed */
|
||||
$this->redirect(URL::getInstance()->absoluteUrl($this->getRoute('order.placed', array('order_id' => $orderEvent->getPlacedOrder()->getId()))));
|
||||
} else {
|
||||
@@ -209,13 +208,13 @@ class OrderController extends BaseFrontController
|
||||
$this->getRequest()->attributes->get('order_id')
|
||||
);
|
||||
|
||||
if(null === $placedOrder) {
|
||||
if (null === $placedOrder) {
|
||||
throw new TheliaProcessException("No placed order", TheliaProcessException::NO_PLACED_ORDER, $placedOrder);
|
||||
}
|
||||
|
||||
$customer = $this->getSecurityContext()->getCustomerUser();
|
||||
|
||||
if(null === $customer || $placedOrder->getCustomerId() !== $customer->getId()) {
|
||||
if (null === $customer || $placedOrder->getCustomerId() !== $customer->getId()) {
|
||||
throw new TheliaProcessException("Received placed order id does not belong to the current customer", TheliaProcessException::PLACED_ORDER_ID_BAD_CURRENT_CUSTOMER, $placedOrder);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,9 @@
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event;
|
||||
namespace Thelia\Core\Event\Address;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
use Thelia\Model\Address;
|
||||
use Thelia\Model\Customer;
|
||||
|
||||
@@ -243,8 +244,6 @@ class AddressCreateOrUpdateEvent extends ActionEvent
|
||||
return $this->isDefault;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param \Thelia\Model\Customer $customer
|
||||
*/
|
||||
@@ -21,8 +21,9 @@
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event;
|
||||
namespace Thelia\Core\Event\Address;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
use Thelia\Model\Address;
|
||||
|
||||
/**
|
||||
@@ -21,7 +21,9 @@
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event;
|
||||
namespace Thelia\Core\Event\Attribute;
|
||||
|
||||
use Thelia\Core\Event\Attribute\AttributeAvEvent;
|
||||
|
||||
class AttributeAvCreateEvent extends AttributeAvEvent
|
||||
{
|
||||
@@ -21,7 +21,9 @@
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event;
|
||||
namespace Thelia\Core\Event\Attribute;
|
||||
|
||||
use Thelia\Core\Event\Attribute\AttributeAvEvent;
|
||||
|
||||
class AttributeAvDeleteEvent extends AttributeAvEvent
|
||||
{
|
||||
@@ -21,7 +21,8 @@
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event;
|
||||
namespace Thelia\Core\Event\Attribute;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
use Thelia\Model\AttributeAv;
|
||||
|
||||
class AttributeAvEvent extends ActionEvent
|
||||
@@ -21,7 +21,9 @@
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event;
|
||||
namespace Thelia\Core\Event\Attribute;
|
||||
|
||||
use Thelia\Core\Event\Attribute\AttributeAvCreateEvent;
|
||||
|
||||
class AttributeAvUpdateEvent extends AttributeAvCreateEvent
|
||||
{
|
||||
@@ -21,7 +21,9 @@
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event;
|
||||
namespace Thelia\Core\Event\Attribute;
|
||||
|
||||
use Thelia\Core\Event\Attribute\AttributeEvent;
|
||||
|
||||
class AttributeCreateEvent extends AttributeEvent
|
||||
{
|
||||
@@ -21,7 +21,9 @@
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event;
|
||||
namespace Thelia\Core\Event\Attribute;
|
||||
|
||||
use Thelia\Core\Event\Attribute\AttributeEvent;
|
||||
|
||||
class AttributeDeleteEvent extends AttributeEvent
|
||||
{
|
||||
@@ -21,7 +21,8 @@
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event;
|
||||
namespace Thelia\Core\Event\Attribute;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
use Thelia\Model\Attribute;
|
||||
|
||||
class AttributeEvent extends ActionEvent
|
||||
@@ -21,7 +21,9 @@
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event;
|
||||
namespace Thelia\Core\Event\Attribute;
|
||||
|
||||
use Thelia\Core\Event\Attribute\AttributeCreateEvent;
|
||||
|
||||
class AttributeUpdateEvent extends AttributeCreateEvent
|
||||
{
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user