Beispiel #1
0
 public function testSearchById()
 {
     $category = CategoryQuery::create()->findOne();
     if (null === $category) {
         $category = new \Thelia\Model\Category();
         $category->setParent(0);
         $category->setVisible(1);
         $category->setTitle('foo');
         $category->save();
     }
     $otherParameters = array("visible" => "*");
     $this->baseTestSearchById($category->getId(), $otherParameters);
 }
Beispiel #2
0
function createCategory($faker, $parent, $position, &$categoryIdList, $contentIdList)
{
    $category = new Thelia\Model\Category();
    $category->setParent($parent);
    $category->setVisible(1);
    $category->setPosition($position);
    setI18n($category);
    $category->save();
    $categoryId = $category->getId();
    $categoryIdList[] = $categoryId;
    //add random associated content
    $alreadyPicked = array();
    for ($i = 1; $i < rand(0, 3); $i++) {
        $categoryAssociatedContent = new Thelia\Model\CategoryAssociatedContent();
        do {
            $pick = array_rand($contentIdList, 1);
        } while (in_array($pick, $alreadyPicked));
        $alreadyPicked[] = $pick;
        $categoryAssociatedContent->setContentId($contentIdList[$pick])->setCategoryId($categoryId)->setPosition($i)->save();
    }
    $image = new \Thelia\Model\CategoryImage();
    $image->setCategoryId($categoryId);
    generate_image($image, 'category', $categoryId);
    $document = new \Thelia\Model\CategoryDocument();
    $document->setCategoryId($categoryId);
    generate_document($document, 'category', $categoryId);
    return $category;
}
Beispiel #3
0
function createCategories($faker, $con)
{
    echo "start creating categories\n";
    $categories = array();
    if (($handle = fopen(THELIA_ROOT . '/setup/import/categories.csv', "r")) !== FALSE) {
        $row = 0;
        while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
            $row++;
            if ($row == 1) {
                continue;
            }
            $category = new \Thelia\Model\Category();
            $category->setVisible(1)->setPosition($row - 1)->setParent(0)->setLocale('fr_FR')->setTitle(trim($data[0]))->setChapo($faker->text(20))->setDescription($faker->text(100))->setLocale('en_US')->setTitle(trim($data[1]))->setChapo($faker->text(20))->setDescription($faker->text(100))->save($con);
            $categories[trim($data[1])] = $category;
        }
        fclose($handle);
    }
    echo "categories created successfully\n";
    return $categories;
}
 $folder->delete();
 $content = Thelia\Model\ContentQuery::create()->find();
 $content->delete();
 $content = Thelia\Model\ContentI18nQuery::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();
 $stmt = $con->prepare("SET foreign_key_checks = 1");
 $stmt->execute();
 //categories and products
 for ($i = 0; $i < 100; $i++) {
     $category = new Thelia\Model\Category();
     $category->setParent(0);
     $category->setVisible(1);
     $category->setPosition($i);
     setI18n($faker, $category);
     $category->save();
     for ($j = 0; $j < 10; $j++) {
         $product = new Thelia\Model\Product();
         $product->setRef($category->getId() . '_' . $j . '_' . $faker->randomNumber(8));
         $product->addCategory($category);
         $product->setVisible(1);
         $product->setPosition($j);
         setI18n($faker, $product);
         $product->save();
     }
 }