LayoutProcessor::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 3
dl 0
loc 8
rs 10
1
<?php
2
/**
3
 * Copyright (c) 2020. Volodymyr Hryvinskyi.  All rights reserved.
4
 * @author: <mailto:[email protected]>
5
 * @github: <https://github.com/hryvinskyi>
6
 */
7
8
declare(strict_types=1);
9
10
namespace Hryvinskyi\InvisibleCaptcha\Block\Checkout;
11
12
use Hryvinskyi\InvisibleCaptcha\Helper\Config\Frontend;
13
use Hryvinskyi\InvisibleCaptcha\Helper\Config\General;
14
use Hryvinskyi\InvisibleCaptcha\Model\LayoutSettings;
15
use Magento\Checkout\Block\Checkout\LayoutProcessorInterface;
16
17
/**
18
 * Class LayoutProcessor
19
 */
20
class LayoutProcessor implements LayoutProcessorInterface
21
{
22
    /**
23
     * @var LayoutSettings
24
     */
25
    private $layoutSettings;
26
27
    /**
28
     * @var General
29
     */
30
    private $generalConfig;
31
32
    /**
33
     * @var Frontend
34
     */
35
    private $frontendConfig;
36
37
    /**
38
     * AuthenticationPopupPlugin constructor.
39
     *
40
     * @param LayoutSettings $layoutSettings
41
     * @param General $generalConfig
42
     * @param Frontend $frontendConfig
43
     */
44
    public function __construct(
45
        LayoutSettings $layoutSettings,
46
        General $generalConfig,
47
        Frontend $frontendConfig
48
    ) {
49
        $this->layoutSettings = $layoutSettings;
50
        $this->generalConfig = $generalConfig;
51
        $this->frontendConfig = $frontendConfig;
52
    }
53
54
    /**
55
     * @inheritDoc
56
     */
57
    public function process($layout)
58
    {
59
        $layout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
60
        ['shippingAddress']['children']['customer-email']['children']['invisible-captcha']['config']
61
            = $this->layoutSettings->getCaptchaSettings();
62
63
        $layout['components']['checkout']['children']['authentication']['children']['invisible-captcha']['config']
64
            = $this->layoutSettings->getCaptchaSettings();
65
66
        if (!$this->generalConfig->hasEnabled()
67
            || !$this->frontendConfig->hasEnabled()
68
            || !$this->frontendConfig->hasEnabledCustomerLogin()
69
        ) {
70
            if (isset($layout['components']['checkout']['children']['authentication']['children']['invisible-captcha'])) {
71
                unset($layout['components']['checkout']['children']['authentication']['children']['invisible-captcha']);
72
            }
73
74
            if (isset($layout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
75
                ['shippingAddress']['children']['customer-email']['children']['invisible-captcha'])) {
76
                unset($layout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
77
                    ['shippingAddress']['children']['customer-email']['children']['invisible-captcha']);
78
            }
79
        }
80
81
        return $layout;
82
    }
83
}