Skip to content

Commit

Permalink
Merge pull request #150 from chihiro-adachi/admin_product_class
Browse files Browse the repository at this point in the history
管理画面:商品登録(商品規格)
  • Loading branch information
Shinichi Takahashi committed May 1, 2015
2 parents 8430f6f + bd9b9d5 commit 0ac6ecc
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 191 deletions.
122 changes: 122 additions & 0 deletions src/Eccube/Controller/Admin/Product/ProductClassController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?php

namespace Eccube\Controller\Admin\Product;

use Doctrine\Common\Util\Debug;
use Eccube\Application;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\HttpKernelInterface;

class ProductClassController
{
public function index(Application $app, Request $request, $product_id)
{
/** @var $Product \Eccube\Entity\Product */
$Product = $app['orm.em']
->getRepository('\Eccube\Entity\Product')
->find($product_id);

if (!$Product) {
throw new NotFoundHttpException();
}

/** @var $ProductClasses \Eccube\Entity\ProductClass[] */
$ProductClasses = $Product->getProductClasses();
$ClassName1 = null;
$ClassName2 = null;
// 規格名を取得
if (isset($ProductClasses[0])) {
$ClassCategory1 = $ProductClasses[0]->getClassCategory1();
if ($ClassCategory1) {
$ClassName1 = $ClassCategory1->getClassName();
}
$ClassCategory2 = $ProductClasses[0]->getClassCategory2();
if ($ClassCategory2) {
$ClassName2 = $ClassCategory2->getClassName();
}
}

$builder = $app['form.factory']->createBuilder();
$builder
->add('class1', 'entity', array(
'class' => 'Eccube\Entity\ClassName',
'property' => 'name',
'empty_value' => '--',
'data' => $ClassName1,
))
->add('class2', 'entity', array(
'class' => 'Eccube\Entity\ClassName',
'property' => 'name',
'empty_value' => '--',
'data' => $ClassName2,
))
->add('product_classess', 'collection', array(
'type' => 'admin_product_class',
'data' => $ProductClasses,
))
;

$form = $builder->getForm();

if ('POST' === $request->getMethod()) {
$form->handleRequest($request);
if ($form->isValid()) {
$data = $form->getData();
foreach ($data['product_classess'] as $ProdcutClass) {
$app['orm.em']->persist($ProdcutClass);
}
$app['orm.em']->flush();
$app['session']->getFlashBag()->add('admin.success', 'admin.product.product_class.save.complete');
return $app->redirect($app['url_generator']->generate('admin_product_product_class', array('product_id' => $product_id)));
}
}

return $app['view']->render('Admin/Product/product_class.twig', array(
'maintitle' => '商品管理',
'subtitle' => '商品マスター',
'form' => $form->createView(),
'Product' => $Product
));
}

public function edit(Application $app, Request $request)
{
/* @var $softDeleteFilter \Eccube\Doctrine\Filter\SoftDeleteFilter */
$softDeleteFilter = $app['orm.em']->getFilters()->getFilter('soft_delete');
$softDeleteFilter->setExcludes(array(
'Eccube\Entity\ProductClass'
));

if ($request->get('product_id')) {
$Product = $app['eccube.repository.product']->find($request->get('product_id'));
if (!$Product) {
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
} else {
$Product = new \Eccube\Entity\Product();
}

$searchForm = $app['form.factory']
->createBuilder('admin_search_product')
->getForm();
if ($request->getMethod() === 'POST') {
$searchForm->handleRequest($request);
}

$form = $app['form.factory']
->createBuilder('admin_product', $Product)
->getForm();
if ($request->getMethod() === 'POST') {
$form->handleRequest($request);
}

return $app['view']->render('Admin/Product/product.twig', array(
'maintitle' => '商品管理',
'subtitle' => '商品登録',
'form' => $form->createView(),
'searchForm' => $searchForm->createView(),
));
}

}
5 changes: 4 additions & 1 deletion src/Eccube/ControllerProvider/AdminControllerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ public function connect(Application $app)
// products
$controllers->match('/products/', '\Eccube\Controller\Admin\Product\ProductController::index')->bind('admin_product');
$controllers->match('/products/product.php', '\Eccube\Controller\Admin\Product\ProductController::edit')->bind('admin_product_product');
$controllers->match('/products/product/class/{product_id}', '\Eccube\Controller\Admin\Product\ProductClassController::index')
->assert('product_id', '\d+') // todo 変数名調整
->bind('admin_product_product_class');

// category
$controllers->match('/category/', '\Eccube\Controller\Admin\Product\CategoryController::index')->bind('admin_category');
Expand Down Expand Up @@ -270,7 +273,7 @@ public function connect(Application $app)
->assert('classCategoryId', '\d+')
->bind('admin_class_category_delete');

$controllers->match('/products/product_class.php', '\\Eccube\\Page\\Admin\\Products\\ProductClass')->bind('admin_product_product_class');
//$controllers->match('/products/product_class.php', '\\Eccube\\Page\\Admin\\Products\\ProductClass')->bind('admin_product_product_class');
$controllers->match('/products/product_rank.php', '\\Eccube\\Page\\Admin\\Products\\ProductRank')->bind('admin_product_product_rank');
$controllers->match('/products/product_select.php', '\\Eccube\\Page\\Admin\\Products\\ProductSelect')->bind('admin_product_product_select');
$controllers->match('/products/upload_csv.php', '\\Eccube\\Page\\Admin\\Products\\UploadCSV')->bind('admin_product_upload_csv');
Expand Down
10 changes: 10 additions & 0 deletions src/Eccube/Form/Type/Admin/ProductClassType.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'mapped' => false,
))
->add('down_real_filename', 'hidden')
->add('class_category1', null, array(
'required' => false,
'read_only' => true,
'disabled' => true,
))
->add('class_category2', null, array(
'required' => false,
'read_only' => true,
'disabled' => true,
))
;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Eccube/Resource/locale/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ admin.category.save.complete: カテゴリを保存しました。
admin.category.save.error: カテゴリを保存できませんでした。
admin.category.delete.complete: カテゴリを削除しました。
admin.category.delete.error: カテゴリを削除できませんでした。

admin.product.product_class.save.complete: 商品規格を登録しました。
Loading

0 comments on commit 0ac6ecc

Please sign in to comment.