$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); $productPrice = new \Thelia\Model\ProductPrice(); $productPrice->setProductSaleElements($stock); $productPrice->setCurrency($currency); $productPrice->setPrice($price); $productPrice->setPromoPrice($promoPrice); $productPrice->save(); //associate attributes - or not - to PSE $alreadyPicked = array(); $minAttrCount = $pse_count == 1 ? 0 : 1; for ($attrIdx = 0; $attrIdx < rand($minAttrCount, count($attributeList)); $attrIdx++) { $featureProduct = new Thelia\Model\AttributeCombination(); do {