Checkout   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A getCurrentCheckoutMethod() 0 14 4
1
<?php
2
3
/**
4
 * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
16
 *
17
 * PHP version 5
18
 *
19
 * @category  Payone
20
 * @package   Payone_Magento2_Plugin
21
 * @author    FATCHIP GmbH <[email protected]>
22
 * @copyright 2003 - 2016 Payone GmbH
23
 * @license   <http://www.gnu.org/licenses/> GNU Lesser General Public License
24
 * @link      http://www.payone.de
25
 */
26
27
namespace Payone\Core\Helper;
28
29
use Magento\Quote\Model\Quote;
30
use Magento\Checkout\Model\Type\Onepage;
31
32
/**
33
 * Helper class for everything that has to do with the checkout
34
 */
35
class Checkout extends \Payone\Core\Helper\Base
36
{
37
    /**
38
     * Checkout session
39
     *
40
     * @var \Magento\Customer\Model\Session
41
     */
42
    protected $customerSession;
43
44
    /**
45
     * @var \Magento\Checkout\Helper\Data
46
     */
47
    protected $checkoutData;
48
49
    /**
50
     * Constructor
51
     *
52
     * @param \Magento\Framework\App\Helper\Context      $context
53
     * @param \Magento\Store\Model\StoreManagerInterface $storeManager
54
     * @param \Payone\Core\Helper\Shop                   $shopHelper
55
     * @param \Magento\Customer\Model\Session            $customerSession
56
     * @param \Magento\Checkout\Helper\Data              $checkoutData
57
     */
58
    public function __construct(
59
        \Magento\Framework\App\Helper\Context $context,
60
        \Magento\Store\Model\StoreManagerInterface $storeManager,
61
        \Payone\Core\Helper\Shop $shopHelper,
62
        \Magento\Customer\Model\Session $customerSession,
63
        \Magento\Checkout\Helper\Data $checkoutData
64
    ) {
65
        parent::__construct($context, $storeManager, $shopHelper);
66
        $this->customerSession = $customerSession;
67
        $this->checkoutData = $checkoutData;
68
    }
69
70
    /**
71
     * Get checkout method
72
     *
73
     * @param  Quote $oQuote
74
     * @return string
75
     */
76
    public function getCurrentCheckoutMethod(Quote $oQuote)
77
    {
78
        if ($this->customerSession->isLoggedIn()) {
79
            return Onepage::METHOD_CUSTOMER;
80
        }
81
        if (!$oQuote->getCheckoutMethod()) {
82
            if ($this->checkoutData->isAllowedGuestCheckout($oQuote)) {
83
                $oQuote->setCheckoutMethod(Onepage::METHOD_GUEST);
84
            } else {
85
                $oQuote->setCheckoutMethod(Onepage::METHOD_REGISTER);
86
            }
87
        }
88
        return $oQuote->getCheckoutMethod();
89
    }
90
}
91