Skip to content

Commit 2410622

Browse files
committed
Merge pull request #47 from magento-mpi/develop
[MPI] Optimization and bug fixes
2 parents 1bba5fe + 154f44d commit 2410622

File tree

32 files changed

+1085
-170
lines changed

32 files changed

+1085
-170
lines changed

app/code/Magento/Backend/etc/di.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
<preference for="Magento\Backend\Model\Config\Structure\SearchInterface" type="Magento\Backend\Model\Config\Structure" />
1313
<preference for="Magento\Backend\Model\Config\Backend\File\RequestData\RequestDataInterface" type="Magento\Backend\Model\Config\Backend\File\RequestData" />
1414
<preference for="Magento\Backend\Model\Auth\Credential\StorageInterface" type="Magento\User\Model\User" />
15-
<preference for="Magento\Adminhtml\Helper\Data" type="Magento\Backend\Helper\Data" />
1615
<preference for="Magento\Backend\App\ConfigInterface" type="Magento\Backend\App\Config" />
1716
<preference for="Magento\Backend\Model\UrlInterface" type="Magento\Backend\Model\Url" />
1817
<preference for="Magento\Backend\Block\Widget\Button\ToolbarInterface" type="Magento\Backend\Block\Widget\Button\Toolbar" />

app/code/Magento/Checkout/Controller/Cart/Index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Index extends \Magento\Checkout\Controller\Cart
1515
*/
1616
public function execute()
1717
{
18+
$this->_eventManager->dispatch('collect_totals_failed_items');
1819
if ($this->cart->getQuote()->getItemsCount()) {
1920
$this->cart->init();
2021
$this->cart->save();

app/code/Magento/Core/etc/di.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@
1414
<preference for="Magento\Framework\Authorization\PolicyInterface" type="Magento\Framework\Authorization\Policy\DefaultPolicy" />
1515
<preference for="Magento\Framework\Authorization\RoleLocatorInterface" type="Magento\Framework\Authorization\RoleLocator\DefaultRoleLocator" />
1616
<preference for="Magento\Framework\Session\SessionManagerInterface" type="Magento\Framework\Session\Generic" />
17-
<preference for="Magento\Core\Model\DataService\ConfigInterface" type="Magento\Core\Model\DataService\Config" />
1817
<preference for="Magento\Framework\App\Config\ScopeConfigInterface" type="Magento\Framework\App\Config" />
1918
<preference for="Magento\Framework\App\Config\ReinitableConfigInterface" type="Magento\Framework\App\ReinitableConfig" />
2019
<preference for="Magento\Framework\App\Config\MutableScopeConfigInterface" type="Magento\Framework\App\MutableScopeConfig" />
2120
<preference for="Magento\Framework\App\Config\Storage\WriterInterface" type="Magento\Framework\App\Config\Storage\Writer" />
2221
<preference for="Magento\Framework\View\Design\Theme\FileInterface" type="Magento\Core\Model\Theme\File" />
2322
<preference for="Magento\Framework\Config\ConverterInterface" type="Magento\Framework\Config\Converter\Dom"/>
24-
<preference for="Magento\Core\Model\Url\SecurityInfoInterface" type="Magento\Core\Model\Url\SecurityInfo\Proxy" />
2523
<preference for="Magento\Framework\App\DefaultPathInterface" type="Magento\Framework\App\DefaultPath\DefaultPath" />
2624
<preference for="Magento\Framework\Encryption\EncryptorInterface" type="Magento\Framework\Encryption\Encryptor" />
2725
<preference for="Magento\Framework\Filter\Encrypt\AdapterInterface" type="Magento\Framework\Filter\Encrypt\Basic" />
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\OfflinePayments\Block\Form;
7+
8+
/**
9+
* Abstract class for Cash On Delivery and Bank Transfer payment method form
10+
*/
11+
abstract class AbstractInstruction extends \Magento\Payment\Block\Form
12+
{
13+
/**
14+
* Instructions text
15+
*
16+
* @var string
17+
*/
18+
protected $_instructions;
19+
20+
/**
21+
* Get instructions text from config
22+
*
23+
* @return string
24+
*/
25+
public function getInstructions()
26+
{
27+
if (is_null($this->_instructions)) {
28+
$this->_instructions = $this->getMethod()->getInstructions();
29+
}
30+
return $this->_instructions;
31+
}
32+
}

app/code/Magento/OfflinePayments/Block/Form/Banktransfer.php

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,12 @@
88
/**
99
* Block for Bank Transfer payment method form
1010
*/
11-
class Banktransfer extends \Magento\Payment\Block\Form
11+
class Banktransfer extends \Magento\OfflinePayments\Block\Form\AbstractInstruction
1212
{
13-
/**
14-
* Instructions text
15-
*
16-
* @var string
17-
*/
18-
protected $_instructions;
19-
2013
/**
2114
* Bank transfer template
2215
*
2316
* @var string
2417
*/
2518
protected $_template = 'form/banktransfer.phtml';
26-
27-
/**
28-
* Get instructions text from config
29-
*
30-
* @return string
31-
*/
32-
public function getInstructions()
33-
{
34-
if (is_null($this->_instructions)) {
35-
$this->_instructions = $this->getMethod()->getInstructions();
36-
}
37-
return $this->_instructions;
38-
}
3919
}

app/code/Magento/OfflinePayments/Block/Form/Cashondelivery.php

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,12 @@
88
/**
99
* Block for Cash On Delivery payment method form
1010
*/
11-
class Cashondelivery extends \Magento\Payment\Block\Form
11+
class Cashondelivery extends \Magento\OfflinePayments\Block\Form\AbstractInstruction
1212
{
13-
/**
14-
* Instructions text
15-
*
16-
* @var string
17-
*/
18-
protected $_instructions;
19-
2013
/**
2114
* Cash on delivery template
2215
*
2316
* @var string
2417
*/
2518
protected $_template = 'form/cashondelivery.phtml';
26-
27-
/**
28-
* Get instructions text from config
29-
*
30-
* @return string
31-
*/
32-
public function getInstructions()
33-
{
34-
if (is_null($this->_instructions)) {
35-
$this->_instructions = $this->getMethod()->getInstructions();
36-
}
37-
return $this->_instructions;
38-
}
3919
}

app/code/Magento/OfflinePayments/Model/Banktransfer.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,4 @@ class Banktransfer extends \Magento\Payment\Model\Method\AbstractMethod
3939
* @var bool
4040
*/
4141
protected $_isOffline = true;
42-
43-
/**
44-
* Get instructions text from config
45-
*
46-
* @return string
47-
*/
48-
public function getInstructions()
49-
{
50-
return trim($this->getConfigData('instructions'));
51-
}
5242
}

app/code/Magento/OfflinePayments/Model/Observer.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ public function beforeOrderPaymentSave(\Magento\Framework\Event\Observer $observ
2121
{
2222
/** @var \Magento\Sales\Model\Order\Payment $payment */
2323
$payment = $observer->getEvent()->getPayment();
24-
$banktransfer = \Magento\OfflinePayments\Model\Banktransfer::PAYMENT_METHOD_BANKTRANSFER_CODE;
25-
if ($payment->getMethod() === $banktransfer) {
26-
$payment->setAdditionalInformation('instructions', $payment->getMethodInstance()->getInstructions());
24+
if ($payment->getMethod() === Banktransfer::PAYMENT_METHOD_BANKTRANSFER_CODE) {
25+
$payment->setAdditionalInformation(
26+
'instructions',
27+
$payment->getMethodInstance()->getConfigData('instructions')
28+
);
2729
}
2830
}
2931
}

app/code/Magento/OfflineShipping/Model/Config/Backend/Tablerate.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public function __construct(
4646
*/
4747
public function afterSave()
4848
{
49-
$this->_tablerateFactory->create()->uploadAndImport($this);
49+
/** @var \Magento\OfflineShipping\Model\Resource\Carrier\Tablerate $tableRate */
50+
$tableRate = $this->_tablerateFactory->create();
51+
$tableRate->uploadAndImport($this);
5052
}
5153
}

app/code/Magento/OfflineShipping/Model/Observer/SalesRule/ActionsTab.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,24 @@ public function prepareForm($observer)
2424
$form = $observer->getForm();
2525
foreach ($form->getElements() as $element) {
2626
/** @var \Magento\Framework\Data\Form\Element\AbstractElement $element */
27-
if ($element->getId() == 'action_fieldset') {
28-
$element->addField(
29-
'simple_free_shipping',
30-
'select',
31-
[
32-
'label' => __('Free Shipping'),
33-
'title' => __('Free Shipping'),
34-
'name' => 'simple_free_shipping',
35-
'options' => [
36-
0 => __('No'),
37-
Rule::FREE_SHIPPING_ITEM => __('For matching items only'),
38-
Rule::FREE_SHIPPING_ADDRESS => __('For shipment with matching items'),
39-
]
40-
]
41-
);
27+
if ($element->getId() != 'action_fieldset') {
28+
continue;
4229
}
30+
31+
$element->addField(
32+
'simple_free_shipping',
33+
'select',
34+
[
35+
'label' => __('Free Shipping'),
36+
'title' => __('Free Shipping'),
37+
'name' => 'simple_free_shipping',
38+
'options' => [
39+
0 => __('No'),
40+
Rule::FREE_SHIPPING_ITEM => __('For matching items only'),
41+
Rule::FREE_SHIPPING_ADDRESS => __('For shipment with matching items'),
42+
]
43+
]
44+
);
4345
}
4446
}
4547
}

app/code/Magento/Payment/Block/Info/Instructions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function getInstructions()
3333
if (is_null($this->_instructions)) {
3434
$this->_instructions = $this->getInfo()->getAdditionalInformation(
3535
'instructions'
36-
) ?: $this->getMethod()->getInstructions();
36+
) ?: $this->getMethod()->getConfigData('instructions');
3737
}
3838
return $this->_instructions;
3939
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\OfflinePayments\Block\Form;
7+
8+
class AbstractInstructionTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \Magento\OfflinePayments\Block\Form\AbstractInstruction
12+
*/
13+
protected $_model;
14+
15+
protected function setUp()
16+
{
17+
$context = $this->getMock('Magento\Framework\View\Element\Template\Context', [], [], '', false);
18+
$this->_model = $this->getMockForAbstractClass(
19+
'Magento\OfflinePayments\Block\Form\AbstractInstruction',
20+
['context' => $context]
21+
);
22+
}
23+
24+
public function testGetInstructions()
25+
{
26+
$method = $this->getMock(
27+
'Magento\Payment\Model\MethodInterface',
28+
['getInstructions', 'getCode', 'getFormBlockType', 'getTitle'],
29+
[],
30+
'',
31+
false
32+
);
33+
$method->expects($this->once())
34+
->method('getInstructions')
35+
->willReturn('instructions');
36+
$this->_model->setData('method', $method);
37+
38+
$this->assertEquals('instructions', $this->_model->getInstructions());
39+
}
40+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\OfflinePayments\Block\Info;
7+
8+
class CheckmoTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \Magento\OfflinePayments\Block\Info\Checkmo
12+
*/
13+
protected $_model;
14+
15+
protected function setUp()
16+
{
17+
$context = $this->getMock('Magento\Framework\View\Element\Template\Context', [], [], '', false);
18+
$this->_model = new \Magento\OfflinePayments\Block\Info\Checkmo($context);
19+
}
20+
21+
/**
22+
* @dataProvider getPayableToDataProvider
23+
*/
24+
public function testGetPayableTo($details, $expected)
25+
{
26+
$info = $this->getMock('Magento\Payment\Model\Info', ['getAdditionalData'], [], '', false);
27+
$info->expects($this->once())
28+
->method('getAdditionalData')
29+
->willReturn(serialize($details));
30+
$this->_model->setData('info', $info);
31+
32+
$this->assertEquals($expected, $this->_model->getPayableTo());
33+
}
34+
35+
/**
36+
* @return array
37+
*/
38+
public function getPayableToDataProvider()
39+
{
40+
return [
41+
[['payable_to' => 'payable'], 'payable'],
42+
['', '']
43+
];
44+
}
45+
46+
/**
47+
* @dataProvider getMailingAddressDataProvider
48+
*/
49+
public function testGetMailingAddress($details, $expected)
50+
{
51+
$info = $this->getMock('Magento\Payment\Model\Info', ['getAdditionalData'], [], '', false);
52+
$info->expects($this->once())
53+
->method('getAdditionalData')
54+
->willReturn(serialize($details));
55+
$this->_model->setData('info', $info);
56+
57+
$this->assertEquals($expected, $this->_model->getMailingAddress());
58+
}
59+
60+
/**
61+
* @return array
62+
*/
63+
public function getMailingAddressDataProvider()
64+
{
65+
return [
66+
[['mailing_address' => 'blah@blah.com'], 'blah@blah.com'],
67+
['', '']
68+
];
69+
}
70+
71+
public function testConvertAdditionalDataIsNeverCalled()
72+
{
73+
$info = $this->getMock('Magento\Payment\Model\Info', ['getAdditionalData'], [], '', false);
74+
$info->expects($this->once())
75+
->method('getAdditionalData')
76+
->willReturn(serialize(['mailing_address' => 'blah@blah.com']));
77+
$this->_model->setData('info', $info);
78+
79+
// First we set the property $this->_mailingAddress
80+
$this->_model->getMailingAddress();
81+
82+
// And now we get already setted property $this->_mailingAddress
83+
$this->assertEquals('blah@blah.com', $this->_model->getMailingAddress());
84+
}
85+
}

dev/tests/unit/testsuite/Magento/OfflinePayments/Model/BanktransferTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,23 @@ class BanktransferTest extends \PHPUnit_Framework_TestCase
1212
*/
1313
protected $_object;
1414

15+
/**
16+
* @var \PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
protected $_scopeConfig;
19+
1520
protected function setUp()
1621
{
1722
$objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this);
1823
$eventManager = $this->getMock('Magento\Framework\Event\ManagerInterface', [], [], '', false);
1924
$paymentDataMock = $this->getMock('Magento\Payment\Helper\Data', [], [], '', false);
20-
$scopeConfig = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface');
25+
$this->_scopeConfig = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface', [], [], '', false);
2126
$this->_object = $objectManagerHelper->getObject(
2227
'Magento\OfflinePayments\Model\Banktransfer',
2328
[
2429
'eventManager' => $eventManager,
2530
'paymentData' => $paymentDataMock,
26-
'scopeConfig' => $scopeConfig,
31+
'scopeConfig' => $this->_scopeConfig,
2732
]
2833
);
2934
}

0 commit comments

Comments
 (0)