Merge branches 'coupon' and 'master' of https://github.com/thelia/thelia into coupon

* 'coupon' of https://github.com/thelia/thelia:

# By Etienne Roudeix (17) and others
# Via Etienne Roudeix (9) and others
* 'master' of https://github.com/thelia/thelia: (52 commits)
  fix content faker
  fix typo and remove url generation in postInsert model
  add covers annotation in ProductRewriteTest
  create test for UrlRewritingTrait
  payment loop
  fix postage display
  postage + invoice step
  template is not mandatory in product table.
  refactor rewrriten method name
  Changed getDefaultCategory in getDefaultCategoryId
  remove old model classes:
  Working : Content : fix loop giving no elements
  Working : Content : fix loop giving no elements
  Added missing files...
  Started product management
  Working : Content : fix loop giving no elements
  Working : Product : fix loop giving no elements
  cart billing integration
  empty cart or delivery exception
  remove isntall routing and template
  ...
This commit is contained in:
gmorel
2013-09-17 22:55:29 +02:00
178 changed files with 20645 additions and 2315 deletions

View File

@@ -5,12 +5,7 @@ use Thelia\Constraint\Rule\AvailableForTotalAmountManager;
use Thelia\Constraint\Rule\AvailableForXArticlesManager;
use Thelia\Constraint\Rule\Operators;
use Thelia\Coupon\CouponRuleCollection;
use Thelia\Model\ProductImage;
use Thelia\Model\CategoryImage;
use Thelia\Model\FolderImage;
use Thelia\Model\ContentImage;
use Imagine\Image\Color;
use Imagine\Image\Point;
require __DIR__ . '/../core/bootstrap.php';
@@ -24,12 +19,17 @@ $con = \Propel\Runtime\Propel::getConnection(
);
$con->beginTransaction();
// Intialize URL management
$url = new Thelia\Tools\URL();
$currency = \Thelia\Model\CurrencyQuery::create()->filterByCode('EUR')->findOne();
try {
$stmt = $con->prepare("SET foreign_key_checks = 0");
$stmt->execute();
echo "Clearing tables\n";
$productAssociatedContent = Thelia\Model\ProductAssociatedContentQuery::create()
->find();
$productAssociatedContent->delete();
@@ -126,9 +126,24 @@ try {
->find();
$productPrice->delete();
\Thelia\Model\ProductImageQuery::create()->find()->delete();
\Thelia\Model\CategoryImageQuery::create()->find()->delete();
\Thelia\Model\FolderImageQuery::create()->find()->delete();
\Thelia\Model\ContentImageQuery::create()->find()->delete();
\Thelia\Model\ProductDocumentQuery::create()->find()->delete();
\Thelia\Model\CategoryDocumentQuery::create()->find()->delete();
\Thelia\Model\FolderDocumentQuery::create()->find()->delete();
\Thelia\Model\ContentDocumentQuery::create()->find()->delete();
\Thelia\Model\CouponQuery::create()->find()->delete();
$stmt = $con->prepare("SET foreign_key_checks = 1");
$stmt->execute();
echo "Creating customer\n";
//customer
$customer = new Thelia\Model\Customer();
$customer->createOrUpdate(
@@ -186,11 +201,13 @@ try {
}
}
echo "Creating features\n";
//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->setVisible(1);
$feature->setPosition($i);
setI18n($faker, $feature);
@@ -209,6 +226,8 @@ try {
}
}
echo "Creating attributes\n";
//attributes and attributes_av
$attributeList = array();
for($i=0; $i<4; $i++) {
@@ -231,6 +250,8 @@ try {
}
}
echo "Creating templates\n";
$template = new Thelia\Model\Template();
setI18n($faker, $template, array("Name" => 20));
$template->save();
@@ -253,52 +274,75 @@ try {
->save();
}
echo "Creating folders and content\n";
//folders and contents
$contentIdList = array();
for($i=0; $i<4; $i++) {
$folder = new Thelia\Model\Folder();
$folder->setParent(0);
$folder->setVisible(rand(1, 10)>7 ? 0 : 1);
$folder->setPosition($i);
$folder->setVisible(1);
$folder->setPosition($i+1);
setI18n($faker, $folder);
$folder->save();
$image = new FolderImage();
$image = new \Thelia\Model\FolderImage();
$image->setFolderId($folder->getId());
generate_image($image, 1, 'folder', $folder->getId());
for($j=1; $j<rand(0, 5); $j++) {
$document = new \Thelia\Model\FolderDocument();
$document->setFolderId($folder->getId());
generate_document($document, 1, 'folder', $folder->getId());
for($j=0; $j<3; $j++) {
$subfolder = new Thelia\Model\Folder();
$subfolder->setParent($folder->getId());
$subfolder->setVisible(rand(1, 10)>7 ? 0 : 1);
$subfolder->setPosition($j);
$subfolder->setVisible(1);
$subfolder->setPosition($j+1);
setI18n($faker, $subfolder);
$subfolder->save();
$image = new FolderImage();
$image = new \Thelia\Model\FolderImage();
$image->setFolderId($subfolder->getId());
generate_image($image, 1, 'folder', $subfolder->getId());
for($k=0; $k<rand(0, 5); $k++) {
$document = new \Thelia\Model\FolderDocument();
$document->setFolderId($folder->getId());
generate_document($document, 1, 'folder', $subfolder->getId());
for($k=0; $k<4; $k++) {
$content = new Thelia\Model\Content();
$content->addFolder($subfolder);
$content->setVisible(rand(1, 10)>7 ? 0 : 1);
$content->setPosition($k);
$contentFolders = $content->getContentFolders();
$collection = new \Propel\Runtime\Collection\Collection();
$collection->prepend($contentFolders[0]->setDefaultFolder(1));
$content->setContentFolders($collection);
$content->setVisible(1);
$content->setPosition($k+1);
setI18n($faker, $content);
$content->save();
$contentId = $content->getId();
$contentIdList[] = $contentId;
$image = new ContentImage();
$image->setContentId($content->getId());
$image = new \Thelia\Model\ContentImage();
$image->setContentId($contentId);
generate_image($image, 1, 'content', $contentId);
$document = new \Thelia\Model\ContentDocument();
$document->setContentId($contentId);
generate_document($document, 1, 'content', $contentId);
}
}
}
echo "Creating categories and products\n";
//categories and products
$productIdList = array();
$categoryIdList = array();
@@ -406,20 +450,30 @@ try {
}
}
echo "Generating coupons fixtures\n";
generateCouponFixtures($thelia);
$con->commit();
echo "Successfully terminated.\n";
} catch (Exception $e) {
echo "error : ".$e->getMessage()."\n";
$con->rollBack();
}
function createProduct($faker, $category, $position, $template, &$productIdList)
function createProduct($faker, Thelia\Model\Category $category, $position, $template, &$productIdList)
{
$product = new Thelia\Model\Product();
$product->setRef($category->getId() . '_' . $position . '_' . $faker->randomNumber(8));
$product->addCategory($category);
$product->setVisible(rand(1, 10)>7 ? 0 : 1);
$product->setVisible(1);
$productCategories = $product->getProductCategories();
$collection = new \Propel\Runtime\Collection\Collection();
$collection->prepend($productCategories[0]->setDefaultCategory(1));
$product->setProductCategories($collection);
$product->setVisible(1);
$product->setPosition($position);
$product->setTaxRuleId(1);
$product->setTemplate($template);
@@ -430,10 +484,14 @@ function createProduct($faker, $category, $position, $template, &$productIdList)
$productId = $product->getId();
$productIdList[] = $productId;
$image = new ProductImage();
$image = new \Thelia\Model\ProductImage();
$image->setProductId($productId);
generate_image($image, 1, 'product', $productId);
$document = new \Thelia\Model\ProductDocument();
$document->setProductId($productId);
generate_document($document, 1, 'product', $productId);
return $product;
}
@@ -441,7 +499,7 @@ function createCategory($faker, $parent, $position, &$categoryIdList, $contentId
{
$category = new Thelia\Model\Category();
$category->setParent($parent);
$category->setVisible(rand(1, 10)>7 ? 0 : 1);
$category->setVisible(1);
$category->setPosition($position);
setI18n($faker, $category);
@@ -465,10 +523,14 @@ function createCategory($faker, $parent, $position, &$categoryIdList, $contentId
->save();
}
$image = new CategoryImage();
$image = new \Thelia\Model\CategoryImage();
$image->setCategoryId($categoryId);
generate_image($image, 1, 'category', $categoryId);
$document = new \Thelia\Model\CategoryDocument();
$document->setCategoryId($categoryId);
generate_document($document, 1, 'category', $categoryId);
return $category;
}
@@ -481,37 +543,36 @@ function generate_image($image, $position, $typeobj, $id) {
->setDescription($faker->text(250))
->setChapo($faker->text(40))
->setPostscriptum($faker->text(40))
->setPosition($position)
->setFile(sprintf("sample-image-%s.png", $id))
->save()
;
// Generate images
$imagine = new Imagine\Gd\Imagine();
$image = $imagine->create(new Imagine\Image\Box(320,240), new Color('#E9730F'));
$image = $imagine->create(new Imagine\Image\Box(320,240), new Imagine\Image\Color('#E9730F'));
$white = new Color('#FFF');
$white = new Imagine\Image\Color('#FFF');
$font = $imagine->font(__DIR__.'/faker-assets/FreeSans.ttf', 14, $white);
$tbox = $font->box("THELIA");
$image->draw()->text("THELIA", $font, new Point((320 - $tbox->getWidth()) / 2, 30));
$image->draw()->text("THELIA", $font, new Imagine\Image\Point((320 - $tbox->getWidth()) / 2, 30));
$str = sprintf("%s sample image", ucfirst($typeobj));
$tbox = $font->box($str);
$image->draw()->text($str, $font, new Point((320 - $tbox->getWidth()) / 2, 80));
$image->draw()->text($str, $font, new Imagine\Image\Point((320 - $tbox->getWidth()) / 2, 80));
$font = $imagine->font(__DIR__.'/faker-assets/FreeSans.ttf', 18, $white);
$str = sprintf("%s ID %d", strtoupper($typeobj), $id);
$tbox = $font->box($str);
$image->draw()->text($str, $font, new Point((320 - $tbox->getWidth()) / 2, 180));
$image->draw()->text($str, $font, new Imagine\Image\Point((320 - $tbox->getWidth()) / 2, 180));
$image->draw()
->line(new Point(0, 0), new Point(319, 0), $white)
->line(new Point(319, 0), new Point(319, 239), $white)
->line(new Point(319, 239), new Point(0,239), $white)
->line(new Point(0, 239), new Point(0, 0), $white)
->line(new Imagine\Image\Point(0, 0), new Imagine\Image\Point(319, 0), $white)
->line(new Imagine\Image\Point(319, 0), new Imagine\Image\Point(319, 239), $white)
->line(new Imagine\Image\Point(319, 239), new Imagine\Image\Point(0,239), $white)
->line(new Imagine\Image\Point(0, 239), new Imagine\Image\Point(0, 0), $white)
;
$image_file = sprintf("%s/../local/media/images/%s/sample-image-%s.png", __DIR__, $typeobj, $id);
@@ -521,6 +582,26 @@ function generate_image($image, $position, $typeobj, $id) {
$image->save($image_file);
}
function generate_document($document, $position, $typeobj, $id) {
global $faker;
$document
->setTitle($faker->text(20))
->setDescription($faker->text(250))
->setChapo($faker->text(40))
->setPostscriptum($faker->text(40))
->setFile(sprintf("sample-document-%s.txt", $id))
->save()
;
$document_file = sprintf("%s/../local/media/documents/%s/sample-document-%s.txt", __DIR__, $typeobj, $id);
if (! is_dir(dirname($document_file))) mkdir(dirname($document_file), 0777, true);
file_put_contents($document_file, $faker->text(256));
}
function setI18n($faker, &$object, $fields = array('Title' => 20, 'Description' => 50) )
{
$localeList = $localeList = array('fr_FR', 'en_US', 'es_ES', 'it_IT');