- Update Coupon Controller/Form/Event - create()
- Rule serialization/unserialization managed in Model/Coupon now
This commit is contained in:
gmorel
2013-08-30 11:06:33 +02:00
parent 8dd8c733d3
commit 71fa04a193
7 changed files with 463 additions and 46 deletions

View File

@@ -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');