Skip to content

Commit 1771d70

Browse files
Merge pull request #133 from magento-firedrakes/bugfixes
[Firedrakes] [Github] Bugfixes.
2 parents 471976c + 13174eb commit 1771d70

File tree

8 files changed

+193
-17
lines changed

8 files changed

+193
-17
lines changed

app/code/Magento/Sales/Model/Order.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,10 +1442,12 @@ public function getPaymentById($paymentId)
14421442
*/
14431443
public function setPayment(\Magento\Sales\Api\Data\OrderPaymentInterface $payment = null)
14441444
{
1445-
$payment->setOrder($this)->setParentId($this->getId());
1446-
if (!$payment->getId()) {
1447-
$this->setData(OrderInterface::PAYMENT, $payment);
1448-
$this->setDataChanges(true);
1445+
$this->setData(OrderInterface::PAYMENT, $payment);
1446+
if ($payment !== null) {
1447+
$payment->setOrder($this)->setParentId($this->getId());
1448+
if (!$payment->getId()) {
1449+
$this->setDataChanges(true);
1450+
}
14491451
}
14501452
return $payment;
14511453
}

app/code/Magento/Sales/Setup/InstallSchema.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3216,12 +3216,6 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
32163216
'12,4',
32173217
[],
32183218
'Grand Total'
3219-
)->addColumn(
3220-
'base_grand_total',
3221-
\Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL,
3222-
'12,4',
3223-
[],
3224-
'Base Grand Total'
32253219
)->addColumn(
32263220
'created_at',
32273221
\Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
@@ -3240,9 +3234,6 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
32403234
)->addIndex(
32413235
$installer->getIdxName('sales_invoice_grid', ['grand_total']),
32423236
['grand_total']
3243-
)->addIndex(
3244-
$installer->getIdxName('sales_invoice_grid', ['base_grand_total']),
3245-
['base_grand_total']
32463237
)->addIndex(
32473238
$installer->getIdxName('sales_invoice_grid', ['order_id']),
32483239
['order_id']

app/code/Magento/Sales/Setup/UpgradeSchema.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Magento\Framework\Setup\UpgradeSchemaInterface;
88
use Magento\Framework\Setup\ModuleContextInterface;
99
use Magento\Framework\Setup\SchemaSetupInterface;
10+
use Magento\Framework\DB\Adapter\AdapterInterface;
1011

1112
/**
1213
* @codeCoverageIgnore
@@ -53,5 +54,43 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
5354

5455
$installer->endSetup();
5556
}
57+
if (version_compare($context->getVersion(), '2.0.3', '<')) {
58+
$this->addColumnBaseGrandTotal($installer);
59+
$this->addIndexBaseGrandTotal($installer);
60+
}
61+
}
62+
63+
/**
64+
* @param SchemaSetupInterface $installer
65+
* @return void
66+
*/
67+
private function addColumnBaseGrandTotal(SchemaSetupInterface $installer)
68+
{
69+
$connection = $installer->getConnection();
70+
$connection->addColumn(
71+
$installer->getTable('sales_invoice_grid'),
72+
'base_grand_total',
73+
[
74+
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL,
75+
'nullable' => true,
76+
'length' => '12,4',
77+
'comment' => 'Base Grand Total',
78+
'after' => 'grand_total'
79+
]
80+
);
81+
}
82+
83+
/**
84+
* @param SchemaSetupInterface $installer
85+
* @return void
86+
*/
87+
private function addIndexBaseGrandTotal(SchemaSetupInterface $installer)
88+
{
89+
$connection = $installer->getConnection();
90+
$connection->addIndex(
91+
$installer->getTable('sales_invoice_grid'),
92+
$installer->getIdxName('sales_invoice_grid', ['base_grand_total']),
93+
['base_grand_total']
94+
);
5695
}
57-
}
96+
}

app/code/Magento/Sales/Test/Unit/Model/OrderTest.php

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Sales\Test\Unit\Model;
77

8+
use Magento\Sales\Api\Data\OrderInterface;
89
use Magento\Sales\Model\Order;
910
use Magento\Sales\Model\ResourceModel\Order\Status\History\CollectionFactory as HistoryCollectionFactory;
1011

@@ -757,6 +758,115 @@ public function testLoadByIncrementIdAndStoreId()
757758
$this->assertSame($this->order, $this->order->loadByIncrementIdAndStoreId($incrementId, $storeId));
758759
}
759760

761+
public function testSetPaymentWithId()
762+
{
763+
$this->order->setId(123);
764+
$payment = $this->getMockBuilder(\Magento\Sales\Model\Order\Payment::class)
765+
->disableOriginalConstructor()
766+
->getMock();
767+
$this->order->setData(OrderInterface::PAYMENT, $payment);
768+
$this->order->setDataChanges(false);
769+
770+
$payment->expects($this->once())
771+
->method('setOrder')
772+
->with($this->order)
773+
->willReturnSelf();
774+
775+
$payment->expects($this->once())
776+
->method('setParentId')
777+
->with(123)
778+
->willReturnSelf();
779+
780+
$payment->expects($this->any())
781+
->method('getId')
782+
->willReturn(1);
783+
784+
$this->order->setPayment($payment);
785+
786+
$this->assertEquals(
787+
$this->order->getData(
788+
OrderInterface::PAYMENT
789+
),
790+
$payment
791+
);
792+
793+
$this->assertFalse(
794+
$this->order->hasDataChanges()
795+
);
796+
}
797+
798+
public function testSetPaymentNoId()
799+
{
800+
$this->order->setId(123);
801+
$this->order->setDataChanges(false);
802+
803+
$payment = $this->getMockBuilder(\Magento\Sales\Model\Order\Payment::class)
804+
->disableOriginalConstructor()
805+
->getMock();
806+
807+
$payment->expects($this->once())
808+
->method('setOrder')
809+
->with($this->order)
810+
->willReturnSelf();
811+
812+
$payment->expects($this->once())
813+
->method('setParentId')
814+
->with(123)
815+
->willReturnSelf();
816+
817+
$payment->expects($this->any())
818+
->method('getId')
819+
->willReturn(null);
820+
821+
$this->order->setPayment($payment);
822+
823+
$this->assertEquals(
824+
$this->order->getData(
825+
OrderInterface::PAYMENT
826+
),
827+
$payment
828+
);
829+
830+
$this->assertTrue(
831+
$this->order->hasDataChanges()
832+
);
833+
}
834+
835+
public function testSetPaymentNull()
836+
{
837+
$this->assertEquals(null, $this->order->setPayment(null));
838+
839+
$this->assertEquals(
840+
$this->order->getData(
841+
OrderInterface::PAYMENT
842+
),
843+
null
844+
);
845+
846+
$this->assertTrue(
847+
$this->order->hasDataChanges()
848+
);
849+
}
850+
851+
public function testResetOrderWillResetPayment()
852+
{
853+
$payment = $this->getMockBuilder(\Magento\Sales\Model\Order\Payment::class)
854+
->disableOriginalConstructor()
855+
->getMock();
856+
$this->order->setData(OrderInterface::PAYMENT, $payment);
857+
$this->order->reset();
858+
$this->assertEquals(
859+
$this->order->getData(
860+
OrderInterface::PAYMENT
861+
),
862+
null
863+
);
864+
865+
$this->assertTrue(
866+
$this->order->hasDataChanges()
867+
);
868+
}
869+
760870
public function notInvoicingStatesProvider()
761871
{
762872
return [

app/code/Magento/Sales/etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9-
<module name="Magento_Sales" setup_version="2.0.2">
9+
<module name="Magento_Sales" setup_version="2.0.3">
1010
<sequence>
1111
<module name="Magento_Rule"/>
1212
<module name="Magento_Catalog"/>

app/code/Magento/Sales/view/adminhtml/templates/order/address/form.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<span><?php /* @escapeNotVerified */ echo $block->getHeaderText() ?></span>
1919
</legend>
2020
<br>
21-
<div class="form-inline">
21+
<div class="form-inline" data-mage-init='{"Magento_Sales/order/edit/address/form":{}}'>
2222
<?php echo $block->getForm()->toHtml() ?>
2323
</div>
2424
</fieldset>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Copyright © 2016 Magento. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define([
6+
'jquery'
7+
], function ($) {
8+
'use strict';
9+
10+
/**
11+
* Currently Magento App stores both region_id and region (as text) values.
12+
* To prevent missing region (as text) we need to copy it in hidden field.
13+
* @param {Array} config
14+
* @param {String} element
15+
*/
16+
return function (config, element) {
17+
var form = $(element),
18+
regionId = form.find('#region_id'),
19+
20+
/**
21+
* Set region callback
22+
*/
23+
setRegion = function () {
24+
form.find('#region').val(regionId.filter(':visible').find(':selected').text());
25+
};
26+
27+
if (regionId.is('visible')) {
28+
setRegion();
29+
}
30+
31+
regionId.on('change', setRegion);
32+
form.find('#country_id').on('change', setRegion);
33+
};
34+
});

app/code/Magento/SalesRule/view/adminhtml/ui_component/sales_rule_form.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<fieldset name="general">
5252
<argument name="data" xsi:type="array">
5353
<item name="config" xsi:type="array">
54-
<item name="label" xsi:type="string">Currently Active</item>
54+
<item name="label" xsi:type="string" translate="true">Currently Active</item>
5555
<item name="additionalClasses" xsi:type="string">fieldset-schedule</item>
5656
</item>
5757
</argument>

0 commit comments

Comments
 (0)