import brand successfully

This commit is contained in:
Manuel Raynaud
2013-09-18 17:27:31 +02:00
parent a16b90f9ce
commit 3a323e7531
2 changed files with 42 additions and 3 deletions

View File

@@ -51,15 +51,46 @@ try {
$categories = createCategories();
createColors();
createBrand();
$con->commit();
} catch (Exception $e) {
echo "error : ".$e->getMessage()."\n";
$con->rollBack();
}
function createBrand()
{
echo "start creating brands feature\n";
if (($handle = fopen(THELIA_ROOT . '/install/import/brand.csv', "r")) !== FALSE) {
$row=0;
$feature = new \Thelia\Model\Feature();
$feature
->setPosition(1)
->setLocale('fr_FR')
->setTitle('Marque')
->setLocale('en_US')
->setTitle('Brand');
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
$row++;
$featureAv = new \Thelia\Model\FeatureAv();
$featureAv
->setPosition($row)
->setLocale('fr_FR')
->setTitle($data[0])
->setLocale('en_US')
->setTitle($data[0]);
$feature->addFeatureAv($featureAv);
}
$feature->save();
fclose($handle);
}
echo "brands feature created successfully\n";
}
function createCategories()
{
echo "start creating categories\n";
$categories = array();
if (($handle = fopen(THELIA_ROOT . '/install/import/categories.csv', "r")) !== FALSE) {
$row=0;
@@ -80,12 +111,13 @@ function createCategories()
}
fclose($handle);
}
echo "categories created successfully\n";
return $categories;
}
function createColors()
{
echo "start creating colors attributes\n";
if (($handle = fopen(THELIA_ROOT . '/install/import/colors.csv', "r")) !== FALSE) {
$row=0;
$attribute = new \Thelia\Model\Attribute();
@@ -111,7 +143,7 @@ function createColors()
$attribute->save();
fclose($handle);
}
echo "colors attributes created with success\n";
}
function clearTables()

7
install/import/brand.csv Normal file
View File

@@ -0,0 +1,7 @@
"MILAN"
"MAGIS"
"OXYO"
"OFFUS"
"PLINK"
"PARRY"
"TOKO"
1 MILAN
2 MAGIS
3 OXYO
4 OFFUS
5 PLINK
6 PARRY
7 TOKO