beginTransaction(); $currency = \Thelia\Model\CurrencyQuery::create()->filterByCode('EUR')->findOne(); try { $feature = Thelia\Model\FeatureQuery::create() ->find(); $feature->delete(); $featureAv = Thelia\Model\FeatureAvQuery::create() ->find(); $featureAv->delete(); $attribute = Thelia\Model\AttributeQuery::create() ->find(); $attribute->delete(); $attributeAv = Thelia\Model\AttributeAvQuery::create() ->find(); $attributeAv->delete(); $category = Thelia\Model\CategoryQuery::create() ->find(); $category->delete(); $product = Thelia\Model\ProductQuery::create() ->find(); $product->delete(); $customer = Thelia\Model\CustomerQuery::create() ->find(); $customer->delete(); $customer = new Thelia\Model\Customer(); $customer->createOrUpdate( 1, "thelia", "thelia", "5 rue rochon", "", "", "0102030405", "0601020304", "63000", "clermont-ferrand", 64, "test@thelia.net", "azerty" ); $folder = Thelia\Model\FolderQuery::create() ->find(); $folder->delete(); $content = Thelia\Model\ContentQuery::create() ->find(); $content->delete(); $accessory = Thelia\Model\AccessoryQuery::create() ->find(); $accessory->delete(); $stock = \Thelia\Model\ProductSaleElementsQuery::create() ->find(); $stock->delete(); $productPrice = \Thelia\Model\ProductPriceQuery::create() ->find(); $productPrice->delete(); //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)); $feature->save(); $featureId = $feature->getId(); $featureList[$featureId] = array(); for($j=0; $jsetFeature($feature); $featureAv->setPosition($j); $featureAv->setTitle($faker->text(20)); $featureAv->setDescription($faker->text(255)); $featureAv->save(); $featureList[$featureId][] = $featureAv->getId(); } } //attributes and attributes_av $attributeList = array(); for($i=0; $i<4; $i++) { $attribute = new Thelia\Model\Attribute(); $attribute->setPosition($i); $attribute->setTitle($faker->text(20)); $attribute->setDescription($faker->text(50)); $attribute->save(); $attributeId = $attribute->getId(); $attributeList[$attributeId] = array(); for($j=0; $jsetAttribute($attribute); $attributeAv->setPosition($j); $attributeAv->setTitle($faker->text(20)); $attributeAv->setDescription($faker->text(255)); $attributeAv->save(); $attributeList[$attributeId][] = $attributeAv->getId(); } } //categories and products $productIdList = array(); $categoryIdList = array(); for($i=0; $i<4; $i++) { $category = createCategory($faker, 0, $i, $categoryIdList); for($j=1; $jgetId(), $j, $categoryIdList); for($k=0; $ksetParent(0); $folder->setVisible(rand(1, 10)>7 ? 0 : 1); $folder->setPosition($i); $folder->setTitle($faker->text(20)); $folder->setDescription($faker->text(255)); $folder->save(); for($j=1; $jsetParent($folder->getId()); $subfolder->setVisible(rand(1, 10)>7 ? 0 : 1); $subfolder->setPosition($j); $subfolder->setTitle($faker->text(20)); $subfolder->setDescription($faker->text(255)); $subfolder->save(); for($k=0; $kaddFolder($subfolder); $content->setVisible(rand(1, 10)>7 ? 0 : 1); $content->setPosition($k); $content->setTitle($faker->text(20)); $content->setDescription($faker->text(255)); $content->save(); } } } $con->commit(); } catch (Exception $e) { echo "error : ".$e->getMessage()."\n"; $con->rollBack(); } function createProduct($faker, $category, $position, $currency, &$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->setPosition($position); $product->setTitle($faker->text(20)); $product->setDescription($faker->text(255)); $product->save(); $productId = $product->getId(); $productIdList[] = $productId; $stock = new \Thelia\Model\ProductSaleElements(); $stock->setProduct($product); $stock->setQuantity($faker->randomNumber(1,50)); $stock->setPromo($faker->randomNumber(0,1)); $stock->setNewness($faker->randomNumber(0,1)); $stock->setWeight($faker->randomFloat(2, 100,10000)); $stock->save(); $productPrice = new \Thelia\Model\ProductPrice(); $productPrice->setProductSaleElements($stock); $productPrice->setCurrency($currency); $productPrice->setPrice($faker->randomFloat(2, 20, 250)); $productPrice->setPromoPrice($faker->randomFloat(2, 20, 250)); $productPrice->save(); //add random accessories - or not for($i=1; $isetAccessory($productIdList[array_rand($productIdList, 1)]); $accessory->setProductId($productId); $accessory->setPosition($i); $accessory->save(); } return $product; } function createCategory($faker, $parent, $position, &$categoryIdList) { $category = new Thelia\Model\Category(); $category->setParent($parent); $category->setVisible(rand(1, 10)>7 ? 0 : 1); $category->setPosition($position); $category->setTitle($faker->text(20)); $category->setDescription($faker->text(255)); $category->save(); $categoryIdList[] = $category->getId(); return $category; }