update import using propel collection in all save methods

This commit is contained in:
Manuel Raynaud
2013-09-30 09:31:34 +02:00
parent 0878659368
commit 2928d0d3c0

View File

@@ -41,14 +41,14 @@ $con->beginTransaction();
try { try {
$stmt = $con->prepare("SET foreign_key_checks = 0"); $stmt = $con->prepare("SET foreign_key_checks = 0");
$stmt->execute(); $stmt->execute();
clearTables(); clearTables($con);
$stmt = $con->prepare("SET foreign_key_checks = 1"); $stmt = $con->prepare("SET foreign_key_checks = 1");
$stmt->execute(); $stmt->execute();
$categories = createCategories(); $categories = createCategories($con);
$color = createColors(); $color = createColors($con);
$brand = createBrand(); $brand = createBrand($con);
echo "creating templates\n"; echo "creating templates\n";
$template = new \Thelia\Model\Template(); $template = new \Thelia\Model\Template();
@@ -57,24 +57,24 @@ try {
->setName('template de démo') ->setName('template de démo')
->setLocale('en_US') ->setLocale('en_US')
->setName('demo template') ->setName('demo template')
->save(); ->save($con);
$at = new Thelia\Model\AttributeTemplate(); $at = new Thelia\Model\AttributeTemplate();
$at $at
->setTemplate($template) ->setTemplate($template)
->setAttribute($color) ->setAttribute($color)
->save(); ->save($con);
$ft = new Thelia\Model\FeatureTemplate(); $ft = new Thelia\Model\FeatureTemplate();
$ft $ft
->setTemplate($template) ->setTemplate($template)
->setFeature($brand) ->setFeature($brand)
->save(); ->save($con);
echo "end creating templates\n"; echo "end creating templates\n";
createProduct($faker, $categories, $template, $color, $brand); createProduct($faker, $categories, $template, $color, $brand, $con);
@@ -84,7 +84,7 @@ try {
$con->rollBack(); $con->rollBack();
} }
function createProduct($faker, $categories, $template, $attribute, $feature) function createProduct($faker, $categories, $template, $attribute, $feature, $con)
{ {
echo "start creating products\n"; echo "start creating products\n";
$fileSystem = new \Symfony\Component\Filesystem\Filesystem(); $fileSystem = new \Symfony\Component\Filesystem\Filesystem();
@@ -121,11 +121,11 @@ function createProduct($faker, $categories, $template, $attribute, $feature)
->setChapo($data[3]) ->setChapo($data[3])
->setDescription($data[5]) ->setDescription($data[5])
->setPostscriptum($data[7]) ->setPostscriptum($data[7])
->save(); ->save($con);
$productCategories = $product->getProductCategories()->getFirst(); $productCategories = $product->getProductCategories()->getFirst();
$productCategories->setDefaultCategory(true) $productCategories->setDefaultCategory(true)
->save(); ->save($con);
// Set the position // Set the position
$product->setPosition($product->getNextPosition())->save(); $product->setPosition($product->getNextPosition())->save();
@@ -139,7 +139,7 @@ function createProduct($faker, $categories, $template, $attribute, $feature)
$productImage $productImage
->setProduct($product) ->setProduct($product)
->setFile($image) ->setFile($image)
->save(); ->save($con);
$fileSystem->copy(THELIA_ROOT . 'install/import/images/'.$image, THELIA_ROOT . 'local/media/images/product/'.$image, true); $fileSystem->copy(THELIA_ROOT . 'install/import/images/'.$image, THELIA_ROOT . 'local/media/images/product/'.$image, true);
} }
@@ -160,42 +160,42 @@ function createProduct($faker, $categories, $template, $attribute, $feature)
$stock->setNewness($faker->randomNumber(0,1)); $stock->setNewness($faker->randomNumber(0,1));
$stock->setWeight($faker->randomFloat(2, 100,10000)); $stock->setWeight($faker->randomFloat(2, 100,10000));
$stock->save(); $stock->save($con);
$productPrice = new \Thelia\Model\ProductPrice(); $productPrice = new \Thelia\Model\ProductPrice();
$productPrice->setProductSaleElements($stock); $productPrice->setProductSaleElements($stock);
$productPrice->setCurrencyId(1); $productPrice->setCurrencyId(1);
$productPrice->setPrice($data[8]); $productPrice->setPrice($data[8]);
$productPrice->setPromoPrice($data[9]); $productPrice->setPromoPrice($data[9]);
$productPrice->save(); $productPrice->save($con);
$attributeAv = \Thelia\Model\AttributeAvI18nQuery::create() $attributeAv = \Thelia\Model\AttributeAvI18nQuery::create()
->filterByLocale('en_US') ->filterByLocale('en_US')
->filterByTitle($pse) ->filterByTitle($pse)
->findOne(); ->findOne($con);
$attributeCombination = new \Thelia\Model\AttributeCombination(); $attributeCombination = new \Thelia\Model\AttributeCombination();
$attributeCombination $attributeCombination
->setAttributeId($attribute->getId()) ->setAttributeId($attribute->getId())
->setAttributeAvId($attributeAv->getId()) ->setAttributeAvId($attributeAv->getId())
->setProductSaleElements($stock) ->setProductSaleElements($stock)
->save(); ->save($con);
} }
$productSaleElements = $product->getProductSaleElementss()->getFirst(); $productSaleElements = $product->getProductSaleElementss()->getFirst();
$productSaleElements->setIsDefault(1)->save(); $productSaleElements->setIsDefault(1)->save($con);
$brand = $data[11]; $brand = $data[11];
$featurAv = \Thelia\Model\FeatureAvI18nQuery::create() $featurAv = \Thelia\Model\FeatureAvI18nQuery::create()
->filterByLocale('en_US') ->filterByLocale('en_US')
->filterByTitle($brand) ->filterByTitle($brand)
->findOne(); ->findOne($con);
$featureProduct = new Thelia\Model\FeatureProduct(); $featureProduct = new Thelia\Model\FeatureProduct();
$featureProduct->setProduct($product) $featureProduct->setProduct($product)
->setFeatureId($feature->getId()) ->setFeatureId($feature->getId())
->setFeatureAvId($featurAv->getId()) ->setFeatureAvId($featurAv->getId())
->save() ->save($con)
; ;
@@ -205,7 +205,7 @@ function createProduct($faker, $categories, $template, $attribute, $feature)
echo "end creating products\n"; echo "end creating products\n";
} }
function createBrand() function createBrand($con)
{ {
echo "start creating brands feature\n"; echo "start creating brands feature\n";
if (($handle = fopen(THELIA_ROOT . '/install/import/brand.csv', "r")) !== FALSE) { if (($handle = fopen(THELIA_ROOT . '/install/import/brand.csv', "r")) !== FALSE) {
@@ -229,7 +229,7 @@ function createBrand()
$feature->addFeatureAv($featureAv); $feature->addFeatureAv($featureAv);
} }
$feature->save(); $feature->save($con);
fclose($handle); fclose($handle);
} }
echo "brands feature created successfully\n"; echo "brands feature created successfully\n";
@@ -237,7 +237,7 @@ function createBrand()
return $feature; return $feature;
} }
function createCategories() function createCategories($con)
{ {
echo "start creating categories\n"; echo "start creating categories\n";
$categories = array(); $categories = array();
@@ -255,7 +255,7 @@ function createCategories()
->setTitle(trim($data[0])) ->setTitle(trim($data[0]))
->setLocale('en_US') ->setLocale('en_US')
->setTitle(trim($data[1])) ->setTitle(trim($data[1]))
->save(); ->save($con);
$categories[trim($data[1])] = $category; $categories[trim($data[1])] = $category;
} }
fclose($handle); fclose($handle);
@@ -264,7 +264,7 @@ function createCategories()
return $categories; return $categories;
} }
function createColors() function createColors($con)
{ {
echo "start creating colors attributes\n"; echo "start creating colors attributes\n";
if (($handle = fopen(THELIA_ROOT . '/install/import/colors.csv', "r")) !== FALSE) { if (($handle = fopen(THELIA_ROOT . '/install/import/colors.csv', "r")) !== FALSE) {
@@ -289,91 +289,91 @@ function createColors()
$attribute->addAttributeAv($attributeAv); $attribute->addAttributeAv($attributeAv);
} }
$attribute->save(); $attribute->save($con);
fclose($handle); fclose($handle);
} }
echo "colors attributes created with success\n"; echo "colors attributes created with success\n";
return $attribute; return $attribute;
} }
function clearTables() function clearTables($con)
{ {
$productAssociatedContent = Thelia\Model\ProductAssociatedContentQuery::create() $productAssociatedContent = Thelia\Model\ProductAssociatedContentQuery::create()
->find(); ->find($con);
$productAssociatedContent->delete(); $productAssociatedContent->delete($con);
$categoryAssociatedContent = Thelia\Model\CategoryAssociatedContentQuery::create() $categoryAssociatedContent = Thelia\Model\CategoryAssociatedContentQuery::create()
->find(); ->find($con);
$categoryAssociatedContent->delete(); $categoryAssociatedContent->delete($con);
$featureProduct = Thelia\Model\FeatureProductQuery::create() $featureProduct = Thelia\Model\FeatureProductQuery::create()
->find(); ->find($con);
$featureProduct->delete(); $featureProduct->delete($con);
$attributeCombination = Thelia\Model\AttributeCombinationQuery::create() $attributeCombination = Thelia\Model\AttributeCombinationQuery::create()
->find(); ->find($con);
$attributeCombination->delete(); $attributeCombination->delete($con);
$feature = Thelia\Model\FeatureQuery::create() $feature = Thelia\Model\FeatureQuery::create()
->find(); ->find($con);
$feature->delete(); $feature->delete($con);
$feature = Thelia\Model\FeatureI18nQuery::create() $feature = Thelia\Model\FeatureI18nQuery::create()
->find(); ->find($con);
$feature->delete(); $feature->delete($con);
$featureAv = Thelia\Model\FeatureAvQuery::create() $featureAv = Thelia\Model\FeatureAvQuery::create()
->find(); ->find($con);
$featureAv->delete(); $featureAv->delete($con);
$featureAv = Thelia\Model\FeatureAvI18nQuery::create() $featureAv = Thelia\Model\FeatureAvI18nQuery::create()
->find(); ->find($con);
$featureAv->delete(); $featureAv->delete($con);
$attribute = Thelia\Model\AttributeQuery::create() $attribute = Thelia\Model\AttributeQuery::create()
->find(); ->find($con);
$attribute->delete(); $attribute->delete($con);
$attribute = Thelia\Model\AttributeI18nQuery::create() $attribute = Thelia\Model\AttributeI18nQuery::create()
->find(); ->find($con);
$attribute->delete(); $attribute->delete($con);
$attributeAv = Thelia\Model\AttributeAvQuery::create() $attributeAv = Thelia\Model\AttributeAvQuery::create()
->find(); ->find($con);
$attributeAv->delete(); $attributeAv->delete($con);
$attributeAv = Thelia\Model\AttributeAvI18nQuery::create() $attributeAv = Thelia\Model\AttributeAvI18nQuery::create()
->find(); ->find($con);
$attributeAv->delete(); $attributeAv->delete($con);
$category = Thelia\Model\CategoryQuery::create() $category = Thelia\Model\CategoryQuery::create()
->find(); ->find($con);
$category->delete(); $category->delete($con);
$category = Thelia\Model\CategoryI18nQuery::create() $category = Thelia\Model\CategoryI18nQuery::create()
->find(); ->find($con);
$category->delete(); $category->delete($con);
$product = Thelia\Model\ProductQuery::create() $product = Thelia\Model\ProductQuery::create()
->find(); ->find($con);
$product->delete(); $product->delete($con);
$product = Thelia\Model\ProductI18nQuery::create() $product = Thelia\Model\ProductI18nQuery::create()
->find(); ->find($con);
$product->delete(); $product->delete($con);
$accessory = Thelia\Model\AccessoryQuery::create() $accessory = Thelia\Model\AccessoryQuery::create()
->find(); ->find($con);
$accessory->delete(); $accessory->delete($con);
$stock = \Thelia\Model\ProductSaleElementsQuery::create() $stock = \Thelia\Model\ProductSaleElementsQuery::create()
->find(); ->find($con);
$stock->delete(); $stock->delete($con);
$productPrice = \Thelia\Model\ProductPriceQuery::create() $productPrice = \Thelia\Model\ProductPriceQuery::create()
->find(); ->find($con);
$productPrice->delete(); $productPrice->delete($con);
\Thelia\Model\ProductImageQuery::create()->find()->delete(); \Thelia\Model\ProductImageQuery::create()->find($con)->delete($con);
} }