create a faker for adding some fixtures

This commit is contained in:
Manuel Raynaud
2013-04-30 14:12:52 +02:00
parent 1aaab031fc
commit 5b4daf0659
113 changed files with 3890 additions and 1548 deletions

67
install/faker.php Normal file
View File

@@ -0,0 +1,67 @@
<?php
require __DIR__ . '/../core/bootstrap.php';
$thelia = new Thelia\Core\Thelia("dev", true);
$faker = Faker\Factory::create();
$con = \Propel::getConnection(Thelia\Model\ProductPeer::DATABASE_NAME);
$con->beginTransaction();
try {
//first category
$sweet = new Thelia\Model\Category();
$sweet->setParent(0);
$sweet->setVisible(1);
$sweet->setPosition(1);
$sweet->setDescription($faker->text(255));
$sweet->setTitle($faker->bs);
$sweet->save();
//second category
$jeans = new Thelia\Model\Category();
$jeans->setParent(0);
$jeans->setVisible(1);
$jeans->setPosition(2);
$jeans->setDescription($faker->text(255));
$jeans->setTitle($faker->bs);
$jeans->save();
for ($i=1; $i <= 5; $i++) {
$product = new \Thelia\Model\Product();
$product->addCategory($sweet);
$product->setTitle($faker->bs);
$product->setDescription($faker->text(250));
$product->setStock($faker->randomNumber(1,50));
$product->setPrice($faker->randomFloat(2, 20, 2500));
$product->setVisible(1);
$product->setPosition($i);
$product->setRef($faker->text(255));
$product->save();
}
for ($i=1; $i <= 5; $i++) {
$product = new \Thelia\Model\Product();
$product->addCategory($jeans);
$product->setTitle($faker->bs);
$product->setDescription($faker->text(250));
$product->setStock($faker->randomNumber(1,50));
$product->setPrice($faker->randomFloat(2, 20, 2500));
$product->setVisible(1);
$product->setPosition($i);
$product->setRef($faker->text(255));
$product->save();
}
$con->commit();
} catch (Exception $e) {
echo "error : ".$e->getMessage();
$con->rollBack();
}