Completed
Push — dev/product_visibility ( 1ee472 )
by Kiyotaka
06:23
created

StatusVisibility::checkVisibility()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 0
loc 21
rs 9.584
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.ec-cube.co.jp/
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Eccube\Service\Product;
14
15
16
use Eccube\Doctrine\Query\WhereClause;
17
use Eccube\Entity\Master\ProductStatus;
18
use Eccube\Entity\Product;
19
use Symfony\Component\HttpFoundation\Session\SessionInterface;
20
21
class StatusVisibility extends ProductVisibility
22
{
23
    /**
24
     * @var SessionInterface
25
     */
26
    private $session;
27
28
    public function __construct(SessionInterface $session)
29
    {
30
        $this->session = $session;
31
    }
32
33
    public function checkVisibility(Product $Product)
34
    {
35
        $is_admin = $this->session->has('_security_admin');
36
37
        // 管理ユーザの場合はステータスやオプションにかかわらず閲覧可能.
38
        if (!$is_admin) {
39
            // 在庫なし商品の非表示オプションが有効な場合.
40
            // if ($this->BaseInfo->isOptionNostockHidden()) {
41
            //     if (!$Product->getStockFind()) {
42
            //         return false;
43
            //     }
44
            // }
45
            // 公開ステータスでない商品は表示しない.
46
            if ($Product->getStatus()->getId() !== ProductStatus::DISPLAY_SHOW) {
47
                return false;
48
            }
49
        }
50
51
        return true;
52
53
    }
54
55
    protected function createStatements($params, $queryKey)
56
    {
57
        return [
58
            WhereClause::eq('p.Status', ':ProductStatus', ProductStatus::DISPLAY_SHOW)
59
        ];
60
    }
61
62
}
63