WIP
- Coupon Controller
This commit is contained in:
@@ -34,6 +34,16 @@
|
||||
<route id="admin.category" path="/admin/catalog/category">
|
||||
<default key="_controller">Thelia\Controller\Admin\CategoryController::processAction</default>
|
||||
</route>
|
||||
<route id="admin.category.ajax" path="/admin/catalog/category/parent/{parentId}.{_format}" methods="GET">
|
||||
<default key="_controller">Thelia\Controller\Admin\CategoryController::getByParentIdAction</default>
|
||||
<requirement key="_format">xml|json</requirement>
|
||||
</route>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- Route to the Coupon controller (process Coupon browsing) -->
|
||||
<route id="admin.coupon.list" path="/admin/coupon">
|
||||
@@ -53,6 +63,11 @@
|
||||
<default key="action">read</default>
|
||||
</route>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- Routes to the Config (system variables) controller -->
|
||||
|
||||
<route id="admin.configuration.variables.default" path="/admin/configuration/variables">
|
||||
|
||||
@@ -256,4 +256,16 @@ class CategoryController extends BaseAdminController
|
||||
// We did not recognized the action -> return a 404 page
|
||||
return $this->pageNotFound();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Category from its parent id
|
||||
*
|
||||
* @return mixed|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function getByParentIdAction($parentId, $_format = 'json')
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.catalog.view")) return $response;
|
||||
|
||||
return $this->render('categories', $args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,9 +77,12 @@ class CouponController extends BaseAdminController
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
protected function createCoupon($args)
|
||||
protected function createAction($args)
|
||||
{
|
||||
$this->checkAuth("ADMIN", "admin.coupon.view");
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.coupon.create")) return $response;
|
||||
|
||||
$message = false;
|
||||
|
||||
if ($this->getRequest()->isMethod('POST')) {
|
||||
try {
|
||||
|
||||
83
core/lib/Thelia/Tools/Rest/ResponseRest.php
Normal file
83
core/lib/Thelia/Tools/Rest/ResponseRest.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Thelia\Tools\Rest;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
use Symfony\Component\Serializer\Serializer;
|
||||
use Symfony\Component\Serializer\Encoder\XmlEncoder;
|
||||
use Symfony\Component\Serializer\Encoder\JsonEncoder;
|
||||
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
|
||||
|
||||
|
||||
/**
|
||||
* Class ResponseRest Create a serialized Response
|
||||
*
|
||||
* @package Thelia\Tools\Rest
|
||||
*/
|
||||
class ResponseRest extends Response
|
||||
{
|
||||
/** @var Response Response Object */
|
||||
protected $response;
|
||||
|
||||
/** @var string Response format */
|
||||
protected $format;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $data Array to be serialized
|
||||
* @param string $format serialization format, xml or json available
|
||||
* @param integer $status The response status code
|
||||
* @param array $headers An array of response headers
|
||||
*
|
||||
* @throws \InvalidArgumentException When the HTTP status code is not valid
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function __construct($data = null, $format = 'json', $status = 200, $headers = array())
|
||||
{
|
||||
parent::__construct('', $status, $headers);
|
||||
|
||||
$this->format = $format;
|
||||
$serializer = $this->getSerializer();
|
||||
|
||||
if (isset($data)) {
|
||||
$this->setContent($serializer->serialize($data, $this->format));
|
||||
}
|
||||
|
||||
$this->headers->set('Content-Type', 'application/' . $this->format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Content to be serialized in the response, array or object
|
||||
*
|
||||
* @param array $data array or object to be serialized
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setRestContent($data)
|
||||
{
|
||||
$serializer = $this->getSerializer();
|
||||
|
||||
if (isset($data)) {
|
||||
$this->setContent($serializer->serialize($data, $this->format));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Serializer
|
||||
*
|
||||
* @return Serializer
|
||||
*/
|
||||
protected function getSerializer()
|
||||
{
|
||||
$encoders = array(new XmlEncoder(), new JsonEncoder());
|
||||
$normalizers = array(new GetSetMethodNormalizer());
|
||||
|
||||
return new Serializer($normalizers, $encoders);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user