Skip to content

Commit

Permalink
Merge pull request #47 from magento-mpi/develop
Browse files Browse the repository at this point in the history
[MPI] Optimization and bug fixes
  • Loading branch information
Pechenushko committed Jan 21, 2015
2 parents 1bba5fe + 154f44d commit 2410622
Show file tree
Hide file tree
Showing 32 changed files with 1,085 additions and 170 deletions.
1 change: 0 additions & 1 deletion app/code/Magento/Backend/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<preference for="Magento\Backend\Model\Config\Structure\SearchInterface" type="Magento\Backend\Model\Config\Structure" />
<preference for="Magento\Backend\Model\Config\Backend\File\RequestData\RequestDataInterface" type="Magento\Backend\Model\Config\Backend\File\RequestData" />
<preference for="Magento\Backend\Model\Auth\Credential\StorageInterface" type="Magento\User\Model\User" />
<preference for="Magento\Adminhtml\Helper\Data" type="Magento\Backend\Helper\Data" />
<preference for="Magento\Backend\App\ConfigInterface" type="Magento\Backend\App\Config" />
<preference for="Magento\Backend\Model\UrlInterface" type="Magento\Backend\Model\Url" />
<preference for="Magento\Backend\Block\Widget\Button\ToolbarInterface" type="Magento\Backend\Block\Widget\Button\Toolbar" />
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Checkout/Controller/Cart/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Index extends \Magento\Checkout\Controller\Cart
*/
public function execute()
{
$this->_eventManager->dispatch('collect_totals_failed_items');
if ($this->cart->getQuote()->getItemsCount()) {
$this->cart->init();
$this->cart->save();
Expand Down
2 changes: 0 additions & 2 deletions app/code/Magento/Core/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
<preference for="Magento\Framework\Authorization\PolicyInterface" type="Magento\Framework\Authorization\Policy\DefaultPolicy" />
<preference for="Magento\Framework\Authorization\RoleLocatorInterface" type="Magento\Framework\Authorization\RoleLocator\DefaultRoleLocator" />
<preference for="Magento\Framework\Session\SessionManagerInterface" type="Magento\Framework\Session\Generic" />
<preference for="Magento\Core\Model\DataService\ConfigInterface" type="Magento\Core\Model\DataService\Config" />
<preference for="Magento\Framework\App\Config\ScopeConfigInterface" type="Magento\Framework\App\Config" />
<preference for="Magento\Framework\App\Config\ReinitableConfigInterface" type="Magento\Framework\App\ReinitableConfig" />
<preference for="Magento\Framework\App\Config\MutableScopeConfigInterface" type="Magento\Framework\App\MutableScopeConfig" />
<preference for="Magento\Framework\App\Config\Storage\WriterInterface" type="Magento\Framework\App\Config\Storage\Writer" />
<preference for="Magento\Framework\View\Design\Theme\FileInterface" type="Magento\Core\Model\Theme\File" />
<preference for="Magento\Framework\Config\ConverterInterface" type="Magento\Framework\Config\Converter\Dom"/>
<preference for="Magento\Core\Model\Url\SecurityInfoInterface" type="Magento\Core\Model\Url\SecurityInfo\Proxy" />
<preference for="Magento\Framework\App\DefaultPathInterface" type="Magento\Framework\App\DefaultPath\DefaultPath" />
<preference for="Magento\Framework\Encryption\EncryptorInterface" type="Magento\Framework\Encryption\Encryptor" />
<preference for="Magento\Framework\Filter\Encrypt\AdapterInterface" type="Magento\Framework\Filter\Encrypt\Basic" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\OfflinePayments\Block\Form;

/**
* Abstract class for Cash On Delivery and Bank Transfer payment method form
*/
abstract class AbstractInstruction extends \Magento\Payment\Block\Form
{
/**
* Instructions text
*
* @var string
*/
protected $_instructions;

/**
* Get instructions text from config
*
* @return string
*/
public function getInstructions()
{
if (is_null($this->_instructions)) {
$this->_instructions = $this->getMethod()->getInstructions();
}
return $this->_instructions;
}
}
22 changes: 1 addition & 21 deletions app/code/Magento/OfflinePayments/Block/Form/Banktransfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,12 @@
/**
* Block for Bank Transfer payment method form
*/
class Banktransfer extends \Magento\Payment\Block\Form
class Banktransfer extends \Magento\OfflinePayments\Block\Form\AbstractInstruction
{
/**
* Instructions text
*
* @var string
*/
protected $_instructions;

/**
* Bank transfer template
*
* @var string
*/
protected $_template = 'form/banktransfer.phtml';

/**
* Get instructions text from config
*
* @return string
*/
public function getInstructions()
{
if (is_null($this->_instructions)) {
$this->_instructions = $this->getMethod()->getInstructions();
}
return $this->_instructions;
}
}
22 changes: 1 addition & 21 deletions app/code/Magento/OfflinePayments/Block/Form/Cashondelivery.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,12 @@
/**
* Block for Cash On Delivery payment method form
*/
class Cashondelivery extends \Magento\Payment\Block\Form
class Cashondelivery extends \Magento\OfflinePayments\Block\Form\AbstractInstruction
{
/**
* Instructions text
*
* @var string
*/
protected $_instructions;

/**
* Cash on delivery template
*
* @var string
*/
protected $_template = 'form/cashondelivery.phtml';

/**
* Get instructions text from config
*
* @return string
*/
public function getInstructions()
{
if (is_null($this->_instructions)) {
$this->_instructions = $this->getMethod()->getInstructions();
}
return $this->_instructions;
}
}
10 changes: 0 additions & 10 deletions app/code/Magento/OfflinePayments/Model/Banktransfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,4 @@ class Banktransfer extends \Magento\Payment\Model\Method\AbstractMethod
* @var bool
*/
protected $_isOffline = true;

/**
* Get instructions text from config
*
* @return string
*/
public function getInstructions()
{
return trim($this->getConfigData('instructions'));
}
}
8 changes: 5 additions & 3 deletions app/code/Magento/OfflinePayments/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ public function beforeOrderPaymentSave(\Magento\Framework\Event\Observer $observ
{
/** @var \Magento\Sales\Model\Order\Payment $payment */
$payment = $observer->getEvent()->getPayment();
$banktransfer = \Magento\OfflinePayments\Model\Banktransfer::PAYMENT_METHOD_BANKTRANSFER_CODE;
if ($payment->getMethod() === $banktransfer) {
$payment->setAdditionalInformation('instructions', $payment->getMethodInstance()->getInstructions());
if ($payment->getMethod() === Banktransfer::PAYMENT_METHOD_BANKTRANSFER_CODE) {
$payment->setAdditionalInformation(
'instructions',
$payment->getMethodInstance()->getConfigData('instructions')
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public function __construct(
*/
public function afterSave()
{
$this->_tablerateFactory->create()->uploadAndImport($this);
/** @var \Magento\OfflineShipping\Model\Resource\Carrier\Tablerate $tableRate */
$tableRate = $this->_tablerateFactory->create();
$tableRate->uploadAndImport($this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,24 @@ public function prepareForm($observer)
$form = $observer->getForm();
foreach ($form->getElements() as $element) {
/** @var \Magento\Framework\Data\Form\Element\AbstractElement $element */
if ($element->getId() == 'action_fieldset') {
$element->addField(
'simple_free_shipping',
'select',
[
'label' => __('Free Shipping'),
'title' => __('Free Shipping'),
'name' => 'simple_free_shipping',
'options' => [
0 => __('No'),
Rule::FREE_SHIPPING_ITEM => __('For matching items only'),
Rule::FREE_SHIPPING_ADDRESS => __('For shipment with matching items'),
]
]
);
if ($element->getId() != 'action_fieldset') {
continue;
}

$element->addField(
'simple_free_shipping',
'select',
[
'label' => __('Free Shipping'),
'title' => __('Free Shipping'),
'name' => 'simple_free_shipping',
'options' => [
0 => __('No'),
Rule::FREE_SHIPPING_ITEM => __('For matching items only'),
Rule::FREE_SHIPPING_ADDRESS => __('For shipment with matching items'),
]
]
);
}
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Payment/Block/Info/Instructions.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function getInstructions()
if (is_null($this->_instructions)) {
$this->_instructions = $this->getInfo()->getAdditionalInformation(
'instructions'
) ?: $this->getMethod()->getInstructions();
) ?: $this->getMethod()->getConfigData('instructions');
}
return $this->_instructions;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\OfflinePayments\Block\Form;

class AbstractInstructionTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\OfflinePayments\Block\Form\AbstractInstruction
*/
protected $_model;

protected function setUp()
{
$context = $this->getMock('Magento\Framework\View\Element\Template\Context', [], [], '', false);
$this->_model = $this->getMockForAbstractClass(
'Magento\OfflinePayments\Block\Form\AbstractInstruction',
['context' => $context]
);
}

public function testGetInstructions()
{
$method = $this->getMock(
'Magento\Payment\Model\MethodInterface',
['getInstructions', 'getCode', 'getFormBlockType', 'getTitle'],
[],
'',
false
);
$method->expects($this->once())
->method('getInstructions')
->willReturn('instructions');
$this->_model->setData('method', $method);

$this->assertEquals('instructions', $this->_model->getInstructions());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\OfflinePayments\Block\Info;

class CheckmoTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\OfflinePayments\Block\Info\Checkmo
*/
protected $_model;

protected function setUp()
{
$context = $this->getMock('Magento\Framework\View\Element\Template\Context', [], [], '', false);
$this->_model = new \Magento\OfflinePayments\Block\Info\Checkmo($context);
}

/**
* @dataProvider getPayableToDataProvider
*/
public function testGetPayableTo($details, $expected)
{
$info = $this->getMock('Magento\Payment\Model\Info', ['getAdditionalData'], [], '', false);
$info->expects($this->once())
->method('getAdditionalData')
->willReturn(serialize($details));
$this->_model->setData('info', $info);

$this->assertEquals($expected, $this->_model->getPayableTo());
}

/**
* @return array
*/
public function getPayableToDataProvider()
{
return [
[['payable_to' => 'payable'], 'payable'],
['', '']
];
}

/**
* @dataProvider getMailingAddressDataProvider
*/
public function testGetMailingAddress($details, $expected)
{
$info = $this->getMock('Magento\Payment\Model\Info', ['getAdditionalData'], [], '', false);
$info->expects($this->once())
->method('getAdditionalData')
->willReturn(serialize($details));
$this->_model->setData('info', $info);

$this->assertEquals($expected, $this->_model->getMailingAddress());
}

/**
* @return array
*/
public function getMailingAddressDataProvider()
{
return [
[['mailing_address' => 'blah@blah.com'], 'blah@blah.com'],
['', '']
];
}

public function testConvertAdditionalDataIsNeverCalled()
{
$info = $this->getMock('Magento\Payment\Model\Info', ['getAdditionalData'], [], '', false);
$info->expects($this->once())
->method('getAdditionalData')
->willReturn(serialize(['mailing_address' => 'blah@blah.com']));
$this->_model->setData('info', $info);

// First we set the property $this->_mailingAddress
$this->_model->getMailingAddress();

// And now we get already setted property $this->_mailingAddress
$this->assertEquals('blah@blah.com', $this->_model->getMailingAddress());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,23 @@ class BanktransferTest extends \PHPUnit_Framework_TestCase
*/
protected $_object;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $_scopeConfig;

protected function setUp()
{
$objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this);
$eventManager = $this->getMock('Magento\Framework\Event\ManagerInterface', [], [], '', false);
$paymentDataMock = $this->getMock('Magento\Payment\Helper\Data', [], [], '', false);
$scopeConfig = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface');
$this->_scopeConfig = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface', [], [], '', false);
$this->_object = $objectManagerHelper->getObject(
'Magento\OfflinePayments\Model\Banktransfer',
[
'eventManager' => $eventManager,
'paymentData' => $paymentDataMock,
'scopeConfig' => $scopeConfig,
'scopeConfig' => $this->_scopeConfig,
]
);
}
Expand Down
Loading

0 comments on commit 2410622

Please sign in to comment.