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

フロント側での商品情報表示を制御する拡張機構 #4995

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/config/eccube/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ services:
$shoppingPurchaseFlow: '@eccube.purchase.flow.shopping'
$orderPurchaseFlow: '@eccube.purchase.flow.order'
$_orderStateMachine: '@state_machine.order'
$productVisibilities: '@eccube.product.visibilities'


# makes classes in src/ available to be used as services
Expand Down Expand Up @@ -180,3 +181,6 @@ services:
Eccube\Session\Storage\Handler\SameSiteNoneCompatSessionHandler:
arguments:
- '@native_file_session_handler'

eccube.product.visibilities:
class: ArrayObject
33 changes: 15 additions & 18 deletions src/Eccube/Controller/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

namespace Eccube\Controller;

use ArrayObject;
use Eccube\Entity\BaseInfo;
use Eccube\Entity\Master\ProductStatus;
use Eccube\Entity\Product;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
Expand All @@ -27,6 +27,7 @@
use Eccube\Repository\Master\ProductListMaxRepository;
use Eccube\Repository\ProductRepository;
use Eccube\Service\CartService;
use Eccube\Service\Product\ProductVisibility;
use Eccube\Service\PurchaseFlow\PurchaseContext;
use Eccube\Service\PurchaseFlow\PurchaseFlow;
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination;
Expand Down Expand Up @@ -76,6 +77,11 @@ class ProductController extends AbstractController
*/
protected $productListMaxRepository;

/**
* @var ArrayObject
*/
protected $productVisibilities;

private $title = '';

/**
Expand All @@ -88,6 +94,7 @@ class ProductController extends AbstractController
* @param BaseInfoRepository $baseInfoRepository
* @param AuthenticationUtils $helper
* @param ProductListMaxRepository $productListMaxRepository
* @param ArrayObject $productVisibilities
*/
public function __construct(
PurchaseFlow $cartPurchaseFlow,
Expand All @@ -96,7 +103,8 @@ public function __construct(
ProductRepository $productRepository,
BaseInfoRepository $baseInfoRepository,
AuthenticationUtils $helper,
ProductListMaxRepository $productListMaxRepository
ProductListMaxRepository $productListMaxRepository,
ArrayObject $productVisibilities
) {
$this->purchaseFlow = $cartPurchaseFlow;
$this->customerFavoriteProductRepository = $customerFavoriteProductRepository;
Expand All @@ -105,6 +113,7 @@ public function __construct(
$this->BaseInfo = $baseInfoRepository->get();
$this->helper = $helper;
$this->productListMaxRepository = $productListMaxRepository;
$this->productVisibilities = $productVisibilities;
}

/**
Expand Down Expand Up @@ -509,22 +518,10 @@ protected function getPageTitle($searchData)
*/
protected function checkVisibility(Product $Product)
{
$is_admin = $this->session->has('_security_admin');

// 管理ユーザの場合はステータスやオプションにかかわらず閲覧可能.
if (!$is_admin) {
// 在庫なし商品の非表示オプションが有効な場合.
// if ($this->BaseInfo->isOptionNostockHidden()) {
// if (!$Product->getStockFind()) {
// return false;
// }
// }
// 公開ステータスでない商品は表示しない.
if ($Product->getStatus()->getId() !== ProductStatus::DISPLAY_SHOW) {
return false;
}
}
$invisible = array_filter($this->productVisibilities->getArrayCopy(), function (ProductVisibility $productVisibility) use ($Product) {
return $productVisibility->checkVisibility($Product) === false;
});

return true;
return $invisible == null;
}
}
32 changes: 32 additions & 0 deletions src/Eccube/DependencyInjection/Compiler/ProductVisibilityPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Eccube\DependencyInjection\Compiler;


use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

class ProductVisibilityPass implements CompilerPassInterface
{
const TAG = 'eccube.product.visibility';

public function process(ContainerBuilder $container)
{
$visibilitiesDef = $container->getDefinition('eccube.product.visibilities');
$ids = $container->findTaggedServiceIds(self::TAG);
foreach ($ids as $id => $tag) {
$visibilitiesDef->addMethodCall('append', [new Reference($id)]);
}
}
}
46 changes: 46 additions & 0 deletions src/Eccube/Doctrine/Query/WhereClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,52 @@ public static function lte($x, $y, $param)
return self::newWhereClause(self::expr()->lte($x, $y), $y, $param);
}

/**
* AND演算子のファクトリメソッド。
* Example:
* WhereClause::and(
* WhereClause::eq('status', ':status', '1'),
* WhereClause::eq('price', ':price', 1000),
* )
* @param WhereClause ...$list
* @return WhereClause
*/
public static function and(WhereClause ...$list)
{
$expr = array_map(function(WhereClause $wc) {
return $wc->expr;
}, $list);

$params = array_reduce($list, function($result, WhereClause $wc) {
return $wc->params ? array_merge($result, $wc->params) : $result;
}, []);

return new WhereClause(self::expr()->andX(...$expr), $params);
}

/**
* OR演算子のファクトリメソッド。
* Example:
* WhereClause::or(
* WhereClause::eq('status', ':status1', '1'),
* WhereClause::eq('status', ':status2', '2'),
* )
* @param WhereClause ...$list
* @return WhereClause
*/
public static function or(WhereClause ...$list)
{
$expr = array_map(function(WhereClause $wc) {
return $wc->expr;
}, $list);

$params = array_reduce($list, function($result, WhereClause $wc) {
return $wc->params ? array_merge($result, $wc->params) : $result;
}, []);

return new WhereClause(self::expr()->orX(...$expr), $params);
}

/**
* @return Expr
*/
Expand Down
60 changes: 54 additions & 6 deletions src/Eccube/Entity/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Eccube\Entity;

use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;

Expand Down Expand Up @@ -495,14 +496,14 @@ public function hasProductClass()
private $free_area;

/**
* @var \DateTime
* @var DateTime
*
* @ORM\Column(name="create_date", type="datetimetz")
*/
private $create_date;

/**
* @var \DateTime
* @var DateTime
*
* @ORM\Column(name="update_date", type="datetimetz")
*/
Expand Down Expand Up @@ -566,6 +567,21 @@ public function hasProductClass()
*/
private $Status;


/**
* @var DateTime
*
* @ORM\Column(name="publish_start", type="datetimetz", nullable=true)
*/
private $publishStart;

/**
* @var DateTime
*
* @ORM\Column(name="publish_end", type="datetimetz", nullable=true)
*/
private $publishEnd;

/**
* Constructor
*/
Expand Down Expand Up @@ -780,7 +796,7 @@ public function getFreeArea()
/**
* Set createDate.
*
* @param \DateTime $createDate
* @param DateTime $createDate
*
* @return Product
*/
Expand All @@ -794,7 +810,7 @@ public function setCreateDate($createDate)
/**
* Get createDate.
*
* @return \DateTime
* @return DateTime
*/
public function getCreateDate()
{
Expand All @@ -804,7 +820,7 @@ public function getCreateDate()
/**
* Set updateDate.
*
* @param \DateTime $updateDate
* @param DateTime $updateDate
*
* @return Product
*/
Expand All @@ -818,7 +834,7 @@ public function setUpdateDate($updateDate)
/**
* Get updateDate.
*
* @return \DateTime
* @return DateTime
*/
public function getUpdateDate()
{
Expand Down Expand Up @@ -1073,5 +1089,37 @@ public function getStatus()
{
return $this->Status;
}

/**
* @return DateTime
*/
public function getPublishStart()
{
return $this->publishStart;
}

/**
* @param DateTime $publishStart
*/
public function setPublishStart(DateTime $publishStart)
{
$this->publishStart = $publishStart;
}

/**
* @return DateTime
*/
public function getPublishEnd()
{
return $this->publishEnd;
}

/**
* @param DateTime $publishEnd
*/
public function setPublishEnd(DateTime $publishEnd)
{
$this->publishEnd = $publishEnd;
}
}
}
6 changes: 6 additions & 0 deletions src/Eccube/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Eccube\DependencyInjection\Compiler\NavCompilerPass;
use Eccube\DependencyInjection\Compiler\PaymentMethodPass;
use Eccube\DependencyInjection\Compiler\PluginPass;
use Eccube\DependencyInjection\Compiler\ProductVisibilityPass;
use Eccube\DependencyInjection\Compiler\PurchaseFlowPass;
use Eccube\DependencyInjection\Compiler\QueryCustomizerPass;
use Eccube\DependencyInjection\Compiler\TwigBlockPass;
Expand All @@ -31,6 +32,7 @@
use Eccube\Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Eccube\Doctrine\Query\QueryCustomizer;
use Eccube\Service\Payment\PaymentMethodInterface;
use Eccube\Service\Product\ProductVisibility;
use Eccube\Service\PurchaseFlow\DiscountProcessor;
use Eccube\Service\PurchaseFlow\ItemHolderPostValidator;
use Eccube\Service\PurchaseFlow\ItemHolderPreprocessor;
Expand Down Expand Up @@ -256,6 +258,10 @@ protected function build(ContainerBuilder $container)
$container->registerForAutoconfiguration(PurchaseProcessor::class)
->addTag(PurchaseFlowPass::PURCHASE_PROCESSOR_TAG);
$container->addCompilerPass(new PurchaseFlowPass());

$container->registerForAutoconfiguration(ProductVisibility::class)
->addTag(ProductVisibilityPass::TAG);
$container->addCompilerPass(new ProductVisibilityPass());
}

protected function addEntityExtensionPass(ContainerBuilder $container)
Expand Down
3 changes: 1 addition & 2 deletions src/Eccube/Repository/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ public function findProductsWithSortedClassCategories(array $ids, $indexBy = nul
*/
public function getQueryBuilderBySearchData($searchData)
{
$qb = $this->createQueryBuilder('p')
->andWhere('p.Status = 1');
$qb = $this->createQueryBuilder('p');

// category
$categoryJoin = false;
Expand Down
33 changes: 33 additions & 0 deletions src/Eccube/Service/Product/ProductVisibility.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Eccube\Service\Product;


use Eccube\Doctrine\Query\WhereCustomizer;
use Eccube\Entity\Product;
use Eccube\Repository\QueryKey;

abstract class ProductVisibility extends WhereCustomizer
{
/**
* @param Product $Product
* @return boolean
*/
public abstract function checkVisibility(Product $Product);

public function getQueryKey()
{
return QueryKey::PRODUCT_SEARCH;
}

}
Loading