diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml
index 607514fa1..f3d70ac89 100755
--- a/core/lib/Thelia/Config/Resources/routing/admin.xml
+++ b/core/lib/Thelia/Config/Resources/routing/admin.xml
@@ -34,6 +34,16 @@
Thelia\Controller\Admin\CategoryController::processAction
+
+ Thelia\Controller\Admin\CategoryController::getByParentIdAction
+ xml|json
+
+
+
+
+
+
+
@@ -53,6 +63,11 @@
read
+
+
+
+
+
diff --git a/core/lib/Thelia/Controller/Admin/CategoryController.php b/core/lib/Thelia/Controller/Admin/CategoryController.php
index 9966034f8..582358812 100755
--- a/core/lib/Thelia/Controller/Admin/CategoryController.php
+++ b/core/lib/Thelia/Controller/Admin/CategoryController.php
@@ -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);
+ }
}
diff --git a/core/lib/Thelia/Controller/Admin/CouponController.php b/core/lib/Thelia/Controller/Admin/CouponController.php
index c372ffca3..0895c52bf 100755
--- a/core/lib/Thelia/Controller/Admin/CouponController.php
+++ b/core/lib/Thelia/Controller/Admin/CouponController.php
@@ -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 {
diff --git a/core/lib/Thelia/Tools/Rest/ResponseRest.php b/core/lib/Thelia/Tools/Rest/ResponseRest.php
new file mode 100644
index 000000000..8618d460f
--- /dev/null
+++ b/core/lib/Thelia/Tools/Rest/ResponseRest.php
@@ -0,0 +1,83 @@
+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);
+ }
+
+}
diff --git a/install/faker.php b/install/faker.php
index 8ba653bec..50317386d 100755
--- a/install/faker.php
+++ b/install/faker.php
@@ -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);
diff --git a/install/thelia.sql b/install/thelia.sql
index 99b18513e..c27c5cd4a 100755
--- a/install/thelia.sql
+++ b/install/thelia.sql
@@ -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,
diff --git a/local/config/schema.xml b/local/config/schema.xml
index 159b21831..4427e49c6 100755
--- a/local/config/schema.xml
+++ b/local/config/schema.xml
@@ -1,1129 +1,1124 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
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+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/templates/admin/default/coupon/read.html b/templates/admin/default/coupon/read.html
index 9161f0d72..81557ef36 100755
--- a/templates/admin/default/coupon/read.html
+++ b/templates/admin/default/coupon/read.html
@@ -92,6 +92,13 @@
+boucle coupon
+{loop type="coupon" name="read_coupon" backend_context="true"}
+ inside
+ #ID
+ #CODE
+ #TITLE
+{/loop}
{include file='includes/js.inc.html'}