Exemple #1
0
             $document->setContentId($contentId);
             generate_document($document, 'content', $contentId);
         }
     }
 }
 echo "Creating brands\n";
 $brandIdList = [];
 for ($k = 0; $k < 10; $k++) {
     $brand = new Thelia\Model\Brand();
     $brand->setVisible(1);
     $brand->setPosition($k + 1);
     setI18n($brand);
     $brand->save();
     $brandId = $brand->getId();
     $brandIdList[] = $brandId;
     $image = new \Thelia\Model\BrandImage();
     $image->setBrandId($brandId);
     generate_image($image, 'brand', $brandId);
     $document = new \Thelia\Model\BrandDocument();
     $document->setBrandId($brandId);
     generate_document($document, 'brand', $brandId);
 }
 echo "Creating categories and products\n";
 //categories and products
 $productIdList = array();
 $virtualProductList = array();
 $categoryIdList = array();
 for ($i = 1; $i < $numberCategories; $i++) {
     $category = createCategory($faker, 0, $i, $categoryIdList, $contentIdList);
     for ($j = 1; $j < rand(0, $numberCategories); $j++) {
         $subcategory = createCategory($faker, $category->getId(), $j, $categoryIdList, $contentIdList);
Exemple #2
0
function createBrands($faker, $con)
{
    echo "start creating brands\n";
    $fileSystem = new \Symfony\Component\Filesystem\Filesystem();
    $brands = array();
    if (($handle = fopen(THELIA_ROOT . '/setup/import/brand.csv', "r")) !== FALSE) {
        $row = 0;
        while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
            $row++;
            if ($row == 1) {
                continue;
            }
            $brand = new \Thelia\Model\Brand();
            $brand->setVisible(1)->setPosition($row - 1)->setLocale('fr_FR')->setTitle(trim($data[0]))->setChapo($faker->text(20))->setDescription($faker->text(100))->setLocale('en_US')->setTitle(trim($data[0]))->setChapo($faker->text(20))->setDescription($faker->text(100))->save($con);
            $brands[trim($data[0])] = $brand;
            $images = explode(';', $data[1]);
            $logoId = null;
            foreach ($images as $image) {
                $image = trim($image);
                if (empty($image)) {
                    continue;
                }
                $brandImage = new \Thelia\Model\BrandImage();
                $brandImage->setBrandId($brand->getId())->setFile($image)->save($con);
                if ($logoId === null) {
                    $logoId = $brandImage->getId();
                }
                $fileSystem->copy(THELIA_ROOT . 'setup/import/images/' . $image, THELIA_ROOT . 'local/media/images/brand/' . $image, true);
            }
            if ($logoId !== null) {
                $brand->setLogoImageId($logoId);
                $brand->save($con);
            }
        }
        fclose($handle);
    }
    echo "brands created successfully\n";
    return $brands;
}