/** * insert related product in DB. * * @param $id * * @return RelatedProduct */ private function initRelatedProduct($id) { $fake = $this->getFaker(); $Product = $this->app['eccube.repository.product']->find($id); $RelatedProduct = new RelatedProduct(); $RelatedProduct->setContent($fake->word); $RelatedProduct->setProduct($Product); $RelatedProduct->setChildProduct($Product); $this->app['orm.em']->persist($RelatedProduct); $this->app['orm.em']->flush($RelatedProduct); return $RelatedProduct; }
/** * @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; }
/** * add related product form to admin product. * * @param Request $request * @param Response $response * * @return string $html */ private function addRelatedProductToAdminProduct(Request $request, Response $response) { $app = $this->app; $id = $request->attributes->get('id'); $RelatedProducts = null; if ($id) { $Product = $app['eccube.repository.product']->find($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($id)->setProduct($Product); $RelatedProducts[] = $RelatedProduct; } $builder = $app['form.factory']->createBuilder('admin_product'); $form = $builder->getForm(); $form->get('related_collection')->setData($RelatedProducts); // 商品検索フォーム $searchForm = $app['form.factory']->createBuilder('admin_search_product')->getForm(); $twig = $app->renderView('RelatedProduct/Resource/template/admin/related_product.twig', array('form' => $form->createView(), 'RelatedProducts' => $RelatedProducts, 'searchForm' => $searchForm->createView(), 'Product' => $Product)); $modal = $app->renderView('RelatedProduct/Resource/template/admin/modal.twig', array('searchForm' => $searchForm->createView(), 'Product' => $Product)); $html = $response->getContent(); $html = $html . $modal; // For old and new version $search = '/(<div class="row hidden-xs hidden-sm")|(<div id="detail_box__footer")/'; $newHtml = $twig . '<div id="detail_box__footer" class="row hidden-xs hidden-sm"'; $html = preg_replace($search, $newHtml, $html); return $html; }