11<?php
22/*
3- * This file is part of EC-CUBE
4- *
5- * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
6- * http://www.lockon.co.jp/
7- *
8- * For the full copyright and license information, please view the LICENSE
9- * file that was distributed with this source code.
10- */
3+ * This file is part of the Related Product plugin
4+ *
5+ * Copyright (C) 2016 LOCKON CO.,LTD. All Rights Reserved.
6+ *
7+ * For the full copyright and license information, please view the LICENSE
8+ * file that was distributed with this source code.
9+ */
1110
1211namespace Plugin \RelatedProduct \Controller \Admin ;
1312
1413use Eccube \Application ;
1514use Symfony \Component \HttpFoundation \Request ;
1615
16+ /**
17+ * Class RelatedProductController.
18+ */
1719class RelatedProductController
1820{
19- public function searchProduct (Application $ app , Request $ request )
21+ /**
22+ * search product modal.
23+ *
24+ * @param Application $app
25+ * @param Request $request
26+ * @param int $page_no
27+ *
28+ * @return \Symfony\Component\HttpFoundation\Response
29+ */
30+ public function searchProduct (Application $ app , Request $ request , $ page_no = null )
2031 {
21- if ($ request ->isXmlHttpRequest ()) {
32+ if (!$ request ->isXmlHttpRequest ()) {
33+ return null ;
34+ }
35+
36+ $ pageCount = $ app ['config ' ]['default_page_count ' ];
37+ $ session = $ app ['session ' ];
38+ if ('POST ' === $ request ->getMethod ()) {
39+ log_info ('get search data with parameters ' , array ('id ' => $ request ->get ('id ' ), 'category_id ' => $ request ->get ('category_id ' )));
40+ $ page_no = 1 ;
2241 $ searchData = array (
2342 'id ' => $ request ->get ('id ' ),
2443 );
2544 if ($ categoryId = $ request ->get ('category_id ' )) {
2645 $ Category = $ app ['eccube.repository.category ' ]->find ($ categoryId );
2746 $ searchData ['category_id ' ] = $ Category ;
2847 }
48+ $ session ->set ('eccube.plugin.related_product.product.search ' , $ searchData );
49+ $ session ->set ('eccube.plugin.related_product.product.search.page_no ' , $ page_no );
50+ } else {
51+ $ searchData = (array ) $ session ->get ('eccube.plugin.related_product.product.search ' );
52+ if (is_null ($ page_no )) {
53+ $ page_no = intval ($ session ->get ('eccube.plugin.related_product.product.search.page_no ' ));
54+ } else {
55+ $ session ->set ('eccube.plugin.related_product.product.search.page_no ' , $ page_no );
56+ }
57+ }
2958
30- /** @var $Products \Eccube\Entity\Product[] */
31- $ Products = $ app ['eccube.repository.product ' ]
32- ->getQueryBuilderBySearchDataForAdmin ($ searchData )
33- ->getQuery ()
34- ->getResult ();
59+ $ qb = $ app ['eccube.repository.product ' ]->getQueryBuilderBySearchDataForAdmin ($ searchData );
3560
36- // 表示されている商品は検索結果に含めない
37- $ productId = $ request ->get ('product_id ' );
38- $ ProductsData = array ();
39- $ count = count ($ Products );
40- $ i = 0 ;
41- for ($ i = 0 ; $ i < $ count ; $ i ++) {
42- $ Product = $ Products [$ i ];
43- if ($ Product ->getId () != $ productId ) {
44- $ ProductsData [] = $ Product ;
45- }
46- if ($ i >= 10 ) {
47- break ;
48- }
49- }
61+ /** @var \Knp\Component\Pager\Pagination\SlidingPagination $pagination */
62+ $ pagination = $ app ['paginator ' ]()->paginate (
63+ $ qb ,
64+ $ page_no ,
65+ $ pageCount ,
66+ array ('wrap-queries ' => true )
67+ );
5068
51- $ message = '' ;
52- if ($ count > $ i ) {
53- $ message = '検索結果の上限を超えています。検索条件を設定してください。 ' ;
54- }
69+ $ paths = array ();
70+ $ paths [] = $ app ['config ' ]['template_admin_realdir ' ];
71+ $ app ['twig.loader ' ]->addLoader (new \Twig_Loader_Filesystem ($ paths ));
5572
56- return $ app ->renderView (
57- 'RelatedProduct/Resource/template/Admin/modal_result.twig ' ,
58- array (
59- 'Products ' => $ ProductsData ,
60- 'message ' => $ message ,
61- )
62- );
73+ return $ app ->render ('RelatedProduct/Resource/template/admin/modal_result.twig ' , array (
74+ 'pagination ' => $ pagination ,
75+ ));
76+ }
6377
78+ /**
79+ * get product information.
80+ *
81+ * @param Application $app
82+ * @param Request $request
83+ *
84+ * @return \Symfony\Component\HttpFoundation\Response
85+ */
86+ public function getProduct (Application $ app , Request $ request )
87+ {
88+ if (!$ request ->isXmlHttpRequest ()) {
89+ return null ;
6490 }
91+
92+ $ productId = $ request ->get ('product_id ' );
93+ $ index = $ request ->get ('index ' );
94+ $ Product = $ app ['eccube.repository.product ' ]->find ($ productId );
95+
96+ return $ app ->render ('RelatedProduct/Resource/template/admin/product.twig ' , array (
97+ 'Product ' => $ Product ,
98+ 'index ' => $ index ,
99+ ));
65100 }
66- }
101+ }
0 commit comments