diff --git a/core/lib/Thelia/Model/Base/Accessory.php b/core/lib/Thelia/Model/Base/Accessory.php index f5acd9977..f4110b19e 100644 --- a/core/lib/Thelia/Model/Base/Accessory.php +++ b/core/lib/Thelia/Model/Base/Accessory.php @@ -891,6 +891,10 @@ abstract class Accessory implements ActiveRecordInterface $modifiedColumns = array(); $index = 0; + $this->modifiedColumns[] = AccessoryTableMap::ID; + if (null !== $this->id) { + throw new PropelException('Cannot insert a value for auto-increment primary key (' . AccessoryTableMap::ID . ')'); + } // check the columns in natural order for more readable SQL queries if ($this->isColumnModified(AccessoryTableMap::ID)) { @@ -948,6 +952,13 @@ abstract class Accessory implements ActiveRecordInterface throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); } + try { + $pk = $con->lastInsertId(); + } catch (Exception $e) { + throw new PropelException('Unable to get autoincrement id.', 0, $e); + } + $this->setId($pk); + $this->setNew(false); } @@ -1224,7 +1235,6 @@ abstract class Accessory implements ActiveRecordInterface */ public function copyInto($copyObj, $deepCopy = false, $makeNew = true) { - $copyObj->setId($this->getId()); $copyObj->setProductId($this->getProductId()); $copyObj->setAccessory($this->getAccessory()); $copyObj->setPosition($this->getPosition()); @@ -1232,6 +1242,7 @@ abstract class Accessory implements ActiveRecordInterface $copyObj->setUpdatedAt($this->getUpdatedAt()); if ($makeNew) { $copyObj->setNew(true); + $copyObj->setId(NULL); // this is a auto-increment column, so set to default value } } diff --git a/core/lib/Thelia/Model/Map/AccessoryTableMap.php b/core/lib/Thelia/Model/Map/AccessoryTableMap.php index 80c0548ef..bcd663892 100644 --- a/core/lib/Thelia/Model/Map/AccessoryTableMap.php +++ b/core/lib/Thelia/Model/Map/AccessoryTableMap.php @@ -148,7 +148,7 @@ class AccessoryTableMap extends TableMap $this->setPhpName('Accessory'); $this->setClassName('\\Thelia\\Model\\Accessory'); $this->setPackage('Thelia.Model'); - $this->setUseIdGenerator(false); + $this->setUseIdGenerator(true); $this->setIsCrossRef(true); // columns $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); @@ -429,6 +429,10 @@ class AccessoryTableMap extends TableMap $criteria = $criteria->buildCriteria(); // build Criteria from Accessory object } + if ($criteria->containsKey(AccessoryTableMap::ID) && $criteria->keyContainsValue(AccessoryTableMap::ID) ) { + throw new PropelException('Cannot insert a value for auto-increment primary key ('.AccessoryTableMap::ID.')'); + } + // Set the correct dbName $query = AccessoryQuery::create()->mergeWith($criteria); diff --git a/install/faker.php b/install/faker.php index 23bbed2bb..39c3270e8 100755 --- a/install/faker.php +++ b/install/faker.php @@ -50,86 +50,108 @@ try { ->find(); $content->delete(); - //first category - $sweet = new Thelia\Model\Category(); - $sweet->setParent(0); - $sweet->setVisible(1); - $sweet->setPosition(1); - $sweet->setDescription($faker->text(255)); - $sweet->setTitle($faker->text(20)); + $accessory = Thelia\Model\AccessoryQuery::create() + ->find(); + $accessory->delete(); - $sweet->save(); + //features and features_av + $featureList = array(); + for($i=0; $i<4; $i++) { + $feature = new Thelia\Model\Feature(); + $feature->setVisible(rand(1, 10)>7 ? 0 : 1); + $feature->setPosition($i); + $feature->setTitle($faker->text(20)); + $feature->setDescription($faker->text(50)); - //second category - $jeans = new Thelia\Model\Category(); - $jeans->setParent(0); - $jeans->setVisible(1); - $jeans->setPosition(2); - $jeans->setDescription($faker->text(255)); - $jeans->setTitle($faker->text(20)); + $feature->save(); + $featureId = $feature->getId(); + $featureList[$featureId] = array(); - $jeans->save(); - - //third category - $other = new Thelia\Model\Category(); - $other->setParent($jeans->getId()); - $other->setVisible(1); - $other->setPosition(3); - $other->setDescription($faker->text(255)); - $other->setTitle($faker->text(20)); - - $other->save(); - - for ($i=1; $i <= 5; $i++) { - $product = new \Thelia\Model\Product(); - $product->addCategory($sweet); - $product->setTitle($faker->text(20)); - $product->setDescription($faker->text(250)); -/* $product->setQuantity($faker->randomNumber(1,50)); - $product->setPrice($faker->randomFloat(2, 20, 2500));*/ - $product->setVisible(1); - $product->setPosition($i); - $product->setRef($faker->text(255)); - $product->save(); - - $stock = new \Thelia\Model\ProductSaleElements(); - $stock->setProduct($product); - $stock->setQuantity($faker->randomNumber(1,50)); - $stock->setPromo($faker->randomNumber(0,1)); - $stock->save(); - - $productPrice = new \Thelia\Model\ProductPrice(); - $productPrice->setProductSaleElements($stock); - $productPrice->setCurrency($currency); - $productPrice->setPrice($faker->randomFloat(2, 20, 2500)); - $productPrice->save(); + for($j=0; $jsetFeature($feature); + $featureAv->setPosition($j); + $featureAv->setTitle($faker->text(20)); + $featureAv->setDescription($faker->text(255)); + $featureAv->save(); + $featureList[$featureId][] = $featureAv->getId(); + } } - for ($i=1; $i <= 5; $i++) { - $product = new \Thelia\Model\Product(); - $product->addCategory($jeans); - $product->setTitle($faker->text(20)); - $product->setDescription($faker->text(250)); -/* $product->setQuantity($faker->randomNumber(1,50)); - $product->setPrice($faker->randomFloat(2, 20, 2500));*/ - $product->setVisible(1); - $product->setPosition($i); - $product->setRef($faker->text(255)); - $product->save(); + //categories and products + $productIdList = array(); + $categoryIdList = array(); + for($i=0; $i<4; $i++) { + $category = new Thelia\Model\Category(); + $category->setParent(0); + $category->setVisible(rand(1, 10)>7 ? 0 : 1); + $category->setPosition($i); + $category->setTitle($faker->text(20)); + $category->setDescription($faker->text(255)); - $stock = new \Thelia\Model\ProductSaleElements(); - $stock->setProduct($product); - $stock->setQuantity($faker->randomNumber(1,50)); - $stock->setPromo($faker->randomNumber(0,1)); - $stock->save(); + $category->save(); + $categoryIdList[] = $category->getId(); - $productPrice = new \Thelia\Model\ProductPrice(); - $productPrice->setProductSaleElements($stock); - $productPrice->setCurrency($currency); - $productPrice->setPrice($faker->randomFloat(2, 20, 2500)); - $productPrice->save(); + for($j=0; $jsetParent($category->getId()); + $subcategory->setVisible(rand(1, 10)>7 ? 0 : 1); + $subcategory->setPosition($j); + $subcategory->setTitle($faker->text(20)); + $subcategory->setDescription($faker->text(255)); + $subcategory->save(); + $categoryIdList[] = $subcategory->getId(); + + for($k=0; $ksetRef($subcategory->getId() . '_' . $k . '_' . $faker->randomNumber(8)); + $product->addCategory($subcategory); + $product->setVisible(rand(1, 10)>7 ? 0 : 1); + $product->setPosition($k); + $product->setTitle($faker->text(20)); + $product->setDescription($faker->text(255)); + + $product->save(); + $productId = $product->getId(); + $productIdList[] = $productId; + + //add random accessories - or not + for($l=0; $lsetAccessory($productIdList[array_rand($productIdList, 1)]); + $accessory->setProductId($productId); + $accessory->setPosition($l); + + $accessory->save(); + } + } + } + + for($k=0; $ksetRef($category->getId() . '_' . $k . '_' . $faker->randomNumber(8)); + $product->addCategory($category); + $product->setVisible(rand(1, 10)>7 ? 0 : 1); + $product->setPosition($k); + $product->setTitle($faker->text(20)); + $product->setDescription($faker->text(255)); + + $product->save(); + $productId = $product->getId(); + $productIdList[] = $productId; + + //add random accessories + for($l=0; $lsetAccessory($productIdList[array_rand($productIdList, 1)]); + $accessory->setProductId($productId); + $accessory->setPosition($l); + + $accessory->save(); + } + } } //folders and contents @@ -166,27 +188,6 @@ try { } } - //features and features_av - for($i=0; $i<4; $i++) { - $feature = new Thelia\Model\Feature(); - $feature->setVisible(rand(1, 10)>7 ? 0 : 1); - $feature->setPosition($i); - $feature->setTitle($faker->text(20)); - $feature->setDescription($faker->text(50)); - - $feature->save(); - - for($j=0; $jsetFeature($feature); - $featureAv->setPosition($j); - $featureAv->setTitle($faker->text(20)); - $featureAv->setDescription($faker->text(255)); - - $featureAv->save(); - } - } - $con->commit(); } catch (Exception $e) { echo "error : ".$e->getMessage()."\n"; diff --git a/install/insert.sql b/install/insert.sql index ab349e09a..6518462c4 100755 --- a/install/insert.sql +++ b/install/insert.sql @@ -1,8 +1,8 @@ -INSERT INTO `lang`(`id`,`title`,`code`,`locale`,`url`,`by_default`,`position`,`created_at`,`updated_at`)VALUES -(1, 'Français', 'fr', 'fr_FR', '','1', '1', NOW(), NOW()), -(2, 'English', 'en', 'en_EN', '', '0', '2', NOW(), NOW()), -(3, 'Espanol', 'es', 'es_ES', '', '0', '3', NOW(), NOW()), -(4, 'Italiano', 'it', 'it_IT', '','0', '4', NOW(), NOW()); +INSERT INTO `lang`(`id`,`title`,`code`,`locale`,`url`,`by_default`,`created_at`,`updated_at`)VALUES +(1, 'Français', 'fr', 'fr_FR', '','1', NOW(), NOW()), +(2, 'English', 'en', 'en_EN', '', '0', NOW(), NOW()), +(3, 'Espanol', 'es', 'es_ES', '', '0', NOW(), NOW()), +(4, 'Italiano', 'it', 'it_IT', '','0', NOW(), NOW()); INSERT INTO `config` (`name`, `value`, `secured`, `hidden`, `created_at`, `updated_at`) VALUES ('session_config.default', '1', 1, 1, NOW(), NOW()), @@ -23,11 +23,11 @@ INSERT INTO `customer_title_i18n` (`id`, `locale`, `short`, `long`) VALUES (3, 'en_US', 'Miss', 'Miss'), (3, 'fr_FR', 'Mlle', 'Madamemoiselle'); -INSERT INTO `currency` (`id` ,`code` ,`symbol` ,`rate` ,`by_default`, `position` ,`created_at` ,`updated_at`) +INSERT INTO `currency` (`id` ,`code` ,`symbol` ,`rate` ,`by_default` ,`created_at` ,`updated_at`) VALUES -(1, 'EUR', '€', '1', '1', '1', NOW() , NOW()), -(2, 'USD', '$', '1.26', '0', '2', NOW(), NOW()), -(3, 'GBP', '£', '0.89', '0', '3',NOW(), NOW()); +(1, 'EUR', '€', '1', '1', NOW() , NOW()), +(2, 'USD', '$', '1.26', '0', NOW(), NOW()), +(3, 'GBP', '£', '0.89', '0', NOW(), NOW()); INSERT INTO `currency_i18n` (`id` ,`locale` ,`name`) VALUES diff --git a/install/thelia.sql b/install/thelia.sql index 547f22786..bf36a1708 100755 --- a/install/thelia.sql +++ b/install/thelia.sql @@ -617,8 +617,8 @@ CREATE TABLE `produt_image` `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), - INDEX `idx_product_id` (`product_id`), - CONSTRAINT `fk_product_id` + INDEX `idx_product_image_product_id` (`product_id`), + CONSTRAINT `fk_product_image_product_id` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`) ON UPDATE RESTRICT @@ -640,8 +640,8 @@ CREATE TABLE `product_document` `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), - INDEX `idx_product_id` (`product_id`), - CONSTRAINT `fk_product_id` + INDEX `idx_product_document_product_id` (`product_id`), + CONSTRAINT `fk_product_document_product_id` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`) ON UPDATE RESTRICT @@ -844,7 +844,7 @@ DROP TABLE IF EXISTS `accessory`; CREATE TABLE `accessory` ( - `id` INTEGER NOT NULL, + `id` INTEGER NOT NULL AUTO_INCREMENT, `product_id` INTEGER NOT NULL, `accessory` INTEGER NOT NULL, `position` INTEGER NOT NULL, @@ -1332,8 +1332,8 @@ CREATE TABLE `category_image` `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), - INDEX `idx_category_id` (`category_id`), - CONSTRAINT `fk_category_id` + INDEX `idx_category_image_category_id` (`category_id`), + CONSTRAINT `fk_category_image_category_id` FOREIGN KEY (`category_id`) REFERENCES `category` (`id`) ON UPDATE RESTRICT @@ -1355,8 +1355,8 @@ CREATE TABLE `folder_image` `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), - INDEX `idx_folder_id` (`folder_id`), - CONSTRAINT `fk_folder_id` + INDEX `idx_folder_image_folder_id` (`folder_id`), + CONSTRAINT `fk_folder_image_folder_id` FOREIGN KEY (`folder_id`) REFERENCES `folder` (`id`) ON UPDATE RESTRICT @@ -1378,8 +1378,8 @@ CREATE TABLE `content_image` `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), - INDEX `idx_content_id` (`content_id`), - CONSTRAINT `fk_content_id` + INDEX `idx_content_image_content_id` (`content_id`), + CONSTRAINT `fk_content_image_content_id` FOREIGN KEY (`content_id`) REFERENCES `content` (`id`) ON UPDATE RESTRICT @@ -1401,8 +1401,8 @@ CREATE TABLE `category_document` `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), - INDEX `idx_category_id` (`category_id`), - CONSTRAINT `fk_category_id` + INDEX `idx_category_document_category_id` (`category_id`), + CONSTRAINT `fk_catgory_document_category_id` FOREIGN KEY (`category_id`) REFERENCES `category` (`id`) ON UPDATE RESTRICT @@ -1424,8 +1424,8 @@ CREATE TABLE `content_document` `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), - INDEX `idx_content_id` (`content_id`), - CONSTRAINT `fk_content_id` + INDEX `idx_content_document_content_id` (`content_id`), + CONSTRAINT `fk_content_document_content_id` FOREIGN KEY (`content_id`) REFERENCES `content` (`id`) ON UPDATE RESTRICT @@ -1447,8 +1447,8 @@ CREATE TABLE `folder_document` `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), - INDEX `idx_folder_id` (`folder_id`), - CONSTRAINT `fk_folder_id` + INDEX `idx_folder_document_folder_id` (`folder_id`), + CONSTRAINT `fk_folder_document_folder_id` FOREIGN KEY (`folder_id`) REFERENCES `folder` (`id`) ON UPDATE RESTRICT diff --git a/local/config/schema.xml b/local/config/schema.xml index b52550e9c..48b46b3da 100755 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -459,10 +459,10 @@ - + - + @@ -479,10 +479,10 @@ - + - + @@ -629,7 +629,7 @@ - + @@ -973,10 +973,10 @@ - + - + @@ -993,10 +993,10 @@ - + - + @@ -1013,10 +1013,10 @@ - + - + @@ -1033,10 +1033,10 @@ - + - + @@ -1053,10 +1053,10 @@ - + - + @@ -1073,10 +1073,10 @@ - + - + diff --git a/templates/default/category.html b/templates/default/category.html index acb98e919..6aabd6edf 100755 --- a/templates/default/category.html +++ b/templates/default/category.html @@ -1,70 +1,80 @@ -{*loop name="category0" type="category" parent="0"} -

CATEGORY : #TITLE

- {loop name="category1" type="category" parent="#ID"} -
+
+ +

CATALOG

+ +{loop name="category0" type="category" parent="0" order="manual"} +
+

CATEGORY : #TITLE (#LOOP_COUNT / #LOOP_TOTAL)

+ {loop name="product" type="product" category="#ID"} +
+

PRODUCT : #REF (#LOOP_COUNT / #LOOP_TOTAL)

+

#TITLE

+

#DESCRIPTION

+ {ifloop rel="acc"} +
Accessories
+
    + {loop name="acc" type="accessory" product="#ID" order="accessory"} +
  • #REF
  • + {/loop} +
+ {/ifloop} + {elseloop rel="acc"} +
No accessory
+ {/elseloop} + {ifloop rel="ft"} +
Features
+
    + {loop name="ft" type="feature" order="manual" product="#ID"} +
  • #TITLE
  • + {/loop} +
+ {/ifloop} + {elseloop rel="ft"} +
No feature
+ {/elseloop} +
+ {/loop} + {loop name="catgory1" type="category" parent="#ID"} +

SUBCATEGORY : #TITLE (#LOOP_COUNT / #LOOP_TOTAL)

{loop name="product" type="product" category="#ID"} -

PRODUCT : #REF / #TITLE

- #PRICE € +
+

PRODUCT : #REF (#LOOP_COUNT / #LOOP_TOTAL)

+

#TITLE

+

#DESCRIPTION

+ {ifloop rel="acc"} +
Accessories
+
    + {loop name="acc" type="accessory" product="#ID" order="accessory"} +
  • #REF
  • + {/loop} +
+ {/ifloop} + {elseloop rel="acc"} +
No accessory
+ {/elseloop} + {ifloop rel="ft"} +
Features
+
    + {loop name="ft" type="feature" order="manual" product="#ID"} +
  • #TITLE
  • + {/loop} +
+ {/ifloop} + {elseloop rel="ft"} +
No feature
+ {/elseloop} +
{/loop} -
-
+
{/loop} - - {loop name="product" type="product" category="#ID"} -

PRODUCT : #REF / #TITLE

- #PRICE € - {/loop} -
-
-{/loop*} -

PRODUCTS

-{*loop name="product" type="product" order="promo,min_price" exclude_category="3"} -

PRODUCT : #REF / #TITLE

- price : #PRICE €
- promo price : #PROMO_PRICE €
- is promo : #PROMO
- is new : #NEW
- weight : #WEIGHT
-{/loop*} - -{*loop name="product" type="product" order="ref" feature_available="1: (1 | 2) , 2: 4, 3: 433"} -

PRODUCT : #REF / #TITLE

- price : #PRICE €
- promo price : #PROMO_PRICE €
- is promo : #PROMO
- is new : #NEW
- weight : #WEIGHT
-{/loop*} - -{*loop name="product" type="product" order="ref" feature_values="1: foo"} -

PRODUCT : #REF / #TITLE

- price : #PRICE €
- promo price : #PROMO_PRICE €
- is promo : #PROMO
- is new : #NEW
- weight : #WEIGHT
-{/loop*} - -{loop name="product" type="product" order="ref"} -

PRODUCT #ID : #REF / #TITLE

- -

Accessories

-
    - {loop name="acc" type="accessory" product="#ID" order="accessory"} -
  • #REF
  • - {/loop} -
- -

Features

-
    - {loop name="ft" type="feature" order="manual" product="#ID"} -
  • #TITLE
  • - {/loop} -
- +
{/loop} +
+ +
+

ALL FEATURES AND THEIR AVAILABILITY

    @@ -78,4 +88,35 @@
{/loop} - \ No newline at end of file + + +
+ +
+ {*loop name="product" type="product" order="promo,min_price" exclude_category="3"} +

PRODUCT : #REF / #TITLE

+ price : #PRICE €
+ promo price : #PROMO_PRICE €
+ is promo : #PROMO
+ is new : #NEW
+ weight : #WEIGHT
+ {/loop*} + + {*loop name="product" type="product" order="ref" feature_available="1: (1 | 2) , 2: 4, 3: 433"} +

PRODUCT : #REF / #TITLE

+ price : #PRICE €
+ promo price : #PROMO_PRICE €
+ is promo : #PROMO
+ is new : #NEW
+ weight : #WEIGHT
+ {/loop*} + + {*loop name="product" type="product" order="ref" feature_values="1: foo"} +

PRODUCT : #REF / #TITLE

+ price : #PRICE €
+ promo price : #PROMO_PRICE €
+ is promo : #PROMO
+ is new : #NEW
+ weight : #WEIGHT
+ {/loop*} +
\ No newline at end of file