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

StatusVisibility   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A checkVisibility() 0 21 3
A createStatements() 0 6 1
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