Skip to content

Commit 8e21d5a

Browse files
Merge pull request #1142 from magento-engcom/develop-prs
[EngCom] Public Pull Requests - MAGETWO-69379 use payment method name to make checkbox of agreements more unique #6207 #9717 - MAGETWO-69378 #4272: v2.0.4 Credit memos with adjustment fees cannot be fully refunded with a second credit memo #9715 - MAGETWO-69375 Can't delete last item in cart if Minimum Order is Enable #6151 #9714 - MAGETWO-69230 #7279 bill-to name and ship-to name truncated to 20 chars #9654 - MAGETWO-69155 Fix coding standard in Magento AdminNotification module #9627
2 parents dd80b51 + bc71cd3 commit 8e21d5a

File tree

14 files changed

+144
-115
lines changed

14 files changed

+144
-115
lines changed

app/code/Magento/AdminNotification/Block/Grid/Renderer/Actions.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* See COPYING.txt for license details.
77
*/
88

9-
// @codingStandardsIgnoreFile
10-
119
namespace Magento\AdminNotification\Block\Grid\Renderer;
1210

1311
class Actions extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
@@ -39,9 +37,8 @@ public function __construct(
3937
*/
4038
public function render(\Magento\Framework\DataObject $row)
4139
{
42-
$readDetailsHtml = $row->getUrl() ? '<a class="action-details" target="_blank" href="' . $row->getUrl() . '">' . __(
43-
'Read Details'
44-
) . '</a>' : '';
40+
$readDetailsHtml = $row->getUrl() ? '<a class="action-details" target="_blank" href="' . $row->getUrl() . '">' .
41+
__('Read Details') . '</a>' : '';
4542

4643
$markAsReadHtml = !$row->getIsRead() ? '<a class="action-mark" href="' . $this->getUrl(
4744
'*/*/markAsRead/',

app/code/Magento/AdminNotification/Block/ToolbarEntry.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
// @codingStandardsIgnoreFile
8-
97
namespace Magento\AdminNotification\Block;
108

119
/**

app/code/Magento/AdminNotification/Model/ResourceModel/Grid/Collection.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
// @codingStandardsIgnoreFile
8-
97
/**
108
* AdminNotification Inbox model
119
*
@@ -18,7 +16,7 @@ class Collection extends \Magento\AdminNotification\Model\ResourceModel\Inbox\Co
1816
/**
1917
* Add remove filter
2018
*
21-
* @return \Magento\AdminNotification\Model\ResourceModel\Grid\Collection|\Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
19+
* @return Collection|\Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
2220
*/
2321
protected function _initSelect()
2422
{

app/code/Magento/AdminNotification/Test/Unit/Block/ToolbarEntryTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
// @codingStandardsIgnoreFile
8-
97
/**
108
* Test class for \Magento\AdminNotification\Block\ToolbarEntry
119
*/
@@ -53,7 +51,8 @@ public function testGetLatestUnreadNotifications()
5351

5452
// 1. Create mocks
5553
$notificationList = $this->getMockBuilder(
56-
\Magento\AdminNotification\Model\ResourceModel\Inbox\Collection\Unread::class)
54+
\Magento\AdminNotification\Model\ResourceModel\Inbox\Collection\Unread::class
55+
)
5756
->disableOriginalConstructor()
5857
->getMock();
5958

app/code/Magento/CheckoutAgreements/view/frontend/web/js/view/checkout-agreements.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,26 @@ define([
4545
agreementsModal.showModal();
4646
},
4747

48+
/**
49+
* build a unique id for the term checkbox
50+
*
51+
* @param {Object} context - the ko context
52+
* @param {Number} agreementId
53+
*/
54+
getCheckboxId: function (context, agreementId) {
55+
var paymentMethodName = '',
56+
paymentMethodRenderer = context.$parents[1];
57+
58+
// corresponding payment method fetched from parent context
59+
if (paymentMethodRenderer) {
60+
// item looks like this: {title: "Check / Money order", method: "checkmo"}
61+
paymentMethodName = paymentMethodRenderer.item ?
62+
paymentMethodRenderer.item.method : '';
63+
}
64+
65+
return 'agreement_' + paymentMethodName + '_' + agreementId;
66+
},
67+
4868
/**
4969
* Init modal window for rendered element
5070
*

app/code/Magento/CheckoutAgreements/view/frontend/web/template/checkout/checkout-agreements.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
<div class="checkout-agreement required">
1212
<input type="checkbox" class="required-entry"
1313
data-bind="attr: {
14-
'id': 'agreement_' + agreementId,
14+
'id': $parent.getCheckboxId($parentContext, agreementId),
1515
'name': 'agreement[' + agreementId + ']',
1616
'value': agreementId
1717
}"/>
18-
<label data-bind="attr: {'for': 'agreement_' + agreementId}">
18+
<label data-bind="attr: {'for': $parent.getCheckboxId($parentContext, agreementId)}">
1919
<button type="button"
2020
class="action action-show"
2121
data-bind="click: function(data, event) { return $parent.showContent(data, event) }"

app/code/Magento/Quote/Model/QuoteValidator.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
namespace Magento\Quote\Model;
88

9+
use Magento\Framework\Exception\LocalizedException;
910
use Magento\Quote\Model\Quote as QuoteEntity;
1011
use Magento\Directory\Model\AllowedCountries;
1112
use Magento\Framework\App\ObjectManager;
13+
use Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage as OrderAmountValidationMessage;
1214

1315
/**
1416
* @api
@@ -25,15 +27,25 @@ class QuoteValidator
2527
*/
2628
private $allowedCountryReader;
2729

30+
/**
31+
* @var OrderAmountValidationMessage
32+
*/
33+
private $minimumAmountMessage;
34+
2835
/**
2936
* QuoteValidator constructor.
3037
*
3138
* @param AllowedCountries|null $allowedCountryReader
39+
* @param OrderAmountValidationMessage|null $minimumAmountMessage
3240
*/
33-
public function __construct(AllowedCountries $allowedCountryReader = null)
34-
{
41+
public function __construct(
42+
AllowedCountries $allowedCountryReader = null,
43+
OrderAmountValidationMessage $minimumAmountMessage = null
44+
) {
3545
$this->allowedCountryReader = $allowedCountryReader ?: ObjectManager::getInstance()
3646
->get(AllowedCountries::class);
47+
$this->minimumAmountMessage = $minimumAmountMessage ?: ObjectManager::getInstance()
48+
->get(OrderAmountValidationMessage::class);
3749
}
3850

3951
/**
@@ -98,6 +110,9 @@ public function validateBeforeSubmit(QuoteEntity $quote)
98110
if (!$quote->getPayment()->getMethod()) {
99111
throw new \Magento\Framework\Exception\LocalizedException(__('Please select a valid payment method.'));
100112
}
113+
if (!$quote->validateMinimumAmount($quote->getIsMultiShipping())) {
114+
throw new LocalizedException($this->minimumAmountMessage->getMessage());
115+
}
101116

102117
return $this;
103118
}

app/code/Magento/Quote/Model/ShippingAddressManagement.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ class ShippingAddressManagement implements \Magento\Quote\Model\ShippingAddressM
5252
*/
5353
protected $totalsCollector;
5454

55-
/**
56-
* @var \Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage
57-
*/
58-
private $minimumAmountErrorMessage;
59-
6055
/**
6156
* @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository
6257
* @param QuoteAddressValidator $addressValidator
@@ -117,10 +112,6 @@ public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $addres
117112
$address->setSaveInAddressBook($saveInAddressBook);
118113
$address->setCollectShippingRates(true);
119114

120-
if (!$quote->validateMinimumAmount($quote->getIsMultiShipping())) {
121-
throw new InputException($this->getMinimumAmountErrorMessage()->getMessage());
122-
}
123-
124115
try {
125116
$address->save();
126117
} catch (\Exception $e) {
@@ -145,19 +136,4 @@ public function get($cartId)
145136
/** @var \Magento\Quote\Model\Quote\Address $address */
146137
return $quote->getShippingAddress();
147138
}
148-
149-
/**
150-
* @return \Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage
151-
* @deprecated
152-
*/
153-
private function getMinimumAmountErrorMessage()
154-
{
155-
if ($this->minimumAmountErrorMessage === null) {
156-
$objectManager = ObjectManager::getInstance();
157-
$this->minimumAmountErrorMessage = $objectManager->get(
158-
\Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage::class
159-
);
160-
}
161-
return $this->minimumAmountErrorMessage;
162-
}
163139
}

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,31 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
6666
]
6767
);
6868
}
69+
if (version_compare($context->getVersion(), '2.0.6', '<')) {
70+
$connection = $setup->getConnection(self::$connectionName);
71+
$connection->modifyColumn(
72+
$setup->getTable('quote_address', self::$connectionName),
73+
'firstname',
74+
[
75+
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
76+
'length' => 255,
77+
]
78+
)->modifyColumn(
79+
$setup->getTable('quote_address', self::$connectionName),
80+
'middlename',
81+
[
82+
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
83+
'length' => 40,
84+
]
85+
)->modifyColumn(
86+
$setup->getTable('quote_address', self::$connectionName),
87+
'lastname',
88+
[
89+
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
90+
'length' => 255,
91+
]
92+
);
93+
}
6994
$setup->endSetup();
7095
}
7196
}

app/code/Magento/Quote/Test/Unit/Model/QuoteValidatorTest.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Quote\Model\Quote\Address;
1010
use Magento\Quote\Model\Quote\Payment;
1111
use Magento\Quote\Model\QuoteValidator;
12+
use Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage as OrderAmountValidationMessage;
1213

1314
/**
1415
* Class QuoteValidatorTest
@@ -30,6 +31,11 @@ class QuoteValidatorTest extends \PHPUnit_Framework_TestCase
3031
*/
3132
private $allowedCountryReader;
3233

34+
/**
35+
* @var OrderAmountValidationMessage|\PHPUnit_Framework_MockObject_MockObject
36+
*/
37+
private $orderAmountValidationMessage;
38+
3339
/**
3440
* @return void
3541
*/
@@ -38,8 +44,14 @@ protected function setUp()
3844
$this->allowedCountryReader = $this->getMockBuilder(AllowedCountries::class)
3945
->disableOriginalConstructor()
4046
->getMock();
47+
$this->orderAmountValidationMessage = $this->getMockBuilder(OrderAmountValidationMessage::class)
48+
->disableOriginalConstructor()
49+
->getMock();
4150

42-
$this->quoteValidator = new \Magento\Quote\Model\QuoteValidator($this->allowedCountryReader);
51+
$this->quoteValidator = new \Magento\Quote\Model\QuoteValidator(
52+
$this->allowedCountryReader,
53+
$this->orderAmountValidationMessage
54+
);
4355

4456
$this->quoteMock = $this->getMock(
4557
\Magento\Quote\Model\Quote::class,
@@ -51,6 +63,8 @@ protected function setUp()
5163
'setHasError',
5264
'addMessage',
5365
'isVirtual',
66+
'validateMinimumAmount',
67+
'getIsMultiShipping',
5468
'__wakeup'
5569
],
5670
[],
@@ -185,6 +199,31 @@ public function testValidateBeforeSubmitThrowsExceptionIfPaymentMethodIsNotSelec
185199
$this->quoteValidator->validateBeforeSubmit($this->quoteMock);
186200
}
187201

202+
/**
203+
* @expectedException \Magento\Framework\Exception\LocalizedException
204+
* @expectedExceptionMessage Minimum Order Amount Exceeded.
205+
*/
206+
public function testValidateBeforeSubmitThrowsExceptionIfMinimumOrderAmount()
207+
{
208+
$paymentMock = $this->getMock(\Magento\Quote\Model\Quote\Payment::class, [], [], '', false);
209+
$paymentMock->expects($this->once())->method('getMethod')->willReturn('checkmo');
210+
211+
$billingAddressMock = $this->getMock(\Magento\Quote\Model\Quote\Address::class, [], [], '', false);
212+
$billingAddressMock->expects($this->any())->method('validate')->willReturn(true);
213+
214+
$this->quoteMock->expects($this->any())->method('getBillingAddress')->willReturn($billingAddressMock);
215+
$this->quoteMock->expects($this->any())->method('getPayment')->willReturn($paymentMock);
216+
$this->quoteMock->expects($this->any())->method('isVirtual')->willReturn(true);
217+
218+
$this->quoteMock->expects($this->any())->method('getIsMultiShipping')->willReturn(false);
219+
$this->quoteMock->expects($this->any())->method('validateMinimumAmount')->willReturn(false);
220+
221+
$this->orderAmountValidationMessage->expects($this->once())->method('getMessage')
222+
->willReturn(__("Minimum Order Amount Exceeded."));
223+
224+
$this->quoteValidator->validateBeforeSubmit($this->quoteMock);
225+
}
226+
188227
/**
189228
* Test case when country id not present in allowed countries list.
190229
*

0 commit comments

Comments
 (0)