WIP
- Coupon Controller
This commit is contained in:
@@ -34,6 +34,16 @@
|
|||||||
<route id="admin.category" path="/admin/catalog/category">
|
<route id="admin.category" path="/admin/catalog/category">
|
||||||
<default key="_controller">Thelia\Controller\Admin\CategoryController::processAction</default>
|
<default key="_controller">Thelia\Controller\Admin\CategoryController::processAction</default>
|
||||||
</route>
|
</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 to the Coupon controller (process Coupon browsing) -->
|
||||||
<route id="admin.coupon.list" path="/admin/coupon">
|
<route id="admin.coupon.list" path="/admin/coupon">
|
||||||
@@ -53,6 +63,11 @@
|
|||||||
<default key="action">read</default>
|
<default key="action">read</default>
|
||||||
</route>
|
</route>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Routes to the Config (system variables) controller -->
|
<!-- Routes to the Config (system variables) controller -->
|
||||||
|
|
||||||
<route id="admin.configuration.variables.default" path="/admin/configuration/variables">
|
<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
|
// We did not recognized the action -> return a 404 page
|
||||||
return $this->pageNotFound();
|
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
|
* @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')) {
|
if ($this->getRequest()->isMethod('POST')) {
|
||||||
try {
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -516,31 +516,31 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
|
|||||||
$date = new \DateTime();
|
$date = new \DateTime();
|
||||||
$coupon1->setExpirationDate($date->setTimestamp(strtotime("today + 2 months")));
|
$coupon1->setExpirationDate($date->setTimestamp(strtotime("today + 2 months")));
|
||||||
|
|
||||||
$rule1 = new Thelia\Coupon\Rule\AvailableForTotalAmount(
|
// $rule1 = new Thelia\Constraint\Rule\AvailableForTotalAmount(
|
||||||
array(
|
// array(
|
||||||
Thelia\Coupon\Rule\AvailableForTotalAmount::PARAM1_PRICE => new Thelia\Coupon\Parameter\RuleValidator(
|
// Thelia\Constraint\Rule\AvailableForTotalAmount::PARAM1_PRICE => new Thelia\Constraint\Validator\RuleValidator(
|
||||||
Thelia\Coupon\Rule\Operators::SUPERIOR,
|
// Thelia\Constraint\Rule\Operators::SUPERIOR,
|
||||||
new Thelia\Coupon\Parameter\PriceParam(
|
// new Thelia\Constraint\Validator\PriceParam(
|
||||||
40.00,
|
// 40.00,
|
||||||
'EUR'
|
// 'EUR'
|
||||||
)
|
// )
|
||||||
)
|
// )
|
||||||
)
|
// )
|
||||||
);
|
// );
|
||||||
$rule2 = new Thelia\Coupon\Rule\AvailableForTotalAmount(
|
// $rule2 = new Thelia\Constraint\Rule\AvailableForTotalAmount(
|
||||||
array(
|
// array(
|
||||||
Thelia\Coupon\Rule\AvailableForTotalAmount::PARAM1_PRICE => new Thelia\Coupon\Parameter\RuleValidator(
|
// Thelia\Constraint\Rule\AvailableForTotalAmount::PARAM1_PRICE => new Thelia\Coupon\Parameter\RuleValidator(
|
||||||
Thelia\Coupon\Rule\Operators::INFERIOR,
|
// Thelia\Constraint\Rule\Operators::INFERIOR,
|
||||||
new Thelia\Coupon\Parameter\PriceParam(
|
// new Thelia\Constraint\Parameter\PriceParam(
|
||||||
400.00,
|
// 400.00,
|
||||||
'EUR'
|
// 'EUR'
|
||||||
)
|
// )
|
||||||
)
|
// )
|
||||||
)
|
// )
|
||||||
);
|
// );
|
||||||
$rules = new \Thelia\Coupon\CouponRuleCollection(array($rule1, $rule2));
|
// $rules = new \Thelia\Coupon\CouponRuleCollection(array($rule1, $rule2));
|
||||||
|
|
||||||
$coupon1->setSerializedRules(base64_encode(serialize($rules)));
|
// $coupon1->setSerializedRules(base64_encode(serialize($rules)));
|
||||||
|
|
||||||
$coupon1->setIsCumulative(1);
|
$coupon1->setIsCumulative(1);
|
||||||
$coupon1->setIsRemovingPostage(0);
|
$coupon1->setIsRemovingPostage(0);
|
||||||
|
|||||||
@@ -1028,6 +1028,49 @@ CREATE TABLE `message`
|
|||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) ENGINE=InnoDB;
|
) ENGINE=InnoDB;
|
||||||
|
|
||||||
|
-- ---------------------------------------------------------------------
|
||||||
|
-- rewriting
|
||||||
|
-- ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `rewriting`;
|
||||||
|
|
||||||
|
CREATE TABLE `rewriting`
|
||||||
|
(
|
||||||
|
`id` INTEGER NOT NULL,
|
||||||
|
`url` VARCHAR(255) NOT NULL,
|
||||||
|
`product_id` INTEGER,
|
||||||
|
`category_id` INTEGER,
|
||||||
|
`folder_id` INTEGER,
|
||||||
|
`content_id` INTEGER,
|
||||||
|
`created_at` DATETIME,
|
||||||
|
`updated_at` DATETIME,
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
INDEX `idx_rewriting_product_id` (`product_id`),
|
||||||
|
INDEX `idx_rewriting_category_id` (`category_id`),
|
||||||
|
INDEX `idx_rewriting_folder_id` (`folder_id`),
|
||||||
|
INDEX `idx_rewriting_content_id` (`content_id`),
|
||||||
|
CONSTRAINT `fk_rewriting_product_id`
|
||||||
|
FOREIGN KEY (`product_id`)
|
||||||
|
REFERENCES `product` (`id`)
|
||||||
|
ON UPDATE RESTRICT
|
||||||
|
ON DELETE CASCADE,
|
||||||
|
CONSTRAINT `fk_rewriting_category_id`
|
||||||
|
FOREIGN KEY (`category_id`)
|
||||||
|
REFERENCES `category` (`id`)
|
||||||
|
ON UPDATE RESTRICT
|
||||||
|
ON DELETE CASCADE,
|
||||||
|
CONSTRAINT `fk_rewriting_folder_id`
|
||||||
|
FOREIGN KEY (`folder_id`)
|
||||||
|
REFERENCES `folder` (`id`)
|
||||||
|
ON UPDATE RESTRICT
|
||||||
|
ON DELETE CASCADE,
|
||||||
|
CONSTRAINT `fk_rewriting_content_id`
|
||||||
|
FOREIGN KEY (`content_id`)
|
||||||
|
REFERENCES `content` (`id`)
|
||||||
|
ON UPDATE RESTRICT
|
||||||
|
ON DELETE CASCADE
|
||||||
|
) ENGINE=InnoDB;
|
||||||
|
|
||||||
-- ---------------------------------------------------------------------
|
-- ---------------------------------------------------------------------
|
||||||
-- coupon
|
-- coupon
|
||||||
-- ---------------------------------------------------------------------
|
-- ---------------------------------------------------------------------
|
||||||
@@ -1039,9 +1082,6 @@ CREATE TABLE `coupon`
|
|||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
`code` VARCHAR(45) NOT NULL,
|
`code` VARCHAR(45) NOT NULL,
|
||||||
`type` VARCHAR(255) NOT NULL,
|
`type` VARCHAR(255) NOT NULL,
|
||||||
`title` VARCHAR(255) NOT NULL,
|
|
||||||
`short_description` TEXT NOT NULL,
|
|
||||||
`description` LONGTEXT NOT NULL,
|
|
||||||
`amount` FLOAT NOT NULL,
|
`amount` FLOAT NOT NULL,
|
||||||
`is_used` TINYINT NOT NULL,
|
`is_used` TINYINT NOT NULL,
|
||||||
`is_enabled` TINYINT NOT NULL,
|
`is_enabled` TINYINT NOT NULL,
|
||||||
@@ -1077,21 +1117,16 @@ CREATE TABLE `coupon_order`
|
|||||||
(
|
(
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
`order_id` INTEGER NOT NULL,
|
`order_id` INTEGER NOT NULL,
|
||||||
`code` VARCHAR(45) NOT NULL,
|
|
||||||
`value` FLOAT NOT NULL,
|
`value` FLOAT NOT NULL,
|
||||||
`created_at` DATETIME,
|
`created_at` DATETIME,
|
||||||
`updated_at` DATETIME,
|
`updated_at` DATETIME,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
INDEX `idx_coupon_order_order_id` (`order_id`),
|
INDEX `idx_coupon_order_order_id` (`order_id`),
|
||||||
INDEX `fk_coupon_order_coupon_idx` (`code`),
|
|
||||||
CONSTRAINT `fk_coupon_order_order_id`
|
CONSTRAINT `fk_coupon_order_order_id`
|
||||||
FOREIGN KEY (`order_id`)
|
FOREIGN KEY (`order_id`)
|
||||||
REFERENCES `order` (`id`)
|
REFERENCES `order` (`id`)
|
||||||
ON UPDATE RESTRICT
|
ON UPDATE RESTRICT
|
||||||
ON DELETE CASCADE,
|
ON DELETE CASCADE
|
||||||
CONSTRAINT `fk_coupon_order_coupon`
|
|
||||||
FOREIGN KEY (`code`)
|
|
||||||
REFERENCES `coupon` (`code`)
|
|
||||||
) ENGINE=InnoDB;
|
) ENGINE=InnoDB;
|
||||||
|
|
||||||
-- ---------------------------------------------------------------------
|
-- ---------------------------------------------------------------------
|
||||||
@@ -1433,55 +1468,6 @@ CREATE TABLE `category_associated_content`
|
|||||||
ON DELETE CASCADE
|
ON DELETE CASCADE
|
||||||
) ENGINE=InnoDB;
|
) ENGINE=InnoDB;
|
||||||
|
|
||||||
-- ---------------------------------------------------------------------
|
|
||||||
-- rewriting_url
|
|
||||||
-- ---------------------------------------------------------------------
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `rewriting_url`;
|
|
||||||
|
|
||||||
CREATE TABLE `rewriting_url`
|
|
||||||
(
|
|
||||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
||||||
`url` VARCHAR(255) NOT NULL,
|
|
||||||
`view` VARCHAR(255) NOT NULL,
|
|
||||||
`view_id` VARCHAR(255),
|
|
||||||
`view_locale` VARCHAR(255) NOT NULL,
|
|
||||||
`redirected` INTEGER,
|
|
||||||
`created_at` DATETIME,
|
|
||||||
`updated_at` DATETIME,
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
UNIQUE INDEX `url_UNIQUE` (`url`),
|
|
||||||
INDEX `idx_view_id` (`view_id`),
|
|
||||||
INDEX `idx_rewriting_url_redirected` (`redirected`),
|
|
||||||
CONSTRAINT `fk_rewriting_url_redirected`
|
|
||||||
FOREIGN KEY (`redirected`)
|
|
||||||
REFERENCES `rewriting_url` (`id`)
|
|
||||||
ON UPDATE RESTRICT
|
|
||||||
ON DELETE RESTRICT
|
|
||||||
) ENGINE=InnoDB;
|
|
||||||
|
|
||||||
-- ---------------------------------------------------------------------
|
|
||||||
-- rewriting_argument
|
|
||||||
-- ---------------------------------------------------------------------
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `rewriting_argument`;
|
|
||||||
|
|
||||||
CREATE TABLE `rewriting_argument`
|
|
||||||
(
|
|
||||||
`rewriting_url_id` INTEGER NOT NULL,
|
|
||||||
`parameter` VARCHAR(255) NOT NULL,
|
|
||||||
`value` VARCHAR(255) NOT NULL,
|
|
||||||
`created_at` DATETIME,
|
|
||||||
`updated_at` DATETIME,
|
|
||||||
PRIMARY KEY (`rewriting_url_id`,`parameter`,`value`),
|
|
||||||
INDEX `fk_rewriting_argument_rewirting_url_id` (`rewriting_url_id`),
|
|
||||||
CONSTRAINT `fk_rewriting_argument_rewirting_url_id`
|
|
||||||
FOREIGN KEY (`rewriting_url_id`)
|
|
||||||
REFERENCES `rewriting_url` (`id`)
|
|
||||||
ON UPDATE RESTRICT
|
|
||||||
ON DELETE CASCADE
|
|
||||||
) ENGINE=InnoDB;
|
|
||||||
|
|
||||||
-- ---------------------------------------------------------------------
|
-- ---------------------------------------------------------------------
|
||||||
-- category_i18n
|
-- category_i18n
|
||||||
-- ---------------------------------------------------------------------
|
-- ---------------------------------------------------------------------
|
||||||
@@ -1921,6 +1907,9 @@ CREATE TABLE `coupon_i18n`
|
|||||||
(
|
(
|
||||||
`id` INTEGER NOT NULL,
|
`id` INTEGER NOT NULL,
|
||||||
`locale` VARCHAR(5) DEFAULT 'en_EN' NOT NULL,
|
`locale` VARCHAR(5) DEFAULT 'en_EN' NOT NULL,
|
||||||
|
`title` VARCHAR(255) NOT NULL,
|
||||||
|
`short_description` TEXT NOT NULL,
|
||||||
|
`description` LONGTEXT NOT NULL,
|
||||||
PRIMARY KEY (`id`,`locale`),
|
PRIMARY KEY (`id`,`locale`),
|
||||||
CONSTRAINT `coupon_i18n_FK_1`
|
CONSTRAINT `coupon_i18n_FK_1`
|
||||||
FOREIGN KEY (`id`)
|
FOREIGN KEY (`id`)
|
||||||
@@ -2185,9 +2174,6 @@ CREATE TABLE `coupon_version`
|
|||||||
`id` INTEGER NOT NULL,
|
`id` INTEGER NOT NULL,
|
||||||
`code` VARCHAR(45) NOT NULL,
|
`code` VARCHAR(45) NOT NULL,
|
||||||
`type` VARCHAR(255) NOT NULL,
|
`type` VARCHAR(255) NOT NULL,
|
||||||
`title` VARCHAR(255) NOT NULL,
|
|
||||||
`short_description` TEXT NOT NULL,
|
|
||||||
`description` LONGTEXT NOT NULL,
|
|
||||||
`amount` FLOAT NOT NULL,
|
`amount` FLOAT NOT NULL,
|
||||||
`is_used` TINYINT NOT NULL,
|
`is_used` TINYINT NOT NULL,
|
||||||
`is_enabled` TINYINT NOT NULL,
|
`is_enabled` TINYINT NOT NULL,
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -92,6 +92,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</aside> <!-- #enable / Enable confirmation -->
|
</aside> <!-- #enable / Enable confirmation -->
|
||||||
|
|
||||||
|
boucle coupon
|
||||||
|
{loop type="coupon" name="read_coupon" backend_context="true"}
|
||||||
|
inside
|
||||||
|
#ID
|
||||||
|
#CODE
|
||||||
|
#TITLE
|
||||||
|
{/loop}
|
||||||
|
|
||||||
{include file='includes/js.inc.html'}
|
{include file='includes/js.inc.html'}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user