Inheritance: extends Eccube\Entity\AbstractEntity
Exemplo n.º 1
0
 public function setUp()
 {
     parent::setUp();
     $softDeleteFilter = $this->app['orm.em']->getFilters()->getFilter('soft_delete');
     $softDeleteFilter->setExcludes(array('Eccube\\Entity\\ProductClass'));
     // soft_delete filter を有効にする
     $config = $this->app['orm.em']->getConfiguration();
     $config->addFilter("soft_delete", '\\Eccube\\Doctrine\\Filter\\SoftDeleteFilter');
     $this->app['orm.em']->getFilters()->enable('soft_delete');
     // eccube_install.sh で追加される Member
     $Member = $this->app['eccube.repository.member']->find(2);
     $Product = new Product();
     $ProductClass = new ProductClass();
     $Disp = $this->app['eccube.repository.master.disp']->find(\Eccube\Entity\Master\Disp::DISPLAY_HIDE);
     $ProductType = $this->app['eccube.repository.master.product_type']->find($this->app['config']['product_type_normal']);
     $Product->setName('test')->setCreator($Member)->setDelFlg(Constant::DISABLED)->addProductClass($ProductClass)->setStatus($Disp);
     $ProductClass->setPrice02(1000)->setCreator($Member)->setDelFlg(Constant::DISABLED)->setStockUnlimited(true)->setProductType($ProductType)->setProduct($Product);
     $ProductStock = new \Eccube\Entity\ProductStock();
     $ProductStock->setCreator($Member);
     $ProductClass->setProductStock($ProductStock);
     $ProductStock->setProductClass($ProductClass);
     $this->app['orm.em']->persist($Product);
     $this->app['orm.em']->persist($ProductClass);
     $this->app['orm.em']->persist($ProductStock);
     $this->app['orm.em']->flush();
     $this->Product = $Product;
     $this->ProductClass = $ProductClass;
 }
Exemplo n.º 2
0
 /**
  * AdContents constructor.
  * @param Application $app
  * @param Product $product
  */
 public function __construct(Application $app, Product $product)
 {
     $shop_name = $app['eccube.repository.base_info']->get()->getShopName();
     $homepage_url = $app->url('homepage');
     $product_url = $app->url('product_detail', array('id' => $product->getId()));
     $this->headline = CsvContentsUtil::clipText($product->getName(), 15);
     $this->description1 = CsvContentsUtil::clipText($product->getDescriptionDetail(), 19);
     $this->description2 = CsvContentsUtil::clipText($shop_name, 19);
     $this->display_url = CsvContentsUtil::removeHttpText(CsvContentsUtil::clipText($homepage_url, 29));
     $this->link_url = CsvContentsUtil::clipText($product_url, 1024);
     $now = new \DateTime();
     $ad_name = $now->format('Ymd') . '_' . str_pad($product->getId(), 4, 0, STR_PAD_LEFT);
     $this->ad_inner_name = CsvContentsUtil::clipText($ad_name, 50);
 }
 public function setUp()
 {
     self::$app['orm.em']->getConnection()->beginTransaction();
     // eccube_install.sh で追加される Member
     $Member = self::$app['eccube.repository.member']->find(2);
     $Product = new Product();
     $ProductClass = new ProductClass();
     $Disp = self::$app['eccube.repository.master.disp']->find(\Eccube\Entity\Master\Disp::DISPLAY_HIDE);
     $ProductType = self::$app['eccube.repository.master.product_type']->find(self::$app['config']['product_type_normal']);
     $Product->setName('test')->setCreator($Member)->setDelFlg(Constant::DISABLED)->addProductClass($ProductClass)->setStatus($Disp);
     $ProductClass->setPrice02(1000)->setCreator($Member)->setDelFlg(Constant::DISABLED)->setStockUnlimited(true)->setProductType($ProductType)->setProduct($Product);
     $ProductStock = new \Eccube\Entity\ProductStock();
     $ProductStock->setCreator($Member);
     $ProductClass->setProductStock($ProductStock);
     $ProductStock->setProductClass($ProductClass);
     self::$app['orm.em']->persist($Product);
     self::$app['orm.em']->persist($ProductClass);
     self::$app['orm.em']->persist($ProductStock);
     self::$app['orm.em']->flush();
     $this->Product = $Product;
     $this->ProductClass = $ProductClass;
 }
Exemplo n.º 4
0
 /**
  * タグの登録
  *
  * @param array $row
  * @param Product $Product
  * @param Application $app
  * @param CsvImportService $data
  */
 protected function createProductTag($row, Product $Product, $app, $data)
 {
     // タグの削除
     $ProductTags = $Product->getProductTag();
     foreach ($ProductTags as $ProductTags) {
         $Product->removeProductTag($ProductTags);
         $this->em->remove($ProductTags);
     }
     if ($row['タグ(ID)'] == '') {
         return;
     }
     // タグの登録
     $tags = explode(',', $row['タグ(ID)']);
     foreach ($tags as $tag_id) {
         $Tag = null;
         if (preg_match('/^\\d+$/', $tag_id)) {
             $Tag = $app['eccube.repository.master.tag']->find($tag_id);
             if ($Tag) {
                 $ProductTags = new ProductTag();
                 $ProductTags->setProduct($Product)->setTag($Tag);
                 $Product->addProductTag($ProductTags);
                 $this->em->persist($ProductTags);
             }
         }
         if (!$Tag) {
             $this->addErrors($data->key() + 1 . '行目のタグ(ID)「' . $tag_id . '」が存在しません。');
         }
     }
 }
Exemplo n.º 5
0
 /**
  * 商品カテゴリの削除、登録
  */
 protected function createProductCategory($row, Product $Product, $app, $data)
 {
     if ($row['商品カテゴリ(ID)'] != '') {
         // カテゴリの削除
         $ProductCategories = $Product->getProductCategories();
         foreach ($ProductCategories as $ProductCategory) {
             $Product->removeProductCategory($ProductCategory);
             $this->em->remove($ProductCategory);
             $this->em->flush($ProductCategory);
         }
         // カテゴリの登録
         $categories = explode(',', $row['商品カテゴリ(ID)']);
         $rank = 1;
         foreach ($categories as $category) {
             if (is_numeric($category)) {
                 $Category = $app['eccube.repository.category']->find($category);
                 if (!$Category) {
                     $this->addErrors($data->key() + 1 . '行目の商品カテゴリ(ID)「' . $category . '」が存在しません。');
                 } else {
                     $ProductCategory = new ProductCategory();
                     $ProductCategory->setProductId($Product->getId());
                     $ProductCategory->setCategoryId($Category->getId());
                     $ProductCategory->setProduct($Product);
                     $ProductCategory->setCategory($Category);
                     $ProductCategory->setRank($rank);
                     $Product->addProductCategory($ProductCategory);
                     $rank++;
                     $this->em->persist($ProductCategory);
                 }
             } else {
                 $this->addErrors($data->key() + 1 . '行目の商品カテゴリ(ID)「' . $category . '」が存在しません。');
             }
         }
     }
 }
 /**
  * {@inheritDoc}
  */
 public function copyProperties($srcObject, array $excludeAttribute = array())
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'copyProperties', array($srcObject, $excludeAttribute));
     return parent::copyProperties($srcObject, $excludeAttribute);
 }
Exemplo n.º 7
0
 /**
  * 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;
 }
 /**
  * 規格なし商品を除いて商品規格を取得.
  *
  * @param Product $Product
  * @return \Eccube\Entity\ProductClass[]
  */
 private function getProductClassesExcludeNonClass(Product $Product)
 {
     $ProductClasses = $Product->getProductClasses();
     return $ProductClasses->filter(function ($ProductClass) {
         $ClassCategory1 = $ProductClass->getClassCategory1();
         $ClassCategory2 = $ProductClass->getClassCategory2();
         return $ClassCategory1 || $ClassCategory2;
     });
 }
Exemplo n.º 9
0
 /**
  * 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;
 }
 /**
  * @param Product $product
  * @param AdContents $ad_contents
  */
 private function createAdGroupWithSearchWord(Product $product, AdContents $ad_contents)
 {
     $group_name = CsvContentsUtil::clipText($product->getName() . '×' . '検索ワード', 50);
     $group = new AdGroup($group_name, $ad_contents);
     $search_word = $product->getSearchWord();
     $keywords = preg_split('/[\\s 、,]+/u', $search_word, -1, PREG_SPLIT_NO_EMPTY);
     foreach ($keywords as $word) {
         $group->addKeyword($product->getName() . ' ' . $word);
     }
     if (!empty($group->getKeywords())) {
         array_push($this->ad_groups, $group);
     }
 }
Exemplo n.º 11
0
 /**
  * @param Product $Product
  *
  * @return array RelatedProducts
  */
 private function createRelatedProductData($Product)
 {
     $app = $this->app;
     $RelatedProducts = null;
     $id = $Product->getId();
     if ($id) {
         $RelatedProducts = $app['eccube.plugin.repository.related_product']->getRelatedProduct($Product, Constant::DISABLED);
     } else {
         $Product = new Product();
     }
     $maxCount = $app['config']['related_product_max_item_count'];
     $loop = $maxCount - count($RelatedProducts);
     for ($i = 0; $i < $loop; ++$i) {
         $RelatedProduct = new RelatedProduct();
         $RelatedProduct->setProductId($Product->getId())->setProduct($Product);
         $RelatedProducts[] = $RelatedProduct;
     }
     return $RelatedProducts;
 }