import product and images
@@ -50,14 +50,139 @@ try {
|
||||
|
||||
|
||||
$categories = createCategories();
|
||||
createColors();
|
||||
createBrand();
|
||||
$color = createColors();
|
||||
$brand = createBrand();
|
||||
|
||||
echo "creating templates\n";
|
||||
$template = new \Thelia\Model\Template();
|
||||
$template
|
||||
->setLocale('fr_FR')
|
||||
->setName('template de démo')
|
||||
->setLocale('en_US')
|
||||
->setName('demo template')
|
||||
->save();
|
||||
|
||||
$at = new Thelia\Model\AttributeTemplate();
|
||||
|
||||
$at
|
||||
->setTemplate($template)
|
||||
->setAttribute($color)
|
||||
->save();
|
||||
|
||||
$ft = new Thelia\Model\FeatureTemplate();
|
||||
|
||||
$ft
|
||||
->setTemplate($template)
|
||||
->setFeature($brand)
|
||||
->save();
|
||||
echo "end creating templates\n";
|
||||
|
||||
createProduct($categories, $template);
|
||||
|
||||
|
||||
|
||||
$con->commit();
|
||||
} catch (Exception $e) {
|
||||
echo "error : ".$e->getMessage()."\n";
|
||||
$con->rollBack();
|
||||
}
|
||||
|
||||
function createProduct($categories, $template)
|
||||
{
|
||||
echo "start creating products\n";
|
||||
$fileSystem = new \Symfony\Component\Filesystem\Filesystem();
|
||||
if (($handle = fopen(THELIA_ROOT . '/install/import/products.csv', "r")) !== FALSE) {
|
||||
$row=0;
|
||||
while (($data = fgetcsv($handle, 100000, ";")) !== FALSE) {
|
||||
$row++;
|
||||
if($row == 1) continue;
|
||||
$product = new \Thelia\Model\Product();
|
||||
$productCategories = explode(';', $data[13]);
|
||||
$product
|
||||
->setRef($data[0])
|
||||
->setVisible(1)
|
||||
->setTaxRuleId(1)
|
||||
->setTemplate($template)
|
||||
;
|
||||
foreach($productCategories as $productCategory) {
|
||||
|
||||
$productCategory = trim($productCategory);
|
||||
if(array_key_exists($productCategory, $categories)) {
|
||||
$product->addCategory($categories[$productCategory]);
|
||||
}
|
||||
}
|
||||
|
||||
$productCategories = $product->getProductCategories();
|
||||
$collection = new \Propel\Runtime\Collection\Collection();
|
||||
foreach($productCategories as $i => $productCategory) {
|
||||
if($i == 0) {
|
||||
$collection->append($productCategory->setDefaultCategory(1));
|
||||
} else {
|
||||
$collection->append($productCategory);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$product->setProductCategories($collection);
|
||||
|
||||
$product
|
||||
->setLocale('en_US')
|
||||
->setTitle($data[1])
|
||||
->setChapo($data[2])
|
||||
->setDescription($data[4])
|
||||
->setPostscriptum($data[6])
|
||||
->setLocale('fr_Fr')
|
||||
->setTitle($data[1])
|
||||
->setChapo($data[3])
|
||||
->setDescription($data[5])
|
||||
->setPostscriptum($data[7])
|
||||
->save();
|
||||
|
||||
$images = explode(';', $data[10]);
|
||||
|
||||
foreach ($images as $image) {
|
||||
$image = trim($image);
|
||||
if(empty($image)) continue;
|
||||
var_dump($image);
|
||||
$productImage = new \Thelia\Model\ProductImage();
|
||||
$productImage
|
||||
->setProduct($product)
|
||||
->setFile($image)
|
||||
->save();
|
||||
$fileSystem->copy(THELIA_ROOT . 'install/import/images/'.$image, THELIA_ROOT . 'local/media/images/product/'.$image, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* $product = new Thelia\Model\Product();
|
||||
$product->setRef($category->getId() . '_' . $position . '_' . $faker->randomNumber(8));
|
||||
$product->addCategory($category);
|
||||
$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);
|
||||
|
||||
setI18n($faker, $product);
|
||||
|
||||
$product->save();
|
||||
$productId = $product->getId();
|
||||
$productIdList[] = $productId;
|
||||
|
||||
$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);*/
|
||||
echo "end creating products\n";
|
||||
}
|
||||
|
||||
function createBrand()
|
||||
{
|
||||
echo "start creating brands feature\n";
|
||||
@@ -86,6 +211,8 @@ function createBrand()
|
||||
fclose($handle);
|
||||
}
|
||||
echo "brands feature created successfully\n";
|
||||
|
||||
return $feature;
|
||||
}
|
||||
|
||||
function createCategories()
|
||||
@@ -103,11 +230,11 @@ function createCategories()
|
||||
->setPosition($row-1)
|
||||
->setParent(0)
|
||||
->setLocale('fr_FR')
|
||||
->setTitle($data[0])
|
||||
->setTitle(trim($data[0]))
|
||||
->setLocale('en_US')
|
||||
->setTitle($data[1])
|
||||
->setTitle(trim($data[1]))
|
||||
->save();
|
||||
$categories[$data[1]] = $category->getId();
|
||||
$categories[trim($data[1])] = $category;
|
||||
}
|
||||
fclose($handle);
|
||||
}
|
||||
@@ -144,6 +271,7 @@ function createColors()
|
||||
fclose($handle);
|
||||
}
|
||||
echo "colors attributes created with success\n";
|
||||
return $attribute;
|
||||
}
|
||||
|
||||
function clearTables()
|
||||
|
||||
0
install/import/images/PROD001-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 50 KiB After Width: | Height: | Size: 50 KiB |
0
install/import/images/PROD001-2.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 105 KiB After Width: | Height: | Size: 105 KiB |
0
install/import/images/PROD001-3.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 100 KiB After Width: | Height: | Size: 100 KiB |
0
install/import/images/PROD001-4.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 108 KiB After Width: | Height: | Size: 108 KiB |
0
install/import/images/PROD001-5.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 102 KiB After Width: | Height: | Size: 102 KiB |
0
install/import/images/PROD002-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 138 KiB After Width: | Height: | Size: 138 KiB |
0
install/import/images/PROD002-2.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 124 KiB After Width: | Height: | Size: 124 KiB |
0
install/import/images/PROD002-3.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 73 KiB After Width: | Height: | Size: 73 KiB |
0
install/import/images/PROD002-4.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 128 KiB After Width: | Height: | Size: 128 KiB |
0
install/import/images/PROD002-5.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 127 KiB After Width: | Height: | Size: 127 KiB |
0
install/import/images/PROD002-6.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 126 KiB After Width: | Height: | Size: 126 KiB |
0
install/import/images/PROD003-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 157 KiB After Width: | Height: | Size: 157 KiB |
0
install/import/images/PROD003-2.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 267 KiB After Width: | Height: | Size: 267 KiB |
0
install/import/images/PROD003-3.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 254 KiB After Width: | Height: | Size: 254 KiB |
0
install/import/images/PROD004-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 217 KiB After Width: | Height: | Size: 217 KiB |
0
install/import/images/PROD004-2.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 123 KiB After Width: | Height: | Size: 123 KiB |
0
install/import/images/PROD005-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 155 KiB After Width: | Height: | Size: 155 KiB |
0
install/import/images/PROD005-2.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 142 KiB After Width: | Height: | Size: 142 KiB |
0
install/import/images/PROD005-3.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 141 KiB After Width: | Height: | Size: 141 KiB |
0
install/import/images/PROD005-4.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 79 KiB After Width: | Height: | Size: 79 KiB |
0
install/import/images/PROD005-5.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 144 KiB After Width: | Height: | Size: 144 KiB |
0
install/import/images/PROD005-6.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 139 KiB After Width: | Height: | Size: 139 KiB |
0
install/import/images/PROD006-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 208 KiB After Width: | Height: | Size: 208 KiB |
0
install/import/images/PROD006-2.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 127 KiB After Width: | Height: | Size: 127 KiB |
0
install/import/images/PROD006-3.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 208 KiB After Width: | Height: | Size: 208 KiB |
0
install/import/images/PROD006-4.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 203 KiB After Width: | Height: | Size: 203 KiB |
0
install/import/images/PROD006-5.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 203 KiB After Width: | Height: | Size: 203 KiB |
0
install/import/images/PROD006-6.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 199 KiB After Width: | Height: | Size: 199 KiB |
0
install/import/images/PROD007-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 254 KiB After Width: | Height: | Size: 254 KiB |
0
install/import/images/PROD007-2.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 159 KiB After Width: | Height: | Size: 159 KiB |
0
install/import/images/PROD007-3.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 247 KiB After Width: | Height: | Size: 247 KiB |
0
install/import/images/PROD007-4.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 247 KiB After Width: | Height: | Size: 247 KiB |
0
install/import/images/PROD008-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 177 KiB After Width: | Height: | Size: 177 KiB |
0
install/import/images/PROD008-2.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 120 KiB After Width: | Height: | Size: 120 KiB |
0
install/import/images/PROD008-3.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 184 KiB After Width: | Height: | Size: 184 KiB |
0
install/import/images/PROD008-4.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 190 KiB After Width: | Height: | Size: 190 KiB |
0
install/import/images/PROD008-5.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 184 KiB After Width: | Height: | Size: 184 KiB |
0
install/import/images/PROD009-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 126 KiB After Width: | Height: | Size: 126 KiB |
0
install/import/images/PROD009-2.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 123 KiB After Width: | Height: | Size: 123 KiB |
0
install/import/images/PROD009-3.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 74 KiB |
0
install/import/images/PROD010-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 264 KiB After Width: | Height: | Size: 264 KiB |
0
install/import/images/PROD010-2.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 160 KiB After Width: | Height: | Size: 160 KiB |
0
install/import/images/PROD010-3.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 263 KiB After Width: | Height: | Size: 263 KiB |
0
install/import/images/PROD010-4.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 255 KiB After Width: | Height: | Size: 255 KiB |
0
install/import/images/PROD011-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 100 KiB After Width: | Height: | Size: 100 KiB |
0
install/import/images/PROD011-2.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 108 KiB After Width: | Height: | Size: 108 KiB |
0
install/import/images/PROD011-3.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 61 KiB |
0
install/import/images/PROD011-4.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 106 KiB |
0
install/import/images/PROD012-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 100 KiB After Width: | Height: | Size: 100 KiB |
0
install/import/images/PROD012-2.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 68 KiB After Width: | Height: | Size: 68 KiB |
0
install/import/images/PROD013-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 77 KiB After Width: | Height: | Size: 77 KiB |
0
install/import/images/PROD014-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 108 KiB After Width: | Height: | Size: 108 KiB |
0
install/import/images/PROD014-2.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 100 KiB After Width: | Height: | Size: 100 KiB |
0
install/import/images/PROD014-3.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 53 KiB After Width: | Height: | Size: 53 KiB |
0
install/import/images/PROD014-4.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 102 KiB After Width: | Height: | Size: 102 KiB |
0
install/import/images/PROD015-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 46 KiB |
0
install/import/images/PROD015-2.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 55 KiB |
0
install/import/images/PROD016-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 134 KiB After Width: | Height: | Size: 134 KiB |
0
install/import/images/PROD017-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 231 KiB After Width: | Height: | Size: 231 KiB |
0
install/import/images/PROD017-2.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 144 KiB After Width: | Height: | Size: 144 KiB |
0
install/import/images/PROD017-3.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 223 KiB After Width: | Height: | Size: 223 KiB |
0
install/import/images/PROD017-4.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 221 KiB After Width: | Height: | Size: 221 KiB |
0
install/import/images/PROD018-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 120 KiB After Width: | Height: | Size: 120 KiB |
0
install/import/images/PROD019-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 148 KiB After Width: | Height: | Size: 148 KiB |
0
install/import/images/PROD019-2.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 146 KiB After Width: | Height: | Size: 146 KiB |
0
install/import/images/PROD019-3.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 83 KiB After Width: | Height: | Size: 83 KiB |
0
install/import/images/PROD019-4.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 136 KiB After Width: | Height: | Size: 136 KiB |
0
install/import/images/PROD019-5.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 140 KiB After Width: | Height: | Size: 140 KiB |
0
install/import/images/PROD020-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 96 KiB After Width: | Height: | Size: 96 KiB |
0
install/import/images/PROD021-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 104 KiB After Width: | Height: | Size: 104 KiB |
0
install/import/images/PROD021-2.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 98 KiB After Width: | Height: | Size: 98 KiB |
0
install/import/images/PROD021-3.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 94 KiB After Width: | Height: | Size: 94 KiB |
0
install/import/images/PROD021-4.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 56 KiB |
0
install/import/images/PROD022-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 101 KiB After Width: | Height: | Size: 101 KiB |
0
install/import/images/PROD022-2.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 168 KiB After Width: | Height: | Size: 168 KiB |
0
install/import/images/PROD022-3.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 158 KiB After Width: | Height: | Size: 158 KiB |
0
install/import/images/PROD022-4.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 156 KiB After Width: | Height: | Size: 156 KiB |
0
install/import/images/PROD022-5.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 158 KiB After Width: | Height: | Size: 158 KiB |
0
install/import/images/PROD023-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 108 KiB After Width: | Height: | Size: 108 KiB |
0
install/import/images/PROD023-2.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 103 KiB After Width: | Height: | Size: 103 KiB |
0
install/import/images/PROD023-3.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 61 KiB |
0
install/import/images/PROD023-4.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 105 KiB After Width: | Height: | Size: 105 KiB |
0
install/import/images/PROD023-5.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 103 KiB After Width: | Height: | Size: 103 KiB |
0
install/import/images/PROD023-6.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 103 KiB After Width: | Height: | Size: 103 KiB |
0
install/import/images/PROD024-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 218 KiB After Width: | Height: | Size: 218 KiB |
0
install/import/images/PROD024-2.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 217 KiB After Width: | Height: | Size: 217 KiB |
0
install/import/images/PROD024-3.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 222 KiB After Width: | Height: | Size: 222 KiB |
0
install/import/images/PROD024-4.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 211 KiB After Width: | Height: | Size: 211 KiB |
0
install/import/images/PROD024-5.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 139 KiB After Width: | Height: | Size: 139 KiB |
0
install/import/images/PROD025-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 129 KiB After Width: | Height: | Size: 129 KiB |
0
install/import/images/PROD025-2.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 208 KiB After Width: | Height: | Size: 208 KiB |
0
install/import/images/PROD025-3.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 204 KiB After Width: | Height: | Size: 204 KiB |
0
install/import/images/PROD026-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 61 KiB |
0
install/import/images/PROD027-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 68 KiB After Width: | Height: | Size: 68 KiB |
0
install/import/images/PROD028-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 86 KiB After Width: | Height: | Size: 86 KiB |
0
install/import/images/PROD029-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 68 KiB After Width: | Height: | Size: 68 KiB |
0
install/import/images/PROD030-1.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 100 KiB After Width: | Height: | Size: 100 KiB |
0
install/import/images/PROD030-2.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 94 KiB After Width: | Height: | Size: 94 KiB |
0
install/import/images/PROD030-3.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 123 KiB After Width: | Height: | Size: 123 KiB |