| <?php |
| <?php |
| /* |
| /* |
| * This file is part of EC-CUBE |
| * This file is part of EC-CUBE |
| * |
| * |
| * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. |
| * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. |
| * |
| * |
| * http://www.lockon.co.jp/ |
| * http://www.lockon.co.jp/ |
| * |
| * |
| * This program is free software; you can redistribute it and/or |
| * This program is free software; you can redistribute it and/or |
| * modify it under the terms of the GNU General Public License |
| * modify it under the terms of the GNU General Public License |
| * as published by the Free Software Foundation; either version 2 |
| * as published by the Free Software Foundation; either version 2 |
| * of the License, or (at your option) any later version. |
| * of the License, or (at your option) any later version. |
| * |
| * |
| * This program is distributed in the hope that it will be useful, |
| * This program is distributed in the hope that it will be useful, |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| * GNU General Public License for more details. |
| * GNU General Public License for more details. |
| * |
| * |
| * You should have received a copy of the GNU General Public License |
| * You should have received a copy of the GNU General Public License |
| * along with this program; if not, write to the Free Software |
| * along with this program; if not, write to the Free Software |
| * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| */ |
| */ |
| |
| |
| |
| |
| namespace Eccube\Controller\Admin\Product; |
| namespace Eccube\Controller\Admin\Product; |
| |
| |
| use Eccube\Application; |
| use Eccube\Application; |
| use Eccube\Common\Constant; |
| use Eccube\Common\Constant; |
| use Eccube\Controller\AbstractController; |
| use Eccube\Controller\AbstractController; |
| use Eccube\Entity\Master\CsvType; |
| use Eccube\Entity\Master\CsvType; |
| use Eccube\Event\EccubeEvents; |
| use Eccube\Event\EccubeEvents; |
| use Eccube\Event\EventArgs; |
| use Eccube\Event\EventArgs; |
| use Symfony\Component\Filesystem\Filesystem; |
| use Symfony\Component\Filesystem\Filesystem; |
| use Symfony\Component\HttpFoundation\File\File; |
| use Symfony\Component\HttpFoundation\File\File; |
| use Symfony\Component\HttpFoundation\Request; |
| use Symfony\Component\HttpFoundation\Request; |
| use Symfony\Component\HttpFoundation\StreamedResponse; |
| use Symfony\Component\HttpFoundation\StreamedResponse; |
| . | |
| use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; |
| use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
| use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
| . | |
| use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException; |
| |
| |
| class ProductController extends AbstractController |
| class ProductController extends AbstractController |
| { |
| { |
| public function index(Application $app, Request $request, $page_no = null) |
| public function index(Application $app, Request $request, $page_no = null) |
| { |
| { |
| |
| |
| $session = $app['session']; |
| $session = $app['session']; |
| |
| |
| $builder = $app['form.factory'] |
| $builder = $app['form.factory'] |
| ->createBuilder('admin_search_product'); |
| ->createBuilder('admin_search_product'); |
| |
| |
| $event = new EventArgs( |
| $event = new EventArgs( |
| array( |
| array( |
| 'builder' => $builder, |
| 'builder' => $builder, |
| ), |
| ), |
| $request |
| $request |
| ); |
| ); |
| $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_INDEX_INITIALIZE, $event); |
| $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_INDEX_INITIALIZE, $event); |
| |
| |
| $searchForm = $builder->getForm(); |
| $searchForm = $builder->getForm(); |
| |
| |
| $pagination = array(); |
| $pagination = array(); |
| |
| |
| $disps = $app['eccube.repository.master.disp']->findAll(); |
| $disps = $app['eccube.repository.master.disp']->findAll(); |
| $pageMaxis = $app['eccube.repository.master.page_max']->findAll(); |
| $pageMaxis = $app['eccube.repository.master.page_max']->findAll(); |
| $page_count = $app['config']['default_page_count']; |
| $page_count = $app['config']['default_page_count']; |
| $page_status = null; |
| $page_status = null; |
| $active = false; |
| $active = false; |
| |
| |
| if ('POST' === $request->getMethod()) { |
| if ('POST' === $request->getMethod()) { |
| |
| |
| $searchForm->handleRequest($request); |
| $searchForm->handleRequest($request); |
| |
| |
| if ($searchForm->isValid()) { |
| if ($searchForm->isValid()) { |
| $searchData = $searchForm->getData(); |
| $searchData = $searchForm->getData(); |
| |
| |
| // paginator |
| // paginator |
| $qb = $app['eccube.repository.product']->getQueryBuilderBySearchDataForAdmin($searchData); |
| $qb = $app['eccube.repository.product']->getQueryBuilderBySearchDataForAdmin($searchData); |
| $page_no = 1; |
| $page_no = 1; |
| |
| |
| $event = new EventArgs( |
| $event = new EventArgs( |
| array( |
| array( |
| 'qb' => $qb, |
| 'qb' => $qb, |
| 'searchData' => $searchData, |
| 'searchData' => $searchData, |
| ), |
| ), |
| $request |
| $request |
| ); |
| ); |
| $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_INDEX_SEARCH, $event); |
| $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_INDEX_SEARCH, $event); |
| $searchData = $event->getArgument('searchData'); |
| $searchData = $event->getArgument('searchData'); |
| |
| |
| $pagination = $app['paginator']()->paginate( |
| $pagination = $app['paginator']()->paginate( |
| $qb, |
| $qb, |
| $page_no, |
| $page_no, |
| $page_count, |
| $page_count, |
| array('wrap-queries' => true) |
| array('wrap-queries' => true) |
| ); |
| ); |
| |
| |
| // sessionのデータ保持 |
| // sessionのデータ保持 |
| $session->set('eccube.admin.product.search', $searchData); |
| $session->set('eccube.admin.product.search', $searchData); |
| } |
| } |
| } else { |
| } else { |
| if (is_null($page_no)) { |
| if (is_null($page_no)) { |
| // sessionを削除 |
| // sessionを削除 |
| $session->remove('eccube.admin.product.search'); |
| $session->remove('eccube.admin.product.search'); |
| } else { |
| } else { |
| // pagingなどの処理 |
| // pagingなどの処理 |
| $searchData = $session->get('eccube.admin.product.search'); |
| $searchData = $session->get('eccube.admin.product.search'); |
| if (!is_null($searchData)) { |
| if (!is_null($searchData)) { |
| |
| |
| // 公開ステータス |
| // 公開ステータス |
| $status = $request->get('status'); |
| $status = $request->get('status'); |
| if (!empty($status)) { |
| if (!empty($status)) { |
| if ($status != $app['config']['admin_product_stock_status']) { |
| if ($status != $app['config']['admin_product_stock_status']) { |
| $searchData['link_status'] = $app['eccube.repository.master.disp']->find($status); |
| $searchData['link_status'] = $app['eccube.repository.master.disp']->find($status); |
| $searchData['status'] = null; |
| $searchData['status'] = null; |
| $session->set('eccube.admin.product.search', $searchData); |
| $session->set('eccube.admin.product.search', $searchData); |
| } else { |
| } else { |
| $searchData['stock_status'] = Constant::DISABLED; |
| $searchData['stock_status'] = Constant::DISABLED; |
| } |
| } |
| $page_status = $status; |
| $page_status = $status; |
| } else { |
| } else { |
| $searchData['link_status'] = null; |
| $searchData['link_status'] = null; |
| $searchData['stock_status'] = null; |
| $searchData['stock_status'] = null; |
| } |
| } |
| // 表示件数 |
| // 表示件数 |
| $pcount = $request->get('page_count'); |
| $pcount = $request->get('page_count'); |
| |
| |
| $page_count = empty($pcount) ? $page_count : $pcount; |
| $page_count = empty($pcount) ? $page_count : $pcount; |
| |
| |
| $qb = $app['eccube.repository.product']->getQueryBuilderBySearchDataForAdmin($searchData); |
| $qb = $app['eccube.repository.product']->getQueryBuilderBySearchDataForAdmin($searchData); |
| |
| |
| $event = new EventArgs( |
| $event = new EventArgs( |
| array( |
| array( |
| 'qb' => $qb, |
| 'qb' => $qb, |
| 'searchData' => $searchData, |
| 'searchData' => $searchData, |
| ), |
| ), |
| $request |
| $request |
| ); |
| ); |
| $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_INDEX_SEARCH, $event); |
| $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_INDEX_SEARCH, $event); |
| $searchData = $event->getArgument('searchData'); |
| $searchData = $event->getArgument('searchData'); |
| |
| |
| $pagination = $app['paginator']()->paginate( |
| $pagination = $app['paginator']()->paginate( |
| $qb, |
| $qb, |
| $page_no, |
| $page_no, |
| $page_count, |
| $page_count, |
| array('wrap-queries' => true) |
| array('wrap-queries' => true) |
| ); |
| ); |
| |
| |
| // セッションから検索条件を復元 |
| // セッションから検索条件を復元 |
| if (!empty($searchData['category_id'])) { |
| if (!empty($searchData['category_id'])) { |
| $searchData['category_id'] = $app['eccube.repository.category']->find($searchData['category_id']); |
| $searchData['category_id'] = $app['eccube.repository.category']->find($searchData['category_id']); |
| } |
| } |
| if (empty($status)) { |
| if (empty($status)) { |
| if (count($searchData['status']) > 0) { |
| if (count($searchData['status']) > 0) { |
| $status_ids = array(); |
| $status_ids = array(); |
| foreach ($searchData['status'] as $Status) { |
| foreach ($searchData['status'] as $Status) { |
| $status_ids[] = $Status->getId(); |
| $status_ids[] = $Status->getId(); |
| } |
| } |
| $searchData['status'] = $app['eccube.repository.master.disp']->findBy(array('id' => $status_ids)); |
| $searchData['status'] = $app['eccube.repository.master.disp']->findBy(array('id' => $status_ids)); |
| } |
| } |
| $searchData['link_status'] = null; |
| $searchData['link_status'] = null; |
| $searchData['stock_status'] = null; |
| $searchData['stock_status'] = null; |
| } |
| } |
| $searchForm->setData($searchData); |
| $searchForm->setData($searchData); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| return $app->render('Product/index.twig', array( |
| return $app->render('Product/index.twig', array( |
| 'searchForm' => $searchForm->createView(), |
| 'searchForm' => $searchForm->createView(), |
| 'pagination' => $pagination, |
| 'pagination' => $pagination, |
| 'disps' => $disps, |
| 'disps' => $disps, |
| 'pageMaxis' => $pageMaxis, |
| 'pageMaxis' => $pageMaxis, |
| 'page_no' => $page_no, |
| 'page_no' => $page_no, |
| 'page_status' => $page_status, |
| 'page_status' => $page_status, |
| 'page_count' => $page_count, |
| 'page_count' => $page_count, |
| 'active' => $active, |
| 'active' => $active, |
| )); |
| )); |
| } |
| } |
| |
| |
| public function addImage(Application $app, Request $request) |
| public function addImage(Application $app, Request $request) |
| { |
| { |
| . | |
| if (!$request->isXmlHttpRequest()) { |
| |
| throw new BadRequestHttpException(); |
| |
| } |
| |
| |
| $images = $request->files->get('admin_product'); |
| $images = $request->files->get('admin_product'); |
| |
| |
| $files = array(); |
| $files = array(); |
| if (count($images) > 0) { |
| if (count($images) > 0) { |
| foreach ($images as $img) { |
| foreach ($images as $img) { |
| foreach ($img as $image) { |
| foreach ($img as $image) { |
| . | |
| //ファイルフォーマット検証 |
| |
| $mimeType = $image->getMimeType(); |
| |
| if (0 !== strpos($mimeType, 'image')) { |
| |
| throw new UnsupportedMediaTypeHttpException(); |
| |
| } |
| |
| |
| $extension = $image->getClientOriginalExtension(); |
| $extension = $image->getClientOriginalExtension(); |
| $filename = date('mdHis') . uniqid('_') . '.' . $extension; |
| $filename = date('mdHis') . uniqid('_') . '.' . $extension; |
| $image->move($app['config']['image_temp_realdir'], $filename); |
| $image->move($app['config']['image_temp_realdir'], $filename); |
| $files[] = $filename; |
| $files[] = $filename; |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| $event = new EventArgs( |
| $event = new EventArgs( |
| array( |
| array( |
| 'images' => $images, |
| 'images' => $images, |
| 'files' => $files, |
| 'files' => $files, |
| ), |
| ), |
| $request |
| $request |
| ); |
| ); |
| $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_ADD_IMAGE_COMPLETE, $event); |
| $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_ADD_IMAGE_COMPLETE, $event); |
| $files = $event->getArgument('files'); |
| $files = $event->getArgument('files'); |
| |
| |
| return $app->json(array('files' => $files), 200); |
| return $app->json(array('files' => $files), 200); |
| } |
| } |
| |
| |
| public function edit(Application $app, Request $request, $id = null) |
| public function edit(Application $app, Request $request, $id = null) |
| { |
| { |
| $has_class = false; |
| $has_class = false; |
| if (is_null($id)) { |
| if (is_null($id)) { |
| $Product = new \Eccube\Entity\Product(); |
| $Product = new \Eccube\Entity\Product(); |
| $ProductClass = new \Eccube\Entity\ProductClass(); |
| $ProductClass = new \Eccube\Entity\ProductClass(); |
| $Disp = $app['eccube.repository.master.disp']->find(\Eccube\Entity\Master\Disp::DISPLAY_HIDE); |
| $Disp = $app['eccube.repository.master.disp']->find(\Eccube\Entity\Master\Disp::DISPLAY_HIDE); |
| $Product |
| $Product |
| ->setDelFlg(Constant::DISABLED) |
| ->setDelFlg(Constant::DISABLED) |
| ->addProductClass($ProductClass) |
| ->addProductClass($ProductClass) |
| ->setStatus($Disp); |
| ->setStatus($Disp); |
| $ProductClass |
| $ProductClass |
| ->setDelFlg(Constant::DISABLED) |
| ->setDelFlg(Constant::DISABLED) |
| ->setStockUnlimited(true) |
| ->setStockUnlimited(true) |
| ->setProduct($Product); |
| ->setProduct($Product); |
| $ProductStock = new \Eccube\Entity\ProductStock(); |
| $ProductStock = new \Eccube\Entity\ProductStock(); |
| $ProductClass->setProductStock($ProductStock); |
| $ProductClass->setProductStock($ProductStock); |
| $ProductStock->setProductClass($ProductClass); |
| $ProductStock->setProductClass($ProductClass); |
| } else { |
| } else { |
| $Product = $app['eccube.repository.product']->find($id); |
| $Product = $app['eccube.repository.product']->find($id); |
| if (!$Product) { |
| if (!$Product) { |
| throw new NotFoundHttpException(); |
| throw new NotFoundHttpException(); |
| } |
| } |
| // 規格あり商品か |
| // 規格あり商品か |
| $has_class = $Product->hasProductClass(); |
| $has_class = $Product->hasProductClass(); |
| if (!$has_class) { |
| if (!$has_class) { |
| $ProductClasses = $Product->getProductClasses(); |
| $ProductClasses = $Product->getProductClasses(); |
| $ProductClass = $ProductClasses[0]; |
| $ProductClass = $ProductClasses[0]; |
| $BaseInfo = $app['eccube.repository.base_info']->get(); |
| $BaseInfo = $app['eccube.repository.base_info']->get(); |
| if ($BaseInfo->getOptionProductTaxRule() == Constant::ENABLED && $ProductClass->getTaxRule() && !$ProductClass->getTaxRule()->getDelFlg()) { |
| if ($BaseInfo->getOptionProductTaxRule() == Constant::ENABLED && $ProductClass->getTaxRule() && !$ProductClass->getTaxRule()->getDelFlg()) { |
| $ProductClass->setTaxRate($ProductClass->getTaxRule()->getTaxRate()); |
| $ProductClass->setTaxRate($ProductClass->getTaxRule()->getTaxRate()); |
| } |
| } |
| $ProductStock = $ProductClasses[0]->getProductStock(); |
| $ProductStock = $ProductClasses[0]->getProductStock(); |
| } |
| } |
| } |
| } |
| |
| |
| $builder = $app['form.factory'] |
| $builder = $app['form.factory'] |
| ->createBuilder('admin_product', $Product); |
| ->createBuilder('admin_product', $Product); |
| |
| |
| // 規格あり商品の場合、規格関連情報をFormから除外 |
| // 規格あり商品の場合、規格関連情報をFormから除外 |
| if ($has_class) { |
| if ($has_class) { |
| $builder->remove('class'); |
| $builder->remove('class'); |
| } |
| } |
| |
| |
| $event = new EventArgs( |
| $event = new EventArgs( |
| array( |
| array( |
| 'builder' => $builder, |
| 'builder' => $builder, |
| 'Product' => $Product, |
| 'Product' => $Product, |
| ), |
| ), |
| $request |
| $request |
| ); |
| ); |
| $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_EDIT_INITIALIZE, $event); |
| $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_EDIT_INITIALIZE, $event); |
| |
| |
| $form = $builder->getForm(); |
| $form = $builder->getForm(); |
| |
| |
| if (!$has_class) { |
| if (!$has_class) { |
| $ProductClass->setStockUnlimited((boolean)$ProductClass->getStockUnlimited()); |
| $ProductClass->setStockUnlimited((boolean)$ProductClass->getStockUnlimited()); |
| $form['class']->setData($ProductClass); |
| $form['class']->setData($ProductClass); |
| } |
| } |
| |
| |
| // ファイルの登録 |
| // ファイルの登録 |
| $images = array(); |
| $images = array(); |
| $ProductImages = $Product->getProductImage(); |
| $ProductImages = $Product->getProductImage(); |
| foreach ($ProductImages as $ProductImage) { |
| foreach ($ProductImages as $ProductImage) { |
| $images[] = $ProductImage->getFileName(); |
| $images[] = $ProductImage->getFileName(); |
| } |
| } |
| $form['images']->setData($images); |
| $form['images']->setData($images); |
| |
| |
| $categories = array(); |
| $categories = array(); |
| $ProductCategories = $Product->getProductCategories(); |
| $ProductCategories = $Product->getProductCategories(); |
| foreach ($ProductCategories as $ProductCategory) { |
| foreach ($ProductCategories as $ProductCategory) { |
| /* @var $ProductCategory \Eccube\Entity\ProductCategory */ |
| /* @var $ProductCategory \Eccube\Entity\ProductCategory */ |
| $categories[] = $ProductCategory->getCategory(); |
| $categories[] = $ProductCategory->getCategory(); |
| } |
| } |
| $form['Category']->setData($categories); |
| $form['Category']->setData($categories); |
| |
| |
| if ('POST' === $request->getMethod()) { |
| if ('POST' === $request->getMethod()) { |
| $form->handleRequest($request); |
| $form->handleRequest($request); |
| if ($form->isValid()) { |
| if ($form->isValid()) { |
| $Product = $form->getData(); |
| $Product = $form->getData(); |
| |
| |
| if (!$has_class) { |
| if (!$has_class) { |
| $ProductClass = $form['class']->getData(); |
| $ProductClass = $form['class']->getData(); |
| |
| |
| // 個別消費税 |
| // 個別消費税 |
| $BaseInfo = $app['eccube.repository.base_info']->get(); |
| $BaseInfo = $app['eccube.repository.base_info']->get(); |
| if ($BaseInfo->getOptionProductTaxRule() == Constant::ENABLED) { |
| if ($BaseInfo->getOptionProductTaxRule() == Constant::ENABLED) { |
| if ($ProductClass->getTaxRate()) { |
| if ($ProductClass->getTaxRate()) { |
| if ($ProductClass->getTaxRule() && !$ProductClass->getTaxRule()->getDelFlg()) { |
| if ($ProductClass->getTaxRule() && !$ProductClass->getTaxRule()->getDelFlg()) { |
| $ProductClass->getTaxRule()->setTaxRate($ProductClass->getTaxRate()); |
| $ProductClass->getTaxRule()->setTaxRate($ProductClass->getTaxRate()); |
| } else { |
| } else { |
| $taxrule = $app['eccube.repository.tax_rule']->newTaxRule(); |
| $taxrule = $app['eccube.repository.tax_rule']->newTaxRule(); |
| $taxrule->setTaxRate($ProductClass->getTaxRate()); |
| $taxrule->setTaxRate($ProductClass->getTaxRate()); |
| $taxrule->setApplyDate(new \DateTime()); |
| $taxrule->setApplyDate(new \DateTime()); |
| $taxrule->setProduct($Product); |
| $taxrule->setProduct($Product); |
| $taxrule->setProductClass($ProductClass); |
| $taxrule->setProductClass($ProductClass); |
| $ProductClass->setTaxRule($taxrule); |
| $ProductClass->setTaxRule($taxrule); |
| } |
| } |
| } else { |
| } else { |
| if ($ProductClass->getTaxRule()) { |
| if ($ProductClass->getTaxRule()) { |
| $ProductClass->getTaxRule()->setDelFlg(Constant::ENABLED); |
| $ProductClass->getTaxRule()->setDelFlg(Constant::ENABLED); |
| } |
| } |
| } |
| } |
| } |
| } |
| $app['orm.em']->persist($ProductClass); |
| $app['orm.em']->persist($ProductClass); |
| |
| |
| // 在庫情報を作成 |
| // 在庫情報を作成 |
| if (!$ProductClass->getStockUnlimited()) { |
| if (!$ProductClass->getStockUnlimited()) { |
| $ProductStock->setStock($ProductClass->getStock()); |
| $ProductStock->setStock($ProductClass->getStock()); |
| } else { |
| } else { |
| // 在庫無制限時はnullを設定 |
| // 在庫無制限時はnullを設定 |
| $ProductStock->setStock(null); |
| $ProductStock->setStock(null); |
| } |
| } |
| $app['orm.em']->persist($ProductStock); |
| $app['orm.em']->persist($ProductStock); |
| } |
| } |
| |
| |
| // カテゴリの登録 |
| // カテゴリの登録 |
| // 一度クリア |
| // 一度クリア |
| /* @var $Product \Eccube\Entity\Product */ |
| /* @var $Product \Eccube\Entity\Product */ |
| foreach ($Product->getProductCategories() as $ProductCategory) { |
| foreach ($Product->getProductCategories() as $ProductCategory) { |
| $Product->removeProductCategory($ProductCategory); |
| $Product->removeProductCategory($ProductCategory); |
| $app['orm.em']->remove($ProductCategory); |
| $app['orm.em']->remove($ProductCategory); |
| } |
| } |
| $app['orm.em']->persist($Product); |
| $app['orm.em']->persist($Product); |
| $app['orm.em']->flush(); |
| $app['orm.em']->flush(); |
| |
| |
| $count = 1; |
| $count = 1; |
| $Categories = $form->get('Category')->getData(); |
| $Categories = $form->get('Category')->getData(); |
| foreach ($Categories as $Category) { |
| foreach ($Categories as $Category) { |
| $ProductCategory = new \Eccube\Entity\ProductCategory(); |
| $ProductCategory = new \Eccube\Entity\ProductCategory(); |
| $ProductCategory |
| $ProductCategory |
| ->setProduct($Product) |
| ->setProduct($Product) |
| ->setProductId($Product->getId()) |
| ->setProductId($Product->getId()) |
| ->setCategory($Category) |
| ->setCategory($Category) |
| ->setCategoryId($Category->getId()) |
| ->setCategoryId($Category->getId()) |
| ->setRank($count); |
| ->setRank($count); |
| $app['orm.em']->persist($ProductCategory); |
| $app['orm.em']->persist($ProductCategory); |
| $count++; |
| $count++; |
| /* @var $Product \Eccube\Entity\Product */ |
| /* @var $Product \Eccube\Entity\Product */ |
| $Product->addProductCategory($ProductCategory); |
| $Product->addProductCategory($ProductCategory); |
| } |
| } |
| |
| |
| // 画像の登録 |
| // 画像の登録 |
| $add_images = $form->get('add_images')->getData(); |
| $add_images = $form->get('add_images')->getData(); |
| foreach ($add_images as $add_image) { |
| foreach ($add_images as $add_image) { |
| $ProductImage = new \Eccube\Entity\ProductImage(); |
| $ProductImage = new \Eccube\Entity\ProductImage(); |
| $ProductImage |
| $ProductImage |
| ->setFileName($add_image) |
| ->setFileName($add_image) |
| ->setProduct($Product) |
| ->setProduct($Product) |
| ->setRank(1); |
| ->setRank(1); |
| $Product->addProductImage($ProductImage); |
| $Product->addProductImage($ProductImage); |
| $app['orm.em']->persist($ProductImage); |
| $app['orm.em']->persist($ProductImage); |
| |
| |
| // 移動 |
| // 移動 |
| $file = new File($app['config']['image_temp_realdir'] . '/' . $add_image); |
| $file = new File($app['config']['image_temp_realdir'] . '/' . $add_image); |
| $file->move($app['config']['image_save_realdir']); |
| $file->move($app['config']['image_save_realdir']); |
| } |
| } |
| |
| |
| // 画像の削除 |
| // 画像の削除 |
| $delete_images = $form->get('delete_images')->getData(); |
| $delete_images = $form->get('delete_images')->getData(); |
| foreach ($delete_images as $delete_image) { |
| foreach ($delete_images as $delete_image) { |
| $ProductImage = $app['eccube.repository.product_image'] |
| $ProductImage = $app['eccube.repository.product_image'] |
| ->findOneBy(array('file_name' => $delete_image)); |
| ->findOneBy(array('file_name' => $delete_image)); |
| |
| |
| // 追加してすぐに削除した画像は、Entityに追加されない |
| // 追加してすぐに削除した画像は、Entityに追加されない |
| if ($ProductImage instanceof \Eccube\Entity\ProductImage) { |
| if ($ProductImage instanceof \Eccube\Entity\ProductImage) { |
| $Product->removeProductImage($ProductImage); |
| $Product->removeProductImage($ProductImage); |
| $app['orm.em']->remove($ProductImage); |
| $app['orm.em']->remove($ProductImage); |
| |
| |
| } |
| } |
| $app['orm.em']->persist($Product); |
| $app['orm.em']->persist($Product); |
| |
| |
| // 削除 |
| // 削除 |
| $fs = new Filesystem(); |
| $fs = new Filesystem(); |
| $fs->remove($app['config']['image_save_realdir'] . '/' . $delete_image); |
| $fs->remove($app['config']['image_save_realdir'] . '/' . $delete_image); |
| } |
| } |
| $app['orm.em']->persist($Product); |
| $app['orm.em']->persist($Product); |
| $app['orm.em']->flush(); |
| $app['orm.em']->flush(); |
| |
| |
| |
| |
| $ranks = $request->get('rank_images'); |
| $ranks = $request->get('rank_images'); |
| if ($ranks) { |
| if ($ranks) { |
| foreach ($ranks as $rank) { |
| foreach ($ranks as $rank) { |
| list($filename, $rank_val) = explode('//', $rank); |
| list($filename, $rank_val) = explode('//', $rank); |
| $ProductImage = $app['eccube.repository.product_image'] |
| $ProductImage = $app['eccube.repository.product_image'] |
| ->findOneBy(array( |
| ->findOneBy(array( |
| 'file_name' => $filename, |
| 'file_name' => $filename, |
| 'Product' => $Product, |
| 'Product' => $Product, |
| )); |
| )); |
| $ProductImage->setRank($rank_val); |
| $ProductImage->setRank($rank_val); |
| $app['orm.em']->persist($ProductImage); |
| $app['orm.em']->persist($ProductImage); |
| } |
| } |
| } |
| } |
| $app['orm.em']->flush(); |
| $app['orm.em']->flush(); |
| |
| |
| $event = new EventArgs( |
| $event = new EventArgs( |
| array( |
| array( |
| 'form' => $form, |
| 'form' => $form, |
| 'Product' => $Product, |
| 'Product' => $Product, |
| ), |
| ), |
| $request |
| $request |
| ); |
| ); |
| $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_EDIT_COMPLETE, $event); |
| $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_EDIT_COMPLETE, $event); |
| |
| |
| $app->addSuccess('admin.register.complete', 'admin'); |
| $app->addSuccess('admin.register.complete', 'admin'); |
| |
| |
| return $app->redirect($app->url('admin_product_product_edit', array('id' => $Product->getId()))); |
| return $app->redirect($app->url('admin_product_product_edit', array('id' => $Product->getId()))); |
| } else { |
| } else { |
| $app->addError('admin.register.failed', 'admin'); |
| $app->addError('admin.register.failed', 'admin'); |
| } |
| } |
| } |
| } |
| |
| |
| // 検索結果の保持 |
| // 検索結果の保持 |
| $builder = $app['form.factory'] |
| $builder = $app['form.factory'] |
| ->createBuilder('admin_search_product'); |
| ->createBuilder('admin_search_product'); |
| |
| |
| $event = new EventArgs( |
| $event = new EventArgs( |
| array( |
| array( |
| 'builder' => $builder, |
| 'builder' => $builder, |
| 'Product' => $Product, |
| 'Product' => $Product, |
| ), |
| ), |
| $request |
| $request |
| ); |
| ); |
| $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_EDIT_SEARCH, $event); |
| $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_EDIT_SEARCH, $event); |
| |
| |
| $searchForm = $builder->getForm(); |
| $searchForm = $builder->getForm(); |
| |
| |
| if ('POST' === $request->getMethod()) { |
| if ('POST' === $request->getMethod()) { |
| $searchForm->handleRequest($request); |
| $searchForm->handleRequest($request); |
| } |
| } |
| |
| |
| return $app->render('Product/product.twig', array( |
| return $app->render('Product/product.twig', array( |
| 'Product' => $Product, |
| 'Product' => $Product, |
| 'form' => $form->createView(), |
| 'form' => $form->createView(), |
| 'searchForm' => $searchForm->createView(), |
| 'searchForm' => $searchForm->createView(), |
| 'has_class' => $has_class, |
| 'has_class' => $has_class, |
| 'id' => $id, |
| 'id' => $id, |
| )); |
| )); |
| } |
| } |
| |
| |
| public function delete(Application $app, Request $request, $id = null) |
| public function delete(Application $app, Request $request, $id = null) |
| { |
| { |
| $this->isTokenValid($app); |
| $this->isTokenValid($app); |
| |
| |
| if (!is_null($id)) { |
| if (!is_null($id)) { |
| /* @var $Product \Eccube\Entity\Product */ |
| /* @var $Product \Eccube\Entity\Product */ |
| $Product = $app['eccube.repository.product']->find($id); |
| $Product = $app['eccube.repository.product']->find($id); |
| if (!$Product) { |
| if (!$Product) { |
| $app->deleteMessage(); |
| $app->deleteMessage(); |
| return $app->redirect($app->url('admin_product')); |
| return $app->redirect($app->url('admin_product')); |
| } |
| } |
| |
| |
| if ($Product instanceof \Eccube\Entity\Product) { |
| if ($Product instanceof \Eccube\Entity\Product) { |
| $Product->setDelFlg(Constant::ENABLED); |
| $Product->setDelFlg(Constant::ENABLED); |
| |
| |
| $ProductClasses = $Product->getProductClasses(); |
| $ProductClasses = $Product->getProductClasses(); |
| $deleteImages = array(); |
| $deleteImages = array(); |
| foreach ($ProductClasses as $ProductClass) { |
| foreach ($ProductClasses as $ProductClass) { |
| $ProductClass->setDelFlg(Constant::ENABLED); |
| $ProductClass->setDelFlg(Constant::ENABLED); |
| $Product->removeProductClass($ProductClass); |
| $Product->removeProductClass($ProductClass); |
| |
| |
| $ProductClasses = $Product->getProductClasses(); |
| $ProductClasses = $Product->getProductClasses(); |
| foreach ($ProductClasses as $ProductClass) { |
| foreach ($ProductClasses as $ProductClass) { |
| $ProductClass->setDelFlg(Constant::ENABLED); |
| $ProductClass->setDelFlg(Constant::ENABLED); |
| $Product->removeProductClass($ProductClass); |
| $Product->removeProductClass($ProductClass); |
| |
| |
| $ProductStock = $ProductClass->getProductStock(); |
| $ProductStock = $ProductClass->getProductStock(); |
| $app['orm.em']->remove($ProductStock); |
| $app['orm.em']->remove($ProductStock); |
| } |
| } |
| |
| |
| $ProductImages = $Product->getProductImage(); |
| $ProductImages = $Product->getProductImage(); |
| foreach ($ProductImages as $ProductImage) { |
| foreach ($ProductImages as $ProductImage) { |
| $Product->removeProductImage($ProductImage); |
| $Product->removeProductImage($ProductImage); |
| $deleteImages[] = $ProductImage->getFileName(); |
| $deleteImages[] = $ProductImage->getFileName(); |
| $app['orm.em']->remove($ProductImage); |
| $app['orm.em']->remove($ProductImage); |
| } |
| } |
| |
| |
| $ProductCategories = $Product->getProductCategories(); |
| $ProductCategories = $Product->getProductCategories(); |
| foreach ($ProductCategories as $ProductCategory) { |
| foreach ($ProductCategories as $ProductCategory) { |
| $Product->removeProductCategory($ProductCategory); |
| $Product->removeProductCategory($ProductCategory); |
| $app['orm.em']->remove($ProductCategory); |
| $app['orm.em']->remove($ProductCategory); |
| } |
| } |
| |
| |
| } |
| } |
| |
| |
| $app['orm.em']->persist($Product); |
| $app['orm.em']->persist($Product); |
| |
| |
| $app['orm.em']->flush(); |
| $app['orm.em']->flush(); |
| |
| |
| $event = new EventArgs( |
| $event = new EventArgs( |
| array( |
| array( |
| 'Product' => $Product, |
| 'Product' => $Product, |
| 'ProductClass' => $ProductClasses, |
| 'ProductClass' => $ProductClasses, |
| 'deleteImages' => $deleteImages, |
| 'deleteImages' => $deleteImages, |
| ), |
| ), |
| $request |
| $request |
| ); |
| ); |
| $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_DELETE_COMPLETE, $event); |
| $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_DELETE_COMPLETE, $event); |
| $deleteImages = $event->getArgument('deleteImages'); |
| $deleteImages = $event->getArgument('deleteImages'); |
| |
| |
| // 画像ファイルの削除(commit後に削除させる) |
| // 画像ファイルの削除(commit後に削除させる) |
| foreach ($deleteImages as $deleteImage) { |
| foreach ($deleteImages as $deleteImage) { |
| try { |
| try { |
| $fs = new Filesystem(); |
| $fs = new Filesystem(); |
| $fs->remove($app['config']['image_save_realdir'] . '/' . $deleteImage); |
| $fs->remove($app['config']['image_save_realdir'] . '/' . $deleteImage); |
| } catch (\Exception $e) { |
| } catch (\Exception $e) { |
| // エラーが発生しても無視する |
| // エラーが発生しても無視する |
| } |
| } |
| } |
| } |
| |
| |
| $app->addSuccess('admin.delete.complete', 'admin'); |
| $app->addSuccess('admin.delete.complete', 'admin'); |
| } else { |
| } else { |
| $app->addError('admin.delete.failed', 'admin'); |
| $app->addError('admin.delete.failed', 'admin'); |
| } |
| } |
| } else { |
| } else { |
| $app->addError('admin.delete.failed', 'admin'); |
| $app->addError('admin.delete.failed', 'admin'); |
| } |
| } |
| |
| |
| return $app->redirect($app->url('admin_product')); |
| return $app->redirect($app->url('admin_product')); |
| } |
| } |
| |
| |
| public function copy(Application $app, Request $request, $id = null) |
| public function copy(Application $app, Request $request, $id = null) |
| { |
| { |
| . | |
| $this->isTokenValid($app); |
| |
| |
| if (!is_null($id)) { |
| if (!is_null($id)) { |
| $Product = $app['eccube.repository.product']->find($id); |
| $Product = $app['eccube.repository.product']->find($id); |
| if ($Product instanceof \Eccube\Entity\Product) { |
| if ($Product instanceof \Eccube\Entity\Product) { |
| $CopyProduct = clone $Product; |
| $CopyProduct = clone $Product; |
| $CopyProduct->copy(); |
| $CopyProduct->copy(); |
| $Disp = $app['eccube.repository.master.disp']->find(\Eccube\Entity\Master\Disp::DISPLAY_HIDE); |
| $Disp = $app['eccube.repository.master.disp']->find(\Eccube\Entity\Master\Disp::DISPLAY_HIDE); |
| $CopyProduct->setStatus($Disp); |
| $CopyProduct->setStatus($Disp); |
| |
| |
| $CopyProductCategories = $CopyProduct->getProductCategories(); |
| $CopyProductCategories = $CopyProduct->getProductCategories(); |
| foreach ($CopyProductCategories as $Category) { |
| foreach ($CopyProductCategories as $Category) { |
| $app['orm.em']->persist($Category); |
| $app['orm.em']->persist($Category); |
| } |
| } |
| |
| |
| // 規格あり商品の場合は, デフォルトの商品規格を取得し登録する. |
| // 規格あり商品の場合は, デフォルトの商品規格を取得し登録する. |
| if ($CopyProduct->hasProductClass()) { |
| if ($CopyProduct->hasProductClass()) { |
| $softDeleteFilter = $app['orm.em']->getFilters()->getFilter('soft_delete'); |
| $softDeleteFilter = $app['orm.em']->getFilters()->getFilter('soft_delete'); |
| $softDeleteFilter->setExcludes(array( |
| $softDeleteFilter->setExcludes(array( |
| 'Eccube\Entity\ProductClass' |
| 'Eccube\Entity\ProductClass' |
| )); |
| )); |
| $dummyClass = $app['eccube.repository.product_class']->findOneBy(array( |
| $dummyClass = $app['eccube.repository.product_class']->findOneBy(array( |
| 'del_flg' => \Eccube\Common\Constant::ENABLED, |
| 'del_flg' => \Eccube\Common\Constant::ENABLED, |
| 'ClassCategory1' => null, |
| 'ClassCategory1' => null, |
| 'ClassCategory2' => null, |
| 'ClassCategory2' => null, |
| 'Product' => $Product, |
| 'Product' => $Product, |
| )); |
| )); |
| $dummyClass = clone $dummyClass; |
| $dummyClass = clone $dummyClass; |
| $dummyClass->setProduct($CopyProduct); |
| $dummyClass->setProduct($CopyProduct); |
| $CopyProduct->addProductClass($dummyClass); |
| $CopyProduct->addProductClass($dummyClass); |
| $softDeleteFilter->setExcludes(array()); |
| $softDeleteFilter->setExcludes(array()); |
| } |
| } |
| |
| |
| $CopyProductClasses = $CopyProduct->getProductClasses(); |
| $CopyProductClasses = $CopyProduct->getProductClasses(); |
| foreach ($CopyProductClasses as $Class) { |
| foreach ($CopyProductClasses as $Class) { |
| $Stock = $Class->getProductStock(); |
| $Stock = $Class->getProductStock(); |
| $CopyStock = clone $Stock; |
| $CopyStock = clone $Stock; |
| $CopyStock->setProductClass($Class); |
| $CopyStock->setProductClass($Class); |
| $app['orm.em']->persist($CopyStock); |
| $app['orm.em']->persist($CopyStock); |
| |
| |
| $app['orm.em']->persist($Class); |
| $app['orm.em']->persist($Class); |
| } |
| } |
| $Images = $CopyProduct->getProductImage(); |
| $Images = $CopyProduct->getProductImage(); |
| foreach ($Images as $Image) { |
| foreach ($Images as $Image) { |
| |
| |
| // 画像ファイルを新規作成 |
| // 画像ファイルを新規作成 |
| $extension = pathinfo($Image->getFileName(), PATHINFO_EXTENSION); |
| $extension = pathinfo($Image->getFileName(), PATHINFO_EXTENSION); |
| $filename = date('mdHis') . uniqid('_') . '.' . $extension; |
| $filename = date('mdHis') . uniqid('_') . '.' . $extension; |
| try { |
| try { |
| $fs = new Filesystem(); |
| $fs = new Filesystem(); |
| $fs->copy($app['config']['image_save_realdir'] . '/' . $Image->getFileName(), $app['config']['image_save_realdir'] . '/' . $filename); |
| $fs->copy($app['config']['image_save_realdir'] . '/' . $Image->getFileName(), $app['config']['image_save_realdir'] . '/' . $filename); |
| } catch (\Exception $e) { |
| } catch (\Exception $e) { |
| // エラーが発生しても無視する |
| // エラーが発生しても無視する |
| } |
| } |
| $Image->setFileName($filename); |
| $Image->setFileName($filename); |
| |
| |
| $app['orm.em']->persist($Image); |
| $app['orm.em']->persist($Image); |
| } |
| } |
| $Tags = $CopyProduct->getProductTag(); |
| $Tags = $CopyProduct->getProductTag(); |
| foreach ($Tags as $Tag) { |
| foreach ($Tags as $Tag) { |
| $app['orm.em']->persist($Tag); |
| $app['orm.em']->persist($Tag); |
| } |
| } |
| |
| |
| $app['orm.em']->persist($CopyProduct); |
| $app['orm.em']->persist($CopyProduct); |
| |
| |
| $app['orm.em']->flush(); |
| $app['orm.em']->flush(); |
| |
| |
| $event = new EventArgs( |
| $event = new EventArgs( |
| array( |
| array( |
| 'Product' => $Product, |
| 'Product' => $Product, |
| 'CopyProduct' => $CopyProduct, |
| 'CopyProduct' => $CopyProduct, |
| 'CopyProductCategories' => $CopyProductCategories, |
| 'CopyProductCategories' => $CopyProductCategories, |
| 'CopyProductClasses' => $CopyProductClasses, |
| 'CopyProductClasses' => $CopyProductClasses, |
| 'images' => $Images, |
| 'images' => $Images, |
| 'Tags' => $Tags, |
| 'Tags' => $Tags, |
| ), |
| ), |
| $request |
| $request |
| ); |
| ); |
| $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_COPY_COMPLETE, $event); |
| $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_COPY_COMPLETE, $event); |
| |
| |
| $app->addSuccess('admin.product.copy.complete', 'admin'); |
| $app->addSuccess('admin.product.copy.complete', 'admin'); |
| |
| |
| return $app->redirect($app->url('admin_product_product_edit', array('id' => $CopyProduct->getId()))); |
| return $app->redirect($app->url('admin_product_product_edit', array('id' => $CopyProduct->getId()))); |
| } else { |
| } else { |
| $app->addError('admin.product.copy.failed', 'admin'); |
| $app->addError('admin.product.copy.failed', 'admin'); |
| } |
| } |
| } else { |
| } else { |
| $app->addError('admin.product.copy.failed', 'admin'); |
| $app->addError('admin.product.copy.failed', 'admin'); |
| } |
| } |
| |
| |
| return $app->redirect($app->url('admin_product')); |
| return $app->redirect($app->url('admin_product')); |
| } |
| } |
| |
| |
| public function display(Application $app, Request $request, $id = null) |
| public function display(Application $app, Request $request, $id = null) |
| { |
| { |
| $event = new EventArgs( |
| $event = new EventArgs( |
| array(), |
| array(), |
| $request |
| $request |
| ); |
| ); |
| $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_DISPLAY_COMPLETE, $event); |
| $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_DISPLAY_COMPLETE, $event); |
| |
| |
| if (!is_null($id)) { |
| if (!is_null($id)) { |
| return $app->redirect($app->url('product_detail', array('id' => $id, 'admin' => '1'))); |
| return $app->redirect($app->url('product_detail', array('id' => $id, 'admin' => '1'))); |
| } |
| } |
| |
| |
| return $app->redirect($app->url('admin_product')); |
| return $app->redirect($app->url('admin_product')); |
| } |
| } |
| |
| |
| /** |
| /** |
| * 商品CSVの出力. |
| * 商品CSVの出力. |
| * |
| * |
| * @param Application $app |
| * @param Application $app |
| * @param Request $request |
| * @param Request $request |
| * @return StreamedResponse |
| * @return StreamedResponse |
| */ |
| */ |
| public function export(Application $app, Request $request) |
| public function export(Application $app, Request $request) |
| { |
| { |
| // タイムアウトを無効にする. |
| // タイムアウトを無効にする. |
| set_time_limit(0); |
| set_time_limit(0); |
| |
| |
| // sql loggerを無効にする. |
| // sql loggerを無効にする. |
| $em = $app['orm.em']; |
| $em = $app['orm.em']; |
| $em->getConfiguration()->setSQLLogger(null); |
| $em->getConfiguration()->setSQLLogger(null); |
| |
| |
| $response = new StreamedResponse(); |
| $response = new StreamedResponse(); |
| $response->setCallback(function () use ($app, $request) { |
| $response->setCallback(function () use ($app, $request) { |
| |
| |
| // CSV種別を元に初期化. |
| // CSV種別を元に初期化. |
| $app['eccube.service.csv.export']->initCsvType(CsvType::CSV_TYPE_PRODUCT); |
| $app['eccube.service.csv.export']->initCsvType(CsvType::CSV_TYPE_PRODUCT); |
| |
| |
| // ヘッダ行の出力. |
| // ヘッダ行の出力. |
| $app['eccube.service.csv.export']->exportHeader(); |
| $app['eccube.service.csv.export']->exportHeader(); |
| |
| |
| // 商品データ検索用のクエリビルダを取得. |
| // 商品データ検索用のクエリビルダを取得. |
| $qb = $app['eccube.service.csv.export'] |
| $qb = $app['eccube.service.csv.export'] |
| ->getProductQueryBuilder($request); |
| ->getProductQueryBuilder($request); |
| |
| |
| // joinする場合はiterateが使えないため, select句をdistinctする. |
| // joinする場合はiterateが使えないため, select句をdistinctする. |
| // http://qiita.com/suin/items/2b1e98105fa3ef89beb7 |
| // http://qiita.com/suin/items/2b1e98105fa3ef89beb7 |
| // distinctのmysqlとpgsqlの挙動をあわせる. |
| // distinctのmysqlとpgsqlの挙動をあわせる. |
| // http://uedatakeshi.blogspot.jp/2010/04/distinct-oeder-by-postgresmysql.html |
| // http://uedatakeshi.blogspot.jp/2010/04/distinct-oeder-by-postgresmysql.html |
| $qb->resetDQLPart('select') |
| $qb->resetDQLPart('select') |
| ->resetDQLPart('orderBy') |
| ->resetDQLPart('orderBy') |
| ->select('p') |
| ->select('p') |
| ->orderBy('p.update_date', 'DESC') |
| ->orderBy('p.update_date', 'DESC') |
| ->distinct(); |
| ->distinct(); |
| |
| |
| // データ行の出力. |
| // データ行の出力. |
| $app['eccube.service.csv.export']->setExportQueryBuilder($qb); |
| $app['eccube.service.csv.export']->setExportQueryBuilder($qb); |
| $app['eccube.service.csv.export']->exportData(function ($entity, $csvService) { |
| $app['eccube.service.csv.export']->exportData(function ($entity, $csvService) { |
| |
| |
| $Csvs = $csvService->getCsvs(); |
| $Csvs = $csvService->getCsvs(); |
| |
| |
| /** @var $Product \Eccube\Entity\Product */ |
| /** @var $Product \Eccube\Entity\Product */ |
| $Product = $entity; |
| $Product = $entity; |
| |
| |
| /** @var $Product \Eccube\Entity\ProductClass[] */ |
| /** @var $Product \Eccube\Entity\ProductClass[] */ |
| $ProductClassess = $Product->getProductClasses(); |
| $ProductClassess = $Product->getProductClasses(); |
| |
| |
| foreach ($ProductClassess as $ProductClass) { |
| foreach ($ProductClassess as $ProductClass) { |
| $row = array(); |
| $row = array(); |
| |
| |
| // CSV出力項目と合致するデータを取得. |
| // CSV出力項目と合致するデータを取得. |
| foreach ($Csvs as $Csv) { |
| foreach ($Csvs as $Csv) { |
| // 商品データを検索. |
| // 商品データを検索. |
| $data = $csvService->getData($Csv, $Product); |
| $data = $csvService->getData($Csv, $Product); |
| if (is_null($data)) { |
| if (is_null($data)) { |
| // 商品規格情報を検索. |
| // 商品規格情報を検索. |
| $data = $csvService->getData($Csv, $ProductClass); |
| $data = $csvService->getData($Csv, $ProductClass); |
| } |
| } |
| $row[] = $data; |
| $row[] = $data; |
| } |
| } |
| |
| |
| //$row[] = number_format(memory_get_usage(true)); |
| //$row[] = number_format(memory_get_usage(true)); |
| // 出力. |
| // 出力. |
| $csvService->fputcsv($row); |
| $csvService->fputcsv($row); |
| } |
| } |
| }); |
| }); |
| }); |
| }); |
| |
| |
| $now = new \DateTime(); |
| $now = new \DateTime(); |
| $filename = 'product_' . $now->format('YmdHis') . '.csv'; |
| $filename = 'product_' . $now->format('YmdHis') . '.csv'; |
| $response->headers->set('Content-Type', 'application/octet-stream'); |
| $response->headers->set('Content-Type', 'application/octet-stream'); |
| $response->headers->set('Content-Disposition', 'attachment; filename=' . $filename); |
| $response->headers->set('Content-Disposition', 'attachment; filename=' . $filename); |
| $response->send(); |
| $response->send(); |
| |
| |
| return $response; |
| return $response; |
| } |
| } |
| } |
| } |
| |
| |