From 85d80d1d7712549d983bda8c953b07a5a06b8d67 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 9 May 2014 10:55:50 +0200 Subject: [PATCH] fix minor bug --- core/lib/Thelia/Action/Currency.php | 2 - core/lib/Thelia/Action/Order.php | 2 +- .../Command/ModuleDeactivateCommand.php | 0 .../Implementation/ConditionAbstract.php | 2 +- .../Implementation/MatchForTotalAmount.php | 2 +- .../Implementation/MatchForXArticles.php | 2 +- core/lib/Thelia/Condition/Operators.php | 2 +- core/lib/Thelia/Config/I18n/cs_CZ.php | 2 +- core/lib/Thelia/Config/I18n/ru_RU.php | 2 +- .../Controller/Admin/CouponController.php | 5 +- .../Controller/Admin/ProductController.php | 1 + .../Controller/Admin/ProfileController.php | 1 + .../Controller/Admin/SessionController.php | 2 +- .../Controller/Admin/TaxRuleController.php | 1 + .../Core/Event/Lang/LangCreateEvent.php | 2 - .../ProductSaleElementEvent.php | 2 +- .../Core/Factory/ActionEventFactory.php | 71 --- core/lib/Thelia/Core/Template/Loop/Coupon.php | 8 +- .../Thelia/Core/Template/Loop/OrderCoupon.php | 2 +- .../lib/Thelia/Core/Template/Loop/Product.php | 2 +- .../Template/Smarty/Plugins/TheliaLoop.php | 2 - .../lib/Thelia/Coupon/Type/CouponAbstract.php | 3 +- core/lib/Thelia/Form/CouponCreationForm.php | 2 +- .../Thelia/Model/AreaDeliveryModuleQuery.php | 1 - core/lib/Thelia/Model/Content.php | 18 +- core/lib/Thelia/Model/Coupon.php | 404 +++++++++--------- core/lib/Thelia/Model/Product.php | 2 +- core/lib/Thelia/Model/ProductSaleElements.php | 1 + core/lib/Thelia/Model/Tax.php | 1 + .../Model/Tools/PositionManagementTrait.php | 4 +- .../Tests/Core/Template/Loop/ContentTest.php | 1 - 31 files changed, 243 insertions(+), 309 deletions(-) mode change 100755 => 100644 core/lib/Thelia/Command/ModuleDeactivateCommand.php delete mode 100644 core/lib/Thelia/Core/Factory/ActionEventFactory.php diff --git a/core/lib/Thelia/Action/Currency.php b/core/lib/Thelia/Action/Currency.php index 0a79e37be..36a664cca 100644 --- a/core/lib/Thelia/Action/Currency.php +++ b/core/lib/Thelia/Action/Currency.php @@ -59,8 +59,6 @@ class Currency extends BaseAction implements EventSubscriberInterface */ public function update(CurrencyUpdateEvent $event) { - $search = CurrencyQuery::create(); - if (null !== $currency = CurrencyQuery::create()->findPk($event->getCurrencyId())) { $currency diff --git a/core/lib/Thelia/Action/Order.php b/core/lib/Thelia/Action/Order.php index 7d27167cc..bd8534219 100644 --- a/core/lib/Thelia/Action/Order.php +++ b/core/lib/Thelia/Action/Order.php @@ -302,7 +302,7 @@ class Order extends BaseAction implements EventSubscriberInterface */ public function createManual(OrderManualEvent $event) { - $placedOrder = $this->createOrder( + $this->createOrder( $event->getDispatcher(), $event->getOrder(), $event->getCurrency(), diff --git a/core/lib/Thelia/Command/ModuleDeactivateCommand.php b/core/lib/Thelia/Command/ModuleDeactivateCommand.php old mode 100755 new mode 100644 diff --git a/core/lib/Thelia/Condition/Implementation/ConditionAbstract.php b/core/lib/Thelia/Condition/Implementation/ConditionAbstract.php index bae7fcf31..e5ebd6746 100644 --- a/core/lib/Thelia/Condition/Implementation/ConditionAbstract.php +++ b/core/lib/Thelia/Condition/Implementation/ConditionAbstract.php @@ -308,4 +308,4 @@ abstract class ConditionAbstract implements ConditionInterface ] ); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Condition/Implementation/MatchForTotalAmount.php b/core/lib/Thelia/Condition/Implementation/MatchForTotalAmount.php index 6b4b48f15..26939193c 100644 --- a/core/lib/Thelia/Condition/Implementation/MatchForTotalAmount.php +++ b/core/lib/Thelia/Condition/Implementation/MatchForTotalAmount.php @@ -271,4 +271,4 @@ class MatchForTotalAmount extends ConditionAbstract ] ); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Condition/Implementation/MatchForXArticles.php b/core/lib/Thelia/Condition/Implementation/MatchForXArticles.php index 0e7c9d832..6e9b0d459 100644 --- a/core/lib/Thelia/Condition/Implementation/MatchForXArticles.php +++ b/core/lib/Thelia/Condition/Implementation/MatchForXArticles.php @@ -225,4 +225,4 @@ class MatchForXArticles extends ConditionAbstract ] ); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Condition/Operators.php b/core/lib/Thelia/Condition/Operators.php index 0d0600967..58402719a 100644 --- a/core/lib/Thelia/Condition/Operators.php +++ b/core/lib/Thelia/Condition/Operators.php @@ -113,4 +113,4 @@ abstract class Operators return $ret; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Config/I18n/cs_CZ.php b/core/lib/Thelia/Config/I18n/cs_CZ.php index 634c0e768..000bd266d 100644 --- a/core/lib/Thelia/Config/I18n/cs_CZ.php +++ b/core/lib/Thelia/Config/I18n/cs_CZ.php @@ -1,4 +1,4 @@ drawBackOfficeInputs(); $serviceId = $condition->getServiceId(); - } - else { + } else { $html = ''; $serviceId = ''; } diff --git a/core/lib/Thelia/Controller/Admin/ProductController.php b/core/lib/Thelia/Controller/Admin/ProductController.php index 7ca94d73f..f4bfb095f 100644 --- a/core/lib/Thelia/Controller/Admin/ProductController.php +++ b/core/lib/Thelia/Controller/Admin/ProductController.php @@ -38,6 +38,7 @@ use Thelia\Core\Event\ProductSaleElement\ProductSaleElementCreateEvent; use Thelia\Core\Security\Resource\AdminResources; use Thelia\Core\Security\AccessManager; +use Thelia\Form\Exception\FormValidationException; use Thelia\Model\AccessoryQuery; use Thelia\Model\CategoryQuery; use Thelia\Model\FeatureQuery; diff --git a/core/lib/Thelia/Controller/Admin/ProfileController.php b/core/lib/Thelia/Controller/Admin/ProfileController.php index 261376f21..3da511192 100644 --- a/core/lib/Thelia/Controller/Admin/ProfileController.php +++ b/core/lib/Thelia/Controller/Admin/ProfileController.php @@ -16,6 +16,7 @@ use Thelia\Core\Security\AccessManager; use Thelia\Core\Security\Resource\AdminResources; use Thelia\Core\Event\Profile\ProfileEvent; use Thelia\Core\Event\TheliaEvents; +use Thelia\Form\Exception\FormValidationException; use Thelia\Form\ProfileCreationForm; use Thelia\Form\ProfileModificationForm; use Thelia\Form\ProfileUpdateModuleAccessForm; diff --git a/core/lib/Thelia/Controller/Admin/SessionController.php b/core/lib/Thelia/Controller/Admin/SessionController.php index 07e716354..381588dc5 100644 --- a/core/lib/Thelia/Controller/Admin/SessionController.php +++ b/core/lib/Thelia/Controller/Admin/SessionController.php @@ -113,7 +113,7 @@ class SessionController extends BaseAdminController /** * we have tou find a way to send cookie */ - if (intval($adminLoginForm->getForm()->get('remember_me')->getData()) > 0) { + if (intval($form->get('remember_me')->getData()) > 0) { // If a remember me field if present and set in the form, create // the cookie thant store "remember me" information $this->createAdminRememberMeCookie($user); diff --git a/core/lib/Thelia/Controller/Admin/TaxRuleController.php b/core/lib/Thelia/Controller/Admin/TaxRuleController.php index dbbbd3eb8..57b4263dd 100644 --- a/core/lib/Thelia/Controller/Admin/TaxRuleController.php +++ b/core/lib/Thelia/Controller/Admin/TaxRuleController.php @@ -16,6 +16,7 @@ use Thelia\Core\Security\Resource\AdminResources; use Thelia\Core\Event\Tax\TaxRuleEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Security\AccessManager; +use Thelia\Form\Exception\FormValidationException; use Thelia\Form\TaxRuleCreationForm; use Thelia\Form\TaxRuleModificationForm; use Thelia\Form\TaxRuleTaxListUpdateForm; diff --git a/core/lib/Thelia/Core/Event/Lang/LangCreateEvent.php b/core/lib/Thelia/Core/Event/Lang/LangCreateEvent.php index 0b0c35bdc..1ee29770d 100644 --- a/core/lib/Thelia/Core/Event/Lang/LangCreateEvent.php +++ b/core/lib/Thelia/Core/Event/Lang/LangCreateEvent.php @@ -182,6 +182,4 @@ class LangCreateEvent extends LangEvent return $this->thousands_separator; } - - } diff --git a/core/lib/Thelia/Core/Event/ProductSaleElement/ProductSaleElementEvent.php b/core/lib/Thelia/Core/Event/ProductSaleElement/ProductSaleElementEvent.php index 4c3f6be85..4b598da5f 100644 --- a/core/lib/Thelia/Core/Event/ProductSaleElement/ProductSaleElementEvent.php +++ b/core/lib/Thelia/Core/Event/ProductSaleElement/ProductSaleElementEvent.php @@ -19,7 +19,7 @@ class ProductSaleElementEvent extends ActionEvent { public $product_sale_element = null; - public function __construct(ProductSaleElement $product_sale_element = null) + public function __construct(ProductSaleElements $product_sale_element = null) { $this->product_sale_element = $product_sale_element; } diff --git a/core/lib/Thelia/Core/Factory/ActionEventFactory.php b/core/lib/Thelia/Core/Factory/ActionEventFactory.php deleted file mode 100644 index d34838124..000000000 --- a/core/lib/Thelia/Core/Factory/ActionEventFactory.php +++ /dev/null @@ -1,71 +0,0 @@ - - */ -class ActionEventFactory -{ - - /** - * @var \Symfony\Component\HttpFoundation\Request - */ - protected $request; - - /** - * @var string - */ - protected $action; - - /** - * array( - * "action.addCart" => "Thelia\Core\Event\CartAction" - * ) - * - * @var array key are action name and value the Event class to dispatch - */ - protected $className; - - protected $defaultClassName = "Thelia\Core\Event\DefaultActionEvent"; - - public function __construct(Request $request, $action, $className) - { - $this->request = $request; - $this->action = $action; - $this->className = $className; - } - - public function createActionEvent() - { - if (array_key_exists($this->action, $this->className)) { - $class = new \ReflectionClass($this->className[$this->action]); - // return $class->newInstance($this->request, $this->action); - } else { - $class = new \ReflectionClass($this->defaultClassName); - } - - if ($class->isSubclassOf("Thelia\Core\Event\ActionEvent") === false) { - throw new \RuntimeException("%s must be a subclass of Thelia\Core\Event\ActionEvent", $class->getName()); - } - - return $class->newInstance($this->request, $this->action); - } -} diff --git a/core/lib/Thelia/Core/Template/Loop/Coupon.php b/core/lib/Thelia/Core/Template/Loop/Coupon.php index 6885463eb..7d0a3899d 100644 --- a/core/lib/Thelia/Core/Template/Loop/Coupon.php +++ b/core/lib/Thelia/Core/Template/Loop/Coupon.php @@ -53,10 +53,10 @@ class Coupon extends BaseI18nLoop implements PropelSearchLoopInterface new TypeCollection( new EnumListType(array( 'id', 'id-reverse', - 'code', 'code-reverse', - 'title', 'title-reverse', - 'enabled', 'enabled-reverse', - 'expiration-date', 'expiration-date-reverse', + 'code', 'code-reverse', + 'title', 'title-reverse', + 'enabled', 'enabled-reverse', + 'expiration-date', 'expiration-date-reverse', 'days-left', 'days-left-reverse', 'usages-left', 'usages-left-reverse' ) diff --git a/core/lib/Thelia/Core/Template/Loop/OrderCoupon.php b/core/lib/Thelia/Core/Template/Loop/OrderCoupon.php index 25bf4a614..f6e08e3cc 100644 --- a/core/lib/Thelia/Core/Template/Loop/OrderCoupon.php +++ b/core/lib/Thelia/Core/Template/Loop/OrderCoupon.php @@ -62,7 +62,7 @@ class OrderCoupon extends BaseLoop implements PropelSearchLoopInterface public function parseResults(LoopResult $loopResult) { - $conditionFactory = $this->container->get('thelia.condition.factory'); + $this->container->get('thelia.condition.factory'); /** @var OrderCoupon $orderCoupon */ foreach ($loopResult->getResultDataCollection() as $orderCoupon) { diff --git a/core/lib/Thelia/Core/Template/Loop/Product.php b/core/lib/Thelia/Core/Template/Loop/Product.php index 70348626b..e90f6b463 100644 --- a/core/lib/Thelia/Core/Template/Loop/Product.php +++ b/core/lib/Thelia/Core/Template/Loop/Product.php @@ -857,7 +857,7 @@ class Product extends BaseI18nLoop implements PropelSearchLoopInterface, SearchL $visible = $this->getVisible(); - if ($visible !== BooleanOrBothType::ANY) $search->filterByVisible($visible ? 1 : 0); + if ($visible !== Type\BooleanOrBothType::ANY) $search->filterByVisible($visible ? 1 : 0); $exclude = $this->getExclude(); diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php index dfc31e3fd..bf3538002 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php @@ -96,8 +96,6 @@ class TheliaLoop extends AbstractSmartyPlugin $loop = $this->createLoopInstance($params); - $dummy = null; - return $loop->count(); } diff --git a/core/lib/Thelia/Coupon/Type/CouponAbstract.php b/core/lib/Thelia/Coupon/Type/CouponAbstract.php index 5a2c5f03a..dee230edc 100644 --- a/core/lib/Thelia/Coupon/Type/CouponAbstract.php +++ b/core/lib/Thelia/Coupon/Type/CouponAbstract.php @@ -354,7 +354,8 @@ abstract class CouponAbstract implements CouponInterface * * @return string HTML string */ - public function drawBackOfficeInputs() { + public function drawBackOfficeInputs() + { return $this->facade->getParser()->render('coupon/type-fragments/remove-x.html', [ 'label' => $this->getInputName(), 'fieldName' => self::INPUT_AMOUNT_NAME, diff --git a/core/lib/Thelia/Form/CouponCreationForm.php b/core/lib/Thelia/Form/CouponCreationForm.php index a42ad85da..dbd271e50 100644 --- a/core/lib/Thelia/Form/CouponCreationForm.php +++ b/core/lib/Thelia/Form/CouponCreationForm.php @@ -145,7 +145,7 @@ class CouponCreationForm extends BaseForm /** * Validate a date entered with the default Language date format. * - * @param string $value + * @param string $value * @param ExecutionContextInterface $context */ public function checkLocalizedDate($value, ExecutionContextInterface $context) diff --git a/core/lib/Thelia/Model/AreaDeliveryModuleQuery.php b/core/lib/Thelia/Model/AreaDeliveryModuleQuery.php index dfb58e863..d4570b5a3 100644 --- a/core/lib/Thelia/Model/AreaDeliveryModuleQuery.php +++ b/core/lib/Thelia/Model/AreaDeliveryModuleQuery.php @@ -17,7 +17,6 @@ use Thelia\Model\Base\AreaDeliveryModuleQuery as BaseAreaDeliveryModuleQuery; class AreaDeliveryModuleQuery extends BaseAreaDeliveryModuleQuery { - public function findByCountryAndModule(Country $country, Module $module) { $response = null; diff --git a/core/lib/Thelia/Model/Content.php b/core/lib/Thelia/Model/Content.php index d40ba286a..2a7936fe6 100644 --- a/core/lib/Thelia/Model/Content.php +++ b/core/lib/Thelia/Model/Content.php @@ -56,9 +56,21 @@ class Content extends BaseContent public function setDefaultFolder($folderId) { -/* ContentFolderQuery::create() - ->filterByContentId($this->getId) - ->update(array("DefaultFolder" => 0));*/ + // Unset previous category + ContentFolderQuery::create() + ->filterByContentId($this->getId()) + ->filterByDefaultFolder(true) + ->find() + ->setByDefault(false) + ->save(); + + // Set new default category + ContentFolderQuery::create() + ->filterByContentId($this->getId()) + ->filterByFolderId($folderId) + ->find() + ->setByDefault(true) + ->save(); return $this; } diff --git a/core/lib/Thelia/Model/Coupon.php b/core/lib/Thelia/Model/Coupon.php index cced6beb7..b94a08f62 100644 --- a/core/lib/Thelia/Model/Coupon.php +++ b/core/lib/Thelia/Model/Coupon.php @@ -1,203 +1,201 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Model; - -use Propel\Runtime\Propel; -use Thelia\Model\Base\Coupon as BaseCoupon; -use Thelia\Model\Exception\InvalidArgumentException; -use Thelia\Model\Map\CouponTableMap; - -/** - * 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) - * - * @package Coupon - * @author Guillaume MOREL - * - */ -class Coupon extends BaseCoupon -{ - - use \Thelia\Model\Tools\ModelEventDispatcherTrait; - - /** - * Create or Update this Coupon - * - * @param string $code Coupon Code - * @param string $title Coupon title - * @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 - * @param string $description Coupon description - * @param boolean $isEnabled Enable/Disable - * @param \DateTime $expirationDate Coupon expiration date - * @param boolean $isAvailableOnSpecialOffers Is available on special offers - * @param boolean $isCumulative Is cumulative - * @param int $maxUsage Coupon quantity - * @param string $defaultSerializedRule Serialized default rule added if none found - * @param string $locale Coupon Language code ISO (ex: fr_FR) - * - * @throws \Exception - */ - public function createOrUpdate($code, $title, array $effects, $type, $isRemovingPostage, $shortDescription, $description, $isEnabled, $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $maxUsage, $defaultSerializedRule, $locale = null) - { - $this - ->setCode($code) - ->setType($type) - ->setEffects($effects) - ->setIsRemovingPostage($isRemovingPostage) - ->setIsEnabled($isEnabled) - ->setExpirationDate($expirationDate) - ->setIsAvailableOnSpecialOffers($isAvailableOnSpecialOffers) - ->setIsCumulative($isCumulative) - ->setMaxUsage($maxUsage) - ->setLocale($locale) - ->setTitle($title) - ->setShortDescription($shortDescription) - ->setDescription($description); - - // If no rule given, set default rule - if (null === $this->getSerializedConditions()) { - $this->setSerializedConditions($defaultSerializedRule); - } - - $this->save(); - } - - /** - * Create or Update this coupon condition - * - * @param string $serializableConditions Serialized conditions ready to be saved - * @param string $locale Coupon Language code ISO (ex: fr_FR) - * - * @throws \Exception - */ - public function createOrUpdateConditions($serializableConditions, $locale) - { - $this->setSerializedConditions($serializableConditions); - - // Set object language (i18n) - if (!is_null($locale)) { - $this->setLocale($locale); - } - - $this->save(); - } - - /** - * 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; - } -} +. */ +/* */ +/**********************************************************************************/ + +namespace Thelia\Model; + +use Thelia\Model\Base\Coupon as BaseCoupon; +use Thelia\Model\Exception\InvalidArgumentException; + +/** + * 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) + * + * @package Coupon + * @author Guillaume MOREL + * + */ +class Coupon extends BaseCoupon +{ + + use \Thelia\Model\Tools\ModelEventDispatcherTrait; + + /** + * Create or Update this Coupon + * + * @param string $code Coupon Code + * @param string $title Coupon title + * @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 + * @param string $description Coupon description + * @param boolean $isEnabled Enable/Disable + * @param \DateTime $expirationDate Coupon expiration date + * @param boolean $isAvailableOnSpecialOffers Is available on special offers + * @param boolean $isCumulative Is cumulative + * @param int $maxUsage Coupon quantity + * @param string $defaultSerializedRule Serialized default rule added if none found + * @param string $locale Coupon Language code ISO (ex: fr_FR) + * + * @throws \Exception + */ + public function createOrUpdate($code, $title, array $effects, $type, $isRemovingPostage, $shortDescription, $description, $isEnabled, $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $maxUsage, $defaultSerializedRule, $locale = null) + { + $this + ->setCode($code) + ->setType($type) + ->setEffects($effects) + ->setIsRemovingPostage($isRemovingPostage) + ->setIsEnabled($isEnabled) + ->setExpirationDate($expirationDate) + ->setIsAvailableOnSpecialOffers($isAvailableOnSpecialOffers) + ->setIsCumulative($isCumulative) + ->setMaxUsage($maxUsage) + ->setLocale($locale) + ->setTitle($title) + ->setShortDescription($shortDescription) + ->setDescription($description); + + // If no rule given, set default rule + if (null === $this->getSerializedConditions()) { + $this->setSerializedConditions($defaultSerializedRule); + } + + $this->save(); + } + + /** + * Create or Update this coupon condition + * + * @param string $serializableConditions Serialized conditions ready to be saved + * @param string $locale Coupon Language code ISO (ex: fr_FR) + * + * @throws \Exception + */ + public function createOrUpdateConditions($serializableConditions, $locale) + { + $this->setSerializedConditions($serializableConditions); + + // Set object language (i18n) + if (!is_null($locale)) { + $this->setLocale($locale); + } + + $this->save(); + } + + /** + * 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/Product.php b/core/lib/Thelia/Model/Product.php index 2eb3fb584..4028ef680 100644 --- a/core/lib/Thelia/Model/Product.php +++ b/core/lib/Thelia/Model/Product.php @@ -172,7 +172,7 @@ class Product extends BaseProduct $this->setTaxRuleId($taxRuleId); // Create the default product sale element of this product - $sale_elements = $this->createProductSaleElement($con, $baseWeight, $basePrice, $basePrice, $priceCurrencyId, true); + $this->createProductSaleElement($con, $baseWeight, $basePrice, $basePrice, $priceCurrencyId, true); // Store all the stuff ! $con->commit(); diff --git a/core/lib/Thelia/Model/ProductSaleElements.php b/core/lib/Thelia/Model/ProductSaleElements.php index 05398c041..724ea5cad 100644 --- a/core/lib/Thelia/Model/ProductSaleElements.php +++ b/core/lib/Thelia/Model/ProductSaleElements.php @@ -2,6 +2,7 @@ namespace Thelia\Model; +use Propel\Runtime\Exception\PropelException; use Thelia\Model\Base\ProductSaleElements as BaseProductSaleElements; use Thelia\Model\Tools\ProductPriceTools; use Thelia\TaxEngine\Calculator; diff --git a/core/lib/Thelia/Model/Tax.php b/core/lib/Thelia/Model/Tax.php index 69c3a3f23..654d3a31f 100644 --- a/core/lib/Thelia/Model/Tax.php +++ b/core/lib/Thelia/Model/Tax.php @@ -2,6 +2,7 @@ namespace Thelia\Model; +use Propel\Runtime\Exception\PropelException; use Thelia\Exception\TaxEngineException; use Thelia\Model\Base\Tax as BaseTax; use Thelia\Model\Tools\ModelEventDispatcherTrait; diff --git a/core/lib/Thelia/Model/Tools/PositionManagementTrait.php b/core/lib/Thelia/Model/Tools/PositionManagementTrait.php index 66ef33621..cc66bbc75 100644 --- a/core/lib/Thelia/Model/Tools/PositionManagementTrait.php +++ b/core/lib/Thelia/Model/Tools/PositionManagementTrait.php @@ -119,7 +119,7 @@ trait PositionManagementTrait $result->setDispatcher($this->getDispatcher())->setPosition($my_position)->save($cnx); $cnx->commit(); - } catch (Exception $e) { + } catch (\Exception $e) { $cnx->rollback(); } } @@ -185,7 +185,7 @@ trait PositionManagementTrait ; $cnx->commit(); - } catch (Exception $e) { + } catch (\Exception $e) { $cnx->rollback(); } } diff --git a/core/lib/Thelia/Tests/Core/Template/Loop/ContentTest.php b/core/lib/Thelia/Tests/Core/Template/Loop/ContentTest.php index c650ad7c6..2294ce3ca 100755 --- a/core/lib/Thelia/Tests/Core/Template/Loop/ContentTest.php +++ b/core/lib/Thelia/Tests/Core/Template/Loop/ContentTest.php @@ -44,7 +44,6 @@ class ContentTest extends BaseLoopTestor $content = ContentQuery::create()->findOne(); if (null === $content) { $content = new \Thelia\Model\Content(); - $content->setDefaultFolder(0); $content->setVisible(1); $content->setTitle('foo'); $content->save();