WIP
- Update Coupon Controller/Form/Event - create() - Rule serialization/unserialization managed in Model/Coupon now
This commit is contained in:
@@ -23,8 +23,13 @@
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Event\Coupon\CouponCreateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Security\Exception\AuthenticationException;
|
||||
use Thelia\Core\Security\Exception\AuthorizationException;
|
||||
use Thelia\Coupon\CouponRuleCollection;
|
||||
use Thelia\Form\CouponCreationForm;
|
||||
use Thelia\Model\Coupon;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -74,6 +79,52 @@ class CouponController extends BaseAdminController
|
||||
{
|
||||
$this->checkAuth("ADMIN", "admin.coupon.view");
|
||||
|
||||
|
||||
if ($this->getRequest()->isMethod('POST')) {
|
||||
|
||||
$couponCreationForm = new CouponCreationForm($this->getRequest());
|
||||
|
||||
$form = $this->validateForm($couponCreationForm, "POST");
|
||||
|
||||
$data = $form->getData();
|
||||
|
||||
$couponBeingCreated = new Coupon();
|
||||
$couponBeingCreated->setCode($data["code"]);
|
||||
$couponBeingCreated->setType($data["type"]);
|
||||
$couponBeingCreated->setTitle($data["title"]);
|
||||
$couponBeingCreated->setShortDescription($data["shortDescription"]);
|
||||
$couponBeingCreated->setDescription($data["description"]);
|
||||
$couponBeingCreated->setAmount($data["amount"]);
|
||||
$couponBeingCreated->setIsEnabled($data["isEnabled"]);
|
||||
$couponBeingCreated->setExpirationDate($data["expirationDate"]);
|
||||
$couponBeingCreated->setSerializedRules(
|
||||
new CouponRuleCollection(
|
||||
array()
|
||||
)
|
||||
);
|
||||
$couponBeingCreated->setIsCumulative($data["isCumulative"]);
|
||||
$couponBeingCreated->setIsRemovingPostage($data["isRemovingPostage"]);
|
||||
$couponBeingCreated->setMaxUsage($data["maxUsage"]);
|
||||
$couponBeingCreated->setIsAvailableOnSpecialOffers($data["isAvailableOnSpecialOffers"]);
|
||||
|
||||
$couponCreateEvent = new CouponCreateEvent(
|
||||
$couponBeingCreated
|
||||
);
|
||||
|
||||
$this->dispatch(TheliaEvents::BEFORE_CREATE_COUPON, $couponCreateEvent);
|
||||
// @todo Save
|
||||
$this->adminLogAppend(
|
||||
sprintf(
|
||||
'Coupon %s (ID %s) created',
|
||||
$couponBeingCreated->getTitle(),
|
||||
$couponBeingCreated->getId()
|
||||
)
|
||||
);
|
||||
$this->dispatch(TheliaEvents::AFTER_CREATE_COUPON, $couponCreateEvent);
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
return $this->render('coupon/edit', $args);
|
||||
}
|
||||
|
||||
@@ -114,7 +165,6 @@ class CouponController extends BaseAdminController
|
||||
*/
|
||||
public function processAction()
|
||||
{
|
||||
var_dump($this->getRequest()->attributes);
|
||||
// Get the current action
|
||||
$action = $this->getRequest()->get('action', 'browse');
|
||||
|
||||
|
||||
@@ -22,61 +22,60 @@
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event\Coupon;
|
||||
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
use Thelia\Model\Coupon;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/29/13
|
||||
* Time: 3:45 PM
|
||||
*
|
||||
* Occurring when a Coupon is created
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class CouponCreateEvent extends ActionEvent
|
||||
{
|
||||
protected $title;
|
||||
protected $parent;
|
||||
protected $locale;
|
||||
protected $created_category;
|
||||
/**
|
||||
* @var Coupon Coupon being created
|
||||
*/
|
||||
protected $createdCoupon;
|
||||
|
||||
public function __construct($title, $parent, $locale)
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Coupon $coupon Coupon being created
|
||||
*/
|
||||
public function __construct(Coupon $coupon)
|
||||
{
|
||||
$this->title = $title;
|
||||
$this->parent = $parent;
|
||||
$this->locale = $locale;
|
||||
$this->createdCoupon = $coupon;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
/**
|
||||
* Modify Coupon being created
|
||||
*
|
||||
* @param Coupon $createdCoupon Coupon being created
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setCreatedCoupon(Coupon $createdCoupon)
|
||||
{
|
||||
return $this->title;
|
||||
$this->createdCoupon = $createdCoupon;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setTitle($title)
|
||||
/**
|
||||
* Get Coupon being created
|
||||
*
|
||||
* @return Coupon
|
||||
*/
|
||||
public function getCreatedCoupon()
|
||||
{
|
||||
$this->title = $title;
|
||||
return clone $this->createdCoupon;
|
||||
}
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
public function setParent($parent)
|
||||
{
|
||||
$this->parent = $parent;
|
||||
}
|
||||
|
||||
public function getLocale()
|
||||
{
|
||||
return $this->locale;
|
||||
}
|
||||
|
||||
public function setLocale($locale)
|
||||
{
|
||||
$this->locale = $locale;
|
||||
}
|
||||
|
||||
public function getCreatedCategory()
|
||||
{
|
||||
return $this->created_category;
|
||||
}
|
||||
|
||||
public function setCreatedCategory(Category $created_category)
|
||||
{
|
||||
$this->created_category = $created_category;
|
||||
var_dump($this->created_category);
|
||||
}
|
||||
}
|
||||
|
||||
82
core/lib/Thelia/Core/Event/Coupon/CouponEditEvent.php
Normal file
82
core/lib/Thelia/Core/Event/Coupon/CouponEditEvent.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?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\Coupon;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
use Thelia\Model\Coupon;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/29/13
|
||||
* Time: 3:45 PM
|
||||
*
|
||||
* Occurring when a Coupon is edited
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class CouponEditEvent extends ActionEvent
|
||||
{
|
||||
/** @var int Coupon being edited id */
|
||||
protected $couponId;
|
||||
|
||||
/** @var Coupon Coupon being created */
|
||||
protected $editedCoupon;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Coupon $coupon Coupon being edited
|
||||
*/
|
||||
public function __construct(Coupon $coupon)
|
||||
{
|
||||
$this->created_coupon = $coupon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify Coupon being created
|
||||
*
|
||||
* @param Coupon $editedCoupon Coupon being created
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setCreatedCoupon(Coupon $editedCoupon)
|
||||
{
|
||||
$this->editedCoupon = $editedCoupon;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Coupon being created
|
||||
*
|
||||
* @return Coupon
|
||||
*/
|
||||
public function getCreatedCoupon()
|
||||
{
|
||||
return clone $this->editedCoupon;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -177,4 +177,56 @@ final class TheliaEvents
|
||||
* Sent on cimage cache clear request
|
||||
*/
|
||||
const IMAGE_CLEAR_CACHE = "action.clearImageCache";
|
||||
|
||||
|
||||
/**
|
||||
* Sent just before a successful insert of a new Coupon in the database.
|
||||
*/
|
||||
|
||||
const BEFORE_CREATE_COUPON = "action.before_create_coupon";
|
||||
|
||||
/**
|
||||
* Sent just after a successful insert of a new Coupon in the database.
|
||||
*/
|
||||
const AFTER_CREATE_COUPON = "action.after_create_coupon";
|
||||
|
||||
/**
|
||||
* Sent just before a successful update of a new Coupon in the database.
|
||||
*/
|
||||
const BEFORE_EDIT_COUPON = "action.before_edit_coupon";
|
||||
|
||||
/**
|
||||
* Sent just after a successful update of a new Coupon in the database.
|
||||
*/
|
||||
const AFTER_EDIT_COUPON = "action.after_edit_coupon";
|
||||
|
||||
/**
|
||||
* Sent just before a successful disable of a new Coupon in the database.
|
||||
*/
|
||||
const BEFORE_DISABLE_COUPON = "action.before_disable_coupon";
|
||||
|
||||
/**
|
||||
* Sent just after a successful disable of a new Coupon in the database.
|
||||
*/
|
||||
const AFTER_DISABLE_COUPON = "action.after_disable_coupon";
|
||||
|
||||
/**
|
||||
* Sent just before a successful enable of a new Coupon in the database.
|
||||
*/
|
||||
const BEFORE_ENABLE_COUPON = "action.before_enable_coupon";
|
||||
|
||||
/**
|
||||
* Sent just after a successful enable of a new Coupon in the database.
|
||||
*/
|
||||
const AFTER_ENABLE_COUPON = "action.after_enable_coupon";
|
||||
|
||||
/**
|
||||
* Sent just before an attempt to use a Coupon
|
||||
*/
|
||||
const BEFORE_USE_COUPON = "action.before_use_coupon";
|
||||
|
||||
/**
|
||||
* Sent just after an attempt to use a Coupon
|
||||
*/
|
||||
const AFTER_USE_COUPON = "action.after_use_coupon";
|
||||
}
|
||||
|
||||
168
core/lib/Thelia/Form/CouponCreationForm.php
Executable file
168
core/lib/Thelia/Form/CouponCreationForm.php
Executable file
@@ -0,0 +1,168 @@
|
||||
<?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\Form;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/29/13
|
||||
* Time: 3:45 PM
|
||||
*
|
||||
* Allow to build a form Coupon
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class CouponCreationForm extends BaseForm
|
||||
{
|
||||
/**
|
||||
* Build Coupon form
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function buildForm()
|
||||
{
|
||||
$this->formBuilder
|
||||
->add(
|
||||
"code",
|
||||
"text",
|
||||
array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
)
|
||||
->add(
|
||||
"type",
|
||||
"text",
|
||||
array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
)
|
||||
->add(
|
||||
"title",
|
||||
"text",
|
||||
array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
)
|
||||
->add(
|
||||
"shortDescription",
|
||||
"text",
|
||||
array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
)
|
||||
->add(
|
||||
"description",
|
||||
"text",
|
||||
array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
)
|
||||
->add(
|
||||
"amount",
|
||||
"text",
|
||||
array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
)
|
||||
->add(
|
||||
"isEnabled",
|
||||
"text",
|
||||
array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
)
|
||||
->add(
|
||||
"expirationDate",
|
||||
"text",
|
||||
array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
)
|
||||
->add(
|
||||
"isCumulative",
|
||||
"text",
|
||||
array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
)
|
||||
->add(
|
||||
"isRemovingPostage",
|
||||
"text",
|
||||
array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
)
|
||||
->add(
|
||||
"maxUsage",
|
||||
"text",
|
||||
array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
)
|
||||
->add(
|
||||
"isAvailableOnSpecialOffers",
|
||||
"text",
|
||||
array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get form name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return "thelia_coupon_creation";
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,77 @@
|
||||
<?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\Model;
|
||||
|
||||
use Thelia\Coupon\CouponRuleCollection;
|
||||
use Thelia\Model\Base\Coupon as BaseCoupon;
|
||||
|
||||
class Coupon extends BaseCoupon {
|
||||
/**
|
||||
* 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)
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class Coupon extends BaseCoupon
|
||||
{
|
||||
/**
|
||||
* Set the value of [serialized_rules] column.
|
||||
*
|
||||
* @param CouponRuleCollection $rules A set of Rules
|
||||
*
|
||||
* @return \Thelia\Model\Coupon The current object (for fluent API support)
|
||||
*/
|
||||
public function setSerializedRules(CouponRuleCollection $rules)
|
||||
{
|
||||
if ($rules !== null) {
|
||||
|
||||
$v = (string) base64_encode(serialize($rules));
|
||||
}
|
||||
|
||||
if ($this->serialized_rules !== $v) {
|
||||
$this->serialized_rules = $v;
|
||||
$this->modifiedColumns[] = CouponTableMap::SERIALIZED_RULES;
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
} // setSerializedRules()
|
||||
|
||||
|
||||
/**
|
||||
* Get the [serialized_rules] column value.
|
||||
*
|
||||
* @return CouponRuleCollection Rules ready to be processed
|
||||
*/
|
||||
public function getSerializedRules()
|
||||
{
|
||||
return unserialize(base64_decode($this->serialized_rules));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
# Sqlfile -> Database map
|
||||
thelia.sql=thelia
|
||||
Reference in New Issue
Block a user