Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EC-CUBE 4.1 対応 #5

Merged
merged 3 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Packaging for EC-CUBE Plugin
on:
release:
types: [ published ]
jobs:
deploy:
name: Build
runs-on: ubuntu-18.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Packaging
working-directory: ../
run: |
rm -rf $GITHUB_WORKSPACE/doc
rm -rf $GITHUB_WORKSPACE/.github
find $GITHUB_WORKSPACE -name "dummy" -delete
find $GITHUB_WORKSPACE -name ".git*" -and ! -name ".gitkeep" -print0 | xargs -0 rm -rf
chmod -R o+w $GITHUB_WORKSPACE
cd $GITHUB_WORKSPACE
tar cvzf ../${{ github.event.repository.name }}-${{ github.event.release.tag_name }}.tar.gz ./*
- name: Upload binaries to release of TGZ
uses: svenstaro/upload-release-action@v1-release
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ runner.workspace }}/${{ github.event.repository.name }}-${{ github.event.release.tag_name }}.tar.gz
asset_name: ${{ github.event.repository.name }}-${{ github.event.release.tag_name }}.tar.gz
tag: ${{ github.ref }}
overwrite: true

5 changes: 3 additions & 2 deletions Amp4Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Plugin\Amp4;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Eccube\Common\EccubeConfig;
use Eccube\Entity\Layout;
Expand Down Expand Up @@ -119,7 +120,7 @@ public function __construct(DeviceTypeRepository $deviceTypeRepository,
LayoutRepository $layoutRepository,
ConfigRepository $configRepository,
PageRepository $pageRepository,
EntityManager $entityManager,
EntityManagerInterface $entityManager,
EccubeConfig $eccubeConfig,
Environment $twig,
Filesystem $filesystem,
Expand Down Expand Up @@ -921,4 +922,4 @@ public function adminContentBlockDeleteComplete(EventArgs $eventArgs)
}
}
}
}
}
23 changes: 14 additions & 9 deletions Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
use Eccube\Twig\Extension\IntlExtension;
use Eccube\Util\StringUtil;
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination;
use Knp\Component\Pager\Paginator;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Component\Asset\Packages;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
Expand All @@ -39,9 +40,13 @@ class ApiController extends AbstractController
*/
protected $BaseInfo;

public function __construct(BaseInfoRepository $baseInfoRepository)
/** @var Packages */
protected $assetPackages;

public function __construct(BaseInfoRepository $baseInfoRepository, Packages $assetPackages)
{
$this->BaseInfo = $baseInfoRepository->get();
$this->assetPackages = $assetPackages;
}

/**
Expand Down Expand Up @@ -141,14 +146,14 @@ public function newsJson(Request $request, NewsRepository $newsRepository, IntlE
* @Route("/amp-api/products/list/class_categories.json", name="amp_api_products_list_class_categories")
*
* @param Request $request
* @param Paginator $paginator
* @param PaginatorInterface $paginator
* @param ProductRepository $productRepository
* @param ProductListMaxRepository $productListMaxRepository
* @param EccubeExtension $eccubeExtension
* @param CsrfTokenManagerInterface $tokenManager
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function productsClassCategories(Request $request, Paginator $paginator,
public function productsClassCategories(Request $request, PaginatorInterface $paginator,
ProductRepository $productRepository,
ProductListMaxRepository $productListMaxRepository,
EccubeExtension $eccubeExtension,
Expand Down Expand Up @@ -219,7 +224,7 @@ public function productsClassCategories(Request $request, Paginator $paginator,
'product_url' => $this->generateUrl('product_detail', ['id' => $ProductsAndClassCategorie->getId()], UrlGeneratorInterface::ABSOLUTE_URL),
'add_card_url' => $this->generateUrl('product_add_cart', ['id' => $ProductsAndClassCategorie->getId(), 'type' => 'amp'], UrlGeneratorInterface::ABSOLUTE_URL),
'product_name' => $ProductsAndClassCategorie->getName(),
'product_image' => $request->getSchemeAndHttpHost() . $this->get('assets.packages')->getUrl($eccubeExtension->getNoImageProduct($ProductsAndClassCategorie->getMainListImage()), 'save_image'),
'product_image' => $request->getSchemeAndHttpHost() . $this->assetPackages->getUrl($eccubeExtension->getNoImageProduct($ProductsAndClassCategorie->getMainListImage()), 'save_image'),
];

if ($ProductsAndClassCategorie->hasProductClass()) {
Expand Down Expand Up @@ -249,13 +254,13 @@ public function productsClassCategories(Request $request, Paginator $paginator,
* @Route("/amp-api/products/list.json", name="amp_api_products_list")
*
* @param Request $request
* @param Paginator $paginator
* @param PaginatorInterface $paginator
* @param ProductRepository $productRepository
* @param ProductListMaxRepository $productListMaxRepository
* @param ProductListOrderByRepository $productListOrderByRepository
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function productList(Request $request, Paginator $paginator,
public function productList(Request $request, PaginatorInterface $paginator,
ProductRepository $productRepository,
ProductListMaxRepository $productListMaxRepository,
ProductListOrderByRepository $productListOrderByRepository)
Expand Down Expand Up @@ -626,7 +631,7 @@ public function cardListJson(Request $request, CartService $cartService, EccubeE
$reData['items'][0]['carts'][0]['items'][] = [
'product_name' => $product->getName(),
'product_image' => $request->getSchemeAndHttpHost() .
$this->get('assets.packages')->getUrl($eccubeExtension->getNoImageProduct($product->getMainListImage()), 'save_image'),
$this->assetPackages->getUrl($eccubeExtension->getNoImageProduct($product->getMainListImage()), 'save_image'),
'product_class_name' => $productClassName,
'product_price' => sprintf("¥%s", number_format($item->getPriceIncTax())),
'product_quantity' => number_format($item->getQuantity()),
Expand Down Expand Up @@ -718,4 +723,4 @@ private function checkVisibility(Product $Product)
return true;
}

}
}
3 changes: 2 additions & 1 deletion Controller/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Eccube\Controller\AbstractController;
use Eccube\Entity\Product;
use Symfony\Component\HttpFoundation\Request;
use Knp\Component\Pager\PaginatorInterface;
use Knp\Component\Pager\Paginator;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
Expand All @@ -37,7 +38,7 @@ class ProductController extends \Eccube\Controller\ProductController
* @param Paginator $paginator
* @return array|void
*/
public function index(Request $request, Paginator $paginator)
public function index(Request $request, PaginatorInterface $paginator)
{
$reData = parent::index($request, $paginator);

Expand Down
24 changes: 10 additions & 14 deletions PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,15 @@
namespace Plugin\Amp4;

use Doctrine\ORM\EntityManager;
use Eccube\Entity\Block;
use Eccube\Entity\BlockPosition;
use Eccube\Entity\Layout;
use Eccube\Entity\Master\DeviceType;
use Eccube\Entity\Page;
use Eccube\Entity\PageLayout;
use Eccube\Plugin\AbstractPluginManager;
use Eccube\Repository\BlockRepository;
use Eccube\Repository\LayoutRepository;
use Eccube\Repository\Master\DeviceTypeRepository;
use Eccube\Repository\PageLayoutRepository;
use Eccube\Repository\PageRepository;
use Plugin\Amp4\Entity\Config;
use Plugin\Amp4\Entity\Master\DeviceTypeTrait;
use Plugin\Amp4\Repository\ConfigRepository;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
Expand All @@ -48,9 +44,9 @@ public function enable(array $meta, ContainerInterface $container)
$entityManager = $container->get('doctrine.orm.entity_manager');

/** @var \Eccube\Repository\Master\DeviceTypeRepository $deviceTypeRepository */
$deviceTypeRepository = $container->get(DeviceTypeRepository::class);
$deviceTypeRepository = $entityManager->getRepository(DeviceType::class);
/** @var \Eccube\Repository\BlockRepository $blockRepository */
$blockRepository = $container->get(BlockRepository::class);
$blockRepository = $entityManager->getRepository(Block::class);

$ampDevice = $deviceTypeRepository->find(DeviceTypeTrait::$DEVICE_TYPE_AMP);
if (!$ampDevice) {
Expand Down Expand Up @@ -123,17 +119,17 @@ public function enable(array $meta, ContainerInterface $container)
}

/** @var $Config \Plugin\Amp4\Entity\Config */
$Config = $container->get(ConfigRepository::class)->get();
$Config = $entityManager->getRepository(Config::class)->get();
$Config->setAmpHeaderCss(file_get_contents(__DIR__ . '/Resource/amp_css/header.css'));
$Config->setOptimize(false);
$Config->setCanonical(false);
$Config->setAmpTwigApiUrl("");

$entityManager->persist($Config);

$ampPages = $container->get(PageRepository::class)->findBy(['url' => ['homepage', 'product_list', 'product_detail']]);
$ampPages = $entityManager->getRepository(Page::class)->findBy(['url' => ['homepage', 'product_list', 'product_detail']]);

$ampPageLayout = $container->get(PageLayoutRepository::class)->findOneBy([], ['sort_no' => 'DESC']);
$ampPageLayout = $entityManager->getRepository(PageLayout::class)->findOneBy([], ['sort_no' => 'DESC']);
$sortNo = $ampPageLayout ? $ampPageLayout->getSortNo() + 1 : 1;

/** @var $ampPage Page */
Expand Down Expand Up @@ -183,12 +179,12 @@ public function uninstall(array $meta, ContainerInterface $container)
{
/** @var $entityManager EntityManager */
$entityManager = $container->get('doctrine.orm.entity_manager');
$ampDevice = $container->get(DeviceTypeRepository::class)->find(DeviceTypeTrait::$DEVICE_TYPE_AMP);
$ampDevice = $entityManager->getRepository(DeviceType::class)->find(DeviceTypeTrait::$DEVICE_TYPE_AMP);

if ($ampDevice) {

$ampLayouts = $container->get(LayoutRepository::class)->findBy(['DeviceType' => $ampDevice]);
$ampPageLayouts = $container->get(PageLayoutRepository::class)->findBy(['Layout' => $ampLayouts]);
$ampLayouts = $entityManager->getRepository(Layout::class)->findBy(['DeviceType' => $ampDevice]);
$ampPageLayouts = $entityManager->getRepository(PageLayout::class)->findBy(['Layout' => $ampLayouts]);

/** @var $ampPageLayout PageLayout */
foreach ($ampPageLayouts as $ampPageLayout) {
Expand Down
19 changes: 12 additions & 7 deletions Repository/ConfigRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Eccube\Repository\BaseInfoRepository;
use Plugin\Amp4\Entity\Config;
use Symfony\Bridge\Doctrine\RegistryInterface;
use Symfony\Component\Asset\Packages;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

Expand All @@ -29,26 +30,30 @@ class ConfigRepository extends AbstractRepository
protected $config;

/**
* @var \Eccube\Entity\BaseInfo
* @var BaseInfoRepository;
*/
protected $baseInfo;
protected $baseInfoRepository;

/**
* @var ContainerInterface
*/
protected $container;

/** @var Packages */
protected $assetPackages;

/**
* ConfigRepository constructor.
* @param RegistryInterface $registry
* @param BaseInfoRepository $baseInfoRepository
* @param ContainerInterface $container
* @throws \Exception
*/
public function __construct(RegistryInterface $registry, BaseInfoRepository $baseInfoRepository, ContainerInterface $container)
public function __construct(RegistryInterface $registry, BaseInfoRepository $baseInfoRepository, ContainerInterface $container, Packages $assetPackages)
{
$this->baseInfo = $baseInfoRepository->get();
$this->baseInfoRepository = $baseInfoRepository;
$this->container = $container;
$this->assetPackages = $assetPackages;
parent::__construct($registry, Config::class);
}

Expand Down Expand Up @@ -77,11 +82,11 @@ public function get($id = 1)
$start_url .= "amp/";


$assets = $this->container->get('assets.packages');
$assets = $this->assetPackages;

$reData = [
'name' => $this->baseInfo->getShopName(),
'short_name' => $this->baseInfo->getShopName(),
'name' => $this->baseInfoRepository->get()->getShopName(),
'short_name' => $this->baseInfoRepository->get()->getShopName(),
'theme_color' => '#ffffff',
'background_color' => '#ffffff',
'display' => 'standalone',
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "ec-cube/Amp4",
"version": "0.0.0",
"name": "ec-cube/amp4",
"version": "1.0.0",
"description": "AMP",
"type": "eccube-plugin",
"require": {
"ec-cube/plugin-installer": "~0.0.3"
"ec-cube/plugin-installer": "~0.0.6 || ^2.0"
},
"extra": {
"code": "Amp4"
}
}
}