WIP : Coupon : Fix condition edition
This commit is contained in:
@@ -26,6 +26,7 @@ namespace Thelia\Action;
|
|||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
use Thelia\Condition\ConditionFactory;
|
use Thelia\Condition\ConditionFactory;
|
||||||
use Thelia\Condition\ConditionManagerInterface;
|
use Thelia\Condition\ConditionManagerInterface;
|
||||||
|
use Thelia\Core\Event\Condition\ConditionCreateOrUpdateEvent;
|
||||||
use Thelia\Core\Event\Coupon\CouponConsumeEvent;
|
use Thelia\Core\Event\Coupon\CouponConsumeEvent;
|
||||||
use Thelia\Core\Event\Coupon\CouponCreateOrUpdateEvent;
|
use Thelia\Core\Event\Coupon\CouponCreateOrUpdateEvent;
|
||||||
use Thelia\Core\Event\TheliaEvents;
|
use Thelia\Core\Event\TheliaEvents;
|
||||||
@@ -68,7 +69,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
|||||||
*/
|
*/
|
||||||
public function update(CouponCreateOrUpdateEvent $event)
|
public function update(CouponCreateOrUpdateEvent $event)
|
||||||
{
|
{
|
||||||
$coupon = $event->getCoupon();
|
$coupon = $event->getCouponModel();
|
||||||
|
|
||||||
$this->createOrUpdate($coupon, $event);
|
$this->createOrUpdate($coupon, $event);
|
||||||
}
|
}
|
||||||
@@ -76,13 +77,13 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
|||||||
/**
|
/**
|
||||||
* Occurring when a Coupon condition is about to be updated
|
* Occurring when a Coupon condition is about to be updated
|
||||||
*
|
*
|
||||||
* @param CouponCreateOrUpdateEvent $event Event creation or update Coupon Rule
|
* @param CouponCreateOrUpdateEvent $event Event creation or update Coupon condition
|
||||||
*/
|
*/
|
||||||
public function updateCondition(CouponCreateOrUpdateEvent $event)
|
public function updateCondition(CouponCreateOrUpdateEvent $event)
|
||||||
{
|
{
|
||||||
$coupon = $event->getCoupon();
|
$modelCoupon = $event->getCouponModel();
|
||||||
|
|
||||||
$this->createOrUpdateCondition($coupon, $event);
|
$this->createOrUpdateCondition($modelCoupon, $event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -153,7 +154,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
|||||||
$event->getCode(),
|
$event->getCode(),
|
||||||
$event->getTitle(),
|
$event->getTitle(),
|
||||||
$event->getAmount(),
|
$event->getAmount(),
|
||||||
$event->getType(),
|
$event->getServiceId(),
|
||||||
$event->isRemovingPostage(),
|
$event->isRemovingPostage(),
|
||||||
$event->getShortDescription(),
|
$event->getShortDescription(),
|
||||||
$event->getDescription(),
|
$event->getDescription(),
|
||||||
@@ -166,7 +167,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
|||||||
$event->getLocale()
|
$event->getLocale()
|
||||||
);
|
);
|
||||||
|
|
||||||
$event->setCoupon($coupon);
|
$event->setCouponModel($coupon);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -188,7 +189,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
|||||||
$event->getLocale()
|
$event->getLocale()
|
||||||
);
|
);
|
||||||
|
|
||||||
$event->setCoupon($coupon);
|
$event->setCouponModel($coupon);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ use Symfony\Component\HttpFoundation\Request;
|
|||||||
use Symfony\Component\Routing\Router;
|
use Symfony\Component\Routing\Router;
|
||||||
use Thelia\Condition\ConditionFactory;
|
use Thelia\Condition\ConditionFactory;
|
||||||
use Thelia\Condition\ConditionManagerInterface;
|
use Thelia\Condition\ConditionManagerInterface;
|
||||||
use Thelia\Core\Event\Condition\ConditionCreateOrUpdateEvent;
|
|
||||||
use Thelia\Core\Event\Coupon\CouponConsumeEvent;
|
use Thelia\Core\Event\Coupon\CouponConsumeEvent;
|
||||||
use Thelia\Core\Event\Coupon\CouponCreateOrUpdateEvent;
|
use Thelia\Core\Event\Coupon\CouponCreateOrUpdateEvent;
|
||||||
use Thelia\Core\Event\TheliaEvents;
|
use Thelia\Core\Event\TheliaEvents;
|
||||||
@@ -336,23 +335,36 @@ class CouponController extends BaseAdminController
|
|||||||
// $conditionFactory->serializeCouponConditionCollection($conditions)
|
// $conditionFactory->serializeCouponConditionCollection($conditions)
|
||||||
// );
|
// );
|
||||||
|
|
||||||
$conditionEvent = new ConditionCreateOrUpdateEvent(
|
$couponEvent = new CouponCreateOrUpdateEvent(
|
||||||
$conditions
|
$coupon->getCode(),
|
||||||
|
$coupon->getTitle(),
|
||||||
|
$coupon->getAmount(),
|
||||||
|
$coupon->getType(),
|
||||||
|
$coupon->getShortDescription(),
|
||||||
|
$coupon->getDescription(),
|
||||||
|
$coupon->getIsEnabled(),
|
||||||
|
$coupon->getExpirationDate(),
|
||||||
|
$coupon->getIsAvailableOnSpecialOffers(),
|
||||||
|
$coupon->getIsCumulative(),
|
||||||
|
$coupon->getIsRemovingPostage(),
|
||||||
|
$coupon->getMaxUsage(),
|
||||||
|
$coupon->getLocale()
|
||||||
);
|
);
|
||||||
$conditionEvent->setCouponModel($coupon);
|
$couponEvent->setCouponModel($coupon);
|
||||||
|
$couponEvent->setConditions($conditions);
|
||||||
|
|
||||||
$eventToDispatch = TheliaEvents::COUPON_CONDITION_UPDATE;
|
$eventToDispatch = TheliaEvents::COUPON_CONDITION_UPDATE;
|
||||||
// Dispatch Event to the Action
|
// Dispatch Event to the Action
|
||||||
$this->dispatch(
|
$this->dispatch(
|
||||||
$eventToDispatch,
|
$eventToDispatch,
|
||||||
$conditionEvent
|
$couponEvent
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->adminLogAppend(
|
$this->adminLogAppend(
|
||||||
sprintf(
|
sprintf(
|
||||||
'Coupon %s (ID %s) conditions updated',
|
'Coupon %s (ID %s) conditions updated',
|
||||||
$conditionEvent->getCouponModel()->getTitle(),
|
$couponEvent->getCouponModel()->getTitle(),
|
||||||
$conditionEvent->getCouponModel()->getServiceId()
|
$couponEvent->getCouponModel()->getType()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -489,14 +501,14 @@ class CouponController extends BaseAdminController
|
|||||||
sprintf(
|
sprintf(
|
||||||
'Coupon %s (ID ) ' . $log,
|
'Coupon %s (ID ) ' . $log,
|
||||||
$couponEvent->getTitle(),
|
$couponEvent->getTitle(),
|
||||||
$couponEvent->getCoupon()->getId()
|
$couponEvent->getCouponModel()->getId()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->redirect(
|
$this->redirect(
|
||||||
str_replace(
|
str_replace(
|
||||||
'{id}',
|
'{id}',
|
||||||
$couponEvent->getCoupon()->getId(),
|
$couponEvent->getCouponModel()->getId(),
|
||||||
$creationForm->getSuccessUrl()
|
$creationForm->getSuccessUrl()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,106 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**********************************************************************************/
|
|
||||||
/* */
|
|
||||||
/* Thelia */
|
|
||||||
/* */
|
|
||||||
/* Copyright (c) OpenStudio */
|
|
||||||
/* email : info@thelia.net */
|
|
||||||
/* web : http://www.thelia.net */
|
|
||||||
/* */
|
|
||||||
/* This program is free software; you can redistribute it and/or modify */
|
|
||||||
/* it under the terms of the GNU General Public License as published by */
|
|
||||||
/* the Free Software Foundation; either version 3 of the License */
|
|
||||||
/* */
|
|
||||||
/* This program is distributed in the hope that it will be useful, */
|
|
||||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
|
||||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
|
||||||
/* GNU General Public License for more details. */
|
|
||||||
/* */
|
|
||||||
/* You should have received a copy of the GNU General Public License */
|
|
||||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
||||||
/* */
|
|
||||||
/**********************************************************************************/
|
|
||||||
|
|
||||||
namespace Thelia\Core\Event\Condition;
|
|
||||||
|
|
||||||
use Thelia\Core\Event\ActionEvent;
|
|
||||||
use Thelia\Coupon\ConditionCollection;
|
|
||||||
use Thelia\Coupon\Type\CouponInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by JetBrains PhpStorm.
|
|
||||||
* Date: 8/29/13
|
|
||||||
* Time: 3:45 PM
|
|
||||||
*
|
|
||||||
* Occurring when a Condition is created or updated
|
|
||||||
*
|
|
||||||
* @package Coupon
|
|
||||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class ConditionCreateOrUpdateEvent extends ActionEvent
|
|
||||||
{
|
|
||||||
/** @var ConditionCollection Array of ConditionManagerInterface */
|
|
||||||
protected $conditions = null;
|
|
||||||
|
|
||||||
/** @var CouponInterface Coupon model associated with this conditions */
|
|
||||||
protected $couponModel = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor
|
|
||||||
*
|
|
||||||
* @param ConditionCollection $conditions Array of ConditionManagerInterface
|
|
||||||
*/
|
|
||||||
public function __construct(ConditionCollection $conditions)
|
|
||||||
{
|
|
||||||
$this->conditions = $conditions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Conditions
|
|
||||||
*
|
|
||||||
* @return null|ConditionCollection Array of ConditionManagerInterface
|
|
||||||
*/
|
|
||||||
public function getConditions()
|
|
||||||
{
|
|
||||||
return $this->conditions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set Conditions
|
|
||||||
*
|
|
||||||
* @param ConditionCollection $conditions Array of ConditionManagerInterface
|
|
||||||
*
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function setConditions(ConditionCollection $conditions)
|
|
||||||
{
|
|
||||||
$this->conditions = $conditions;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set Coupon Model associated to this condition
|
|
||||||
*
|
|
||||||
* @param CouponInterface $couponModel Coupon Model
|
|
||||||
*
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function setCouponModel($couponModel)
|
|
||||||
{
|
|
||||||
$this->couponModel = $couponModel;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Coupon Model associated to this condition
|
|
||||||
*
|
|
||||||
* @return null|CouponInterface
|
|
||||||
*/
|
|
||||||
public function getCouponModel()
|
|
||||||
{
|
|
||||||
return $this->couponModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -31,7 +31,7 @@ use Thelia\Model\Coupon;
|
|||||||
* Date: 8/29/13
|
* Date: 8/29/13
|
||||||
* Time: 3:45 PM
|
* Time: 3:45 PM
|
||||||
*
|
*
|
||||||
* Occurring when a Coupon is created
|
* Occurring when a Coupon is created or updated
|
||||||
*
|
*
|
||||||
* @package Coupon
|
* @package Coupon
|
||||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||||
@@ -76,10 +76,10 @@ class CouponCreateOrUpdateEvent extends ActionEvent
|
|||||||
protected $isAvailableOnSpecialOffers = false;
|
protected $isAvailableOnSpecialOffers = false;
|
||||||
|
|
||||||
/** @var Coupon Coupon model */
|
/** @var Coupon Coupon model */
|
||||||
protected $coupon = null;
|
protected $couponModel = null;
|
||||||
|
|
||||||
/** @var string Coupon type */
|
/** @var string Coupon Service id */
|
||||||
protected $type;
|
protected $serviceId;
|
||||||
|
|
||||||
/** @var string Language code ISO (ex: fr_FR) */
|
/** @var string Language code ISO (ex: fr_FR) */
|
||||||
protected $locale = null;
|
protected $locale = null;
|
||||||
@@ -90,7 +90,7 @@ class CouponCreateOrUpdateEvent extends ActionEvent
|
|||||||
* @param string $code Coupon Code
|
* @param string $code Coupon Code
|
||||||
* @param string $title Coupon title
|
* @param string $title Coupon title
|
||||||
* @param float $amount Amount removed from the Total Checkout
|
* @param float $amount Amount removed from the Total Checkout
|
||||||
* @param string $type Coupon type
|
* @param string $serviceId Coupon Service id
|
||||||
* @param string $shortDescription Coupon short description
|
* @param string $shortDescription Coupon short description
|
||||||
* @param string $description Coupon description
|
* @param string $description Coupon description
|
||||||
* @param bool $isEnabled Enable/Disable
|
* @param bool $isEnabled Enable/Disable
|
||||||
@@ -102,7 +102,7 @@ class CouponCreateOrUpdateEvent extends ActionEvent
|
|||||||
* @param string $locale Coupon Language code ISO (ex: fr_FR)
|
* @param string $locale Coupon Language code ISO (ex: fr_FR)
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
$code, $title, $amount, $type, $shortDescription, $description, $isEnabled, \DateTime $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $isRemovingPostage, $maxUsage, $locale
|
$code, $title, $amount, $serviceId, $shortDescription, $description, $isEnabled, \DateTime $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $isRemovingPostage, $maxUsage, $locale
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
$this->amount = $amount;
|
$this->amount = $amount;
|
||||||
@@ -116,7 +116,7 @@ class CouponCreateOrUpdateEvent extends ActionEvent
|
|||||||
$this->maxUsage = $maxUsage;
|
$this->maxUsage = $maxUsage;
|
||||||
$this->shortDescription = $shortDescription;
|
$this->shortDescription = $shortDescription;
|
||||||
$this->title = $title;
|
$this->title = $title;
|
||||||
$this->type = $type;
|
$this->serviceId = $serviceId;
|
||||||
$this->locale = $locale;
|
$this->locale = $locale;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,13 +234,13 @@ class CouponCreateOrUpdateEvent extends ActionEvent
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Coupon type (effect)
|
* Get Coupon Service id (Type)
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getType()
|
public function getServiceId()
|
||||||
{
|
{
|
||||||
return $this->type;
|
return $this->serviceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -256,13 +256,13 @@ class CouponCreateOrUpdateEvent extends ActionEvent
|
|||||||
/**
|
/**
|
||||||
* Set Coupon Model
|
* Set Coupon Model
|
||||||
*
|
*
|
||||||
* @param \Thelia\Model\Coupon $coupon Coupon Model
|
* @param Coupon $couponModel Coupon Model
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setCoupon($coupon)
|
public function setCouponModel(Coupon $couponModel)
|
||||||
{
|
{
|
||||||
$this->coupon = $coupon;
|
$this->couponModel = $couponModel;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -272,13 +272,13 @@ class CouponCreateOrUpdateEvent extends ActionEvent
|
|||||||
*
|
*
|
||||||
* @return \Thelia\Model\Coupon
|
* @return \Thelia\Model\Coupon
|
||||||
*/
|
*/
|
||||||
public function getCoupon()
|
public function getCouponModel()
|
||||||
{
|
{
|
||||||
return $this->coupon;
|
return $this->couponModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Rules
|
* Get Conditions
|
||||||
*
|
*
|
||||||
* @return null|ConditionCollection Array of ConditionManagerInterface
|
* @return null|ConditionCollection Array of ConditionManagerInterface
|
||||||
*/
|
*/
|
||||||
@@ -288,15 +288,15 @@ class CouponCreateOrUpdateEvent extends ActionEvent
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set Rules
|
* Set Conditions
|
||||||
*
|
*
|
||||||
* @param ConditionCollection $rules Array of ConditionManagerInterface
|
* @param ConditionCollection $conditions Array of ConditionManagerInterface
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setConditions(ConditionCollection $rules)
|
public function setConditions(ConditionCollection $conditions)
|
||||||
{
|
{
|
||||||
$this->conditions = $rules;
|
$this->conditions = $conditions;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ $(function($){
|
|||||||
|
|
||||||
// Save conditions on click
|
// Save conditions on click
|
||||||
$.couponManager.onClickSaveCondition = function() {
|
$.couponManager.onClickSaveCondition = function() {
|
||||||
$('#constraint-save-btn').on('click', function () {
|
$('#condition-save-btn').on('click', function () {
|
||||||
if($('#category-condition').val() == 'thelia.condition.match_for_everyone') {
|
if($('#category-condition').val() == 'thelia.condition.match_for_everyone') {
|
||||||
// // @todo translate message + put it in modal
|
// // @todo translate message + put it in modal
|
||||||
var r = confirm("Do you really want to set this coupon available to everyone ?");
|
var r = confirm("Do you really want to set this coupon available to everyone ?");
|
||||||
@@ -106,7 +106,7 @@ $(function($){
|
|||||||
|
|
||||||
// Remove condition on click
|
// Remove condition on click
|
||||||
$.couponManager.onClickDeleteCondition = function() {
|
$.couponManager.onClickDeleteCondition = function() {
|
||||||
$('.constraint-delete-btn').on('click', function (e) {
|
$('.condition-delete-btn').on('click', function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
$.couponManager.removeConditionAjax($this.attr('data-int'));
|
$.couponManager.removeConditionAjax($this.attr('data-int'));
|
||||||
|
|||||||
@@ -194,13 +194,13 @@
|
|||||||
</a>
|
</a>
|
||||||
|
|
||||||
<div id="condition-add-organizer" class="form-group col-md-2">
|
<div id="condition-add-organizer" class="form-group col-md-2">
|
||||||
<label for="type">{intl l='Condition type :'}</label>
|
{*<label for="type">{intl l='Condition type :'}</label>*}
|
||||||
<label class="radio">
|
{*<label class="radio">*}
|
||||||
<input type="radio" name="type" class="form-control" id="type" value="1" checked> {intl l='And'}
|
{*<input type="radio" name="type" class="form-control" id="type" value="1" checked> {intl l='And'}*}
|
||||||
</label>
|
{*</label>*}
|
||||||
<label class="radio">
|
{*<label class="radio">*}
|
||||||
<input type="radio" name="type" class="form-control" value="2"> {intl l='Or'}
|
{*<input type="radio" name="type" class="form-control" value="2"> {intl l='Or'}*}
|
||||||
</label>
|
{*</label>*}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="condition-add-type" class="form-group col-md-4">
|
<div id="condition-add-type" class="form-group col-md-4">
|
||||||
|
|||||||
Reference in New Issue
Block a user