function createCategory($faker, $parent, $position, &$categoryIdList, $contentIdList) { $category = new Thelia\Model\Category(); $category->setParent($parent); $category->setVisible(1); $category->setPosition($position); setI18n($category); $category->save(); $categoryId = $category->getId(); $categoryIdList[] = $categoryId; //add random associated content $alreadyPicked = array(); for ($i = 1; $i < rand(0, 3); $i++) { $categoryAssociatedContent = new Thelia\Model\CategoryAssociatedContent(); do { $pick = array_rand($contentIdList, 1); } while (in_array($pick, $alreadyPicked)); $alreadyPicked[] = $pick; $categoryAssociatedContent->setContentId($contentIdList[$pick])->setCategoryId($categoryId)->setPosition($i)->save(); } $image = new \Thelia\Model\CategoryImage(); $image->setCategoryId($categoryId); generate_image($image, 'category', $categoryId); $document = new \Thelia\Model\CategoryDocument(); $document->setCategoryId($categoryId); generate_document($document, 'category', $categoryId); return $category; }
$stmt->execute(); //categories and products for ($i = 0; $i < 100; $i++) { $category = new Thelia\Model\Category(); $category->setParent(0); $category->setVisible(1); $category->setPosition($i); setI18n($faker, $category); $category->save(); for ($j = 0; $j < 10; $j++) { $product = new Thelia\Model\Product(); $product->setRef($category->getId() . '_' . $j . '_' . $faker->randomNumber(8)); $product->addCategory($category); $product->setVisible(1); $product->setPosition($j); setI18n($faker, $product); $product->save(); } } $con->commit(); } catch (Exception $e) { echo "error : " . $e->getMessage() . "\n"; $con->rollBack(); } function setI18n($faker, &$object, $fields = array('Title' => 20, 'Description' => 50)) { $localeList = array('fr_FR', 'en_US', 'es_ES', 'it_IT', 'de_DE'); foreach ($localeList as $locale) { $object->setLocale($locale); foreach ($fields as $name => $length) { $func = "set{$name}";