Skip to content

Commit 40cf1a7

Browse files
authored
Merge pull request #39 from EC-CUBE/feature/1.0.0
1.0.0対応
2 parents fcd6591 + dfc38ea commit 40cf1a7

39 files changed

+2596
-868
lines changed

.coveralls.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# for php-coveralls
2+
#src_dir: src
3+
coverage_clover: coverage.clover
4+
json_path: coveralls-upload.json

.travis.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
language: php
2+
3+
sudo: false
4+
5+
cache:
6+
directories:
7+
- $HOME/.composer/cache
8+
9+
php:
10+
- 5.3
11+
- 5.4
12+
- 5.5
13+
- 5.6
14+
- 7.0
15+
16+
env:
17+
# plugin code
18+
global:
19+
PLUGIN_CODE=RelatedProduct
20+
matrix:
21+
# ec-cube master
22+
- ECCUBE_VERSION=master DB=mysql USER=root DBNAME=myapp_test DBPASS=' ' DBUSER=root
23+
- ECCUBE_VERSION=master DB=pgsql USER=postgres DBNAME=myapp_test DBPASS=password DBUSER=postgres
24+
- ECCUBE_VERSION=master DB=sqlite
25+
# ec-cube 3.0.9
26+
- ECCUBE_VERSION=3.0.9 DB=mysql USER=root DBNAME=myapp_test DBPASS=' ' DBUSER=root
27+
- ECCUBE_VERSION=3.0.9 DB=pgsql USER=postgres DBNAME=myapp_test DBPASS=password DBUSER=postgres
28+
# ec-cube 3.0.10
29+
- ECCUBE_VERSION=3.0.10 DB=mysql USER=root DBNAME=myapp_test DBPASS=' ' DBUSER=root
30+
- ECCUBE_VERSION=3.0.10 DB=pgsql USER=postgres DBNAME=myapp_test DBPASS=password DBUSER=postgres
31+
# ec-cube 3.0.11
32+
- ECCUBE_VERSION=3.0.11 DB=mysql USER=root DBNAME=myapp_test DBPASS=' ' DBUSER=root
33+
- ECCUBE_VERSION=3.0.11 DB=pgsql USER=postgres DBNAME=myapp_test DBPASS=password DBUSER=postgres
34+
matrix:
35+
fast_finish: true
36+
include:
37+
exclude:
38+
allow_failures:
39+
- php: 5.3
40+
env: ECCUBE_VERSION=master DB=sqlite
41+
- php: 5.4
42+
env: ECCUBE_VERSION=master DB=sqlite
43+
- php: 5.5
44+
env: ECCUBE_VERSION=master DB=sqlite
45+
- php: 5.6
46+
env: ECCUBE_VERSION=master DB=sqlite
47+
- php: 7.0
48+
env: ECCUBE_VERSION=master DB=sqlite
49+
- php: 7.0
50+
env: ECCUBE_VERSION=3.0.9 DB=mysql USER=root DBNAME=myapp_test DBPASS=' ' DBUSER=root
51+
- php: 7.0
52+
env: ECCUBE_VERSION=3.0.9 DB=pgsql USER=postgres DBNAME=myapp_test DBPASS=password DBUSER=postgres
53+
- php: 7.0
54+
env: ECCUBE_VERSION=3.0.10 DB=mysql USER=root DBNAME=myapp_test DBPASS=' ' DBUSER=root
55+
- php: 7.0
56+
env: ECCUBE_VERSION=3.0.10 DB=pgsql USER=postgres DBNAME=myapp_test DBPASS=password DBUSER=postgres
57+
58+
install:
59+
- gem install mime-types -v 2.99.1
60+
- gem install mailcatcher
61+
62+
before_script:
63+
# archive plugin
64+
- tar cvzf ${HOME}/${PLUGIN_CODE}.tar.gz ./*
65+
# clone ec-cube
66+
- git clone https://github.com/EC-CUBE/ec-cube.git
67+
- cd ec-cube
68+
# checkout version
69+
- sh -c "if [ ! '${ECCUBE_VERSION}' = 'master' ]; then git checkout -b ${ECCUBE_VERSION} refs/tags/${ECCUBE_VERSION}; fi"
70+
# update composer
71+
- composer selfupdate
72+
- composer install --dev --no-interaction -o
73+
# install ec-cube
74+
- sh -c "if [ '$DB' = 'mysql' ]; then sh ./eccube_install.sh mysql none; fi"
75+
- sh -c "if [ '$DB' = 'pgsql' ]; then sh ./eccube_install.sh pgsql none; fi"
76+
- sh -c "if [ '$DB' = 'sqlite' ]; then sh ./eccube_install.sh sqlite3 none; fi"
77+
# install plugin
78+
- php app/console plugin:develop install --path=${HOME}/${PLUGIN_CODE}.tar.gz
79+
# enable plugin
80+
- php app/console plugin:develop enable --code=${PLUGIN_CODE}
81+
# mail catcher
82+
- mailcatcher
83+
84+
script:
85+
# exec phpunit on ec-cube
86+
- phpunit app/Plugin/${PLUGIN_CODE}/Tests
87+
- if [[ $TRAVIS_PHP_VERSION =~ ^[7] ]]; then ./vendor/bin/phpunit -c app/Plugin/${PLUGIN_CODE}/phpunit.xml.dist --coverage-clover=coverage.clover ; fi
88+
89+
after_script:
90+
# disable plugin
91+
- php app/console plugin:develop disable --code=${PLUGIN_CODE}
92+
# uninstall plugin
93+
- php app/console plugin:develop uninstall --code=${PLUGIN_CODE}
94+
# re install plugin
95+
- php app/console plugin:develop install --code=${PLUGIN_CODE}
96+
# re enable plugin
97+
- php app/console plugin:develop enable --code=${PLUGIN_CODE}
98+
99+
after_success:
100+
# for coveralls
101+
- if [[ $TRAVIS_PHP_VERSION =~ ^[7] ]]; then php vendor/bin/coveralls -v -x coverage.clover ; fi
Lines changed: 76 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,101 @@
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

1211
namespace Plugin\RelatedProduct\Controller\Admin;
1312

1413
use Eccube\Application;
1514
use Symfony\Component\HttpFoundation\Request;
1615

16+
/**
17+
* Class RelatedProductController.
18+
*/
1719
class 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

Comments
 (0)