コード例 #1
0
ファイル: Generator.php プロジェクト: shhirose/ec-cube
 /**
  * Product オブジェクトを生成して返す.
  *
  * $product_class_num = 0 としても、商品規格の無い商品を生成できない. 単に ProductClass が生成されないだけなので注意すること.
  *
  * @param string $product_name 商品名. null の場合はランダムな文字列が生成される.
  * @param integer $product_class_num 商品規格の生成数
  * @return \Eccube\Entity\Product
  */
 public function createProduct($product_name = null, $product_class_num = 3)
 {
     $faker = $this->getFaker();
     $Member = $this->app['eccube.repository.member']->find(2);
     $Disp = $this->app['eccube.repository.master.disp']->find(\Eccube\Entity\Master\Disp::DISPLAY_SHOW);
     $ProductType = $this->app['eccube.repository.master.product_type']->find(1);
     $Product = new Product();
     if (is_null($product_name)) {
         $product_name = $faker->word;
     }
     $Product->setName($product_name)->setCreator($Member)->setStatus($Disp)->setDelFlg(Constant::DISABLED)->setDescriptionList($faker->paragraph())->setDescriptionDetail($faker->text());
     $this->app['orm.em']->persist($Product);
     $this->app['orm.em']->flush($Product);
     for ($i = 0; $i < 3; $i++) {
         $ProductImage = new ProductImage();
         $ProductImage->setCreator($Member)->setFileName($faker->word . '.jpg')->setRank($i)->setProduct($Product);
         $this->app['orm.em']->persist($ProductImage);
         $this->app['orm.em']->flush($ProductImage);
         $Product->addProductImage($ProductImage);
     }
     for ($i = 0; $i < $product_class_num; $i++) {
         $ProductStock = new ProductStock();
         $ProductStock->setCreator($Member)->setStock($faker->randomNumber());
         $this->app['orm.em']->persist($ProductStock);
         $this->app['orm.em']->flush($ProductStock);
         $ProductClass = new ProductClass();
         $ProductClass->setCreator($Member)->setProductStock($ProductStock)->setProduct($Product)->setProductType($ProductType)->setStockUnlimited(false)->setPrice02($faker->randomNumber(5))->setDelFlg(Constant::DISABLED);
         $this->app['orm.em']->persist($ProductClass);
         $this->app['orm.em']->flush($ProductClass);
         $Product->addProductClass($ProductClass);
     }
     $Categories = $this->app['eccube.repository.category']->findAll();
     $i = 0;
     foreach ($Categories as $Category) {
         $ProductCategory = new ProductCategory();
         $ProductCategory->setCategory($Category)->setProduct($Product)->setCategoryId($Category->getId())->setProductId($Product->getId())->setRank($i);
         $this->app['orm.em']->persist($ProductCategory);
         $this->app['orm.em']->flush($ProductCategory);
         $Product->addProductCategory($ProductCategory);
         $i++;
     }
     $this->app['orm.em']->flush($Product);
     return $Product;
 }
コード例 #2
0
 /**
  * 商品画像の削除、登録
  */
 protected function createProductImage($row, Product $Product)
 {
     if ($row['商品画像'] != '') {
         // 画像の削除
         $ProductImages = $Product->getProductImage();
         foreach ($ProductImages as $ProductImage) {
             $Product->removeProductImage($ProductImage);
             $this->em->remove($ProductImage);
         }
         // 画像の登録
         $images = explode(',', $row['商品画像']);
         $rank = 1;
         foreach ($images as $image) {
             $ProductImage = new ProductImage();
             $ProductImage->setFileName(Str::trimAll($image));
             $ProductImage->setProduct($Product);
             $ProductImage->setRank($rank);
             $Product->addProductImage($ProductImage);
             $rank++;
             $this->em->persist($ProductImage);
         }
     }
 }
コード例 #3
0
ファイル: Generator.php プロジェクト: ec-cube/ec-cube
 /**
  * Product オブジェクトを生成して返す.
  *
  * $product_class_num = 0 とすると商品規格の無い商品を生成する.
  *
  * @param string $product_name 商品名. null の場合はランダムな文字列が生成される.
  * @param integer $product_class_num 商品規格の生成数
  * @return \Eccube\Entity\Product
  */
 public function createProduct($product_name = null, $product_class_num = 3)
 {
     $faker = $this->getFaker();
     $Member = $this->app['eccube.repository.member']->find(2);
     $Disp = $this->app['eccube.repository.master.disp']->find(\Eccube\Entity\Master\Disp::DISPLAY_SHOW);
     $ProductType = $this->app['eccube.repository.master.product_type']->find(1);
     $DeliveryDates = $this->app['eccube.repository.delivery_date']->findAll();
     $Product = new Product();
     if (is_null($product_name)) {
         $product_name = $faker->word;
     }
     $Product->setName($product_name)->setCreator($Member)->setStatus($Disp)->setDelFlg(Constant::DISABLED)->setDescriptionList($faker->paragraph())->setDescriptionDetail($faker->text());
     $this->app['orm.em']->persist($Product);
     $this->app['orm.em']->flush($Product);
     for ($i = 0; $i < 3; $i++) {
         $ProductImage = new ProductImage();
         $ProductImage->setCreator($Member)->setFileName($faker->word . '.jpg')->setRank($i)->setProduct($Product);
         $this->app['orm.em']->persist($ProductImage);
         $this->app['orm.em']->flush($ProductImage);
         $Product->addProductImage($ProductImage);
     }
     $ClassNames = $this->app['eccube.repository.class_name']->findAll();
     $ClassName1 = $ClassNames[$faker->numberBetween(0, count($ClassNames) - 1)];
     $ClassName2 = $ClassNames[$faker->numberBetween(0, count($ClassNames) - 1)];
     // 同じ ClassName が選択された場合は ClassName1 のみ
     if ($ClassName1->getId() === $ClassName2->getId()) {
         $ClassName2 = null;
     }
     $ClassCategories1 = $this->app['eccube.repository.class_category']->findBy(array('ClassName' => $ClassName1));
     $ClassCategories2 = array();
     if (is_object($ClassName2)) {
         $ClassCategories2 = $this->app['eccube.repository.class_category']->findBy(array('ClassName' => $ClassName2));
     }
     for ($i = 0; $i < $product_class_num; $i++) {
         $ProductStock = new ProductStock();
         $ProductStock->setCreator($Member)->setStock($faker->randomNumber(3));
         $this->app['orm.em']->persist($ProductStock);
         $this->app['orm.em']->flush($ProductStock);
         $ProductClass = new ProductClass();
         $ProductClass->setCode($faker->word)->setCreator($Member)->setStock($ProductStock->getStock())->setProductStock($ProductStock)->setProduct($Product)->setProductType($ProductType)->setStockUnlimited(false)->setPrice02($faker->randomNumber(5))->setDeliveryDate($DeliveryDates[$faker->numberBetween(0, 8)])->setDelFlg(Constant::DISABLED);
         if (array_key_exists($i, $ClassCategories1)) {
             $ProductClass->setClassCategory1($ClassCategories1[$i]);
         }
         if (array_key_exists($i, $ClassCategories2)) {
             $ProductClass->setClassCategory2($ClassCategories2[$i]);
         }
         $this->app['orm.em']->persist($ProductClass);
         $this->app['orm.em']->flush($ProductClass);
         $ProductStock->setProductClass($ProductClass);
         $ProductStock->setProductClassId($ProductClass->getId());
         $this->app['orm.em']->flush($ProductStock);
         $Product->addProductClass($ProductClass);
     }
     // デフォルトの商品規格生成
     $ProductStock = new ProductStock();
     $ProductStock->setCreator($Member)->setStock($faker->randomNumber(3));
     $this->app['orm.em']->persist($ProductStock);
     $this->app['orm.em']->flush($ProductStock);
     $ProductClass = new ProductClass();
     if ($product_class_num > 0) {
         $ProductClass->setDelFlg(Constant::ENABLED);
     } else {
         $ProductClass->setDelFlg(Constant::DISABLED);
     }
     $ProductClass->setCode($faker->word)->setCreator($Member)->setStock($ProductStock->getStock())->setProductStock($ProductStock)->setProduct($Product)->setProductType($ProductType)->setPrice02($faker->randomNumber(5))->setDeliveryDate($DeliveryDates[$faker->numberBetween(0, 8)])->setStockUnlimited(false)->setProduct($Product);
     $this->app['orm.em']->persist($ProductClass);
     $this->app['orm.em']->flush($ProductClass);
     $ProductStock->setProductClass($ProductClass);
     $ProductStock->setProductClassId($ProductClass->getId());
     $this->app['orm.em']->flush($ProductStock);
     $Product->addProductClass($ProductClass);
     $Categories = $this->app['eccube.repository.category']->findAll();
     $i = 0;
     foreach ($Categories as $Category) {
         $ProductCategory = new ProductCategory();
         $ProductCategory->setCategory($Category)->setProduct($Product)->setCategoryId($Category->getId())->setProductId($Product->getId())->setRank($i);
         $this->app['orm.em']->persist($ProductCategory);
         $this->app['orm.em']->flush($ProductCategory);
         $Product->addProductCategory($ProductCategory);
         $i++;
     }
     $this->app['orm.em']->flush($Product);
     return $Product;
 }