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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -516,31 +516,31 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
|
||||
$date = new \DateTime();
|
||||
$coupon1->setExpirationDate($date->setTimestamp(strtotime("today + 2 months")));
|
||||
|
||||
$rule1 = new Thelia\Coupon\Rule\AvailableForTotalAmount(
|
||||
array(
|
||||
Thelia\Coupon\Rule\AvailableForTotalAmount::PARAM1_PRICE => new Thelia\Coupon\Parameter\RuleValidator(
|
||||
Thelia\Coupon\Rule\Operators::SUPERIOR,
|
||||
new Thelia\Coupon\Parameter\PriceParam(
|
||||
40.00,
|
||||
'EUR'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
$rule2 = new Thelia\Coupon\Rule\AvailableForTotalAmount(
|
||||
array(
|
||||
Thelia\Coupon\Rule\AvailableForTotalAmount::PARAM1_PRICE => new Thelia\Coupon\Parameter\RuleValidator(
|
||||
Thelia\Coupon\Rule\Operators::INFERIOR,
|
||||
new Thelia\Coupon\Parameter\PriceParam(
|
||||
400.00,
|
||||
'EUR'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
$rules = new \Thelia\Coupon\CouponRuleCollection(array($rule1, $rule2));
|
||||
// $rule1 = new Thelia\Constraint\Rule\AvailableForTotalAmount(
|
||||
// array(
|
||||
// Thelia\Constraint\Rule\AvailableForTotalAmount::PARAM1_PRICE => new Thelia\Constraint\Validator\RuleValidator(
|
||||
// Thelia\Constraint\Rule\Operators::SUPERIOR,
|
||||
// new Thelia\Constraint\Validator\PriceParam(
|
||||
// 40.00,
|
||||
// 'EUR'
|
||||
// )
|
||||
// )
|
||||
// )
|
||||
// );
|
||||
// $rule2 = new Thelia\Constraint\Rule\AvailableForTotalAmount(
|
||||
// array(
|
||||
// Thelia\Constraint\Rule\AvailableForTotalAmount::PARAM1_PRICE => new Thelia\Coupon\Parameter\RuleValidator(
|
||||
// Thelia\Constraint\Rule\Operators::INFERIOR,
|
||||
// new Thelia\Constraint\Parameter\PriceParam(
|
||||
// 400.00,
|
||||
// 'EUR'
|
||||
// )
|
||||
// )
|
||||
// )
|
||||
// );
|
||||
// $rules = new \Thelia\Coupon\CouponRuleCollection(array($rule1, $rule2));
|
||||
|
||||
$coupon1->setSerializedRules(base64_encode(serialize($rules)));
|
||||
// $coupon1->setSerializedRules(base64_encode(serialize($rules)));
|
||||
|
||||
$coupon1->setIsCumulative(1);
|
||||
$coupon1->setIsRemovingPostage(0);
|
||||
|
||||
@@ -1028,6 +1028,49 @@ CREATE TABLE `message`
|
||||
PRIMARY KEY (`id`)
|
||||
) 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
|
||||
-- ---------------------------------------------------------------------
|
||||
@@ -1039,9 +1082,6 @@ CREATE TABLE `coupon`
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`code` VARCHAR(45) 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,
|
||||
`is_used` TINYINT NOT NULL,
|
||||
`is_enabled` TINYINT NOT NULL,
|
||||
@@ -1077,21 +1117,16 @@ CREATE TABLE `coupon_order`
|
||||
(
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`order_id` INTEGER NOT NULL,
|
||||
`code` VARCHAR(45) NOT NULL,
|
||||
`value` FLOAT NOT NULL,
|
||||
`created_at` DATETIME,
|
||||
`updated_at` DATETIME,
|
||||
PRIMARY KEY (`id`),
|
||||
INDEX `idx_coupon_order_order_id` (`order_id`),
|
||||
INDEX `fk_coupon_order_coupon_idx` (`code`),
|
||||
CONSTRAINT `fk_coupon_order_order_id`
|
||||
FOREIGN KEY (`order_id`)
|
||||
REFERENCES `order` (`id`)
|
||||
ON UPDATE RESTRICT
|
||||
ON DELETE CASCADE,
|
||||
CONSTRAINT `fk_coupon_order_coupon`
|
||||
FOREIGN KEY (`code`)
|
||||
REFERENCES `coupon` (`code`)
|
||||
ON DELETE CASCADE
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
-- ---------------------------------------------------------------------
|
||||
@@ -1433,55 +1468,6 @@ CREATE TABLE `category_associated_content`
|
||||
ON DELETE CASCADE
|
||||
) 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
|
||||
-- ---------------------------------------------------------------------
|
||||
@@ -1921,6 +1907,9 @@ CREATE TABLE `coupon_i18n`
|
||||
(
|
||||
`id` INTEGER 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`),
|
||||
CONSTRAINT `coupon_i18n_FK_1`
|
||||
FOREIGN KEY (`id`)
|
||||
@@ -2185,9 +2174,6 @@ CREATE TABLE `coupon_version`
|
||||
`id` INTEGER NOT NULL,
|
||||
`code` VARCHAR(45) 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,
|
||||
`is_used` TINYINT NOT NULL,
|
||||
`is_enabled` TINYINT NOT NULL,
|
||||
|
||||
@@ -755,6 +755,39 @@
|
||||
<parameter name="log_created_by" value="true" />
|
||||
</behavior>
|
||||
</table>
|
||||
<table name="rewriting" namespace="Thelia\Model">
|
||||
<column name="id" primaryKey="true" required="true" type="INTEGER" />
|
||||
<column name="url" required="true" size="255" type="VARCHAR" />
|
||||
<column name="product_id" type="INTEGER" />
|
||||
<column name="category_id" type="INTEGER" />
|
||||
<column name="folder_id" type="INTEGER" />
|
||||
<column name="content_id" type="INTEGER" />
|
||||
<foreign-key foreignTable="product" name="fk_rewriting_product_id" onDelete="CASCADE" onUpdate="RESTRICT">
|
||||
<reference foreign="id" local="product_id" />
|
||||
</foreign-key>
|
||||
<foreign-key foreignTable="category" name="fk_rewriting_category_id" onDelete="CASCADE" onUpdate="RESTRICT">
|
||||
<reference foreign="id" local="category_id" />
|
||||
</foreign-key>
|
||||
<foreign-key foreignTable="folder" name="fk_rewriting_folder_id" onDelete="CASCADE" onUpdate="RESTRICT">
|
||||
<reference foreign="id" local="folder_id" />
|
||||
</foreign-key>
|
||||
<foreign-key foreignTable="content" name="fk_rewriting_content_id" onDelete="CASCADE" onUpdate="RESTRICT">
|
||||
<reference foreign="id" local="content_id" />
|
||||
</foreign-key>
|
||||
<index name="idx_rewriting_product_id">
|
||||
<index-column name="product_id" />
|
||||
</index>
|
||||
<index name="idx_rewriting_category_id">
|
||||
<index-column name="category_id" />
|
||||
</index>
|
||||
<index name="idx_rewriting_folder_id">
|
||||
<index-column name="folder_id" />
|
||||
</index>
|
||||
<index name="idx_rewriting_content_id">
|
||||
<index-column name="content_id" />
|
||||
</index>
|
||||
<behavior name="timestampable" />
|
||||
</table>
|
||||
<table name="coupon" namespace="Thelia\Model">
|
||||
<column autoIncrement="true" name="id" primaryKey="true" required="true" type="INTEGER" />
|
||||
<column name="code" required="true" size="45" type="VARCHAR" />
|
||||
@@ -802,26 +835,21 @@
|
||||
<index-column name="is_available_on_special_offers" />
|
||||
</index>
|
||||
<behavior name="timestampable" />
|
||||
<behavior name="i18n" />
|
||||
<behavior name="i18n">
|
||||
<parameter name="i18n_columns" value="title, short_description, description" />
|
||||
</behavior>
|
||||
<behavior name="versionable" />
|
||||
</table>
|
||||
<table name="coupon_order" namespace="Thelia\Model">
|
||||
<column autoIncrement="true" name="id" primaryKey="true" required="true" type="INTEGER" />
|
||||
<column name="order_id" required="true" type="INTEGER" />
|
||||
<column name="code" required="true" size="45" type="VARCHAR" />
|
||||
<column name="value" required="true" type="FLOAT" />
|
||||
<foreign-key foreignTable="order" name="fk_coupon_order_order_id" onDelete="CASCADE" onUpdate="RESTRICT">
|
||||
<reference foreign="id" local="order_id" />
|
||||
</foreign-key>
|
||||
<foreign-key foreignTable="coupon" name="fk_coupon_order_coupon">
|
||||
<reference foreign="code" local="code" />
|
||||
</foreign-key>
|
||||
<index name="idx_coupon_order_order_id">
|
||||
<index-column name="order_id" />
|
||||
</index>
|
||||
<index name="fk_coupon_order_coupon_idx">
|
||||
<index-column name="code" />
|
||||
</index>
|
||||
<behavior name="timestampable" />
|
||||
</table>
|
||||
<table name="admin_log" namespace="Thelia\Model">
|
||||
@@ -1093,37 +1121,4 @@
|
||||
</index>
|
||||
<behavior name="timestampable" />
|
||||
</table>
|
||||
<table name="rewriting_url" namespace="Thelia\Model">
|
||||
<column autoIncrement="true" name="id" primaryKey="true" required="true" type="INTEGER" />
|
||||
<column name="url" required="true" size="255" type="VARCHAR" />
|
||||
<column name="view" required="true" size="255" type="VARCHAR" />
|
||||
<column name="view_id" size="255" type="VARCHAR" />
|
||||
<column name="view_locale" required="true" size="255" type="VARCHAR" />
|
||||
<column name="redirected" type="INTEGER" />
|
||||
<foreign-key foreignTable="rewriting_url" name="fk_rewriting_url_redirected" onDelete="RESTRICT" onUpdate="RESTRICT">
|
||||
<reference foreign="id" local="redirected" />
|
||||
</foreign-key>
|
||||
<unique name="url_UNIQUE">
|
||||
<unique-column name="url" />
|
||||
</unique>
|
||||
<index name="idx_view_id">
|
||||
<index-column name="view_id" />
|
||||
</index>
|
||||
<index name="idx_rewriting_url_redirected">
|
||||
<index-column name="redirected" />
|
||||
</index>
|
||||
<behavior name="timestampable" />
|
||||
</table>
|
||||
<table name="rewriting_argument" namespace="Thelia\Model">
|
||||
<column name="rewriting_url_id" primaryKey="true" required="true" type="INTEGER" />
|
||||
<column name="parameter" primaryKey="true" required="true" size="255" type="VARCHAR" />
|
||||
<column name="value" primaryKey="true" required="true" size="255" type="VARCHAR" />
|
||||
<foreign-key foreignTable="rewriting_url" name="fk_rewriting_argument_rewirting_url_id" onDelete="CASCADE" onUpdate="RESTRICT">
|
||||
<reference foreign="id" local="rewriting_url_id" />
|
||||
</foreign-key>
|
||||
<index name="fk_rewriting_argument_rewirting_url_id">
|
||||
<index-column name="rewriting_url_id" />
|
||||
</index>
|
||||
<behavior name="timestampable" />
|
||||
</table>
|
||||
</database>
|
||||
@@ -92,6 +92,13 @@
|
||||
</div>
|
||||
</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'}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user