Skip to content

Commit 1e823a2

Browse files
authored
Merge pull request #358 from magento-troll/sprint19
[EPAM] Sprint 19
2 parents 38a8c8f + f9a3032 commit 1e823a2

File tree

20 files changed

+983
-140
lines changed

20 files changed

+983
-140
lines changed

app/code/Magento/Multishipping/Block/Checkout/Billing.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Billing extends \Magento\Payment\Block\Form\Container
3535
* @param \Magento\Checkout\Model\Session $checkoutSession
3636
* @param \Magento\Payment\Model\Method\SpecificationInterface $paymentSpecification
3737
* @param array $data
38+
* @param array $additionalChecks
3839
*/
3940
public function __construct(
4041
\Magento\Framework\View\Element\Template\Context $context,
@@ -43,12 +44,13 @@ public function __construct(
4344
\Magento\Multishipping\Model\Checkout\Type\Multishipping $multishipping,
4445
\Magento\Checkout\Model\Session $checkoutSession,
4546
\Magento\Payment\Model\Method\SpecificationInterface $paymentSpecification,
46-
array $data = []
47+
array $data = [],
48+
array $additionalChecks = []
4749
) {
4850
$this->_multishipping = $multishipping;
4951
$this->_checkoutSession = $checkoutSession;
5052
$this->paymentSpecification = $paymentSpecification;
51-
parent::__construct($context, $paymentHelper, $methodSpecificationFactory, $data);
53+
parent::__construct($context, $paymentHelper, $methodSpecificationFactory, $data, $additionalChecks);
5254
$this->_isScopePrivate = true;
5355
}
5456

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Payment\Api\Data;
7+
8+
/**
9+
* Payment method interface.
10+
*
11+
* @api
12+
*/
13+
interface PaymentMethodInterface
14+
{
15+
/**
16+
* Get code.
17+
*
18+
* @return string
19+
*/
20+
public function getCode();
21+
22+
/**
23+
* Get title.
24+
*
25+
* @return string
26+
*/
27+
public function getTitle();
28+
29+
/**
30+
* Get store id.
31+
*
32+
* @return int
33+
*/
34+
public function getStoreId();
35+
36+
/**
37+
* Get is active.
38+
*
39+
* @return bool
40+
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
41+
*/
42+
public function getIsActive();
43+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Payment\Api;
7+
8+
/**
9+
* Payment method list interface.
10+
*
11+
* @api
12+
*/
13+
interface PaymentMethodListInterface
14+
{
15+
/**
16+
* Get list of payment methods.
17+
*
18+
* @param int $storeId
19+
* @return \Magento\Payment\Api\Data\PaymentMethodInterface[]
20+
*/
21+
public function getList($storeId);
22+
23+
/**
24+
* Get list of active payment methods.
25+
*
26+
* @param int $storeId
27+
* @return \Magento\Payment\Api\Data\PaymentMethodInterface[]
28+
*/
29+
public function getActiveList($storeId);
30+
}

app/code/Magento/Payment/Block/Form/Container.php

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Payment\Block\Form;
77

8+
use Magento\Framework\App\ObjectManager;
89
use Magento\Payment\Model\Method\AbstractMethod;
910

1011
/**
@@ -24,20 +25,38 @@ class Container extends \Magento\Framework\View\Element\Template
2425
/** @var \Magento\Payment\Model\Checks\SpecificationFactory */
2526
protected $methodSpecificationFactory;
2627

28+
/**
29+
* @var \Magento\Payment\Api\PaymentMethodListInterface
30+
*/
31+
private $paymentMethodList;
32+
33+
/**
34+
* @var \Magento\Payment\Model\Method\InstanceFactory
35+
*/
36+
private $paymentMethodInstanceFactory;
37+
38+
/**
39+
* @var array
40+
*/
41+
protected $additionalChecks;
42+
2743
/**
2844
* @param \Magento\Framework\View\Element\Template\Context $context
2945
* @param \Magento\Payment\Helper\Data $paymentHelper
3046
* @param \Magento\Payment\Model\Checks\SpecificationFactory $methodSpecificationFactory
3147
* @param array $data
48+
* @param array $additionalChecks
3249
*/
3350
public function __construct(
3451
\Magento\Framework\View\Element\Template\Context $context,
3552
\Magento\Payment\Helper\Data $paymentHelper,
3653
\Magento\Payment\Model\Checks\SpecificationFactory $methodSpecificationFactory,
37-
array $data = []
54+
array $data = [],
55+
array $additionalChecks = []
3856
) {
3957
$this->_paymentHelper = $paymentHelper;
4058
$this->methodSpecificationFactory = $methodSpecificationFactory;
59+
$this->additionalChecks = $additionalChecks;
4160
parent::__construct($context, $data);
4261
}
4362

@@ -69,13 +88,17 @@ protected function _prepareLayout()
6988
*/
7089
protected function _canUseMethod($method)
7190
{
72-
return $this->methodSpecificationFactory->create(
91+
$checks = array_merge(
7392
[
7493
AbstractMethod::CHECK_USE_FOR_COUNTRY,
7594
AbstractMethod::CHECK_USE_FOR_CURRENCY,
7695
AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX,
77-
]
78-
)->isApplicable(
96+
AbstractMethod::CHECK_ZERO_TOTAL
97+
],
98+
$this->additionalChecks
99+
);
100+
101+
return $this->methodSpecificationFactory->create($checks)->isApplicable(
79102
$method,
80103
$this->getQuote()
81104
);
@@ -124,11 +147,11 @@ public function getMethods()
124147
$quote = $this->getQuote();
125148
$store = $quote ? $quote->getStoreId() : null;
126149
$methods = [];
127-
$specification = $this->methodSpecificationFactory->create([AbstractMethod::CHECK_ZERO_TOTAL]);
128-
foreach ($this->_paymentHelper->getStoreMethods($store, $quote) as $method) {
129-
if ($this->_canUseMethod($method) && $specification->isApplicable($method, $this->getQuote())) {
130-
$this->_assignMethod($method);
131-
$methods[] = $method;
150+
foreach ($this->getPaymentMethodList()->getActiveList($store) as $method) {
151+
$methodInstance = $this->getPaymentMethodInstanceFactory()->create($method);
152+
if ($methodInstance->isAvailable($quote) && $this->_canUseMethod($methodInstance)) {
153+
$this->_assignMethod($methodInstance);
154+
$methods[] = $methodInstance;
132155
}
133156
}
134157
$this->setData('methods', $methods);
@@ -150,4 +173,36 @@ public function getSelectedMethodCode()
150173
}
151174
return false;
152175
}
176+
177+
/**
178+
* Get payment method list.
179+
*
180+
* @return \Magento\Payment\Api\PaymentMethodListInterface
181+
* @deprecated
182+
*/
183+
private function getPaymentMethodList()
184+
{
185+
if ($this->paymentMethodList === null) {
186+
$this->paymentMethodList = ObjectManager::getInstance()->get(
187+
\Magento\Payment\Api\PaymentMethodListInterface::class
188+
);
189+
}
190+
return $this->paymentMethodList;
191+
}
192+
193+
/**
194+
* Get payment method instance factory.
195+
*
196+
* @return \Magento\Payment\Model\Method\InstanceFactory
197+
* @deprecated
198+
*/
199+
private function getPaymentMethodInstanceFactory()
200+
{
201+
if ($this->paymentMethodInstanceFactory === null) {
202+
$this->paymentMethodInstanceFactory = ObjectManager::getInstance()->get(
203+
\Magento\Payment\Model\Method\InstanceFactory::class
204+
);
205+
}
206+
return $this->paymentMethodInstanceFactory;
207+
}
153208
}

app/code/Magento/Payment/Helper/Data.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public function getMethodInstance($code)
118118
* @param null|string|bool|int $store
119119
* @param Quote|null $quote
120120
* @return AbstractMethod[]
121+
* @deprecated
121122
*/
122123
public function getStoreMethods($store = null, $quote = null)
123124
{
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Payment\Model\Method;
7+
8+
use Magento\Payment\Api\Data\PaymentMethodInterface;
9+
10+
/**
11+
* Payment method instance factory.
12+
*/
13+
class InstanceFactory
14+
{
15+
/**
16+
* @var \Magento\Payment\Helper\Data
17+
*/
18+
private $helper;
19+
20+
/**
21+
* @param \Magento\Payment\Helper\Data $helper
22+
*/
23+
public function __construct(
24+
\Magento\Payment\Helper\Data $helper
25+
) {
26+
$this->helper = $helper;
27+
}
28+
29+
/**
30+
* Create payment method instance.
31+
*
32+
* @param PaymentMethodInterface $paymentMethod
33+
* @return \Magento\Payment\Model\MethodInterface
34+
*/
35+
public function create(PaymentMethodInterface $paymentMethod)
36+
{
37+
$methodInstance = $this->helper->getMethodInstance($paymentMethod->getCode());
38+
$methodInstance->setStore($paymentMethod->getStoreId());
39+
40+
return $methodInstance;
41+
}
42+
}

app/code/Magento/Payment/Model/MethodList.php

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66

77
namespace Magento\Payment\Model;
88

9+
use Magento\Framework\App\ObjectManager;
910
use Magento\Payment\Model\Method\AbstractMethod;
1011

1112
class MethodList
1213
{
1314
/**
1415
* @var \Magento\Payment\Helper\Data
16+
* @deprecated
1517
*/
1618
protected $paymentHelper;
1719

@@ -20,6 +22,16 @@ class MethodList
2022
*/
2123
protected $methodSpecificationFactory;
2224

25+
/**
26+
* @var \Magento\Payment\Api\PaymentMethodListInterface
27+
*/
28+
private $paymentMethodList;
29+
30+
/**
31+
* @var \Magento\Payment\Model\Method\InstanceFactory
32+
*/
33+
private $paymentMethodInstanceFactory;
34+
2335
/**
2436
* @param \Magento\Payment\Helper\Data $paymentHelper
2537
* @param Checks\SpecificationFactory $specificationFactory
@@ -40,14 +52,16 @@ public function __construct(
4052
public function getAvailableMethods(\Magento\Quote\Api\Data\CartInterface $quote = null)
4153
{
4254
$store = $quote ? $quote->getStoreId() : null;
43-
$methods = [];
44-
foreach ($this->paymentHelper->getStoreMethods($store, $quote) as $method) {
45-
if ($this->_canUseMethod($method, $quote)) {
46-
$method->setInfoInstance($quote->getPayment());
47-
$methods[] = $method;
55+
$availableMethods = [];
56+
57+
foreach ($this->getPaymentMethodList()->getActiveList($store) as $method) {
58+
$methodInstance = $this->getPaymentMethodInstanceFactory()->create($method);
59+
if ($methodInstance->isAvailable($quote) && $this->_canUseMethod($methodInstance, $quote)) {
60+
$methodInstance->setInfoInstance($quote->getPayment());
61+
$availableMethods[] = $methodInstance;
4862
}
4963
}
50-
return $methods;
64+
return $availableMethods;
5165
}
5266

5367
/**
@@ -71,4 +85,36 @@ protected function _canUseMethod($method, \Magento\Quote\Api\Data\CartInterface
7185
$quote
7286
);
7387
}
88+
89+
/**
90+
* Get payment method list.
91+
*
92+
* @return \Magento\Payment\Api\PaymentMethodListInterface
93+
* @deprecated
94+
*/
95+
private function getPaymentMethodList()
96+
{
97+
if ($this->paymentMethodList === null) {
98+
$this->paymentMethodList = ObjectManager::getInstance()->get(
99+
\Magento\Payment\Api\PaymentMethodListInterface::class
100+
);
101+
}
102+
return $this->paymentMethodList;
103+
}
104+
105+
/**
106+
* Get payment method instance factory.
107+
*
108+
* @return \Magento\Payment\Model\Method\InstanceFactory
109+
* @deprecated
110+
*/
111+
private function getPaymentMethodInstanceFactory()
112+
{
113+
if ($this->paymentMethodInstanceFactory === null) {
114+
$this->paymentMethodInstanceFactory = ObjectManager::getInstance()->get(
115+
\Magento\Payment\Model\Method\InstanceFactory::class
116+
);
117+
}
118+
return $this->paymentMethodInstanceFactory;
119+
}
74120
}

0 commit comments

Comments
 (0)