Skip to content

Commit

Permalink
Merge pull request #62 from EC-CUBE/improve-40
Browse files Browse the repository at this point in the history
EC-CUBE4.0対応
  • Loading branch information
okazy authored Oct 2, 2018
2 parents f4ad6ae + 22a94ca commit 65a43fe
Show file tree
Hide file tree
Showing 37 changed files with 897 additions and 2,121 deletions.
165 changes: 77 additions & 88 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,103 +1,92 @@
language: php

sudo: required
dist: trusty
group: deprecated-2017Q4

cache:
directories:
- $HOME/.composer/cache
- vendor
- $HOME/.composer/cache
- bin/.phpunit

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2

env:
# plugin code
global:
PLUGIN_CODE=RelatedProduct
matrix:
# ec-cube master
- ECCUBE_VERSION=master DB=mysql USER=root DBNAME=myapp_test DBPASS=' ' DBUSER=root
- ECCUBE_VERSION=master DB=pgsql USER=postgres DBNAME=myapp_test DBPASS=password DBUSER=postgres
- ECCUBE_VERSION=master DB=sqlite
# ec-cube 3.0.9
- ECCUBE_VERSION=3.0.9 DB=mysql USER=root DBNAME=myapp_test DBPASS=' ' DBUSER=root
- ECCUBE_VERSION=3.0.9 DB=pgsql USER=postgres DBNAME=myapp_test DBPASS=password DBUSER=postgres
# ec-cube 3.0.16
- ECCUBE_VERSION=3.0.16 DB=mysql USER=root DBNAME=myapp_test DBPASS=' ' DBUSER=root
- ECCUBE_VERSION=3.0.16 DB=pgsql USER=postgres DBNAME=myapp_test DBPASS=password DBUSER=postgres
matrix:
fail_fast: true
fast_finish: true
include:
- php: 5.3
dist: precise
- php: 7.1
env: ECCUBE_VERSION=master DB=pgsql USER=postgres DBNAME=myapp_test DBPASS=password DBUSER=postgres COVERAGE=true
exclude:
- php: 7.1
env: ECCUBE_VERSION=master DB=pgsql USER=postgres DBNAME=myapp_test DBPASS=password DBUSER=postgres
allow_failures:
- php: 5.4
env: ECCUBE_VERSION=master DB=sqlite
- php: 5.5
env: ECCUBE_VERSION=master DB=sqlite
- php: 5.6
env: ECCUBE_VERSION=master DB=sqlite
- php: 7.0
env: ECCUBE_VERSION=3.0.9 DB=mysql USER=root DBNAME=myapp_test DBPASS=' ' DBUSER=root
- php: 7.0
env: ECCUBE_VERSION=3.0.9 DB=pgsql USER=postgres DBNAME=myapp_test DBPASS=password DBUSER=postgres
- php: 7.1
env: ECCUBE_VERSION=3.0.9 DB=mysql USER=root DBNAME=myapp_test DBPASS=' ' DBUSER=root
- php: 7.1
env: ECCUBE_VERSION=3.0.9 DB=pgsql USER=postgres DBNAME=myapp_test DBPASS=password DBUSER=postgres
PLUGIN_CODE=RelatedProduct4
BRANCH=4.0

install:
- gem install mime-types -v 2.99.1
- gem install mailcatcher
before_install: &php_setup |
phpenv config-rm xdebug.ini || true
echo "opcache.enable_cli=1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
echo "apc.enable_cli=1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini

before_script:
# archive plugin
- tar cvzf ${HOME}/${PLUGIN_CODE}.tar.gz ./*
# clone ec-cube
- git clone https://github.com/EC-CUBE/ec-cube.git
- cd ec-cube
# checkout version
- sh -c "if [ ! '${ECCUBE_VERSION}' = 'master' ]; then git checkout -b ${ECCUBE_VERSION} refs/tags/${ECCUBE_VERSION}; fi"
# update composer
- composer selfupdate
- composer global require hirak/prestissimo
- composer install --dev --no-interaction -o
# install ec-cube
- sh -c "if [ '$DB' = 'mysql' ]; then sh ./eccube_install.sh mysql none; fi"
- sh -c "if [ '$DB' = 'pgsql' ]; then sh ./eccube_install.sh pgsql none; fi"
- sh -c "if [ '$DB' = 'sqlite' ]; then sh ./eccube_install.sh sqlite3 none; fi"
# install plugin
- php app/console plugin:develop install --path=${HOME}/${PLUGIN_CODE}.tar.gz
# enable plugin
- php app/console plugin:develop enable --code=${PLUGIN_CODE}
# mail catcher
- mailcatcher
install_eccube: &install_eccube |
tar cvzf ${HOME}/${PLUGIN_CODE}.tar.gz ./*
git clone https://github.com/EC-CUBE/ec-cube.git
cd ec-cube
git checkout -b ${BRANCH} origin/${BRANCH}
composer selfupdate
composer install --dev --no-interaction -o --apcu-autoloader

script:
# exec phpunit on ec-cube
- if [ !$COVERAGE ]; then ./vendor/bin/phpunit app/Plugin/${PLUGIN_CODE}/Tests; fi
- if [ $COVERAGE ]; then ./vendor/bin/phpunit -c app/Plugin/${PLUGIN_CODE}/phpunit.xml.dist --coverage-clover=coverage.clover; fi
eccube_setup: &eccube_setup |
echo "APP_ENV=test" > .env
bin/console doctrine:database:create
bin/console doctrine:schema:create
bin/console eccube:fixtures:load
bin/console eccube:plugin:install --path=${HOME}/${PLUGIN_CODE}.tar.gz -vvv
bin/console eccube:plugin:enable --code=${PLUGIN_CODE} -vvv

after_script:
# disable plugin
- php app/console plugin:develop disable --code=${PLUGIN_CODE}
# uninstall plugin
- php app/console plugin:develop uninstall --code=${PLUGIN_CODE}
# re install plugin
- php app/console plugin:develop install --code=${PLUGIN_CODE}
# re enable plugin
- php app/console plugin:develop enable --code=${PLUGIN_CODE}

after_success:
# for coveralls
- if [ $COVERAGE ]; then php vendor/bin/coveralls -v -x coverage.clover; fi
jobs:
fast_finish: true
include:
- stage: Inspection
php: 7.1
env: DATABASE_URL=postgres://postgres:password@localhost/cube4_dev DATABASE_SERVER_VERSION=9
install:
- *install_eccube
- *eccube_setup
script: vendor/bin/php-cs-fixer fix --config=.php_cs.dist --dry-run app/Plugin/${PLUGIN_CODE}
- &unit_test
stage: Unit Test
env: DATABASE_URL=mysql://root:@localhost/cube4_dev DATABASE_SERVER_VERSION=5
before_install:
- *php_setup
- gem install mime-types -v 2.99.1
- gem install mailcatcher
install:
- *install_eccube
- *eccube_setup
# mail catcher
- mailcatcher
script:
- ./bin/phpunit app/Plugin/${PLUGIN_CODE}/Tests
after_script:
# disable plugin
- bin/console eccube:plugin:disable --code=${PLUGIN_CODE}
# uninstall plugin
- bin/console eccube:plugin:uninstall --code=${PLUGIN_CODE}
# re install plugin
- bin/console eccube:plugin:install --code=${PLUGIN_CODE}
# re enable plugin
- bin/console eccube:plugin:enable --code=${PLUGIN_CODE}
- <<: *unit_test
env: DATABASE_URL=postgres://postgres:password@localhost/cube4_dev DATABASE_SERVER_VERSION=9
- &coverage
stage: Code Coverage
env: DATABASE_URL=postgres://postgres:password@localhost/cube4_dev DATABASE_SERVER_VERSION=9 COVERAGE=1
before_install:
- *php_setup
- gem install mime-types -v 2.99.1
- gem install mailcatcher
install:
- *install_eccube
- *eccube_setup
# mail catcher
- mailcatcher
script:
- ./bin/phpunit -c app/Plugin/${PLUGIN_CODE}/phpunit.xml.dist --coverage-clover=coverage.clover
after_success:
- php vendor/bin/php-coveralls -v -x coverage.clover
117 changes: 67 additions & 50 deletions Controller/Admin/RelatedProductController.php
Original file line number Diff line number Diff line change
@@ -1,46 +1,91 @@
<?php

/*
* This file is part of the Related Product plugin
* This file is part of EC-CUBE
*
* Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
*
* Copyright (C) 2016 LOCKON CO.,LTD. All Rights Reserved.
* http://www.lockon.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Plugin\RelatedProduct\Controller\Admin;
namespace Plugin\RelatedProduct4\Controller\Admin;

use Eccube\Application;
use Eccube\Controller\AbstractController;
use Eccube\Repository\CategoryRepository;
use Eccube\Repository\ProductRepository;
use Knp\Component\Pager\PaginatorInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;

/**
* Class RelatedProductController.
*/
class RelatedProductController
class RelatedProductController extends AbstractController
{
/**
* @var CategoryRepository
*/
protected $categoryRepository;

/**
* @var ProductRepository
*/
protected $productRepository;

/**
* @var PaginatorInterface
*/
protected $paginator;

/**
* RelatedProductController constructor.
*
* @param CategoryRepository $categoryRepository
* @param ProductRepository $productRepository
* @param PaginatorInterface $paginator
*/
public function __construct(
CategoryRepository $categoryRepository,
ProductRepository $productRepository,
PaginatorInterface $paginator
) {
$this->categoryRepository = $categoryRepository;
$this->productRepository = $productRepository;
$this->paginator = $paginator;
}

/**
* search product modal.
*
* @param Application $app
* @param Request $request
* @param int $page_no
* @param Request $request
* @param int $page_no
*
* @return \Symfony\Component\HttpFoundation\Response|array
*
* @return \Symfony\Component\HttpFoundation\Response
* @Route("/%eccube_admin_route%/related_product/search/product", name="admin_related_product_search")
* @Route("/%eccube_admin_route%/related_product/search/product/page/{page_no}", name="admin_related_product_search_product_page", requirements={"page_no":"\d+"})
*
* @Template("@RelatedProduct4/admin/modal_result.twig")
*/
public function searchProduct(Application $app, Request $request, $page_no = null)
public function searchProduct(Request $request, $page_no = null)
{
if (!$request->isXmlHttpRequest()) {
return null;
}

$pageCount = $app['config']['default_page_count'];
$session = $app['session'];
$pageCount = $this->eccubeConfig['eccube_default_page_count'];
$session = $this->session;
if ('POST' === $request->getMethod()) {
log_info('get search data with parameters ', array('id' => $request->get('id'), 'category_id' => $request->get('category_id')));
$page_no = 1;
$searchData = array(
log_info('get search data with parameters ', [
'id' => $request->get('id'),
);
'category_id' => $request->get('category_id'),
]);
$page_no = 1;
$searchData = ['id' => $request->get('id')];
if ($categoryId = $request->get('category_id')) {
$searchData['category_id'] = $categoryId;
}
Expand All @@ -56,49 +101,21 @@ public function searchProduct(Application $app, Request $request, $page_no = nul
}

if (!empty($searchData['category_id'])) {
$searchData['category_id'] = $app['eccube.repository.category']->find($searchData['category_id']);
$searchData['category_id'] = $this->categoryRepository->find($searchData['category_id']);
}

$qb = $app['eccube.repository.product']->getQueryBuilderBySearchDataForAdmin($searchData);
$qb = $this->productRepository->getQueryBuilderBySearchDataForAdmin($searchData);

/** @var \Knp\Component\Pager\Pagination\SlidingPagination $pagination */
$pagination = $app['paginator']()->paginate(
$pagination = $this->paginator->paginate(
$qb,
$page_no,
$pageCount,
array('wrap-queries' => true)
['wrap-queries' => true]
);

$paths = array();
$paths[] = $app['config']['template_admin_realdir'];
$app['twig.loader']->addLoader(new \Twig_Loader_Filesystem($paths));

return $app->render('RelatedProduct/Resource/template/admin/modal_result.twig', array(
return [
'pagination' => $pagination,
));
}

/**
* get product information.
*
* @param Application $app
* @param Request $request
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function getProduct(Application $app, Request $request)
{
if (!$request->isXmlHttpRequest()) {
return null;
}

$productId = $request->get('product_id');
$index = $request->get('index');
$Product = $app['eccube.repository.product']->find($productId);

return $app->render('RelatedProduct/Resource/template/admin/product.twig', array(
'Product' => $Product,
'index' => $index,
));
];
}
}
Loading

0 comments on commit 65a43fe

Please sign in to comment.