diff --git a/core/lib/Thelia/Controller/Admin/CouponController.php b/core/lib/Thelia/Controller/Admin/CouponController.php index 19c57eb6d..d73830308 100755 --- a/core/lib/Thelia/Controller/Admin/CouponController.php +++ b/core/lib/Thelia/Controller/Admin/CouponController.php @@ -87,14 +87,35 @@ class CouponController extends BaseAdminController if ($this->getRequest()->isMethod('POST')) { try { - $couponCreationForm = new CouponCreationForm($this->getRequest()); - $couponBeingCreated = $this->buildCouponFromForm( - $this->validateForm($couponCreationForm, "POST")->getData() - ); + // Create the form from the request + $creationForm = new CouponCreationForm(Form($this->getRequest())); - $couponCreateEvent = new CouponCreateEvent( - $couponBeingCreated + // Check the form against constraints violations + $form = $this->validateForm($creationForm, "POST"); + + // Get the form field values + $data = $form->getData(); + + var_dump($data); + + $couponCreateEvent = new CouponCreateEvent(); + $couponCreateEvent->setTitle($data['title']); + $couponCreateEvent->setShortDescription($data['shortDescription']); + $couponCreateEvent->setDescription($data['longDescription']); + $couponCreateEvent->setCode($data['code']); + $couponCreateEvent->setAmount($data['amount']); + + $couponCreateEvent->setExpirationDate( + new \DateTime($data['expirationDate']) ); + $couponCreateEvent->setMaxUsage($data['maxUsage']); + $couponCreateEvent->setIsCumulative($data['isCumulative']); + $couponCreateEvent->setIsRemovingPostage($data['isRemovingPostage']); + $couponCreateEvent->setIsAvailableOnSpecialOffers($data['isAvailableOnSpecialOffers']); + + $couponCreateEvent->setIsEnabled($data['isEnabled']); + +// $couponCreateEvent->setRules($data['rules']); $this->dispatch( TheliaEvents::CREATE_COUPON, @@ -103,14 +124,14 @@ class CouponController extends BaseAdminController $this->adminLogAppend( sprintf( 'Coupon %s (ID %s) created', - $couponBeingCreated->getTitle(), - $couponBeingCreated->getId() + $couponCreateEvent->getTitle(), + $couponCreateEvent->getId() ) ); // @todo redirect if successful } catch (FormValidationException $e) { - $couponCreationForm->setErrorMessage($e->getMessage()); - $this->getParserContext()->setErrorForm($couponCreationForm); + $creationForm->setErrorMessage($e->getMessage()); + $this->getParserContext()->setErrorForm($creationForm); } catch (\Exception $e) { Tlog::getInstance()->error( sprintf( @@ -124,7 +145,7 @@ class CouponController extends BaseAdminController } - return $this->render('coupon/edit', array()); + return $this->render('coupon/create', array('action' => 'create')); } /** @@ -138,7 +159,7 @@ class CouponController extends BaseAdminController { $this->checkAuth("ADMIN", "admin.coupon.view"); - return $this->render('coupon/edit', $args); + return $this->render('coupon/update', $args); } /** diff --git a/core/lib/Thelia/Core/Event/Coupon/CouponCreateEvent.php b/core/lib/Thelia/Core/Event/Coupon/CouponCreateEvent.php index 7d6344733..42551432a 100644 --- a/core/lib/Thelia/Core/Event/Coupon/CouponCreateEvent.php +++ b/core/lib/Thelia/Core/Event/Coupon/CouponCreateEvent.php @@ -24,7 +24,6 @@ namespace Thelia\Core\Event\Coupon; use Thelia\Core\Event\ActionEvent; use Thelia\Coupon\CouponRuleCollection; -use Thelia\Model\Coupon; /** * Created by JetBrains PhpStorm. @@ -42,198 +41,6 @@ class CouponCreateEvent extends ActionEvent /** @var CouponRuleCollection Array of CouponRuleInterface */ protected $rules = null; - /** - * @param float $amount - */ - public function setAmount($amount) - { - $this->amount = $amount; - } - - /** - * @return float - */ - public function getAmount() - { - return $this->amount; - } - - /** - * @param string $code - */ - public function setCode($code) - { - $this->code = $code; - } - - /** - * @return string - */ - public function getCode() - { - return $this->code; - } - - /** - * @param string $description - */ - public function setDescription($description) - { - $this->description = $description; - } - - /** - * @return string - */ - public function getDescription() - { - return $this->description; - } - - /** - * @param \DateTime $expirationDate - */ - public function setExpirationDate($expirationDate) - { - $this->expirationDate = $expirationDate; - } - - /** - * @return \DateTime - */ - public function getExpirationDate() - { - return $this->expirationDate; - } - - /** - * @param boolean $isAvailableOnSpecialOffers - */ - public function setIsAvailableOnSpecialOffers($isAvailableOnSpecialOffers) - { - $this->isAvailableOnSpecialOffers = $isAvailableOnSpecialOffers; - } - - /** - * @return boolean - */ - public function getIsAvailableOnSpecialOffers() - { - return $this->isAvailableOnSpecialOffers; - } - - /** - * @param boolean $isCumulative - */ - public function setIsCumulative($isCumulative) - { - $this->isCumulative = $isCumulative; - } - - /** - * @return boolean - */ - public function getIsCumulative() - { - return $this->isCumulative; - } - - /** - * @param boolean $isEnabled - */ - public function setIsEnabled($isEnabled) - { - $this->isEnabled = $isEnabled; - } - - /** - * @return boolean - */ - public function getIsEnabled() - { - return $this->isEnabled; - } - - /** - * @param boolean $isRemovingPostage - */ - public function setIsRemovingPostage($isRemovingPostage) - { - $this->isRemovingPostage = $isRemovingPostage; - } - - /** - * @return boolean - */ - public function getIsRemovingPostage() - { - return $this->isRemovingPostage; - } - - /** - * @param int $maxUsage - */ - public function setMaxUsage($maxUsage) - { - $this->maxUsage = $maxUsage; - } - - /** - * @return int - */ - public function getMaxUsage() - { - return $this->maxUsage; - } - - /** - * @param \Thelia\Coupon\CouponRuleCollection $rules - */ - public function setRules($rules) - { - $this->rules = $rules; - } - - /** - * @return \Thelia\Coupon\CouponRuleCollection - */ - public function getRules() - { - return $this->rules; - } - - /** - * @param string $shortDescription - */ - public function setShortDescription($shortDescription) - { - $this->shortDescription = $shortDescription; - } - - /** - * @return string - */ - public function getShortDescription() - { - return $this->shortDescription; - } - - /** - * @param string $title - */ - public function setTitle($title) - { - $this->title = $title; - } - - /** - * @return string - */ - public function getTitle() - { - return $this->title; - } - /** @var string Coupon code (ex: XMAS) */ protected $code = null; @@ -267,4 +74,301 @@ class CouponCreateEvent extends ActionEvent /** @var bool if Coupon is available for Products already on special offers */ protected $isAvailableOnSpecialOffers = false; + /** + * Return Coupon code (ex: XMAS) + * + * @return string + */ + public function getCode() + { + return $this->code; + } + + /** + * Return Coupon title (ex: Coupon for XMAS) + * + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * Return Coupon short description + * + * @return string + */ + public function getShortDescription() + { + return $this->shortDescription; + } + + /** + * Return Coupon description + * + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * If Coupon is cumulative or prevent any accumulation + * If is cumulative you can sum Coupon effects + * If not cancel all other Coupon and take the last given + * + * @return bool + */ + public function isCumulative() + { + return $this->isCumulative; + } + + /** + * If Coupon is removing Checkout Postage + * + * @return bool + */ + public function isRemovingPostage() + { + return $this->isRemovingPostage; + } + + /** + * Return effects generated by the coupon + * + * @return float Amount removed from the Total Checkout + */ + public function getAmount() + { + return $this->amount; + } + + /** + * Return condition to validate the Coupon or not + * + * @return CouponRuleCollection + */ + public function getRules() + { + return clone $this->rules; + } + + /** + * Set effects generated by the coupon + * + * @param float $amount Amount removed from the Total Checkout + * + * @return $this + */ + public function setAmount($amount) + { + $this->amount = $amount; + + return $this; + } + + /** + * Set Coupon Code + * + * @param string $code Coupon Code + * + * @return $this + */ + public function setCode($code) + { + $this->code = $code; + + return $this; + } + + /** + * Set Coupon description + * + * @param string $description Coupon description + * + * @return $this + */ + public function setDescription($description) + { + $this->description = $description; + + return $this; + } + + /** + * Set Coupon expiration date (date given considered as expired) + * + * @param \DateTime $expirationDate Coupon expiration date + * + * @return $this + */ + public function setExpirationDate($expirationDate) + { + $this->expirationDate = $expirationDate; + + return $this; + } + + /** + * Return Coupon expiration date + * + * @return \DateTime + */ + public function getExpirationDate() + { + return clone $this->expirationDate; + } + + /** + * Set if Coupon is available on special offers + * + * @param boolean $isAvailableOnSpecialOffers is available on special offers + * + * @return $this + */ + public function setIsAvailableOnSpecialOffers($isAvailableOnSpecialOffers) + { + $this->isAvailableOnSpecialOffers = $isAvailableOnSpecialOffers; + + return $this; + } + + /** + * If Coupon is available on special offers + * + * @return boolean + */ + public function getIsAvailableOnSpecialOffers() + { + return $this->isAvailableOnSpecialOffers; + } + + /** + * Set if the Coupon is cumulative with other Coupons or not + * + * @param boolean $isCumulative is cumulative + * + * @return $this + */ + public function setIsCumulative($isCumulative) + { + $this->isCumulative = $isCumulative; + + return $this; + } + + /** + * Enable/Disable the Coupon + * + * @param boolean $isEnabled Enable/Disable + * + * @return $this + */ + public function setIsEnabled($isEnabled) + { + $this->isEnabled = $isEnabled; + + return $this; + } + + /** + * Get if Coupon is enabled or not + * + * @return boolean + */ + public function isEnabled() + { + return $this->isEnabled; + } + + /** + * Set if Coupon is removing Postage + * + * @param boolean $isRemovingPostage is removing Postage + * + * @return $this + */ + public function setIsRemovingPostage($isRemovingPostage) + { + $this->isRemovingPostage = $isRemovingPostage; + + return $this; + } + + /** + * Set how many time a coupon can be used (-1 : unlimited) + * + * @param int $maxUsage Coupon quantity + * + * @return $this + */ + public function setMaxUsage($maxUsage) + { + $this->maxUsage = $maxUsage; + + return $this; + } + + /** + * Return how many time the Coupon can be used again + * Ex : -1 unlimited + * + * @return int + */ + public function getMaxUsage() + { + return $this->maxUsage; + } + + /** + * Replace the existing Rules by those given in parameter + * If one Rule is badly implemented, no Rule will be added + * + * @param CouponRuleCollection $rules CouponRuleInterface to add + * + * @return $this + * @throws \Thelia\Exception\InvalidRuleException + */ + public function setRules(CouponRuleCollection $rules) + { + $this->rules = $rules; + $this->constraintManager = new ConstraintManager( + $this->adapter, + $this->rules + ); + + return $this; + } + + /** + * Set Coupon short description + * + * @param string $shortDescription Coupon short description + * + * @return $this + */ + public function setShortDescription($shortDescription) + { + $this->shortDescription = $shortDescription; + + return $this; + } + + /** + * Set Coupon title + * + * @param string $title Coupon title + * + * @return $this + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } + } diff --git a/templates/admin/default/coupon/create.html b/templates/admin/default/coupon/create.html new file mode 100755 index 000000000..cdbf8fd63 --- /dev/null +++ b/templates/admin/default/coupon/create.html @@ -0,0 +1,5 @@ +{check_auth context="admin" roles="ADMIN" permissions="admin.coupon.create" login_tpl="/admin/login"} + +{$page_title={intl l='Coupon creation'}} + +{include file='coupon/includes/edit.html'} \ No newline at end of file diff --git a/templates/admin/default/coupon/edit.html b/templates/admin/default/coupon/edit.html deleted file mode 100755 index d10c6ddfb..000000000 --- a/templates/admin/default/coupon/edit.html +++ /dev/null @@ -1,313 +0,0 @@ -{check_auth context="admin" roles="ADMIN" permissions="admin.coupon.view" login_tpl="/admin/login"} - -{$page_title={intl l='Coupon'}} - -{$thelia_page_css_file = "assets/bootstrap-editable/css/bootstrap-editable.css"} - -{include file='includes/header.inc.html'} - -
- - - - - -
- -
-
- -
-
- - -
- -
- - -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- - -
-
- -
- - - -
-
- -
-
-
-
- - - More description n°1 about item -
-
- -
-
- - -
-
- - -
-
-
- -
- - -
-
- -
- -
- - -
- - - -
-
- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Rules - - - -
ConditionsOperatorValueActions
Total Amountis superior or equals to300 € - Edit - Delete -
AND NbArticleFromCategoryis equals to12 - Chaussettes rouges - Edit - Delete -
OR Dateis inferior or equals to12/02/2014 - Edit - Delete -
-
-
- -
-
- -
- - - -
- -
- - - - - - - - -
- -
- -
- -
- - - -
-
- - -
- -
- - - -
-
- - -
- - - - - - - - - - - - - -
Categories list
- -
- -
- -
-
- -
- -
- - - -{include file='includes/js.inc.html'} - -{javascripts file='../assets/bootstrap-datepicker/js/bootstrap-datepicker.js'} - -{/javascripts} - -{javascripts file='../assets/js/main.js'} - -{/javascripts} - - - -{include file='includes/footer.inc.html'} \ No newline at end of file diff --git a/templates/admin/default/coupon/includes/edit.html b/templates/admin/default/coupon/includes/edit.html new file mode 100644 index 000000000..506b6bc5c --- /dev/null +++ b/templates/admin/default/coupon/includes/edit.html @@ -0,0 +1,311 @@ + + +{$thelia_page_css_file = "assets/bootstrap-editable/css/bootstrap-editable.css"} + +{include file='includes/header.inc.html'} + +
+ + + + + +
+ +
+
+ +
+
+ + +
+ +
+ + +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ + +
+
+ +
+ + + +
+
+ +
+
+
+
+ + + More description n°1 about item +
+
+ +
+
+ + +
+
+ + +
+
+
+ +
+ + +
+
+ +
+ +
+ + +
+ + + +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Rules + + + +
ConditionsOperatorValueActions
Total Amountis superior or equals to300 € + Edit + Delete +
AND NbArticleFromCategoryis equals to12 - Chaussettes rouges + Edit + Delete +
OR Dateis inferior or equals to12/02/2014 + Edit + Delete +
+
+
+ +
+
+ +
+ + + +
+ +
+ + + + + + + + +
+ +
+ +
+ +
+ + + +
+
+ + +
+ +
+ + + +
+
+ + +
+ + + + + + + + + + + + + +
Categories list
+ +
+ +
+ +
+
+ +
+ +
+ + + +{include file='includes/js.inc.html'} + +{javascripts file='../../assets/bootstrap-datepicker/js/bootstrap-datepicker.js'} + +{/javascripts} + +{javascripts file='../../assets/js/main.js'} + +{/javascripts} + + + +{include file='includes/footer.inc.html'} \ No newline at end of file diff --git a/templates/admin/default/coupon/update.html b/templates/admin/default/coupon/update.html new file mode 100755 index 000000000..ae6ec494a --- /dev/null +++ b/templates/admin/default/coupon/update.html @@ -0,0 +1,5 @@ +{check_auth context="admin" roles="ADMIN" permissions="admin.coupon.edit" login_tpl="/admin/login"} + +{$page_title={intl l='Coupon edition'}} + +{include file='coupon/includes/edit.html'} \ No newline at end of file