Beispiel #1
0
 }
 //add random associated content
 $alreadyPicked = array();
 for ($i = 1; $i < rand(0, 3); $i++) {
     $productAssociatedContent = new Thelia\Model\ProductAssociatedContent();
     do {
         $pick = array_rand($contentIdList, 1);
     } while (in_array($pick, $alreadyPicked));
     $alreadyPicked[] = $pick;
     $productAssociatedContent->setContentId($contentIdList[$pick])->setProductId($productId)->setPosition($i)->save();
 }
 //associate PSE and stocks to products
 $pse_count = rand(1, 7);
 for ($pse_idx = 0; $pse_idx < $pse_count; $pse_idx++) {
     $stock = new \Thelia\Model\ProductSaleElements();
     $stock->setProductId($productId);
     $stock->setRef($productId . '_' . $pse_idx . '_' . $faker->randomNumber(8));
     $stock->setQuantity($faker->numberBetween(1, 50));
     $stock->setPromo($faker->numberBetween(0, 1));
     $stock->setNewness($faker->numberBetween(0, 1));
     $stock->setWeight($faker->randomFloat(2, 1, 5));
     $stock->setIsDefault($pse_idx == 0 ? true : false);
     $stock->setEanCode(substr(str_shuffle("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 13));
     $stock->save();
     // associate document to virtual product
     if (array_key_exists($productId, $virtualProductList)) {
         $virtualDocument = new \Thelia\Model\MetaData();
         $virtualDocument->setMetaKey('virtual')->setElementKey(\Thelia\Model\MetaData::PSE_KEY)->setElementId($stock->getId())->setValue($virtualProductList[$productId])->save();
     }
     $price = $faker->randomFloat(2, 20, 250);
     $promoPrice = $price * $faker->randomFloat(2, 0, 1);