diff --git a/CHANGELOG.md b/CHANGELOG.md old mode 100644 new mode 100755 index abb42e028..ec425be8a --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,5 +25,6 @@ - http://www.mnot.net/cache_docs/ (fr) - http://tomayko.com/writings/things-caches-do (en) - http://symfony.com/doc/current/book/http_cache.html#http-cache-introduction (en and fr) +- Coupon effect inputs are now more customisable (input text, select, ajax, etc.. are usable) and unlimited amount of input for coupon effect are now possible too diff --git a/core/lib/Thelia/Action/Coupon.php b/core/lib/Thelia/Action/Coupon.php index 1b77eb488..1bb8fd654 100755 --- a/core/lib/Thelia/Action/Coupon.php +++ b/core/lib/Thelia/Action/Coupon.php @@ -38,10 +38,6 @@ use Thelia\Model\Coupon as CouponModel; use Thelia\Model\CouponQuery; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Process Coupon Events * * @package Coupon @@ -168,7 +164,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface $coupon->createOrUpdate( $event->getCode(), $event->getTitle(), - $event->getAmount(), + $event->getEffects(), $event->getServiceId(), $event->isRemovingPostage(), $event->getShortDescription(), diff --git a/core/lib/Thelia/Condition/ConditionCollection.php b/core/lib/Thelia/Condition/ConditionCollection.php index 14b4076f6..c7ec67caf 100644 --- a/core/lib/Thelia/Condition/ConditionCollection.php +++ b/core/lib/Thelia/Condition/ConditionCollection.php @@ -27,10 +27,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Thelia\Condition\Implementation\ConditionInterface; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Manage a set of ConditionInterface * * @package Condition diff --git a/core/lib/Thelia/Condition/ConditionEvaluator.php b/core/lib/Thelia/Condition/ConditionEvaluator.php index 49e566158..992e9ca0d 100644 --- a/core/lib/Thelia/Condition/ConditionEvaluator.php +++ b/core/lib/Thelia/Condition/ConditionEvaluator.php @@ -30,10 +30,6 @@ use Thelia\Condition\ConditionCollection; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Validate Conditions * * @package Condition diff --git a/core/lib/Thelia/Condition/ConditionFactory.php b/core/lib/Thelia/Condition/ConditionFactory.php index b472dcb0f..f7440634c 100644 --- a/core/lib/Thelia/Condition/ConditionFactory.php +++ b/core/lib/Thelia/Condition/ConditionFactory.php @@ -30,10 +30,6 @@ use Thelia\Condition\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 diff --git a/core/lib/Thelia/Condition/ConditionOrganizer.php b/core/lib/Thelia/Condition/ConditionOrganizer.php index f678142ab..ebcff5f7d 100644 --- a/core/lib/Thelia/Condition/ConditionOrganizer.php +++ b/core/lib/Thelia/Condition/ConditionOrganizer.php @@ -24,10 +24,6 @@ namespace Thelia\Condition; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Manage how Condition could interact with each others * * @package Condition diff --git a/core/lib/Thelia/Condition/ConditionOrganizerInterface.php b/core/lib/Thelia/Condition/ConditionOrganizerInterface.php index 00f8d55b8..b34982cc7 100644 --- a/core/lib/Thelia/Condition/ConditionOrganizerInterface.php +++ b/core/lib/Thelia/Condition/ConditionOrganizerInterface.php @@ -24,10 +24,6 @@ namespace Thelia\Condition; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Manage how Condition could interact with each other * * @package Condition diff --git a/core/lib/Thelia/Condition/Implementation/ConditionAbstract.php b/core/lib/Thelia/Condition/Implementation/ConditionAbstract.php index 71bd2f60e..b12dc2bd4 100644 --- a/core/lib/Thelia/Condition/Implementation/ConditionAbstract.php +++ b/core/lib/Thelia/Condition/Implementation/ConditionAbstract.php @@ -34,10 +34,6 @@ use Thelia\Model\Currency; use Thelia\Type\FloatType; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Assist in writing a condition of whether the Condition is applied or not * * @package Constraint diff --git a/core/lib/Thelia/Condition/Implementation/ConditionInterface.php b/core/lib/Thelia/Condition/Implementation/ConditionInterface.php index 10759eaa7..8992c6c82 100644 --- a/core/lib/Thelia/Condition/Implementation/ConditionInterface.php +++ b/core/lib/Thelia/Condition/Implementation/ConditionInterface.php @@ -28,10 +28,6 @@ use Thelia\Core\Translation\Translator; use Thelia\Coupon\FacadeInterface; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Manage how the application checks its state in order to check if it matches the implemented condition * * @package Condition diff --git a/core/lib/Thelia/Condition/Implementation/MatchForEveryone.php b/core/lib/Thelia/Condition/Implementation/MatchForEveryone.php index 22d696339..5438bdd91 100644 --- a/core/lib/Thelia/Condition/Implementation/MatchForEveryone.php +++ b/core/lib/Thelia/Condition/Implementation/MatchForEveryone.php @@ -27,10 +27,6 @@ use InvalidArgumentException; use Thelia\Condition\Implementation\ConditionAbstract; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Allow every one, perform no check * * @package Condition diff --git a/core/lib/Thelia/Condition/Implementation/MatchForTotalAmount.php b/core/lib/Thelia/Condition/Implementation/MatchForTotalAmount.php index 09b63ef00..e4f8f8e74 100644 --- a/core/lib/Thelia/Condition/Implementation/MatchForTotalAmount.php +++ b/core/lib/Thelia/Condition/Implementation/MatchForTotalAmount.php @@ -31,10 +31,6 @@ use Thelia\Model\Currency; use Thelia\Model\CurrencyQuery; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Condition AvailableForTotalAmount * Check if a Checkout total amount match criteria * diff --git a/core/lib/Thelia/Condition/Implementation/MatchForXArticles.php b/core/lib/Thelia/Condition/Implementation/MatchForXArticles.php index f1c1ebaac..c99ed67c9 100644 --- a/core/lib/Thelia/Condition/Implementation/MatchForXArticles.php +++ b/core/lib/Thelia/Condition/Implementation/MatchForXArticles.php @@ -30,10 +30,6 @@ use Thelia\Exception\InvalidConditionOperatorException; use Thelia\Exception\InvalidConditionValueException; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Check a Checkout against its Product number * * @package Condition diff --git a/core/lib/Thelia/Condition/Operators.php b/core/lib/Thelia/Condition/Operators.php index 57be8e0bf..cc687acde 100644 --- a/core/lib/Thelia/Condition/Operators.php +++ b/core/lib/Thelia/Condition/Operators.php @@ -26,10 +26,6 @@ namespace Thelia\Condition; use Thelia\Core\Translation\Translator; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Represent available Operations in condition checking * * @package Constraint diff --git a/core/lib/Thelia/Condition/SerializableCondition.php b/core/lib/Thelia/Condition/SerializableCondition.php index cd2f1de44..d147adbd2 100644 --- a/core/lib/Thelia/Condition/SerializableCondition.php +++ b/core/lib/Thelia/Condition/SerializableCondition.php @@ -24,10 +24,6 @@ namespace Thelia\Condition; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * A condition ready to be serialized and stored in DataBase * * @package Condition diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index f5adc68aa..613694ab7 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -499,6 +499,10 @@ Thelia\Controller\Admin\CouponController::readAction \d+ + + Thelia\Controller\Admin\CouponController::getBackOfficeInputsAction + .* + Thelia\Controller\Admin\CouponController::getConditionInputAction .* diff --git a/core/lib/Thelia/Controller/Admin/AbstractSeoCrudController.php b/core/lib/Thelia/Controller/Admin/AbstractSeoCrudController.php old mode 100644 new mode 100755 diff --git a/core/lib/Thelia/Controller/Admin/CouponController.php b/core/lib/Thelia/Controller/Admin/CouponController.php index b382dbb30..d4162f80e 100755 --- a/core/lib/Thelia/Controller/Admin/CouponController.php +++ b/core/lib/Thelia/Controller/Admin/CouponController.php @@ -23,6 +23,7 @@ namespace Thelia\Controller\Admin; +use Symfony\Component\Form\Form; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Router; use Thelia\Condition\ConditionFactory; @@ -31,9 +32,11 @@ use Thelia\Core\Security\Resource\AdminResources; use Thelia\Core\Event\Coupon\CouponCreateOrUpdateEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Security\AccessManager; +use Thelia\Coupon\CouponFactory; use Thelia\Coupon\CouponManager; use Thelia\Condition\ConditionCollection; use Thelia\Coupon\Type\CouponInterface; +use Thelia\Coupon\Type\RemoveXPercent; use Thelia\Form\CouponCreationForm; use Thelia\Form\Exception\FormValidationException; use Thelia\Log\Tlog; @@ -41,12 +44,9 @@ use Thelia\Model\Coupon; use Thelia\Model\CouponQuery; use Thelia\Model\Lang; use Thelia\Tools\I18n; +use Thelia\Tools\Rest\ResponseRest; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Control View and Action (Model) via Events * * @package Coupon @@ -152,6 +152,11 @@ class CouponController extends BaseAdminController $args['dateFormat'] = $this->getSession()->getLang()->getDateFormat(); $args['availableCoupons'] = $this->getAvailableCoupons(); + $args['urlAjaxAdminCouponDrawInputs'] = $this->getRoute( + 'admin.coupon.draw.inputs', + array('couponServiceId' => 'couponServiceId'), + Router::ABSOLUTE_URL + ); $args['formAction'] = 'admin/coupon/create'; return $this->render( @@ -181,6 +186,9 @@ class CouponController extends BaseAdminController return $this->pageNotFound(); } + /** @var CouponFactory $couponFactory */ + $couponFactory = $this->container->get('thelia.coupon.factory'); + $couponManager = $couponFactory->buildCouponFromModel($coupon); // Parameters given to the template $args = array(); @@ -247,6 +255,12 @@ class CouponController extends BaseAdminController } $args['couponCode'] = $coupon->getCode(); $args['availableCoupons'] = $this->getAvailableCoupons(); + $args['couponInputsHtml'] = $couponManager->drawBackOfficeInputs(); + $args['urlAjaxAdminCouponDrawInputs'] = $this->getRoute( + 'admin.coupon.draw.inputs', + array('couponServiceId' => 'couponServiceId'), + Router::ABSOLUTE_URL + ); $args['availableConditions'] = $this->getAvailableConditions(); $args['urlAjaxGetConditionInput'] = $this->getRoute( 'admin.coupon.condition.input', @@ -332,9 +346,9 @@ class CouponController extends BaseAdminController $couponEvent = new CouponCreateOrUpdateEvent( $coupon->getCode(), - $coupon->getTitle(), - $coupon->getAmount(), $coupon->getType(), + $coupon->getTitle(), + array('quantity' => $coupon->getAmount()), $coupon->getShortDescription(), $coupon->getDescription(), $coupon->getIsEnabled(), @@ -455,12 +469,7 @@ class CouponController extends BaseAdminController // 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['type'], $data['shortDescription'], $data['description'], $data['isEnabled'], \DateTime::createFromFormat('Y-m-d', $data['expirationDate']), $data['isAvailableOnSpecialOffers'], $data['isCumulative'], $data['isRemovingPostage'], $data['maxUsage'], $data['locale'] - ); + $couponEvent = $this->feedCouponCreateOrUpdateEvent($form); // Dispatch Event to the Action $this->dispatch( @@ -524,7 +533,6 @@ class CouponController extends BaseAdminController $condition = array(); $condition['serviceId'] = $availableCondition->getServiceId(); $condition['name'] = $availableCondition->getName(); - // $condition['toolTip'] = $availableCondition->getToolTip(); $cleanedConditions[] = $condition; } @@ -548,6 +556,7 @@ class CouponController extends BaseAdminController $condition['serviceId'] = $availableCoupon->getServiceId(); $condition['name'] = $availableCoupon->getName(); $condition['toolTip'] = $availableCoupon->getToolTip(); + $condition['inputName'] = $availableCoupon->getInputName(); $cleanedCoupons[] = $condition; } @@ -572,4 +581,86 @@ class CouponController extends BaseAdminController return $cleanedConditions; } + /** + * Draw the input displayed in the BackOffice + * allowing Admin to set its Coupon effect + * + * @param string $couponServiceId Coupon service id + * + * @return ResponseRest + */ + public function getBackOfficeInputsAction($couponServiceId) + { + /** @var CouponInterface $coupon */ + $coupon = $this->container->get($couponServiceId); + + if (!$coupon instanceof CouponInterface) { + $this->pageNotFound(); + } + + $response = new ResponseRest($coupon->drawBackOfficeInputs()); + + return $response; + } + + /** + * Add percentage logic if found in the Coupon post data + * + * @param array $effects Effect parameters to populate + * @param array $extendedInputNames Extended Inputs to manage + * + * @return array Populated effect with percentage + */ + protected function addExtendedLogic(array $effects, array $extendedInputNames) + { + /** @var Request $request */ + $request = $this->container->get('request'); + $postData = $request->request; + // Validate quantity input + + if ($postData->has(RemoveXPercent::INPUT_EXTENDED__NAME)) { + $extentedPostData = $postData->get(RemoveXPercent::INPUT_EXTENDED__NAME); + + foreach ($extendedInputNames as $extendedInputName) { + if (isset($extentedPostData[$extendedInputName])) { + $inputValue = $extentedPostData[$extendedInputName]; + $effects[$extendedInputName] = $inputValue; + } + } + } + + return $effects; + } + + /** + * Feed the Coupon Create or Update event with the User inputs + * + * @param Form $form + * + * @return CouponCreateOrUpdateEvent + */ + protected function feedCouponCreateOrUpdateEvent(Form $form) + { + // Get the form field values + $data = $form->getData(); + $serviceId = $data['type']; + /** @var CouponInterface $couponManager */ + $couponManager = $this->container->get($serviceId); + $effects = array('amount' => $data['amount']); + $effects = $this->addExtendedLogic($effects, $couponManager->getExtendedInputs()); + + $couponEvent = new CouponCreateOrUpdateEvent( + $data['code'], $serviceId, $data['title'], $effects, $data['shortDescription'], $data['description'], $data['isEnabled'], \DateTime::createFromFormat('Y-m-d', $data['expirationDate']), $data['isAvailableOnSpecialOffers'], $data['isCumulative'], $data['isRemovingPostage'], $data['maxUsage'], $data['locale'] + ); + + // If Update mode + $couponQuery = new CouponQuery(); + $coupon = $couponQuery->findOneByCode($data['code']); + if (isset($coupon)) { + $couponEvent->setCouponModel($coupon); + } + + return $couponEvent; + } + } diff --git a/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterCouponConditionPass.php b/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterCouponConditionPass.php index 7caf79c5e..127d0e334 100755 --- a/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterCouponConditionPass.php +++ b/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterCouponConditionPass.php @@ -28,10 +28,6 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; /** - * Created by JetBrains PhpStorm. - * Date: 9/05/13 - * Time: 3:24 PM - * * Class RegisterListenersPass * Source code come from Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RegisterKernelListenersPass class * diff --git a/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterCouponPass.php b/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterCouponPass.php index cf6f32842..a499c8ed1 100755 --- a/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterCouponPass.php +++ b/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterCouponPass.php @@ -28,10 +28,6 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; /** - * Created by JetBrains PhpStorm. - * Date: 9/05/13 - * Time: 3:24 PM - * * Class RegisterListenersPass * Source code come from Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RegisterKernelListenersPass class * diff --git a/core/lib/Thelia/Core/Event/Coupon/CouponConsumeEvent.php b/core/lib/Thelia/Core/Event/Coupon/CouponConsumeEvent.php index ace8cb0b7..70b656b92 100644 --- a/core/lib/Thelia/Core/Event/Coupon/CouponConsumeEvent.php +++ b/core/lib/Thelia/Core/Event/Coupon/CouponConsumeEvent.php @@ -25,10 +25,6 @@ namespace Thelia\Core\Event\Coupon; use Thelia\Core\Event\ActionEvent; /** - * Created by JetBrains PhpStorm. - * Date: 8/29/13 - * Time: 3:45 PM - * * Occurring when a Coupon is consumed * * @package Coupon diff --git a/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php b/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php index 19edf4e45..de236ac3c 100644 --- a/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php +++ b/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php @@ -25,12 +25,9 @@ namespace Thelia\Core\Event\Coupon; use Thelia\Core\Event\ActionEvent; use Thelia\Condition\ConditionCollection; use Thelia\Model\Coupon; +use Thelia\Model\Exception\InvalidArgumentException; /** - * Created by JetBrains PhpStorm. - * Date: 8/29/13 - * Time: 3:45 PM - * * Occurring when a Coupon is created or updated * * @package Coupon @@ -69,6 +66,9 @@ class CouponCreateOrUpdateEvent extends ActionEvent /** @var float Amount that will be removed from the Checkout (Coupon Effect) */ protected $amount = 0; + /** @var array Effects ready to be serialized */ + protected $effects = array(); + /** @var int Max time a Coupon can be used (-1 = unlimited) */ protected $maxUsage = -1; @@ -88,9 +88,11 @@ class CouponCreateOrUpdateEvent extends ActionEvent * Constructor * * @param string $code Coupon Code - * @param string $title Coupon title - * @param float $amount Amount removed from the Total Checkout * @param string $serviceId Coupon Service id + * @param string $title Coupon title + * @param array $effects Coupon effects ready to be serialized + * 'amount' key is mandatory and reflects + * the amount deduced from the cart * @param string $shortDescription Coupon short description * @param string $description Coupon description * @param bool $isEnabled Enable/Disable @@ -101,11 +103,8 @@ class CouponCreateOrUpdateEvent extends ActionEvent * @param int $maxUsage Coupon quantity * @param string $locale Coupon Language code ISO (ex: fr_FR) */ - public function __construct( - $code, $title, $amount, $serviceId, $shortDescription, $description, $isEnabled, \DateTime $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $isRemovingPostage, $maxUsage, $locale - ) + public function __construct($code, $serviceId, $title, array $effects, $shortDescription, $description, $isEnabled, \DateTime $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $isRemovingPostage, $maxUsage, $locale) { - $this->amount = $amount; $this->code = $code; $this->description = $description; $this->expirationDate = $expirationDate; @@ -118,6 +117,7 @@ class CouponCreateOrUpdateEvent extends ActionEvent $this->title = $title; $this->serviceId = $serviceId; $this->locale = $locale; + $this->setEffects($effects); } /** @@ -189,7 +189,7 @@ class CouponCreateOrUpdateEvent extends ActionEvent */ public function getAmount() { - return $this->amount; + return $this->effects['amount']; } /** @@ -253,6 +253,71 @@ class CouponCreateOrUpdateEvent extends ActionEvent return $this->locale; } + /** + * Set effects ready to be serialized + * + * @param array $effects Effect ready to be serialized + * Needs at least the key 'amount' + * with the amount removed from the cart + * @throws \Thelia\Model\Exception\InvalidArgumentException + */ + public function setEffects(array $effects) + { + if (null === $effects['amount']) { + throw new InvalidArgumentException('Missing key \'amount\' in Coupon effect ready to be serialized array'); + } + $this->amount = $effects['amount']; + $this->effects = $effects; + } + + /** + * Get effects ready to be serialized + * + * @return array + */ + public function getEffects() + { + return $this->effects; + } + + /** + * Get if the Coupon will be available on special offers or not + * + * @return boolean + */ + public function getIsAvailableOnSpecialOffers() + { + return $this->isAvailableOnSpecialOffers; + } + + /** + * Get if the Coupon effect cancel other Coupon effects + * + * @return boolean + */ + public function getIsCumulative() + { + return $this->isCumulative; + } + + /** + * Get if Coupon is enabled or not + * + * @return boolean + */ + public function getIsEnabled() + { + return $this->isEnabled; + } + + /** + * @return boolean + */ + public function getIsRemovingPostage() + { + return $this->isRemovingPostage; + } + /** * Set Coupon Model * diff --git a/core/lib/Thelia/Core/Event/UpdateFilePositionEvent.php b/core/lib/Thelia/Core/Event/UpdateFilePositionEvent.php old mode 100644 new mode 100755 diff --git a/core/lib/Thelia/Core/Event/UpdateSeoEvent.php b/core/lib/Thelia/Core/Event/UpdateSeoEvent.php old mode 100644 new mode 100755 diff --git a/core/lib/Thelia/Core/Security/Exception/ResourceException.php b/core/lib/Thelia/Core/Security/Exception/ResourceException.php old mode 100644 new mode 100755 diff --git a/core/lib/Thelia/Core/Template/Loop/Coupon.php b/core/lib/Thelia/Core/Template/Loop/Coupon.php index e211103da..85a221a29 100755 --- a/core/lib/Thelia/Core/Template/Loop/Coupon.php +++ b/core/lib/Thelia/Core/Template/Loop/Coupon.php @@ -40,10 +40,6 @@ use Thelia\Model\CouponQuery; use Thelia\Type; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Coupon Loop * * @package Thelia\Core\Template\Loop @@ -111,7 +107,7 @@ class Coupon extends BaseI18nLoop implements PropelSearchLoopInterface $coupon->getTitle(), $coupon->getShortDescription(), $coupon->getDescription(), - $coupon->getAmount(), + $coupon->getEffects(), $coupon->getIsCumulative(), $coupon->getIsRemovingPostage(), $coupon->getIsAvailableOnSpecialOffers(), diff --git a/core/lib/Thelia/Coupon/BaseFacade.php b/core/lib/Thelia/Coupon/BaseFacade.php index 9d28be69f..3df562333 100644 --- a/core/lib/Thelia/Coupon/BaseFacade.php +++ b/core/lib/Thelia/Coupon/BaseFacade.php @@ -36,10 +36,6 @@ use Thelia\Model\Currency; use Thelia\Model\CurrencyQuery; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Allow to assist in getting relevant data on the current application state * * @package Coupon diff --git a/core/lib/Thelia/Coupon/CouponFactory.php b/core/lib/Thelia/Coupon/CouponFactory.php index 214dd0d9c..b157922a2 100644 --- a/core/lib/Thelia/Coupon/CouponFactory.php +++ b/core/lib/Thelia/Coupon/CouponFactory.php @@ -31,10 +31,6 @@ use Thelia\Exception\InvalidConditionException; use Thelia\Model\Coupon; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Generate a CouponInterface * * @package Coupon @@ -116,7 +112,7 @@ class CouponFactory $model->getTitle(), $model->getShortDescription(), $model->getDescription(), - $model->getAmount(), + $model->getEffects(), $isCumulative, $isRemovingPostage, $model->getIsAvailableOnSpecialOffers(), diff --git a/core/lib/Thelia/Coupon/CouponManager.php b/core/lib/Thelia/Coupon/CouponManager.php index c4eff7888..c11a7e896 100644 --- a/core/lib/Thelia/Coupon/CouponManager.php +++ b/core/lib/Thelia/Coupon/CouponManager.php @@ -29,10 +29,6 @@ use Thelia\Coupon\Type\CouponInterface; use Thelia\Model\Coupon; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Manage how Coupons could interact with a Checkout * * @package Coupon diff --git a/core/lib/Thelia/Coupon/FacadeInterface.php b/core/lib/Thelia/Coupon/FacadeInterface.php index 4c264430c..2b78a49d6 100644 --- a/core/lib/Thelia/Coupon/FacadeInterface.php +++ b/core/lib/Thelia/Coupon/FacadeInterface.php @@ -31,10 +31,6 @@ use Thelia\Core\HttpFoundation\Request; use Thelia\Model\Coupon; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Allow to assist in getting relevant data on the current application state * * @package Coupon @@ -167,4 +163,11 @@ interface FacadeInterface */ public function getAvailableCurrencies(); + /** + * Return the event dispatcher, + * + * @return \Symfony\Component\EventDispatcher\EventDispatcher + */ + public function getDispatcher(); + } \ No newline at end of file diff --git a/core/lib/Thelia/Coupon/Type/CouponAbstract.php b/core/lib/Thelia/Coupon/Type/CouponAbstract.php index 98c258c27..5e83afb85 100644 --- a/core/lib/Thelia/Coupon/Type/CouponAbstract.php +++ b/core/lib/Thelia/Coupon/Type/CouponAbstract.php @@ -32,10 +32,6 @@ use Thelia\Condition\ConditionOrganizerInterface; use Thelia\Exception\InvalidConditionException; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Assist in writing a CouponInterface * * @package Coupon @@ -44,6 +40,13 @@ use Thelia\Exception\InvalidConditionException; */ abstract class CouponAbstract implements CouponInterface { + const INPUT_EXTENDED__NAME = 'thelia_coupon_creation_extended'; + + const INPUT_AMOUNT_NAME = 'amount'; + + /** @var array Extended Inputs to manage */ + protected $extendedInputs = array(); + /** @var FacadeInterface Provide necessary value from Thelia */ protected $facade = null; @@ -66,6 +69,9 @@ abstract class CouponAbstract implements CouponInterface /** @var float Amount that will be removed from the Checkout (Coupon Effect) */ protected $amount = 0; + /** @var array Get the Coupon effects params */ + protected $effects = array('amount' => 0); + /** @var string Coupon code (ex: XMAS) */ protected $code = null; @@ -127,6 +133,60 @@ abstract class CouponAbstract implements CouponInterface return $this; } + /** + * Set Coupon + * + * @param FacadeInterface $facade Provides necessary value from Thelia + * @param string $code Coupon code (ex: XMAS) + * @param string $title Coupon title (ex: Coupon for XMAS) + * @param string $shortDescription Coupon short description + * @param string $description Coupon description + * @param array $effects Coupon effects params + * @param bool $isCumulative If Coupon is cumulative + * @param bool $isRemovingPostage If Coupon is removing postage + * @param bool $isAvailableOnSpecialOffers If available on Product already + * on special offer price + * @param bool $isEnabled False if Coupon is disabled by admin + * @param int $maxUsage How many usage left + * @param \Datetime $expirationDate When the Code is expiring + * + * @return $this + */ + public function set( + FacadeInterface $facade, + $code, + $title, + $shortDescription, + $description, + array $effects, + $isCumulative, + $isRemovingPostage, + $isAvailableOnSpecialOffers, + $isEnabled, + $maxUsage, + \DateTime $expirationDate + ) + { + $this->code = $code; + $this->title = $title; + $this->shortDescription = $shortDescription; + $this->description = $description; + + $this->isCumulative = $isCumulative; + $this->isRemovingPostage = $isRemovingPostage; + + $this->isAvailableOnSpecialOffers = $isAvailableOnSpecialOffers; + $this->isEnabled = $isEnabled; + $this->maxUsage = $maxUsage; + $this->expirationDate = $expirationDate; + $this->facade = $facade; + + $this->effects = $effects; + $this->amount = $effects[self::INPUT_AMOUNT_NAME]; + + return $this; + } + /** * Return Coupon code (ex: XMAS) * @@ -307,4 +367,36 @@ abstract class CouponAbstract implements CouponInterface return $this->conditionEvaluator->isMatching($this->conditions); } + /** + * Draw the input displayed in the BackOffice + * allowing Admin to set its Coupon effect + * + * @return string HTML string + */ + public function drawBackOfficeInputs() + { + $label = $this->getInputName(); + $value = $this->amount; + + $html = ' +
+ + +
+ '; + + return $html; + } + + /** + * Get all extended inputs name to manage + * + * @return mixed + */ + public function getExtendedInputs() + { + return $this->extendedInputs; + } + + } diff --git a/core/lib/Thelia/Coupon/Type/CouponInterface.php b/core/lib/Thelia/Coupon/Type/CouponInterface.php index 63c7e4267..a45d6cbab 100644 --- a/core/lib/Thelia/Coupon/Type/CouponInterface.php +++ b/core/lib/Thelia/Coupon/Type/CouponInterface.php @@ -27,10 +27,6 @@ use Thelia\Condition\ConditionCollection; use Thelia\Coupon\FacadeInterface; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Represents a Coupon ready to be processed in a Checkout process * * @package Coupon @@ -46,6 +42,13 @@ interface CouponInterface */ public function getName(); + /** + * Get I18n amount input name + * + * @return string + */ + public function getInputName(); + /** * Get I18n tooltip * @@ -68,7 +71,7 @@ interface CouponInterface * @param string $title Coupon title (ex: Coupon for XMAS) * @param string $shortDescription Coupon short description * @param string $description Coupon description - * @param float $effect Coupon amount/percentage to deduce + * @param array $effects Coupon effects params * @param bool $isCumulative If Coupon is cumulative * @param bool $isRemovingPostage If Coupon is removing postage * @param bool $isAvailableOnSpecialOffers If available on Product already @@ -83,7 +86,7 @@ interface CouponInterface $title, $shortDescription, $description, - $effect, + array $effects, $isCumulative, $isRemovingPostage, $isAvailableOnSpecialOffers, @@ -215,4 +218,19 @@ interface CouponInterface */ public function isMatching(); + /** + * Draw the input displayed in the BackOffice + * allowing Admin to set its Coupon effect + * + * @return string HTML string + */ + public function drawBackOfficeInputs(); + + /** + * Get all extended inputs name to manage + * + * @return mixed + */ + public function getExtendedInputs(); + } diff --git a/core/lib/Thelia/Coupon/Type/RemoveXAmount.php b/core/lib/Thelia/Coupon/Type/RemoveXAmount.php index 1609ffc3e..5de809904 100644 --- a/core/lib/Thelia/Coupon/Type/RemoveXAmount.php +++ b/core/lib/Thelia/Coupon/Type/RemoveXAmount.php @@ -27,10 +27,6 @@ use Thelia\Coupon\FacadeInterface; use Thelia\Coupon\Type\CouponAbstract; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Allow to remove an amount from the checkout total * * @package Coupon @@ -42,55 +38,6 @@ class RemoveXAmount extends CouponAbstract /** @var string Service Id */ protected $serviceId = 'thelia.coupon.type.remove_x_amount'; - /** - * Set Coupon - * - * @param FacadeInterface $facade Provides necessary value from Thelia - * @param string $code Coupon code (ex: XMAS) - * @param string $title Coupon title (ex: Coupon for XMAS) - * @param string $shortDescription Coupon short description - * @param string $description Coupon description - * @param float $amount Coupon amount to deduce - * @param bool $isCumulative If Coupon is cumulative - * @param bool $isRemovingPostage If Coupon is removing postage - * @param bool $isAvailableOnSpecialOffers If available on Product already - * on special offer price - * @param bool $isEnabled False if Coupon is disabled by admin - * @param int $maxUsage How many usage left - * @param \Datetime $expirationDate When the Code is expiring - */ - public function set( - FacadeInterface $facade, - $code, - $title, - $shortDescription, - $description, - $amount, - $isCumulative, - $isRemovingPostage, - $isAvailableOnSpecialOffers, - $isEnabled, - $maxUsage, - \DateTime $expirationDate - ) - { - $this->code = $code; - $this->title = $title; - $this->shortDescription = $shortDescription; - $this->description = $description; - - $this->isCumulative = $isCumulative; - $this->isRemovingPostage = $isRemovingPostage; - - $this->amount = $amount; - - $this->isAvailableOnSpecialOffers = $isAvailableOnSpecialOffers; - $this->isEnabled = $isEnabled; - $this->maxUsage = $maxUsage; - $this->expirationDate = $expirationDate; - $this->facade = $facade; - } - /** * Get I18n name * @@ -100,7 +47,19 @@ class RemoveXAmount extends CouponAbstract { return $this->facade ->getTranslator() - ->trans('Remove X amount to total cart', array(), 'constraint'); + ->trans('Remove X amount to total cart', array(), 'coupon'); + } + + /** + * Get I18n amount input name + * + * @return string + */ + public function getInputName() + { + return $this->facade + ->getTranslator() + ->trans('Amount removed from the cart', array(), 'coupon'); } /** @@ -115,7 +74,7 @@ class RemoveXAmount extends CouponAbstract ->trans( 'This coupon will remove the entered amount to the customer total checkout. If the discount is superior to the total checkout price the customer will only pay the postage. Unless if the coupon is set to remove postage too.', array(), - 'constraint' + 'coupon' ); return $toolTip; diff --git a/core/lib/Thelia/Coupon/Type/RemoveXPercent.php b/core/lib/Thelia/Coupon/Type/RemoveXPercent.php index 931ddad67..7d83de333 100644 --- a/core/lib/Thelia/Coupon/Type/RemoveXPercent.php +++ b/core/lib/Thelia/Coupon/Type/RemoveXPercent.php @@ -28,20 +28,24 @@ use Thelia\Coupon\Type\CouponAbstract; use Thelia\Exception\MissingFacadeException; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * @package Coupon * @author Guillaume MOREL * */ class RemoveXPercent extends CouponAbstract { + const INPUT_PERCENTAGE_NAME = 'percentage'; + /** @var string Service Id */ protected $serviceId = 'thelia.coupon.type.remove_x_percent'; - protected $percent = 0; + /** @var float Percentage removed from the Cart */ + protected $percentage = 0; + + /** @var array Extended Inputs to manage */ + protected $extendedInputs = array( + self::INPUT_PERCENTAGE_NAME + ); /** * Set Coupon @@ -51,7 +55,7 @@ class RemoveXPercent extends CouponAbstract * @param string $title Coupon title (ex: Coupon for XMAS) * @param string $shortDescription Coupon short description * @param string $description Coupon description - * @param float $percent Coupon percentage to deduce + * @param array $effects Coupon effects params * @param bool $isCumulative If Coupon is cumulative * @param bool $isRemovingPostage If Coupon is removing postage * @param bool $isAvailableOnSpecialOffers If available on Product already @@ -59,6 +63,8 @@ class RemoveXPercent extends CouponAbstract * @param bool $isEnabled False if Coupon is disabled by admin * @param int $maxUsage How many usage left * @param \Datetime $expirationDate When the Code is expiring + * + * @return $this */ public function set( FacadeInterface $facade, @@ -66,29 +72,21 @@ class RemoveXPercent extends CouponAbstract $title, $shortDescription, $description, - $percent, + array $effects, $isCumulative, $isRemovingPostage, $isAvailableOnSpecialOffers, $isEnabled, $maxUsage, - \DateTime $expirationDate) + \DateTime $expirationDate + ) { - $this->code = $code; - $this->title = $title; - $this->shortDescription = $shortDescription; - $this->description = $description; + parent::set( + $facade, $code, $title, $shortDescription, $description, $effects, $isCumulative, $isRemovingPostage, $isAvailableOnSpecialOffers, $isEnabled, $maxUsage, $expirationDate + ); + $this->percentage = $effects[self::INPUT_PERCENTAGE_NAME]; - $this->isCumulative = $isCumulative; - $this->isRemovingPostage = $isRemovingPostage; - - $this->percent = $percent; - - $this->isAvailableOnSpecialOffers = $isAvailableOnSpecialOffers; - $this->isEnabled = $isEnabled; - $this->maxUsage = $maxUsage; - $this->expirationDate = $expirationDate; - $this->facade = $facade; + return $this; } /** @@ -101,7 +99,7 @@ class RemoveXPercent extends CouponAbstract */ public function exec() { - if ($this->percent >= 100) { + if ($this->percentage >= 100) { throw new \InvalidArgumentException( 'Percentage must be inferior to 100' ); @@ -109,7 +107,7 @@ class RemoveXPercent extends CouponAbstract $basePrice = $this->facade->getCartTotalPrice(); - return $basePrice * (( $this->percent ) / 100); + return $basePrice * (( $this->percentage ) / 100); } @@ -122,7 +120,19 @@ class RemoveXPercent extends CouponAbstract { return $this->facade ->getTranslator() - ->trans('Remove X percent to total cart', array(), 'constraint'); + ->trans('Remove X percent to total cart', array(), 'coupon'); + } + + /** + * Get I18n amount input name + * + * @return string + */ + public function getInputName() + { + return $this->facade + ->getTranslator() + ->trans('Percentage removed from the cart', array(), 'coupon'); } /** @@ -137,10 +147,31 @@ class RemoveXPercent extends CouponAbstract ->trans( 'This coupon will remove the entered percentage to the customer total checkout. If the discount is superior to the total checkout price the customer will only pay the postage. Unless if the coupon is set to remove postage too.', array(), - 'constraint' + 'coupon' ); return $toolTip; } + /** + * Draw the input displayed in the BackOffice + * allowing Admin to set its Coupon effect + * + * @return string HTML string + */ + public function drawBackOfficeInputs() + { + $labelPercentage = $this->getInputName(); + + $html = ' + +
+ + +
+ '; + + return $html; + } + } \ No newline at end of file diff --git a/core/lib/Thelia/Exception/CouponExpiredException.php b/core/lib/Thelia/Exception/CouponExpiredException.php index 271927cb4..3aa912549 100644 --- a/core/lib/Thelia/Exception/CouponExpiredException.php +++ b/core/lib/Thelia/Exception/CouponExpiredException.php @@ -26,10 +26,6 @@ namespace Thelia\Exception; use Thelia\Log\Tlog; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Thrown when an Expired Coupon is tried * * @package Coupon diff --git a/core/lib/Thelia/Exception/InvalidConditionException.php b/core/lib/Thelia/Exception/InvalidConditionException.php index dbc3315c8..89d01a7be 100644 --- a/core/lib/Thelia/Exception/InvalidConditionException.php +++ b/core/lib/Thelia/Exception/InvalidConditionException.php @@ -26,10 +26,6 @@ namespace Thelia\Exception; use Thelia\Log\Tlog; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Thrown when a Condition is badly implemented * * @package Condition diff --git a/core/lib/Thelia/Exception/InvalidConditionOperatorException.php b/core/lib/Thelia/Exception/InvalidConditionOperatorException.php index eaef6b9fc..b336aac9a 100644 --- a/core/lib/Thelia/Exception/InvalidConditionOperatorException.php +++ b/core/lib/Thelia/Exception/InvalidConditionOperatorException.php @@ -26,10 +26,6 @@ namespace Thelia\Exception; use Thelia\Log\Tlog; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Thrown when a Condition receive an invalid Operator * * @package Condition diff --git a/core/lib/Thelia/Exception/InvalidConditionValueException.php b/core/lib/Thelia/Exception/InvalidConditionValueException.php index 46e3d3628..65f94ae3a 100644 --- a/core/lib/Thelia/Exception/InvalidConditionValueException.php +++ b/core/lib/Thelia/Exception/InvalidConditionValueException.php @@ -26,10 +26,6 @@ namespace Thelia\Exception; use Thelia\Log\Tlog; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Thrown when a Condition receives an invalid Parameter * * @package Condition diff --git a/core/lib/Thelia/Exception/MissingFacadeException.php b/core/lib/Thelia/Exception/MissingFacadeException.php index 5616e9575..e717b1457 100644 --- a/core/lib/Thelia/Exception/MissingFacadeException.php +++ b/core/lib/Thelia/Exception/MissingFacadeException.php @@ -26,10 +26,6 @@ namespace Thelia\Exception; use Thelia\Log\Tlog; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Thrown when the Facade is not set * * @package Coupon diff --git a/core/lib/Thelia/Exception/NotImplementedException.php b/core/lib/Thelia/Exception/NotImplementedException.php index 1240ea82b..96b2117c8 100644 --- a/core/lib/Thelia/Exception/NotImplementedException.php +++ b/core/lib/Thelia/Exception/NotImplementedException.php @@ -26,10 +26,6 @@ namespace Thelia\Exception; use Symfony\Component\DependencyInjection\Exception\BadMethodCallException; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Thrown when an Abstract method has not been implemented * * @package Exception diff --git a/core/lib/Thelia/Form/CouponCreationForm.php b/core/lib/Thelia/Form/CouponCreationForm.php index 9a38b0d83..9742f8fa0 100755 --- a/core/lib/Thelia/Form/CouponCreationForm.php +++ b/core/lib/Thelia/Form/CouponCreationForm.php @@ -29,10 +29,6 @@ use Symfony\Component\Validator\Constraints\NotBlank; use Symfony\Component\Validator\Constraints\NotEqualTo; /** - * Created by JetBrains PhpStorm. - * Date: 8/29/13 - * Time: 3:45 PM - * * Allow to build a form Coupon * * @package Coupon diff --git a/core/lib/Thelia/Form/SeoFieldsTrait.php b/core/lib/Thelia/Form/SeoFieldsTrait.php old mode 100644 new mode 100755 diff --git a/core/lib/Thelia/Form/SeoForm.php b/core/lib/Thelia/Form/SeoForm.php old mode 100644 new mode 100755 diff --git a/core/lib/Thelia/Model/Base/Coupon.php b/core/lib/Thelia/Model/Base/Coupon.php index 012b97313..93dd13a3e 100644 --- a/core/lib/Thelia/Model/Base/Coupon.php +++ b/core/lib/Thelia/Model/Base/Coupon.php @@ -79,10 +79,10 @@ abstract class Coupon implements ActiveRecordInterface protected $type; /** - * The value for the amount field. - * @var double + * The value for the serialized_effects field. + * @var string */ - protected $amount; + protected $serialized_effects; /** * The value for the is_enabled field. @@ -510,14 +510,14 @@ abstract class Coupon implements ActiveRecordInterface } /** - * Get the [amount] column value. + * Get the [serialized_effects] column value. * - * @return double + * @return string */ - public function getAmount() + public function getSerializedEffects() { - return $this->amount; + return $this->serialized_effects; } /** @@ -732,25 +732,25 @@ abstract class Coupon implements ActiveRecordInterface } // setType() /** - * Set the value of [amount] column. + * Set the value of [serialized_effects] column. * - * @param double $v new value + * @param string $v new value * @return \Thelia\Model\Coupon The current object (for fluent API support) */ - public function setAmount($v) + public function setSerializedEffects($v) { if ($v !== null) { - $v = (double) $v; + $v = (string) $v; } - if ($this->amount !== $v) { - $this->amount = $v; - $this->modifiedColumns[] = CouponTableMap::AMOUNT; + if ($this->serialized_effects !== $v) { + $this->serialized_effects = $v; + $this->modifiedColumns[] = CouponTableMap::SERIALIZED_EFFECTS; } return $this; - } // setAmount() + } // setSerializedEffects() /** * Sets the value of the [is_enabled] column. @@ -1073,8 +1073,8 @@ abstract class Coupon implements ActiveRecordInterface $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : CouponTableMap::translateFieldName('Type', TableMap::TYPE_PHPNAME, $indexType)]; $this->type = (null !== $col) ? (string) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : CouponTableMap::translateFieldName('Amount', TableMap::TYPE_PHPNAME, $indexType)]; - $this->amount = (null !== $col) ? (double) $col : null; + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : CouponTableMap::translateFieldName('SerializedEffects', TableMap::TYPE_PHPNAME, $indexType)]; + $this->serialized_effects = (null !== $col) ? (string) $col : null; $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : CouponTableMap::translateFieldName('IsEnabled', TableMap::TYPE_PHPNAME, $indexType)]; $this->is_enabled = (null !== $col) ? (boolean) $col : null; @@ -1401,8 +1401,8 @@ abstract class Coupon implements ActiveRecordInterface if ($this->isColumnModified(CouponTableMap::TYPE)) { $modifiedColumns[':p' . $index++] = 'TYPE'; } - if ($this->isColumnModified(CouponTableMap::AMOUNT)) { - $modifiedColumns[':p' . $index++] = 'AMOUNT'; + if ($this->isColumnModified(CouponTableMap::SERIALIZED_EFFECTS)) { + $modifiedColumns[':p' . $index++] = 'SERIALIZED_EFFECTS'; } if ($this->isColumnModified(CouponTableMap::IS_ENABLED)) { $modifiedColumns[':p' . $index++] = 'IS_ENABLED'; @@ -1457,8 +1457,8 @@ abstract class Coupon implements ActiveRecordInterface case 'TYPE': $stmt->bindValue($identifier, $this->type, PDO::PARAM_STR); break; - case 'AMOUNT': - $stmt->bindValue($identifier, $this->amount, PDO::PARAM_STR); + case 'SERIALIZED_EFFECTS': + $stmt->bindValue($identifier, $this->serialized_effects, PDO::PARAM_STR); break; case 'IS_ENABLED': $stmt->bindValue($identifier, (int) $this->is_enabled, PDO::PARAM_INT); @@ -1565,7 +1565,7 @@ abstract class Coupon implements ActiveRecordInterface return $this->getType(); break; case 3: - return $this->getAmount(); + return $this->getSerializedEffects(); break; case 4: return $this->getIsEnabled(); @@ -1632,7 +1632,7 @@ abstract class Coupon implements ActiveRecordInterface $keys[0] => $this->getId(), $keys[1] => $this->getCode(), $keys[2] => $this->getType(), - $keys[3] => $this->getAmount(), + $keys[3] => $this->getSerializedEffects(), $keys[4] => $this->getIsEnabled(), $keys[5] => $this->getExpirationDate(), $keys[6] => $this->getMaxUsage(), @@ -1701,7 +1701,7 @@ abstract class Coupon implements ActiveRecordInterface $this->setType($value); break; case 3: - $this->setAmount($value); + $this->setSerializedEffects($value); break; case 4: $this->setIsEnabled($value); @@ -1763,7 +1763,7 @@ abstract class Coupon implements ActiveRecordInterface if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); if (array_key_exists($keys[1], $arr)) $this->setCode($arr[$keys[1]]); if (array_key_exists($keys[2], $arr)) $this->setType($arr[$keys[2]]); - if (array_key_exists($keys[3], $arr)) $this->setAmount($arr[$keys[3]]); + if (array_key_exists($keys[3], $arr)) $this->setSerializedEffects($arr[$keys[3]]); if (array_key_exists($keys[4], $arr)) $this->setIsEnabled($arr[$keys[4]]); if (array_key_exists($keys[5], $arr)) $this->setExpirationDate($arr[$keys[5]]); if (array_key_exists($keys[6], $arr)) $this->setMaxUsage($arr[$keys[6]]); @@ -1789,7 +1789,7 @@ abstract class Coupon implements ActiveRecordInterface if ($this->isColumnModified(CouponTableMap::ID)) $criteria->add(CouponTableMap::ID, $this->id); if ($this->isColumnModified(CouponTableMap::CODE)) $criteria->add(CouponTableMap::CODE, $this->code); if ($this->isColumnModified(CouponTableMap::TYPE)) $criteria->add(CouponTableMap::TYPE, $this->type); - if ($this->isColumnModified(CouponTableMap::AMOUNT)) $criteria->add(CouponTableMap::AMOUNT, $this->amount); + if ($this->isColumnModified(CouponTableMap::SERIALIZED_EFFECTS)) $criteria->add(CouponTableMap::SERIALIZED_EFFECTS, $this->serialized_effects); if ($this->isColumnModified(CouponTableMap::IS_ENABLED)) $criteria->add(CouponTableMap::IS_ENABLED, $this->is_enabled); if ($this->isColumnModified(CouponTableMap::EXPIRATION_DATE)) $criteria->add(CouponTableMap::EXPIRATION_DATE, $this->expiration_date); if ($this->isColumnModified(CouponTableMap::MAX_USAGE)) $criteria->add(CouponTableMap::MAX_USAGE, $this->max_usage); @@ -1866,7 +1866,7 @@ abstract class Coupon implements ActiveRecordInterface { $copyObj->setCode($this->getCode()); $copyObj->setType($this->getType()); - $copyObj->setAmount($this->getAmount()); + $copyObj->setSerializedEffects($this->getSerializedEffects()); $copyObj->setIsEnabled($this->getIsEnabled()); $copyObj->setExpirationDate($this->getExpirationDate()); $copyObj->setMaxUsage($this->getMaxUsage()); @@ -2399,7 +2399,7 @@ abstract class Coupon implements ActiveRecordInterface $this->id = null; $this->code = null; $this->type = null; - $this->amount = null; + $this->serialized_effects = null; $this->is_enabled = null; $this->expiration_date = null; $this->max_usage = null; @@ -2703,7 +2703,7 @@ abstract class Coupon implements ActiveRecordInterface $version->setId($this->getId()); $version->setCode($this->getCode()); $version->setType($this->getType()); - $version->setAmount($this->getAmount()); + $version->setSerializedEffects($this->getSerializedEffects()); $version->setIsEnabled($this->getIsEnabled()); $version->setExpirationDate($this->getExpirationDate()); $version->setMaxUsage($this->getMaxUsage()); @@ -2755,7 +2755,7 @@ abstract class Coupon implements ActiveRecordInterface $this->setId($version->getId()); $this->setCode($version->getCode()); $this->setType($version->getType()); - $this->setAmount($version->getAmount()); + $this->setSerializedEffects($version->getSerializedEffects()); $this->setIsEnabled($version->getIsEnabled()); $this->setExpirationDate($version->getExpirationDate()); $this->setMaxUsage($version->getMaxUsage()); diff --git a/core/lib/Thelia/Model/Base/CouponQuery.php b/core/lib/Thelia/Model/Base/CouponQuery.php index d480f06c4..164609b6f 100644 --- a/core/lib/Thelia/Model/Base/CouponQuery.php +++ b/core/lib/Thelia/Model/Base/CouponQuery.php @@ -25,7 +25,7 @@ use Thelia\Model\Map\CouponTableMap; * @method ChildCouponQuery orderById($order = Criteria::ASC) Order by the id column * @method ChildCouponQuery orderByCode($order = Criteria::ASC) Order by the code column * @method ChildCouponQuery orderByType($order = Criteria::ASC) Order by the type column - * @method ChildCouponQuery orderByAmount($order = Criteria::ASC) Order by the amount column + * @method ChildCouponQuery orderBySerializedEffects($order = Criteria::ASC) Order by the serialized_effects column * @method ChildCouponQuery orderByIsEnabled($order = Criteria::ASC) Order by the is_enabled column * @method ChildCouponQuery orderByExpirationDate($order = Criteria::ASC) Order by the expiration_date column * @method ChildCouponQuery orderByMaxUsage($order = Criteria::ASC) Order by the max_usage column @@ -41,7 +41,7 @@ use Thelia\Model\Map\CouponTableMap; * @method ChildCouponQuery groupById() Group by the id column * @method ChildCouponQuery groupByCode() Group by the code column * @method ChildCouponQuery groupByType() Group by the type column - * @method ChildCouponQuery groupByAmount() Group by the amount column + * @method ChildCouponQuery groupBySerializedEffects() Group by the serialized_effects column * @method ChildCouponQuery groupByIsEnabled() Group by the is_enabled column * @method ChildCouponQuery groupByExpirationDate() Group by the expiration_date column * @method ChildCouponQuery groupByMaxUsage() Group by the max_usage column @@ -72,7 +72,7 @@ use Thelia\Model\Map\CouponTableMap; * @method ChildCoupon findOneById(int $id) Return the first ChildCoupon filtered by the id column * @method ChildCoupon findOneByCode(string $code) Return the first ChildCoupon filtered by the code column * @method ChildCoupon findOneByType(string $type) Return the first ChildCoupon filtered by the type column - * @method ChildCoupon findOneByAmount(double $amount) Return the first ChildCoupon filtered by the amount column + * @method ChildCoupon findOneBySerializedEffects(string $serialized_effects) Return the first ChildCoupon filtered by the serialized_effects column * @method ChildCoupon findOneByIsEnabled(boolean $is_enabled) Return the first ChildCoupon filtered by the is_enabled column * @method ChildCoupon findOneByExpirationDate(string $expiration_date) Return the first ChildCoupon filtered by the expiration_date column * @method ChildCoupon findOneByMaxUsage(int $max_usage) Return the first ChildCoupon filtered by the max_usage column @@ -88,7 +88,7 @@ use Thelia\Model\Map\CouponTableMap; * @method array findById(int $id) Return ChildCoupon objects filtered by the id column * @method array findByCode(string $code) Return ChildCoupon objects filtered by the code column * @method array findByType(string $type) Return ChildCoupon objects filtered by the type column - * @method array findByAmount(double $amount) Return ChildCoupon objects filtered by the amount column + * @method array findBySerializedEffects(string $serialized_effects) Return ChildCoupon objects filtered by the serialized_effects column * @method array findByIsEnabled(boolean $is_enabled) Return ChildCoupon objects filtered by the is_enabled column * @method array findByExpirationDate(string $expiration_date) Return ChildCoupon objects filtered by the expiration_date column * @method array findByMaxUsage(int $max_usage) Return ChildCoupon objects filtered by the max_usage column @@ -195,7 +195,7 @@ abstract class CouponQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT ID, CODE, TYPE, AMOUNT, IS_ENABLED, EXPIRATION_DATE, MAX_USAGE, IS_CUMULATIVE, IS_REMOVING_POSTAGE, IS_AVAILABLE_ON_SPECIAL_OFFERS, IS_USED, SERIALIZED_CONDITIONS, CREATED_AT, UPDATED_AT, VERSION FROM coupon WHERE ID = :p0'; + $sql = 'SELECT ID, CODE, TYPE, SERIALIZED_EFFECTS, IS_ENABLED, EXPIRATION_DATE, MAX_USAGE, IS_CUMULATIVE, IS_REMOVING_POSTAGE, IS_AVAILABLE_ON_SPECIAL_OFFERS, IS_USED, SERIALIZED_CONDITIONS, CREATED_AT, UPDATED_AT, VERSION FROM coupon WHERE ID = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); @@ -384,44 +384,32 @@ abstract class CouponQuery extends ModelCriteria } /** - * Filter the query on the amount column + * Filter the query on the serialized_effects column * * Example usage: * - * $query->filterByAmount(1234); // WHERE amount = 1234 - * $query->filterByAmount(array(12, 34)); // WHERE amount IN (12, 34) - * $query->filterByAmount(array('min' => 12)); // WHERE amount > 12 + * $query->filterBySerializedEffects('fooValue'); // WHERE serialized_effects = 'fooValue' + * $query->filterBySerializedEffects('%fooValue%'); // WHERE serialized_effects LIKE '%fooValue%' * * - * @param mixed $amount The value to use as filter. - * Use scalar values for equality. - * Use array values for in_array() equivalent. - * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $serializedEffects The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildCouponQuery The current query, for fluid interface */ - public function filterByAmount($amount = null, $comparison = null) + public function filterBySerializedEffects($serializedEffects = null, $comparison = null) { - if (is_array($amount)) { - $useMinMax = false; - if (isset($amount['min'])) { - $this->addUsingAlias(CouponTableMap::AMOUNT, $amount['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($amount['max'])) { - $this->addUsingAlias(CouponTableMap::AMOUNT, $amount['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { + if (null === $comparison) { + if (is_array($serializedEffects)) { $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $serializedEffects)) { + $serializedEffects = str_replace('*', '%', $serializedEffects); + $comparison = Criteria::LIKE; } } - return $this->addUsingAlias(CouponTableMap::AMOUNT, $amount, $comparison); + return $this->addUsingAlias(CouponTableMap::SERIALIZED_EFFECTS, $serializedEffects, $comparison); } /** diff --git a/core/lib/Thelia/Model/Base/CouponVersion.php b/core/lib/Thelia/Model/Base/CouponVersion.php index 67c077cfa..fa615af46 100644 --- a/core/lib/Thelia/Model/Base/CouponVersion.php +++ b/core/lib/Thelia/Model/Base/CouponVersion.php @@ -74,10 +74,10 @@ abstract class CouponVersion implements ActiveRecordInterface protected $type; /** - * The value for the amount field. - * @var double + * The value for the serialized_effects field. + * @var string */ - protected $amount; + protected $serialized_effects; /** * The value for the is_enabled field. @@ -464,14 +464,14 @@ abstract class CouponVersion implements ActiveRecordInterface } /** - * Get the [amount] column value. + * Get the [serialized_effects] column value. * - * @return double + * @return string */ - public function getAmount() + public function getSerializedEffects() { - return $this->amount; + return $this->serialized_effects; } /** @@ -690,25 +690,25 @@ abstract class CouponVersion implements ActiveRecordInterface } // setType() /** - * Set the value of [amount] column. + * Set the value of [serialized_effects] column. * - * @param double $v new value + * @param string $v new value * @return \Thelia\Model\CouponVersion The current object (for fluent API support) */ - public function setAmount($v) + public function setSerializedEffects($v) { if ($v !== null) { - $v = (double) $v; + $v = (string) $v; } - if ($this->amount !== $v) { - $this->amount = $v; - $this->modifiedColumns[] = CouponVersionTableMap::AMOUNT; + if ($this->serialized_effects !== $v) { + $this->serialized_effects = $v; + $this->modifiedColumns[] = CouponVersionTableMap::SERIALIZED_EFFECTS; } return $this; - } // setAmount() + } // setSerializedEffects() /** * Sets the value of the [is_enabled] column. @@ -1031,8 +1031,8 @@ abstract class CouponVersion implements ActiveRecordInterface $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : CouponVersionTableMap::translateFieldName('Type', TableMap::TYPE_PHPNAME, $indexType)]; $this->type = (null !== $col) ? (string) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : CouponVersionTableMap::translateFieldName('Amount', TableMap::TYPE_PHPNAME, $indexType)]; - $this->amount = (null !== $col) ? (double) $col : null; + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : CouponVersionTableMap::translateFieldName('SerializedEffects', TableMap::TYPE_PHPNAME, $indexType)]; + $this->serialized_effects = (null !== $col) ? (string) $col : null; $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : CouponVersionTableMap::translateFieldName('IsEnabled', TableMap::TYPE_PHPNAME, $indexType)]; $this->is_enabled = (null !== $col) ? (boolean) $col : null; @@ -1313,8 +1313,8 @@ abstract class CouponVersion implements ActiveRecordInterface if ($this->isColumnModified(CouponVersionTableMap::TYPE)) { $modifiedColumns[':p' . $index++] = 'TYPE'; } - if ($this->isColumnModified(CouponVersionTableMap::AMOUNT)) { - $modifiedColumns[':p' . $index++] = 'AMOUNT'; + if ($this->isColumnModified(CouponVersionTableMap::SERIALIZED_EFFECTS)) { + $modifiedColumns[':p' . $index++] = 'SERIALIZED_EFFECTS'; } if ($this->isColumnModified(CouponVersionTableMap::IS_ENABLED)) { $modifiedColumns[':p' . $index++] = 'IS_ENABLED'; @@ -1369,8 +1369,8 @@ abstract class CouponVersion implements ActiveRecordInterface case 'TYPE': $stmt->bindValue($identifier, $this->type, PDO::PARAM_STR); break; - case 'AMOUNT': - $stmt->bindValue($identifier, $this->amount, PDO::PARAM_STR); + case 'SERIALIZED_EFFECTS': + $stmt->bindValue($identifier, $this->serialized_effects, PDO::PARAM_STR); break; case 'IS_ENABLED': $stmt->bindValue($identifier, (int) $this->is_enabled, PDO::PARAM_INT); @@ -1470,7 +1470,7 @@ abstract class CouponVersion implements ActiveRecordInterface return $this->getType(); break; case 3: - return $this->getAmount(); + return $this->getSerializedEffects(); break; case 4: return $this->getIsEnabled(); @@ -1537,7 +1537,7 @@ abstract class CouponVersion implements ActiveRecordInterface $keys[0] => $this->getId(), $keys[1] => $this->getCode(), $keys[2] => $this->getType(), - $keys[3] => $this->getAmount(), + $keys[3] => $this->getSerializedEffects(), $keys[4] => $this->getIsEnabled(), $keys[5] => $this->getExpirationDate(), $keys[6] => $this->getMaxUsage(), @@ -1603,7 +1603,7 @@ abstract class CouponVersion implements ActiveRecordInterface $this->setType($value); break; case 3: - $this->setAmount($value); + $this->setSerializedEffects($value); break; case 4: $this->setIsEnabled($value); @@ -1665,7 +1665,7 @@ abstract class CouponVersion implements ActiveRecordInterface if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); if (array_key_exists($keys[1], $arr)) $this->setCode($arr[$keys[1]]); if (array_key_exists($keys[2], $arr)) $this->setType($arr[$keys[2]]); - if (array_key_exists($keys[3], $arr)) $this->setAmount($arr[$keys[3]]); + if (array_key_exists($keys[3], $arr)) $this->setSerializedEffects($arr[$keys[3]]); if (array_key_exists($keys[4], $arr)) $this->setIsEnabled($arr[$keys[4]]); if (array_key_exists($keys[5], $arr)) $this->setExpirationDate($arr[$keys[5]]); if (array_key_exists($keys[6], $arr)) $this->setMaxUsage($arr[$keys[6]]); @@ -1691,7 +1691,7 @@ abstract class CouponVersion implements ActiveRecordInterface if ($this->isColumnModified(CouponVersionTableMap::ID)) $criteria->add(CouponVersionTableMap::ID, $this->id); if ($this->isColumnModified(CouponVersionTableMap::CODE)) $criteria->add(CouponVersionTableMap::CODE, $this->code); if ($this->isColumnModified(CouponVersionTableMap::TYPE)) $criteria->add(CouponVersionTableMap::TYPE, $this->type); - if ($this->isColumnModified(CouponVersionTableMap::AMOUNT)) $criteria->add(CouponVersionTableMap::AMOUNT, $this->amount); + if ($this->isColumnModified(CouponVersionTableMap::SERIALIZED_EFFECTS)) $criteria->add(CouponVersionTableMap::SERIALIZED_EFFECTS, $this->serialized_effects); if ($this->isColumnModified(CouponVersionTableMap::IS_ENABLED)) $criteria->add(CouponVersionTableMap::IS_ENABLED, $this->is_enabled); if ($this->isColumnModified(CouponVersionTableMap::EXPIRATION_DATE)) $criteria->add(CouponVersionTableMap::EXPIRATION_DATE, $this->expiration_date); if ($this->isColumnModified(CouponVersionTableMap::MAX_USAGE)) $criteria->add(CouponVersionTableMap::MAX_USAGE, $this->max_usage); @@ -1776,7 +1776,7 @@ abstract class CouponVersion implements ActiveRecordInterface $copyObj->setId($this->getId()); $copyObj->setCode($this->getCode()); $copyObj->setType($this->getType()); - $copyObj->setAmount($this->getAmount()); + $copyObj->setSerializedEffects($this->getSerializedEffects()); $copyObj->setIsEnabled($this->getIsEnabled()); $copyObj->setExpirationDate($this->getExpirationDate()); $copyObj->setMaxUsage($this->getMaxUsage()); @@ -1874,7 +1874,7 @@ abstract class CouponVersion implements ActiveRecordInterface $this->id = null; $this->code = null; $this->type = null; - $this->amount = null; + $this->serialized_effects = null; $this->is_enabled = null; $this->expiration_date = null; $this->max_usage = null; diff --git a/core/lib/Thelia/Model/Base/CouponVersionQuery.php b/core/lib/Thelia/Model/Base/CouponVersionQuery.php index eebd85dd9..1cfdb8fb8 100644 --- a/core/lib/Thelia/Model/Base/CouponVersionQuery.php +++ b/core/lib/Thelia/Model/Base/CouponVersionQuery.php @@ -24,7 +24,7 @@ use Thelia\Model\Map\CouponVersionTableMap; * @method ChildCouponVersionQuery orderById($order = Criteria::ASC) Order by the id column * @method ChildCouponVersionQuery orderByCode($order = Criteria::ASC) Order by the code column * @method ChildCouponVersionQuery orderByType($order = Criteria::ASC) Order by the type column - * @method ChildCouponVersionQuery orderByAmount($order = Criteria::ASC) Order by the amount column + * @method ChildCouponVersionQuery orderBySerializedEffects($order = Criteria::ASC) Order by the serialized_effects column * @method ChildCouponVersionQuery orderByIsEnabled($order = Criteria::ASC) Order by the is_enabled column * @method ChildCouponVersionQuery orderByExpirationDate($order = Criteria::ASC) Order by the expiration_date column * @method ChildCouponVersionQuery orderByMaxUsage($order = Criteria::ASC) Order by the max_usage column @@ -40,7 +40,7 @@ use Thelia\Model\Map\CouponVersionTableMap; * @method ChildCouponVersionQuery groupById() Group by the id column * @method ChildCouponVersionQuery groupByCode() Group by the code column * @method ChildCouponVersionQuery groupByType() Group by the type column - * @method ChildCouponVersionQuery groupByAmount() Group by the amount column + * @method ChildCouponVersionQuery groupBySerializedEffects() Group by the serialized_effects column * @method ChildCouponVersionQuery groupByIsEnabled() Group by the is_enabled column * @method ChildCouponVersionQuery groupByExpirationDate() Group by the expiration_date column * @method ChildCouponVersionQuery groupByMaxUsage() Group by the max_usage column @@ -67,7 +67,7 @@ use Thelia\Model\Map\CouponVersionTableMap; * @method ChildCouponVersion findOneById(int $id) Return the first ChildCouponVersion filtered by the id column * @method ChildCouponVersion findOneByCode(string $code) Return the first ChildCouponVersion filtered by the code column * @method ChildCouponVersion findOneByType(string $type) Return the first ChildCouponVersion filtered by the type column - * @method ChildCouponVersion findOneByAmount(double $amount) Return the first ChildCouponVersion filtered by the amount column + * @method ChildCouponVersion findOneBySerializedEffects(string $serialized_effects) Return the first ChildCouponVersion filtered by the serialized_effects column * @method ChildCouponVersion findOneByIsEnabled(boolean $is_enabled) Return the first ChildCouponVersion filtered by the is_enabled column * @method ChildCouponVersion findOneByExpirationDate(string $expiration_date) Return the first ChildCouponVersion filtered by the expiration_date column * @method ChildCouponVersion findOneByMaxUsage(int $max_usage) Return the first ChildCouponVersion filtered by the max_usage column @@ -83,7 +83,7 @@ use Thelia\Model\Map\CouponVersionTableMap; * @method array findById(int $id) Return ChildCouponVersion objects filtered by the id column * @method array findByCode(string $code) Return ChildCouponVersion objects filtered by the code column * @method array findByType(string $type) Return ChildCouponVersion objects filtered by the type column - * @method array findByAmount(double $amount) Return ChildCouponVersion objects filtered by the amount column + * @method array findBySerializedEffects(string $serialized_effects) Return ChildCouponVersion objects filtered by the serialized_effects column * @method array findByIsEnabled(boolean $is_enabled) Return ChildCouponVersion objects filtered by the is_enabled column * @method array findByExpirationDate(string $expiration_date) Return ChildCouponVersion objects filtered by the expiration_date column * @method array findByMaxUsage(int $max_usage) Return ChildCouponVersion objects filtered by the max_usage column @@ -183,7 +183,7 @@ abstract class CouponVersionQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT ID, CODE, TYPE, AMOUNT, IS_ENABLED, EXPIRATION_DATE, MAX_USAGE, IS_CUMULATIVE, IS_REMOVING_POSTAGE, IS_AVAILABLE_ON_SPECIAL_OFFERS, IS_USED, SERIALIZED_CONDITIONS, CREATED_AT, UPDATED_AT, VERSION FROM coupon_version WHERE ID = :p0 AND VERSION = :p1'; + $sql = 'SELECT ID, CODE, TYPE, SERIALIZED_EFFECTS, IS_ENABLED, EXPIRATION_DATE, MAX_USAGE, IS_CUMULATIVE, IS_REMOVING_POSTAGE, IS_AVAILABLE_ON_SPECIAL_OFFERS, IS_USED, SERIALIZED_CONDITIONS, CREATED_AT, UPDATED_AT, VERSION FROM coupon_version WHERE ID = :p0 AND VERSION = :p1'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key[0], PDO::PARAM_INT); @@ -386,44 +386,32 @@ abstract class CouponVersionQuery extends ModelCriteria } /** - * Filter the query on the amount column + * Filter the query on the serialized_effects column * * Example usage: * - * $query->filterByAmount(1234); // WHERE amount = 1234 - * $query->filterByAmount(array(12, 34)); // WHERE amount IN (12, 34) - * $query->filterByAmount(array('min' => 12)); // WHERE amount > 12 + * $query->filterBySerializedEffects('fooValue'); // WHERE serialized_effects = 'fooValue' + * $query->filterBySerializedEffects('%fooValue%'); // WHERE serialized_effects LIKE '%fooValue%' * * - * @param mixed $amount The value to use as filter. - * Use scalar values for equality. - * Use array values for in_array() equivalent. - * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $serializedEffects The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildCouponVersionQuery The current query, for fluid interface */ - public function filterByAmount($amount = null, $comparison = null) + public function filterBySerializedEffects($serializedEffects = null, $comparison = null) { - if (is_array($amount)) { - $useMinMax = false; - if (isset($amount['min'])) { - $this->addUsingAlias(CouponVersionTableMap::AMOUNT, $amount['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($amount['max'])) { - $this->addUsingAlias(CouponVersionTableMap::AMOUNT, $amount['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { + if (null === $comparison) { + if (is_array($serializedEffects)) { $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $serializedEffects)) { + $serializedEffects = str_replace('*', '%', $serializedEffects); + $comparison = Criteria::LIKE; } } - return $this->addUsingAlias(CouponVersionTableMap::AMOUNT, $amount, $comparison); + return $this->addUsingAlias(CouponVersionTableMap::SERIALIZED_EFFECTS, $serializedEffects, $comparison); } /** diff --git a/core/lib/Thelia/Model/Base/OrderCouponQuery.php b/core/lib/Thelia/Model/Base/OrderCouponQuery.php old mode 100644 new mode 100755 diff --git a/core/lib/Thelia/Model/Coupon.php b/core/lib/Thelia/Model/Coupon.php index c4f74569d..55fa6445d 100755 --- a/core/lib/Thelia/Model/Coupon.php +++ b/core/lib/Thelia/Model/Coupon.php @@ -27,13 +27,10 @@ use Propel\Runtime\Propel; use Thelia\Constraint\Rule\CouponRuleInterface; use Thelia\Coupon\ConditionCollection; use Thelia\Model\Base\Coupon as BaseCoupon; +use Thelia\Model\Exception\InvalidArgumentException; use Thelia\Model\Map\CouponTableMap; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Used to provide an effect (mostly a discount) * at the end of the Customer checkout tunnel * It will be usable for a Customer only if it matches the Coupon criteria (Rules) @@ -53,7 +50,7 @@ class Coupon extends BaseCoupon * * @param string $code Coupon Code * @param string $title Coupon title - * @param float $amount Amount removed from the Total Checkout + * @param array $effects Ready to be serialized in JSON effect params * @param string $type Coupon type * @param bool $isRemovingPostage Is removing Postage * @param string $shortDescription Coupon short description @@ -68,20 +65,20 @@ class Coupon extends BaseCoupon * * @throws \Exception */ - function createOrUpdate($code, $title, $amount, $type, $isRemovingPostage, $shortDescription, $description, $isEnabled, $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $maxUsage, $defaultSerializedRule, $locale = null) + function createOrUpdate($code, $title, array $effects, $type, $isRemovingPostage, $shortDescription, $description, $isEnabled, $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $maxUsage, $defaultSerializedRule, $locale = null) { $this->setCode($code) - ->setTitle($title) - ->setShortDescription($shortDescription) - ->setDescription($description) ->setType($type) - ->setAmount($amount) + ->setEffects($effects) ->setIsRemovingPostage($isRemovingPostage) ->setIsEnabled($isEnabled) ->setExpirationDate($expirationDate) ->setIsAvailableOnSpecialOffers($isAvailableOnSpecialOffers) ->setIsCumulative($isCumulative) ->setMaxUsage($maxUsage); + $this->setTitle($title) + ->setShortDescription($shortDescription) + ->setDescription($description); // If no rule given, set default rule if (null === $this->getSerializedConditions()) { @@ -132,4 +129,98 @@ class Coupon extends BaseCoupon throw $e; } } + + /** + * Set Coupon amount + * + * @param float $amount Amount deduced from the Cart + * + * @return $this + */ + public function setAmount($amount) + { + $effects = $this->unserializeEffects($this->getSerializedEffects()); + $effects['amount'] = floatval($amount); + $this->setEffects($effects); + + return $this; + } + + /** + * Get the amount removed from the coupon to the cart + * + * @return float + */ + public function getAmount() + { + $amount = $this->getEffects()['amount']; + + return floatval($amount); + } + + /** + * Get the Coupon effects + * + * @return array + * @throws Exception\InvalidArgumentException + */ + public function getEffects() + { + $effects = $this->unserializeEffects($this->getSerializedEffects()); + + if (null === $effects['amount']) { + throw new InvalidArgumentException('Missing key \'amount\' in Coupon effect coming from database'); + } + + return $effects; + } + + /** + * Get the Coupon effects + * + * @param array $effects Effect ready to be serialized + * Needs at least the key 'amount' + * with the amount removed from the cart + * + * @throws Exception\InvalidArgumentException + * @return $this + */ + public function setEffects(array $effects) + { + if (null === $effects['amount']) { + throw new InvalidArgumentException('Missing key \'amount\' in Coupon effect ready to be serialized array'); + } + + $this->setSerializedEffects($this->serializeEffects($effects)); + + return $this; + } + + /** + * Return unserialized effects + * + * @param string $serializedEffects Serialized effect string to unserialize + * + * @return array + */ + public function unserializeEffects($serializedEffects) + { + $effects = json_decode($serializedEffects, true); + + return $effects; + } + + /** + * Return serialized effects + * + * @param array $unserializedEffects Unserialized array string to serialize + * + * @return string + */ + public function serializeEffects(array $unserializedEffects) + { + $effects = json_encode($unserializedEffects); + + return $effects; + } } diff --git a/core/lib/Thelia/Model/Map/CouponTableMap.php b/core/lib/Thelia/Model/Map/CouponTableMap.php index 70d689a2a..830102ad3 100644 --- a/core/lib/Thelia/Model/Map/CouponTableMap.php +++ b/core/lib/Thelia/Model/Map/CouponTableMap.php @@ -85,9 +85,9 @@ class CouponTableMap extends TableMap const TYPE = 'coupon.TYPE'; /** - * the column name for the AMOUNT field + * the column name for the SERIALIZED_EFFECTS field */ - const AMOUNT = 'coupon.AMOUNT'; + const SERIALIZED_EFFECTS = 'coupon.SERIALIZED_EFFECTS'; /** * the column name for the IS_ENABLED field @@ -165,11 +165,11 @@ class CouponTableMap extends TableMap * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ protected static $fieldNames = array ( - self::TYPE_PHPNAME => array('Id', 'Code', 'Type', 'Amount', 'IsEnabled', 'ExpirationDate', 'MaxUsage', 'IsCumulative', 'IsRemovingPostage', 'IsAvailableOnSpecialOffers', 'IsUsed', 'SerializedConditions', 'CreatedAt', 'UpdatedAt', 'Version', ), - self::TYPE_STUDLYPHPNAME => array('id', 'code', 'type', 'amount', 'isEnabled', 'expirationDate', 'maxUsage', 'isCumulative', 'isRemovingPostage', 'isAvailableOnSpecialOffers', 'isUsed', 'serializedConditions', 'createdAt', 'updatedAt', 'version', ), - self::TYPE_COLNAME => array(CouponTableMap::ID, CouponTableMap::CODE, CouponTableMap::TYPE, CouponTableMap::AMOUNT, CouponTableMap::IS_ENABLED, CouponTableMap::EXPIRATION_DATE, CouponTableMap::MAX_USAGE, CouponTableMap::IS_CUMULATIVE, CouponTableMap::IS_REMOVING_POSTAGE, CouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS, CouponTableMap::IS_USED, CouponTableMap::SERIALIZED_CONDITIONS, CouponTableMap::CREATED_AT, CouponTableMap::UPDATED_AT, CouponTableMap::VERSION, ), - self::TYPE_RAW_COLNAME => array('ID', 'CODE', 'TYPE', 'AMOUNT', 'IS_ENABLED', 'EXPIRATION_DATE', 'MAX_USAGE', 'IS_CUMULATIVE', 'IS_REMOVING_POSTAGE', 'IS_AVAILABLE_ON_SPECIAL_OFFERS', 'IS_USED', 'SERIALIZED_CONDITIONS', 'CREATED_AT', 'UPDATED_AT', 'VERSION', ), - self::TYPE_FIELDNAME => array('id', 'code', 'type', 'amount', 'is_enabled', 'expiration_date', 'max_usage', 'is_cumulative', 'is_removing_postage', 'is_available_on_special_offers', 'is_used', 'serialized_conditions', 'created_at', 'updated_at', 'version', ), + self::TYPE_PHPNAME => array('Id', 'Code', 'Type', 'SerializedEffects', 'IsEnabled', 'ExpirationDate', 'MaxUsage', 'IsCumulative', 'IsRemovingPostage', 'IsAvailableOnSpecialOffers', 'IsUsed', 'SerializedConditions', 'CreatedAt', 'UpdatedAt', 'Version', ), + self::TYPE_STUDLYPHPNAME => array('id', 'code', 'type', 'serializedEffects', 'isEnabled', 'expirationDate', 'maxUsage', 'isCumulative', 'isRemovingPostage', 'isAvailableOnSpecialOffers', 'isUsed', 'serializedConditions', 'createdAt', 'updatedAt', 'version', ), + self::TYPE_COLNAME => array(CouponTableMap::ID, CouponTableMap::CODE, CouponTableMap::TYPE, CouponTableMap::SERIALIZED_EFFECTS, CouponTableMap::IS_ENABLED, CouponTableMap::EXPIRATION_DATE, CouponTableMap::MAX_USAGE, CouponTableMap::IS_CUMULATIVE, CouponTableMap::IS_REMOVING_POSTAGE, CouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS, CouponTableMap::IS_USED, CouponTableMap::SERIALIZED_CONDITIONS, CouponTableMap::CREATED_AT, CouponTableMap::UPDATED_AT, CouponTableMap::VERSION, ), + self::TYPE_RAW_COLNAME => array('ID', 'CODE', 'TYPE', 'SERIALIZED_EFFECTS', 'IS_ENABLED', 'EXPIRATION_DATE', 'MAX_USAGE', 'IS_CUMULATIVE', 'IS_REMOVING_POSTAGE', 'IS_AVAILABLE_ON_SPECIAL_OFFERS', 'IS_USED', 'SERIALIZED_CONDITIONS', 'CREATED_AT', 'UPDATED_AT', 'VERSION', ), + self::TYPE_FIELDNAME => array('id', 'code', 'type', 'serialized_effects', 'is_enabled', 'expiration_date', 'max_usage', 'is_cumulative', 'is_removing_postage', 'is_available_on_special_offers', 'is_used', 'serialized_conditions', 'created_at', 'updated_at', 'version', ), self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ) ); @@ -180,11 +180,11 @@ class CouponTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'Code' => 1, 'Type' => 2, 'Amount' => 3, 'IsEnabled' => 4, 'ExpirationDate' => 5, 'MaxUsage' => 6, 'IsCumulative' => 7, 'IsRemovingPostage' => 8, 'IsAvailableOnSpecialOffers' => 9, 'IsUsed' => 10, 'SerializedConditions' => 11, 'CreatedAt' => 12, 'UpdatedAt' => 13, 'Version' => 14, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'amount' => 3, 'isEnabled' => 4, 'expirationDate' => 5, 'maxUsage' => 6, 'isCumulative' => 7, 'isRemovingPostage' => 8, 'isAvailableOnSpecialOffers' => 9, 'isUsed' => 10, 'serializedConditions' => 11, 'createdAt' => 12, 'updatedAt' => 13, 'version' => 14, ), - self::TYPE_COLNAME => array(CouponTableMap::ID => 0, CouponTableMap::CODE => 1, CouponTableMap::TYPE => 2, CouponTableMap::AMOUNT => 3, CouponTableMap::IS_ENABLED => 4, CouponTableMap::EXPIRATION_DATE => 5, CouponTableMap::MAX_USAGE => 6, CouponTableMap::IS_CUMULATIVE => 7, CouponTableMap::IS_REMOVING_POSTAGE => 8, CouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS => 9, CouponTableMap::IS_USED => 10, CouponTableMap::SERIALIZED_CONDITIONS => 11, CouponTableMap::CREATED_AT => 12, CouponTableMap::UPDATED_AT => 13, CouponTableMap::VERSION => 14, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'CODE' => 1, 'TYPE' => 2, 'AMOUNT' => 3, 'IS_ENABLED' => 4, 'EXPIRATION_DATE' => 5, 'MAX_USAGE' => 6, 'IS_CUMULATIVE' => 7, 'IS_REMOVING_POSTAGE' => 8, 'IS_AVAILABLE_ON_SPECIAL_OFFERS' => 9, 'IS_USED' => 10, 'SERIALIZED_CONDITIONS' => 11, 'CREATED_AT' => 12, 'UPDATED_AT' => 13, 'VERSION' => 14, ), - self::TYPE_FIELDNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'amount' => 3, 'is_enabled' => 4, 'expiration_date' => 5, 'max_usage' => 6, 'is_cumulative' => 7, 'is_removing_postage' => 8, 'is_available_on_special_offers' => 9, 'is_used' => 10, 'serialized_conditions' => 11, 'created_at' => 12, 'updated_at' => 13, 'version' => 14, ), + self::TYPE_PHPNAME => array('Id' => 0, 'Code' => 1, 'Type' => 2, 'SerializedEffects' => 3, 'IsEnabled' => 4, 'ExpirationDate' => 5, 'MaxUsage' => 6, 'IsCumulative' => 7, 'IsRemovingPostage' => 8, 'IsAvailableOnSpecialOffers' => 9, 'IsUsed' => 10, 'SerializedConditions' => 11, 'CreatedAt' => 12, 'UpdatedAt' => 13, 'Version' => 14, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'serializedEffects' => 3, 'isEnabled' => 4, 'expirationDate' => 5, 'maxUsage' => 6, 'isCumulative' => 7, 'isRemovingPostage' => 8, 'isAvailableOnSpecialOffers' => 9, 'isUsed' => 10, 'serializedConditions' => 11, 'createdAt' => 12, 'updatedAt' => 13, 'version' => 14, ), + self::TYPE_COLNAME => array(CouponTableMap::ID => 0, CouponTableMap::CODE => 1, CouponTableMap::TYPE => 2, CouponTableMap::SERIALIZED_EFFECTS => 3, CouponTableMap::IS_ENABLED => 4, CouponTableMap::EXPIRATION_DATE => 5, CouponTableMap::MAX_USAGE => 6, CouponTableMap::IS_CUMULATIVE => 7, CouponTableMap::IS_REMOVING_POSTAGE => 8, CouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS => 9, CouponTableMap::IS_USED => 10, CouponTableMap::SERIALIZED_CONDITIONS => 11, CouponTableMap::CREATED_AT => 12, CouponTableMap::UPDATED_AT => 13, CouponTableMap::VERSION => 14, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'CODE' => 1, 'TYPE' => 2, 'SERIALIZED_EFFECTS' => 3, 'IS_ENABLED' => 4, 'EXPIRATION_DATE' => 5, 'MAX_USAGE' => 6, 'IS_CUMULATIVE' => 7, 'IS_REMOVING_POSTAGE' => 8, 'IS_AVAILABLE_ON_SPECIAL_OFFERS' => 9, 'IS_USED' => 10, 'SERIALIZED_CONDITIONS' => 11, 'CREATED_AT' => 12, 'UPDATED_AT' => 13, 'VERSION' => 14, ), + self::TYPE_FIELDNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'serialized_effects' => 3, 'is_enabled' => 4, 'expiration_date' => 5, 'max_usage' => 6, 'is_cumulative' => 7, 'is_removing_postage' => 8, 'is_available_on_special_offers' => 9, 'is_used' => 10, 'serialized_conditions' => 11, 'created_at' => 12, 'updated_at' => 13, 'version' => 14, ), self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ) ); @@ -207,7 +207,7 @@ class CouponTableMap extends TableMap $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); $this->addColumn('CODE', 'Code', 'VARCHAR', true, 45, null); $this->addColumn('TYPE', 'Type', 'VARCHAR', true, 255, null); - $this->addColumn('AMOUNT', 'Amount', 'FLOAT', true, null, null); + $this->addColumn('SERIALIZED_EFFECTS', 'SerializedEffects', 'LONGVARCHAR', true, null, null); $this->addColumn('IS_ENABLED', 'IsEnabled', 'BOOLEAN', true, 1, null); $this->addColumn('EXPIRATION_DATE', 'ExpirationDate', 'TIMESTAMP', true, null, null); $this->addColumn('MAX_USAGE', 'MaxUsage', 'INTEGER', true, null, null); @@ -396,7 +396,7 @@ class CouponTableMap extends TableMap $criteria->addSelectColumn(CouponTableMap::ID); $criteria->addSelectColumn(CouponTableMap::CODE); $criteria->addSelectColumn(CouponTableMap::TYPE); - $criteria->addSelectColumn(CouponTableMap::AMOUNT); + $criteria->addSelectColumn(CouponTableMap::SERIALIZED_EFFECTS); $criteria->addSelectColumn(CouponTableMap::IS_ENABLED); $criteria->addSelectColumn(CouponTableMap::EXPIRATION_DATE); $criteria->addSelectColumn(CouponTableMap::MAX_USAGE); @@ -412,7 +412,7 @@ class CouponTableMap extends TableMap $criteria->addSelectColumn($alias . '.ID'); $criteria->addSelectColumn($alias . '.CODE'); $criteria->addSelectColumn($alias . '.TYPE'); - $criteria->addSelectColumn($alias . '.AMOUNT'); + $criteria->addSelectColumn($alias . '.SERIALIZED_EFFECTS'); $criteria->addSelectColumn($alias . '.IS_ENABLED'); $criteria->addSelectColumn($alias . '.EXPIRATION_DATE'); $criteria->addSelectColumn($alias . '.MAX_USAGE'); diff --git a/core/lib/Thelia/Model/Map/CouponVersionTableMap.php b/core/lib/Thelia/Model/Map/CouponVersionTableMap.php index 91e774912..8fbd7e68d 100644 --- a/core/lib/Thelia/Model/Map/CouponVersionTableMap.php +++ b/core/lib/Thelia/Model/Map/CouponVersionTableMap.php @@ -85,9 +85,9 @@ class CouponVersionTableMap extends TableMap const TYPE = 'coupon_version.TYPE'; /** - * the column name for the AMOUNT field + * the column name for the SERIALIZED_EFFECTS field */ - const AMOUNT = 'coupon_version.AMOUNT'; + const SERIALIZED_EFFECTS = 'coupon_version.SERIALIZED_EFFECTS'; /** * the column name for the IS_ENABLED field @@ -156,11 +156,11 @@ class CouponVersionTableMap extends TableMap * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ protected static $fieldNames = array ( - self::TYPE_PHPNAME => array('Id', 'Code', 'Type', 'Amount', 'IsEnabled', 'ExpirationDate', 'MaxUsage', 'IsCumulative', 'IsRemovingPostage', 'IsAvailableOnSpecialOffers', 'IsUsed', 'SerializedConditions', 'CreatedAt', 'UpdatedAt', 'Version', ), - self::TYPE_STUDLYPHPNAME => array('id', 'code', 'type', 'amount', 'isEnabled', 'expirationDate', 'maxUsage', 'isCumulative', 'isRemovingPostage', 'isAvailableOnSpecialOffers', 'isUsed', 'serializedConditions', 'createdAt', 'updatedAt', 'version', ), - self::TYPE_COLNAME => array(CouponVersionTableMap::ID, CouponVersionTableMap::CODE, CouponVersionTableMap::TYPE, CouponVersionTableMap::AMOUNT, CouponVersionTableMap::IS_ENABLED, CouponVersionTableMap::EXPIRATION_DATE, CouponVersionTableMap::MAX_USAGE, CouponVersionTableMap::IS_CUMULATIVE, CouponVersionTableMap::IS_REMOVING_POSTAGE, CouponVersionTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS, CouponVersionTableMap::IS_USED, CouponVersionTableMap::SERIALIZED_CONDITIONS, CouponVersionTableMap::CREATED_AT, CouponVersionTableMap::UPDATED_AT, CouponVersionTableMap::VERSION, ), - self::TYPE_RAW_COLNAME => array('ID', 'CODE', 'TYPE', 'AMOUNT', 'IS_ENABLED', 'EXPIRATION_DATE', 'MAX_USAGE', 'IS_CUMULATIVE', 'IS_REMOVING_POSTAGE', 'IS_AVAILABLE_ON_SPECIAL_OFFERS', 'IS_USED', 'SERIALIZED_CONDITIONS', 'CREATED_AT', 'UPDATED_AT', 'VERSION', ), - self::TYPE_FIELDNAME => array('id', 'code', 'type', 'amount', 'is_enabled', 'expiration_date', 'max_usage', 'is_cumulative', 'is_removing_postage', 'is_available_on_special_offers', 'is_used', 'serialized_conditions', 'created_at', 'updated_at', 'version', ), + self::TYPE_PHPNAME => array('Id', 'Code', 'Type', 'SerializedEffects', 'IsEnabled', 'ExpirationDate', 'MaxUsage', 'IsCumulative', 'IsRemovingPostage', 'IsAvailableOnSpecialOffers', 'IsUsed', 'SerializedConditions', 'CreatedAt', 'UpdatedAt', 'Version', ), + self::TYPE_STUDLYPHPNAME => array('id', 'code', 'type', 'serializedEffects', 'isEnabled', 'expirationDate', 'maxUsage', 'isCumulative', 'isRemovingPostage', 'isAvailableOnSpecialOffers', 'isUsed', 'serializedConditions', 'createdAt', 'updatedAt', 'version', ), + self::TYPE_COLNAME => array(CouponVersionTableMap::ID, CouponVersionTableMap::CODE, CouponVersionTableMap::TYPE, CouponVersionTableMap::SERIALIZED_EFFECTS, CouponVersionTableMap::IS_ENABLED, CouponVersionTableMap::EXPIRATION_DATE, CouponVersionTableMap::MAX_USAGE, CouponVersionTableMap::IS_CUMULATIVE, CouponVersionTableMap::IS_REMOVING_POSTAGE, CouponVersionTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS, CouponVersionTableMap::IS_USED, CouponVersionTableMap::SERIALIZED_CONDITIONS, CouponVersionTableMap::CREATED_AT, CouponVersionTableMap::UPDATED_AT, CouponVersionTableMap::VERSION, ), + self::TYPE_RAW_COLNAME => array('ID', 'CODE', 'TYPE', 'SERIALIZED_EFFECTS', 'IS_ENABLED', 'EXPIRATION_DATE', 'MAX_USAGE', 'IS_CUMULATIVE', 'IS_REMOVING_POSTAGE', 'IS_AVAILABLE_ON_SPECIAL_OFFERS', 'IS_USED', 'SERIALIZED_CONDITIONS', 'CREATED_AT', 'UPDATED_AT', 'VERSION', ), + self::TYPE_FIELDNAME => array('id', 'code', 'type', 'serialized_effects', 'is_enabled', 'expiration_date', 'max_usage', 'is_cumulative', 'is_removing_postage', 'is_available_on_special_offers', 'is_used', 'serialized_conditions', 'created_at', 'updated_at', 'version', ), self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ) ); @@ -171,11 +171,11 @@ class CouponVersionTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'Code' => 1, 'Type' => 2, 'Amount' => 3, 'IsEnabled' => 4, 'ExpirationDate' => 5, 'MaxUsage' => 6, 'IsCumulative' => 7, 'IsRemovingPostage' => 8, 'IsAvailableOnSpecialOffers' => 9, 'IsUsed' => 10, 'SerializedConditions' => 11, 'CreatedAt' => 12, 'UpdatedAt' => 13, 'Version' => 14, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'amount' => 3, 'isEnabled' => 4, 'expirationDate' => 5, 'maxUsage' => 6, 'isCumulative' => 7, 'isRemovingPostage' => 8, 'isAvailableOnSpecialOffers' => 9, 'isUsed' => 10, 'serializedConditions' => 11, 'createdAt' => 12, 'updatedAt' => 13, 'version' => 14, ), - self::TYPE_COLNAME => array(CouponVersionTableMap::ID => 0, CouponVersionTableMap::CODE => 1, CouponVersionTableMap::TYPE => 2, CouponVersionTableMap::AMOUNT => 3, CouponVersionTableMap::IS_ENABLED => 4, CouponVersionTableMap::EXPIRATION_DATE => 5, CouponVersionTableMap::MAX_USAGE => 6, CouponVersionTableMap::IS_CUMULATIVE => 7, CouponVersionTableMap::IS_REMOVING_POSTAGE => 8, CouponVersionTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS => 9, CouponVersionTableMap::IS_USED => 10, CouponVersionTableMap::SERIALIZED_CONDITIONS => 11, CouponVersionTableMap::CREATED_AT => 12, CouponVersionTableMap::UPDATED_AT => 13, CouponVersionTableMap::VERSION => 14, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'CODE' => 1, 'TYPE' => 2, 'AMOUNT' => 3, 'IS_ENABLED' => 4, 'EXPIRATION_DATE' => 5, 'MAX_USAGE' => 6, 'IS_CUMULATIVE' => 7, 'IS_REMOVING_POSTAGE' => 8, 'IS_AVAILABLE_ON_SPECIAL_OFFERS' => 9, 'IS_USED' => 10, 'SERIALIZED_CONDITIONS' => 11, 'CREATED_AT' => 12, 'UPDATED_AT' => 13, 'VERSION' => 14, ), - self::TYPE_FIELDNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'amount' => 3, 'is_enabled' => 4, 'expiration_date' => 5, 'max_usage' => 6, 'is_cumulative' => 7, 'is_removing_postage' => 8, 'is_available_on_special_offers' => 9, 'is_used' => 10, 'serialized_conditions' => 11, 'created_at' => 12, 'updated_at' => 13, 'version' => 14, ), + self::TYPE_PHPNAME => array('Id' => 0, 'Code' => 1, 'Type' => 2, 'SerializedEffects' => 3, 'IsEnabled' => 4, 'ExpirationDate' => 5, 'MaxUsage' => 6, 'IsCumulative' => 7, 'IsRemovingPostage' => 8, 'IsAvailableOnSpecialOffers' => 9, 'IsUsed' => 10, 'SerializedConditions' => 11, 'CreatedAt' => 12, 'UpdatedAt' => 13, 'Version' => 14, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'serializedEffects' => 3, 'isEnabled' => 4, 'expirationDate' => 5, 'maxUsage' => 6, 'isCumulative' => 7, 'isRemovingPostage' => 8, 'isAvailableOnSpecialOffers' => 9, 'isUsed' => 10, 'serializedConditions' => 11, 'createdAt' => 12, 'updatedAt' => 13, 'version' => 14, ), + self::TYPE_COLNAME => array(CouponVersionTableMap::ID => 0, CouponVersionTableMap::CODE => 1, CouponVersionTableMap::TYPE => 2, CouponVersionTableMap::SERIALIZED_EFFECTS => 3, CouponVersionTableMap::IS_ENABLED => 4, CouponVersionTableMap::EXPIRATION_DATE => 5, CouponVersionTableMap::MAX_USAGE => 6, CouponVersionTableMap::IS_CUMULATIVE => 7, CouponVersionTableMap::IS_REMOVING_POSTAGE => 8, CouponVersionTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS => 9, CouponVersionTableMap::IS_USED => 10, CouponVersionTableMap::SERIALIZED_CONDITIONS => 11, CouponVersionTableMap::CREATED_AT => 12, CouponVersionTableMap::UPDATED_AT => 13, CouponVersionTableMap::VERSION => 14, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'CODE' => 1, 'TYPE' => 2, 'SERIALIZED_EFFECTS' => 3, 'IS_ENABLED' => 4, 'EXPIRATION_DATE' => 5, 'MAX_USAGE' => 6, 'IS_CUMULATIVE' => 7, 'IS_REMOVING_POSTAGE' => 8, 'IS_AVAILABLE_ON_SPECIAL_OFFERS' => 9, 'IS_USED' => 10, 'SERIALIZED_CONDITIONS' => 11, 'CREATED_AT' => 12, 'UPDATED_AT' => 13, 'VERSION' => 14, ), + self::TYPE_FIELDNAME => array('id' => 0, 'code' => 1, 'type' => 2, 'serialized_effects' => 3, 'is_enabled' => 4, 'expiration_date' => 5, 'max_usage' => 6, 'is_cumulative' => 7, 'is_removing_postage' => 8, 'is_available_on_special_offers' => 9, 'is_used' => 10, 'serialized_conditions' => 11, 'created_at' => 12, 'updated_at' => 13, 'version' => 14, ), self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ) ); @@ -198,7 +198,7 @@ class CouponVersionTableMap extends TableMap $this->addForeignPrimaryKey('ID', 'Id', 'INTEGER' , 'coupon', 'ID', true, null, null); $this->addColumn('CODE', 'Code', 'VARCHAR', true, 45, null); $this->addColumn('TYPE', 'Type', 'VARCHAR', true, 255, null); - $this->addColumn('AMOUNT', 'Amount', 'FLOAT', true, null, null); + $this->addColumn('SERIALIZED_EFFECTS', 'SerializedEffects', 'LONGVARCHAR', true, null, null); $this->addColumn('IS_ENABLED', 'IsEnabled', 'BOOLEAN', true, 1, null); $this->addColumn('EXPIRATION_DATE', 'ExpirationDate', 'TIMESTAMP', true, null, null); $this->addColumn('MAX_USAGE', 'MaxUsage', 'INTEGER', true, null, null); @@ -410,7 +410,7 @@ class CouponVersionTableMap extends TableMap $criteria->addSelectColumn(CouponVersionTableMap::ID); $criteria->addSelectColumn(CouponVersionTableMap::CODE); $criteria->addSelectColumn(CouponVersionTableMap::TYPE); - $criteria->addSelectColumn(CouponVersionTableMap::AMOUNT); + $criteria->addSelectColumn(CouponVersionTableMap::SERIALIZED_EFFECTS); $criteria->addSelectColumn(CouponVersionTableMap::IS_ENABLED); $criteria->addSelectColumn(CouponVersionTableMap::EXPIRATION_DATE); $criteria->addSelectColumn(CouponVersionTableMap::MAX_USAGE); @@ -426,7 +426,7 @@ class CouponVersionTableMap extends TableMap $criteria->addSelectColumn($alias . '.ID'); $criteria->addSelectColumn($alias . '.CODE'); $criteria->addSelectColumn($alias . '.TYPE'); - $criteria->addSelectColumn($alias . '.AMOUNT'); + $criteria->addSelectColumn($alias . '.SERIALIZED_EFFECTS'); $criteria->addSelectColumn($alias . '.IS_ENABLED'); $criteria->addSelectColumn($alias . '.EXPIRATION_DATE'); $criteria->addSelectColumn($alias . '.MAX_USAGE'); diff --git a/core/lib/Thelia/Tests/Condition/ConditionCollectionTest.php b/core/lib/Thelia/Tests/Condition/ConditionCollectionTest.php index 46f639521..298204c26 100644 --- a/core/lib/Thelia/Tests/Condition/ConditionCollectionTest.php +++ b/core/lib/Thelia/Tests/Condition/ConditionCollectionTest.php @@ -26,10 +26,6 @@ use Thelia\Condition\Implementation\MatchForTotalAmount; use Thelia\Model\CurrencyQuery; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Unit Test ConditionCollection Class * Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-11-17 at 18:59:24. * diff --git a/core/lib/Thelia/Tests/Condition/ConditionEvaluatorTest.php b/core/lib/Thelia/Tests/Condition/ConditionEvaluatorTest.php index 2c85e05e5..1ecd047d5 100644 --- a/core/lib/Thelia/Tests/Condition/ConditionEvaluatorTest.php +++ b/core/lib/Thelia/Tests/Condition/ConditionEvaluatorTest.php @@ -28,10 +28,6 @@ use Thelia\Condition\Operators; use Thelia\Condition\ConditionCollection; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Unit Test ConditionEvaluator Class * * @package Constraint @@ -50,7 +46,7 @@ class ConditionEvaluatorTest extends \PHPUnit_Framework_TestCase } /** - * Test vatiable comparison + * Test variable comparison * * @covers Thelia\Condition\ConditionEvaluator::variableOpComparison */ @@ -91,7 +87,7 @@ class ConditionEvaluatorTest extends \PHPUnit_Framework_TestCase } /** - * Test vatiable comparison + * Test variable comparison * * @covers Thelia\Condition\ConditionEvaluator::variableOpComparison */ @@ -126,7 +122,7 @@ class ConditionEvaluatorTest extends \PHPUnit_Framework_TestCase } /** - * Test vatiable comparison + * Test variable comparison * * @expectedException \Exception * @covers Thelia\Condition\ConditionEvaluator::variableOpComparison @@ -164,8 +160,8 @@ class ConditionEvaluatorTest extends \PHPUnit_Framework_TestCase $collection->add($stubConditionTrue1); $collection->add($stubConditionTrue2); - $conitionEvaluator = new ConditionEvaluator(); - $actual = $conitionEvaluator->isMatching($collection); + $conditionEvaluator = new ConditionEvaluator(); + $actual = $conditionEvaluator->isMatching($collection); $this->assertTrue($actual); } @@ -195,8 +191,8 @@ class ConditionEvaluatorTest extends \PHPUnit_Framework_TestCase $collection->add($stubConditionTrue); $collection->add($stubConditionFalse); - $conitionEvaluator = new ConditionEvaluator(); - $actual = $conitionEvaluator->isMatching($collection); + $conditionEvaluator = new ConditionEvaluator(); + $actual = $conditionEvaluator->isMatching($collection); $this->assertFalse($actual); } diff --git a/core/lib/Thelia/Tests/Condition/ConditionFactoryTest.php b/core/lib/Thelia/Tests/Condition/ConditionFactoryTest.php index 37fde4cea..1894e8e29 100644 --- a/core/lib/Thelia/Tests/Condition/ConditionFactoryTest.php +++ b/core/lib/Thelia/Tests/Condition/ConditionFactoryTest.php @@ -31,10 +31,6 @@ use Thelia\Condition\ConditionCollection; use Thelia\Model\CurrencyQuery; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Unit Test ConditionFactory Class * * @package Condition diff --git a/core/lib/Thelia/Tests/Condition/Implementation/MatchForEveryoneTest.php b/core/lib/Thelia/Tests/Condition/Implementation/MatchForEveryoneTest.php index f59fe04ef..fceb41f93 100644 --- a/core/lib/Thelia/Tests/Condition/Implementation/MatchForEveryoneTest.php +++ b/core/lib/Thelia/Tests/Condition/Implementation/MatchForEveryoneTest.php @@ -29,10 +29,6 @@ use Thelia\Coupon\FacadeInterface; use Thelia\Model\Currency; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Unit Test MatchForEveryone Class * * @package Condition diff --git a/core/lib/Thelia/Tests/Condition/Implementation/MatchForTotalAmountTest.php b/core/lib/Thelia/Tests/Condition/Implementation/MatchForTotalAmountTest.php index d28bf198d..fa69e46b6 100644 --- a/core/lib/Thelia/Tests/Condition/Implementation/MatchForTotalAmountTest.php +++ b/core/lib/Thelia/Tests/Condition/Implementation/MatchForTotalAmountTest.php @@ -33,10 +33,6 @@ use Thelia\Model\Currency; use Thelia\Model\CurrencyQuery; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Unit Test MatchForTotalAmount Class * * @package Condition @@ -666,7 +662,7 @@ class MatchForTotalAmountTest extends \PHPUnit_Framework_TestCase $collection->add($condition1); $serialized = $conditionFactory->serializeConditionCollection($collection); - $unserialized = $conditionFactory->unserializeConditionCollection($serialized); + $conditionFactory->unserializeConditionCollection($serialized); } /** @@ -733,7 +729,7 @@ class MatchForTotalAmountTest extends \PHPUnit_Framework_TestCase $collection->add($condition1); $serialized = $conditionFactory->serializeConditionCollection($collection); - $unserialized = $conditionFactory->unserializeConditionCollection($serialized); + $conditionFactory->unserializeConditionCollection($serialized); } /** @@ -800,7 +796,7 @@ class MatchForTotalAmountTest extends \PHPUnit_Framework_TestCase $collection->add($condition1); $serialized = $conditionFactory->serializeConditionCollection($collection); - $unserialized = $conditionFactory->unserializeConditionCollection($serialized); + $conditionFactory->unserializeConditionCollection($serialized); } /** diff --git a/core/lib/Thelia/Tests/Condition/Implementation/MatchForXArticlesTest.php b/core/lib/Thelia/Tests/Condition/Implementation/MatchForXArticlesTest.php index f33ef0468..4f9f96a4b 100644 --- a/core/lib/Thelia/Tests/Condition/Implementation/MatchForXArticlesTest.php +++ b/core/lib/Thelia/Tests/Condition/Implementation/MatchForXArticlesTest.php @@ -29,10 +29,6 @@ use Thelia\Condition\SerializableCondition; use Thelia\Coupon\FacadeInterface; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Unit Test MatchForXArticles Class * * @package Constraint diff --git a/core/lib/Thelia/Tests/Condition/OperatorsTest.php b/core/lib/Thelia/Tests/Condition/OperatorsTest.php index 5d673e80b..94f5bd1bf 100644 --- a/core/lib/Thelia/Tests/Condition/OperatorsTest.php +++ b/core/lib/Thelia/Tests/Condition/OperatorsTest.php @@ -26,10 +26,6 @@ namespace Thelia\Condition; use Thelia\Core\Translation\Translator; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Unit Test Operators Class * * @package Condition diff --git a/core/lib/Thelia/Tests/Coupon/BaseFacadeTest.php b/core/lib/Thelia/Tests/Coupon/BaseFacadeTest.php index 6e1619aac..c2082edb4 100644 --- a/core/lib/Thelia/Tests/Coupon/BaseFacadeTest.php +++ b/core/lib/Thelia/Tests/Coupon/BaseFacadeTest.php @@ -24,10 +24,6 @@ namespace Thelia\Coupon; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Unit Test BaseFacade Class * Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-11-17 at 18:59:24. * diff --git a/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php b/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php index b70bdf247..648962e01 100644 --- a/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php +++ b/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php @@ -32,10 +32,6 @@ use Thelia\Model\Coupon; use Thelia\Model\CurrencyQuery; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Unit Test CouponFactory Class * Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-11-17 at 18:59:24. * @@ -248,7 +244,6 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua $stubContainer = $this->getMock('\Symfony\Component\DependencyInjection\Container'); - $conditionFactory = new ConditionFactory($stubContainer); $stubFacade->expects($this->any()) ->method('findOneCouponByCode') ->will($this->returnValue(null)); @@ -336,7 +331,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua ->will($this->returnValue(true)); $factory = new CouponFactory($stubContainer); - $actual = $factory->buildCouponFromCode('XMAS'); + $factory->buildCouponFromCode('XMAS'); } @@ -399,7 +394,73 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua ->will($this->returnValue(true)); $factory = new CouponFactory($stubContainer); - $actual = $factory->buildCouponFromCode('XMAS'); + $factory->buildCouponFromCode('XMAS'); } + + /** + * @covers Thelia\Coupon\CouponFactory::buildCouponFromModel + */ + public function testBuildCouponFromModel() + { + $stubFacade = $this->generateFacadeStub(); + + $stubContainer = $this->getMock('\Symfony\Component\DependencyInjection\Container'); + + $conditionFactory = new ConditionFactory($stubContainer); + $couponModel = $this->generateCouponModel($stubFacade, $conditionFactory); + $stubFacade->expects($this->any()) + ->method('findOneCouponByCode') + ->will($this->returnValue($couponModel)); + + $couponManager = new RemoveXAmount($stubFacade); + + + $condition1 = new MatchForTotalAmount($stubFacade); + $operators = array( + MatchForTotalAmount::INPUT1 => Operators::SUPERIOR, + MatchForTotalAmount::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmount::INPUT1 => 40.00, + MatchForTotalAmount::INPUT2 => 'EUR' + ); + $condition1->setValidatorsFromForm($operators, $values); + + $condition2 = new MatchForTotalAmount($stubFacade); + $operators = array( + MatchForTotalAmount::INPUT1 => Operators::INFERIOR, + MatchForTotalAmount::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmount::INPUT1 => 400.00, + MatchForTotalAmount::INPUT2 => 'EUR' + ); + $condition2->setValidatorsFromForm($operators, $values); + + $conditions = new ConditionCollection(); + $conditions->add($condition1); + $conditions->add($condition2); + $stubConditionFactory = $this->getMockBuilder('\Thelia\Condition\ConditionFactory') + ->disableOriginalConstructor() + ->getMock(); + $stubConditionFactory->expects($this->any()) + ->method('unserializeConditionCollection') + ->will($this->returnValue($conditions)); + + + $stubContainer->expects($this->any()) + ->method('get') + ->will($this->onConsecutiveCalls($stubFacade, $couponManager, $stubConditionFactory)); + + $stubContainer->expects($this->any()) + ->method('has') + ->will($this->returnValue(true)); + + $factory = new CouponFactory($stubContainer); + $expected = $couponManager; + $actual = $factory->buildCouponFromModel($couponModel); + + $this->assertEquals($expected, $actual); + } } diff --git a/core/lib/Thelia/Tests/Coupon/CouponManagerTest.php b/core/lib/Thelia/Tests/Coupon/CouponManagerTest.php index bf4b9f1e9..70d15e29a 100644 --- a/core/lib/Thelia/Tests/Coupon/CouponManagerTest.php +++ b/core/lib/Thelia/Tests/Coupon/CouponManagerTest.php @@ -32,10 +32,6 @@ use Thelia\Model\Coupon; use Thelia\Model\CurrencyQuery; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Unit Test CouponManager Class * Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-11-17 at 18:59:24. * @@ -407,7 +403,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua $coupon = new RemoveXAmount($stubFacade); $date = new \DateTime(); - $coupon->set($stubFacade, 'XMAS', '', '', '', 21.00, true, true, true, true, 254, $date->setTimestamp(strtotime("today + 3 months")) ); + $coupon->set($stubFacade, 'XMAS', '', '', '', array('amount' => 21.00), true, true, true, true, 254, $date->setTimestamp(strtotime("today + 3 months")) ); $condition1 = new MatchForTotalAmount($stubFacade); $operators = array( @@ -474,7 +470,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua $coupon = new RemoveXAmount($stubFacade); $date = new \DateTime(); - $coupon->set($stubFacade, 'XMAS', '', '', '', 21.00, true, true, true, true, 254, $date->setTimestamp(strtotime("today + 3 months")) ); + $coupon->set($stubFacade, 'XMAS', '', '', '', array('amount' => 21.00), true, true, true, true, 254, $date->setTimestamp(strtotime("today + 3 months")) ); $condition1 = new MatchForTotalAmount($stubFacade); $operators = array( diff --git a/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php b/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php index 41971d4a6..0a1d589b4 100644 --- a/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php +++ b/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php @@ -30,10 +30,6 @@ use Thelia\Coupon\FacadeInterface; use Thelia\Model\CurrencyQuery; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Unit Test RemoveXAmount Class * Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-11-17 at 18:59:24. * @@ -129,7 +125,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesuada tortor vel erat volutpat tincidunt. In vehicula diam est, a convallis eros scelerisque ut. Donec aliquet venenatis iaculis. Ut a arcu gravida, placerat dui eu, iaculis nisl. Quisque adipiscing orci sit amet dui dignissim lacinia. Sed vulputate lorem non dolor adipiscing ornare. Morbi ornare id nisl id aliquam. Ut fringilla elit ante, nec lacinia enim fermentum sit amet. Aenean rutrum lorem eu convallis pharetra. Cras malesuada varius metus, vitae gravida velit. Nam a varius ipsum, ac commodo dolor. Phasellus nec elementum elit. Etiam vel adipiscing leo.'; - $coupon->set($stubFacade, 'XMAS', 'XMAS Coupon', 'Coupon for Springbreak removing 10€ if you have a cart between 40.00€ and 400.00€ (excluded)', $description, 10.00, true, true, true, true, 254, $date->setTimestamp(strtotime("today + 3 months")) ); + $coupon->set($stubFacade, 'XMAS', 'XMAS Coupon', 'Coupon for Springbreak removing 10€ if you have a cart between 40.00€ and 400.00€ (excluded)', $description, array('amount' => 10.00), true, true, true, true, 254, $date->setTimestamp(strtotime("today + 3 months")) ); $condition1 = new MatchForTotalAmount($stubFacade); $operators = array( @@ -204,6 +200,22 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expected, $actual); } + /** + * @covers Thelia\Coupon\Type\RemoveXPercent::getToolTip + */ + public function testGetInputName() + { + $inputName = 'Amount removed from the cart'; + $stubFacade = $this->generateFacadeStub(399, 'EUR', $inputName); + + /** @var FacadeInterface $stubFacade */ + $coupon = new RemoveXAmount($stubFacade); + + $actual = $coupon->getInputName(); + $expected = $inputName; + $this->assertEquals($expected, $actual); + } + /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. diff --git a/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php b/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php index 475e46aba..ac893ae26 100644 --- a/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php +++ b/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php @@ -30,10 +30,6 @@ use Thelia\Coupon\FacadeInterface; use Thelia\Model\CurrencyQuery; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * * Unit Test RemoveXPercent Class * Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-11-17 at 18:59:24. * @@ -119,7 +115,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesuada tortor vel erat volutpat tincidunt. In vehicula diam est, a convallis eros scelerisque ut. Donec aliquet venenatis iaculis. Ut a arcu gravida, placerat dui eu, iaculis nisl. Quisque adipiscing orci sit amet dui dignissim lacinia. Sed vulputate lorem non dolor adipiscing ornare. Morbi ornare id nisl id aliquam. Ut fringilla elit ante, nec lacinia enim fermentum sit amet. Aenean rutrum lorem eu convallis pharetra. Cras malesuada varius metus, vitae gravida velit. Nam a varius ipsum, ac commodo dolor. Phasellus nec elementum elit. Etiam vel adipiscing leo.'; - $coupon->set($stubFacade, 'XMAS', 'XMAS Coupon', 'Coupon for Springbreak removing 10% if you have a cart between 40.00€ and 400.00€ (excluded)', $description, 10.00, true, true, true, true, 254, $date->setTimestamp(strtotime("today + 3 months")) ); + $coupon->set($stubFacade, 'XMAS', 'XMAS Coupon', 'Coupon for Springbreak removing 10% if you have a cart between 40.00€ and 400.00€ (excluded)', $description, array('amount' => 0.00, 'percentage' => 10.00), true, true, true, true, 254, $date->setTimestamp(strtotime("today + 3 months")) ); $condition1 = new MatchForTotalAmount($stubFacade); $operators = array( @@ -160,6 +156,8 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase $this->assertEquals(254, $coupon->getMaxUsage()); $this->assertEquals($date, $coupon->getExpirationDate()); + $this->assertEquals(array(RemoveXPercent::INPUT_PERCENTAGE_NAME), $coupon->getExtendedInputs()); + $this->assertEquals(40.00, $coupon->exec()); } @@ -194,6 +192,22 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expected, $actual); } + /** + * @covers Thelia\Coupon\Type\RemoveXPercent::getToolTip + */ + public function testGetInputName() + { + $inputName = 'Percentage removed from the cart'; + $stubFacade = $this->generateFacadeStub(399, 'EUR', $inputName); + + /** @var FacadeInterface $stubFacade */ + $coupon = new RemoveXPercent($stubFacade); + + $actual = $coupon->getInputName(); + $expected = $inputName; + $this->assertEquals($expected, $actual); + } + /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. diff --git a/install/faker.php b/install/faker.php index 30a55f397..3fd749ee1 100755 --- a/install/faker.php +++ b/install/faker.php @@ -7,6 +7,8 @@ use Thelia\Condition\Implementation\MatchForXArticles; use Thelia\Condition\Operators; use Thelia\Coupon\FacadeInterface; use Thelia\Condition\ConditionCollection; +use Thelia\Coupon\Type\RemoveXAmount; +use Thelia\Coupon\Type\RemoveXPercent; require __DIR__ . '/../core/bootstrap.php'; @@ -663,7 +665,9 @@ Duis interdum lectus nulla, nec pellentesque sapien condimentum at. Suspendisse Praesent ligula lorem, faucibus ut metus quis, fermentum iaculis erat. Pellentesque elit erat, lacinia sed semper ac, sagittis vel elit. Nam eu convallis est. Curabitur rhoncus odio vitae consectetur pellentesque. Nam vitae arcu nec ante scelerisque dignissim vel nec neque. Suspendisse augue nulla, mollis eget dui et, tempor facilisis erat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi ac diam ipsum. Donec convallis dui ultricies velit auctor, non lobortis nulla ultrices. Morbi vitae dignissim ante, sit amet lobortis tortor. Nunc dapibus condimentum augue, in molestie neque congue non. Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesuada tortor vel erat volutpat tincidunt. In vehicula diam est, a convallis eros scelerisque ut. Donec aliquet venenatis iaculis. Ut a arcu gravida, placerat dui eu, iaculis nisl. Quisque adipiscing orci sit amet dui dignissim lacinia. Sed vulputate lorem non dolor adipiscing ornare. Morbi ornare id nisl id aliquam. Ut fringilla elit ante, nec lacinia enim fermentum sit amet. Aenean rutrum lorem eu convallis pharetra. Cras malesuada varius metus, vitae gravida velit. Nam a varius ipsum, ac commodo dolor. Phasellus nec elementum elit. Etiam vel adipiscing leo.'); - $coupon1->setAmount(10.00); + $coupon1->setEffects(array( + RemoveXAmount::INPUT_AMOUNT_NAME => 10.00, + )); $coupon1->setIsUsed(true); $coupon1->setIsEnabled(true); $date = new \DateTime(); @@ -721,7 +725,10 @@ Duis interdum lectus nulla, nec pellentesque sapien condimentum at. Suspendisse Praesent ligula lorem, faucibus ut metus quis, fermentum iaculis erat. Pellentesque elit erat, lacinia sed semper ac, sagittis vel elit. Nam eu convallis est. Curabitur rhoncus odio vitae consectetur pellentesque. Nam vitae arcu nec ante scelerisque dignissim vel nec neque. Suspendisse augue nulla, mollis eget dui et, tempor facilisis erat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi ac diam ipsum. Donec convallis dui ultricies velit auctor, non lobortis nulla ultrices. Morbi vitae dignissim ante, sit amet lobortis tortor. Nunc dapibus condimentum augue, in molestie neque congue non. Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesuada tortor vel erat volutpat tincidunt. In vehicula diam est, a convallis eros scelerisque ut. Donec aliquet venenatis iaculis. Ut a arcu gravida, placerat dui eu, iaculis nisl. Quisque adipiscing orci sit amet dui dignissim lacinia. Sed vulputate lorem non dolor adipiscing ornare. Morbi ornare id nisl id aliquam. Ut fringilla elit ante, nec lacinia enim fermentum sit amet. Aenean rutrum lorem eu convallis pharetra. Cras malesuada varius metus, vitae gravida velit. Nam a varius ipsum, ac commodo dolor. Phasellus nec elementum elit. Etiam vel adipiscing leo.'); - $coupon2->setAmount(10.00); + $coupon2->setEffects(array( + RemoveXPercent::INPUT_AMOUNT_NAME => 0.00, + RemoveXPercent::INPUT_PERCENTAGE_NAME => 10.00, + )); $coupon2->setIsUsed(true); $coupon2->setIsEnabled(true); $date = new \DateTime(); @@ -765,7 +772,10 @@ Duis interdum lectus nulla, nec pellentesque sapien condimentum at. Suspendisse Praesent ligula lorem, faucibus ut metus quis, fermentum iaculis erat. Pellentesque elit erat, lacinia sed semper ac, sagittis vel elit. Nam eu convallis est. Curabitur rhoncus odio vitae consectetur pellentesque. Nam vitae arcu nec ante scelerisque dignissim vel nec neque. Suspendisse augue nulla, mollis eget dui et, tempor facilisis erat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi ac diam ipsum. Donec convallis dui ultricies velit auctor, non lobortis nulla ultrices. Morbi vitae dignissim ante, sit amet lobortis tortor. Nunc dapibus condimentum augue, in molestie neque congue non. Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesuada tortor vel erat volutpat tincidunt. In vehicula diam est, a convallis eros scelerisque ut. Donec aliquet venenatis iaculis. Ut a arcu gravida, placerat dui eu, iaculis nisl. Quisque adipiscing orci sit amet dui dignissim lacinia. Sed vulputate lorem non dolor adipiscing ornare. Morbi ornare id nisl id aliquam. Ut fringilla elit ante, nec lacinia enim fermentum sit amet. Aenean rutrum lorem eu convallis pharetra. Cras malesuada varius metus, vitae gravida velit. Nam a varius ipsum, ac commodo dolor. Phasellus nec elementum elit. Etiam vel adipiscing leo.'); - $coupon3->setAmount(10.00); + $coupon3->setEffects(array( + RemoveXPercent::INPUT_AMOUNT_NAME => 0.00, + RemoveXPercent::INPUT_PERCENTAGE_NAME => 10.00, + )); $coupon3->setIsUsed(false); $coupon3->setIsEnabled(false); $date = new \DateTime(); diff --git a/install/thelia.sql b/install/thelia.sql index 1d0ecfb63..bf3b2dd15 100755 --- a/install/thelia.sql +++ b/install/thelia.sql @@ -1084,7 +1084,7 @@ CREATE TABLE `coupon` `id` INTEGER NOT NULL AUTO_INCREMENT, `code` VARCHAR(45) NOT NULL, `type` VARCHAR(255) NOT NULL, - `amount` FLOAT NOT NULL, + `serialized_effects` TEXT NOT NULL, `is_enabled` TINYINT(1) NOT NULL, `expiration_date` DATETIME NOT NULL, `max_usage` INTEGER NOT NULL, @@ -1101,7 +1101,6 @@ CREATE TABLE `coupon` INDEX `idx_is_enabled` (`is_enabled`), INDEX `idx_is_used` (`is_used`), INDEX `idx_type` (`type`), - INDEX `idx_amount` (`amount`), INDEX `idx_expiration_date` (`expiration_date`), INDEX `idx_is_cumulative` (`is_cumulative`), INDEX `idx_is_removing_postage` (`is_removing_postage`), @@ -2385,7 +2384,7 @@ CREATE TABLE `coupon_version` `id` INTEGER NOT NULL, `code` VARCHAR(45) NOT NULL, `type` VARCHAR(255) NOT NULL, - `amount` FLOAT NOT NULL, + `serialized_effects` TEXT NOT NULL, `is_enabled` TINYINT(1) NOT NULL, `expiration_date` DATETIME NOT NULL, `max_usage` INTEGER NOT NULL, diff --git a/local/config/schema.xml b/local/config/schema.xml index 1613abafc..08322de99 100755 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -1,4 +1,4 @@ - + @@ -852,7 +852,7 @@ - + @@ -876,9 +876,6 @@ - - - diff --git a/templates/backOffice/default/assets/js/coupon.js b/templates/backOffice/default/assets/js/coupon.js index 2c412765a..5cb00acbe 100755 --- a/templates/backOffice/default/assets/js/coupon.js +++ b/templates/backOffice/default/assets/js/coupon.js @@ -127,13 +127,43 @@ $(function($){ }; $.couponManager.onClickUpdateCondition(); + $.couponManager.displayEfffect = function(optionSelected) { + var mainDiv = $('#coupon-type'); + mainDiv.find('.typeToolTip').html(optionSelected.attr('data-description')); + + var inputsDiv = mainDiv.find('.inputs'); + inputsDiv.html('
'); + var url = $.couponManager.urlAjaxAdminCouponDrawInputs; + console.log(url); + url = url.replace('couponServiceId', optionSelected.val()); + console.log(url); + $.ajax({ + type: "GET", + url: url, + data: '', + statusCode: { + 404: function() { + inputsDiv.html($.couponManager.intlPleaseRetry); + }, + 500: function() { + inputsDiv.html($.couponManager.intlPleaseRetry); + } + } + }).done(function(data) { + inputsDiv.html(data); + }); + }; + // Reload effect inputs when changing effect $.couponManager.onEffectChange = function() { - var optionSelected = $("option:selected", this); - $('#effectToolTip').html(optionSelected.attr("data-description")); - $('#effect').on('change', function () { - var optionSelected = $("option:selected", this); - $('#effectToolTip').html(optionSelected.attr("data-description")); + var mainDiv = $('#coupon-type'); + var optionSelected = mainDiv.find('#type option:selected'); + mainDiv.find('.typeToolTip').html(optionSelected.attr('data-description')); + + mainDiv.find('#type').on('change', function () { + var optionSelected = $('option:selected', this); + $.couponManager.displayEfffect(optionSelected); + }); }; $.couponManager.onEffectChange(); diff --git a/templates/backOffice/default/coupon-create.html b/templates/backOffice/default/coupon-create.html index 691067be2..2eaf30990 100755 --- a/templates/backOffice/default/coupon-create.html +++ b/templates/backOffice/default/coupon-create.html @@ -59,6 +59,12 @@ filemanager_title:"{intl l='Files manager'}" , external_plugins: { "filemanager" : "{url file='/tinymce/plugins/filemanager/plugin.min.js'}"} }); + + $(function($){ + // Url alowing to get coupon inputs + $.couponManager.urlAjaxAdminCouponDrawInputs = "{$urlAjaxAdminCouponDrawInputs}"; + $.couponManager.intlPleaseRetry = '{intl l='Please retry'}'; + }); {/block} diff --git a/templates/backOffice/default/coupon-update.html b/templates/backOffice/default/coupon-update.html index 68cfb6a90..457d27d67 100755 --- a/templates/backOffice/default/coupon-update.html +++ b/templates/backOffice/default/coupon-update.html @@ -36,6 +36,8 @@ {/javascripts} + {javascripts file='assets/js/coupon.js'} {/javascripts} @@ -62,6 +64,10 @@ $(function($){ // miniBrowser(0, '/test_to_remove/datas_coupon_edit.json'); + // Url alowing to get coupon inputs + $.couponManager.urlAjaxAdminCouponDrawInputs = "{$urlAjaxAdminCouponDrawInputs}"; + $.couponManager.intlPleaseRetry = '{intl l='Please retry'}'; + // Init Conditions $.couponManager.initConditions = function() { var conditions = []; diff --git a/templates/backOffice/default/coupon/form.html b/templates/backOffice/default/coupon/form.html index d2642657f..1fb0438a3 100755 --- a/templates/backOffice/default/coupon/form.html +++ b/templates/backOffice/default/coupon/form.html @@ -99,32 +99,28 @@
-
+
{form_field form=$form field='type'}
{if $error}{$message}{/if} - {$availableCoupons.0.toolTip} + {$availableCoupons.0.toolTip}
{/form_field}
-
+
{form_field form=$form field='amount'} -
- - - {if $error}{$message}{/if} -
+ {$couponInputsHtml nofilter} {/form_field} {*
*} {**} @@ -208,7 +204,7 @@