public function testSearchByIdComplex() { $product = ProductQuery::create()->orderById(Criteria::ASC)->findOne(); if (null === $product) { $product = new \Thelia\Model\Product(); $product->setDefaultCategory(0); $product->setVisible(1); $product->setTitle('foo'); $product->save(); } $otherParameters = array("visible" => "*", "complex" => 1); $this->baseTestSearchById($product->getId(), $otherParameters); }
function createProduct($faker, Thelia\Model\Category $category, $position, $template, $brandIdList, &$productIdList, &$virtualProductList) { $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->setVirtual(mt_rand(1, 5) > 1 ? 0 : 1); $product->setVisible(1); $product->setPosition($position); $product->setTaxRuleId(1); $product->setTemplate($template); $product->setBrandId($brandIdList[array_rand($brandIdList, 1)]); setI18n($product); $product->save(); $productId = $product->getId(); $productIdList[] = $productId; $image = new \Thelia\Model\ProductImage(); $image->setProductId($productId); generate_image($image, 'product', $productId); $document = new \Thelia\Model\ProductDocument(); $document->setProductId($productId); generate_document($document, 'product', $productId); if ($product->getVirtual() == 1) { $virtualProductList[$productId] = $document->getId(); } return $product; }
function createProduct($faker, $categories, $brands, $contents, $template, $attribute, $feature, $con) { echo "start creating products\n"; $fileSystem = new \Symfony\Component\Filesystem\Filesystem(); if (($handle = fopen(THELIA_ROOT . '/setup/import/products.csv', "r")) !== FALSE) { $row = 0; while (($data = fgetcsv($handle, 100000, ";")) !== FALSE) { $row++; if ($row == 1) { continue; } $product = new \Thelia\Model\Product(); $product->setRef($data[0])->setVisible(1)->setTaxRuleId(1)->setTemplate($template); $productCategories = explode(';', $data[15]); foreach ($productCategories as $productCategory) { $productCategory = trim($productCategory); if (array_key_exists($productCategory, $categories)) { $product->addCategory($categories[$productCategory]); } } $brand = $data[11]; if (array_key_exists($brand, $brands)) { $product->setBrand($brands[$brand]); } $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($con); $productCategories = $product->getProductCategories()->getFirst(); $productCategories->setDefaultCategory(true)->save($con); // Set the position $product->setPosition($product->getNextPosition())->save($con); $images = explode(';', $data[10]); foreach ($images as $image) { $image = trim($image); if (empty($image)) { continue; } $productImage = new \Thelia\Model\ProductImage(); $productImage->setProduct($product)->setFile($image)->save($con); $fileSystem->copy(THELIA_ROOT . 'setup/import/images/' . $image, THELIA_ROOT . 'local/media/images/product/' . $image, true); } $pses = explode(";", $data[12]); foreach ($pses as $pse) { if (empty($pse)) { continue; } $stock = new \Thelia\Model\ProductSaleElements(); $stock->setProduct($product); $stock->setRef($product->getId() . '_' . uniqid('', true)); $stock->setQuantity($faker->numberBetween(1, 50)); if (!empty($data[9])) { $stock->setPromo(1); } else { $stock->setPromo(0); } $stock->setNewness($faker->numberBetween(0, 1)); $stock->setWeight($faker->randomFloat(2, 1, 30)); $stock->save($con); $productPrice = new \Thelia\Model\ProductPrice(); $productPrice->setProductSaleElements($stock); $productPrice->setCurrencyId(1); $productPrice->setPrice($data[8]); $productPrice->setPromoPrice($data[9]); $productPrice->save($con); $attributeAv = \Thelia\Model\AttributeAvI18nQuery::create()->filterByLocale('en_US')->filterByTitle($pse)->findOne($con); $attributeCombination = new \Thelia\Model\AttributeCombination(); $attributeCombination->setAttributeId($attribute->getId())->setAttributeAvId($attributeAv->getId())->setProductSaleElements($stock)->save($con); } $productSaleElements = $product->getProductSaleElementss()->getFirst(); $productSaleElements->setIsDefault(1)->save($con); // associated content $associatedContents = explode(";", $data[14]); foreach ($associatedContents as $associatedContent) { $content = new ProductAssociatedContent(); if (!array_key_exists($associatedContent, $contents)) { continue; } $content->setProduct($product)->setContent($contents[$associatedContent])->save($con); } // feature $features = explode(";", $data[13]); foreach ($features as $aFeature) { $featurAv = \Thelia\Model\FeatureAvI18nQuery::create()->filterByLocale('en_US')->filterByTitle($aFeature)->findOne($con); $featureProduct = new Thelia\Model\FeatureProduct(); $featureProduct->setProduct($product)->setFeatureId($feature->getId())->setFeatureAvId($featurAv->getId())->save($con); } } } echo "end creating products\n"; }
$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(); } } $con->commit(); } catch (Exception $e) { echo "error : " . $e->getMessage() . "\n"; $con->rollBack(); } function setI18n($faker, &$object, $fields = array('Title' => 20, 'Description' => 50)) {