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');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user