/** * 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); }
/** * 商品カテゴリの削除、登録 */ protected function createProductCategory($row, Product $Product, $app, $data) { // カテゴリの削除 $ProductCategories = $Product->getProductCategories(); foreach ($ProductCategories as $ProductCategory) { $Product->removeProductCategory($ProductCategory); $this->em->remove($ProductCategory); $this->em->flush($ProductCategory); } if ($row['商品カテゴリ(ID)'] == '') { // 入力されていなければ削除のみ return; } // カテゴリの登録 $categories = explode(',', $row['商品カテゴリ(ID)']); $rank = 1; foreach ($categories as $category) { if (preg_match('/^\\d+$/', $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 getId() { if ($this->__isInitialized__ === false) { return (int) parent::getId(); } $this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', array()); return parent::getId(); }
/** * @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; }