Skip to content

Commit

Permalink
Merge pull request #1142 from magento-engcom/develop-prs
Browse files Browse the repository at this point in the history
[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
  • Loading branch information
ishakhsuvarov authored May 27, 2017
2 parents dd80b51 + bc71cd3 commit 8e21d5a
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

namespace Magento\AdminNotification\Block\Grid\Renderer;

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

$markAsReadHtml = !$row->getIsRead() ? '<a class="action-mark" href="' . $this->getUrl(
'*/*/markAsRead/',
Expand Down
2 changes: 0 additions & 2 deletions app/code/Magento/AdminNotification/Block/ToolbarEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

namespace Magento\AdminNotification\Block;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

/**
* AdminNotification Inbox model
*
Expand All @@ -18,7 +16,7 @@ class Collection extends \Magento\AdminNotification\Model\ResourceModel\Inbox\Co
/**
* Add remove filter
*
* @return \Magento\AdminNotification\Model\ResourceModel\Grid\Collection|\Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
* @return Collection|\Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
*/
protected function _initSelect()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

/**
* Test class for \Magento\AdminNotification\Block\ToolbarEntry
*/
Expand Down Expand Up @@ -53,7 +51,8 @@ public function testGetLatestUnreadNotifications()

// 1. Create mocks
$notificationList = $this->getMockBuilder(
\Magento\AdminNotification\Model\ResourceModel\Inbox\Collection\Unread::class)
\Magento\AdminNotification\Model\ResourceModel\Inbox\Collection\Unread::class
)
->disableOriginalConstructor()
->getMock();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ define([
agreementsModal.showModal();
},

/**
* build a unique id for the term checkbox
*
* @param {Object} context - the ko context
* @param {Number} agreementId
*/
getCheckboxId: function (context, agreementId) {
var paymentMethodName = '',
paymentMethodRenderer = context.$parents[1];

// corresponding payment method fetched from parent context
if (paymentMethodRenderer) {
// item looks like this: {title: "Check / Money order", method: "checkmo"}
paymentMethodName = paymentMethodRenderer.item ?
paymentMethodRenderer.item.method : '';
}

return 'agreement_' + paymentMethodName + '_' + agreementId;
},

/**
* Init modal window for rendered element
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
<div class="checkout-agreement required">
<input type="checkbox" class="required-entry"
data-bind="attr: {
'id': 'agreement_' + agreementId,
'id': $parent.getCheckboxId($parentContext, agreementId),
'name': 'agreement[' + agreementId + ']',
'value': agreementId
}"/>
<label data-bind="attr: {'for': 'agreement_' + agreementId}">
<label data-bind="attr: {'for': $parent.getCheckboxId($parentContext, agreementId)}">
<button type="button"
class="action action-show"
data-bind="click: function(data, event) { return $parent.showContent(data, event) }"
Expand Down
19 changes: 17 additions & 2 deletions app/code/Magento/Quote/Model/QuoteValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

namespace Magento\Quote\Model;

use Magento\Framework\Exception\LocalizedException;
use Magento\Quote\Model\Quote as QuoteEntity;
use Magento\Directory\Model\AllowedCountries;
use Magento\Framework\App\ObjectManager;
use Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage as OrderAmountValidationMessage;

/**
* @api
Expand All @@ -25,15 +27,25 @@ class QuoteValidator
*/
private $allowedCountryReader;

/**
* @var OrderAmountValidationMessage
*/
private $minimumAmountMessage;

/**
* QuoteValidator constructor.
*
* @param AllowedCountries|null $allowedCountryReader
* @param OrderAmountValidationMessage|null $minimumAmountMessage
*/
public function __construct(AllowedCountries $allowedCountryReader = null)
{
public function __construct(
AllowedCountries $allowedCountryReader = null,
OrderAmountValidationMessage $minimumAmountMessage = null
) {
$this->allowedCountryReader = $allowedCountryReader ?: ObjectManager::getInstance()
->get(AllowedCountries::class);
$this->minimumAmountMessage = $minimumAmountMessage ?: ObjectManager::getInstance()
->get(OrderAmountValidationMessage::class);
}

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

return $this;
}
Expand Down
24 changes: 0 additions & 24 deletions app/code/Magento/Quote/Model/ShippingAddressManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ class ShippingAddressManagement implements \Magento\Quote\Model\ShippingAddressM
*/
protected $totalsCollector;

/**
* @var \Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage
*/
private $minimumAmountErrorMessage;

/**
* @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository
* @param QuoteAddressValidator $addressValidator
Expand Down Expand Up @@ -117,10 +112,6 @@ public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $addres
$address->setSaveInAddressBook($saveInAddressBook);
$address->setCollectShippingRates(true);

if (!$quote->validateMinimumAmount($quote->getIsMultiShipping())) {
throw new InputException($this->getMinimumAmountErrorMessage()->getMessage());
}

try {
$address->save();
} catch (\Exception $e) {
Expand All @@ -145,19 +136,4 @@ public function get($cartId)
/** @var \Magento\Quote\Model\Quote\Address $address */
return $quote->getShippingAddress();
}

/**
* @return \Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage
* @deprecated
*/
private function getMinimumAmountErrorMessage()
{
if ($this->minimumAmountErrorMessage === null) {
$objectManager = ObjectManager::getInstance();
$this->minimumAmountErrorMessage = $objectManager->get(
\Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage::class
);
}
return $this->minimumAmountErrorMessage;
}
}
25 changes: 25 additions & 0 deletions app/code/Magento/Quote/Setup/UpgradeSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,31 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
]
);
}
if (version_compare($context->getVersion(), '2.0.6', '<')) {
$connection = $setup->getConnection(self::$connectionName);
$connection->modifyColumn(
$setup->getTable('quote_address', self::$connectionName),
'firstname',
[
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'length' => 255,
]
)->modifyColumn(
$setup->getTable('quote_address', self::$connectionName),
'middlename',
[
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'length' => 40,
]
)->modifyColumn(
$setup->getTable('quote_address', self::$connectionName),
'lastname',
[
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'length' => 255,
]
);
}
$setup->endSetup();
}
}
41 changes: 40 additions & 1 deletion app/code/Magento/Quote/Test/Unit/Model/QuoteValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Magento\Quote\Model\Quote\Address;
use Magento\Quote\Model\Quote\Payment;
use Magento\Quote\Model\QuoteValidator;
use Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage as OrderAmountValidationMessage;

/**
* Class QuoteValidatorTest
Expand All @@ -30,6 +31,11 @@ class QuoteValidatorTest extends \PHPUnit_Framework_TestCase
*/
private $allowedCountryReader;

/**
* @var OrderAmountValidationMessage|\PHPUnit_Framework_MockObject_MockObject
*/
private $orderAmountValidationMessage;

/**
* @return void
*/
Expand All @@ -38,8 +44,14 @@ protected function setUp()
$this->allowedCountryReader = $this->getMockBuilder(AllowedCountries::class)
->disableOriginalConstructor()
->getMock();
$this->orderAmountValidationMessage = $this->getMockBuilder(OrderAmountValidationMessage::class)
->disableOriginalConstructor()
->getMock();

$this->quoteValidator = new \Magento\Quote\Model\QuoteValidator($this->allowedCountryReader);
$this->quoteValidator = new \Magento\Quote\Model\QuoteValidator(
$this->allowedCountryReader,
$this->orderAmountValidationMessage
);

$this->quoteMock = $this->getMock(
\Magento\Quote\Model\Quote::class,
Expand All @@ -51,6 +63,8 @@ protected function setUp()
'setHasError',
'addMessage',
'isVirtual',
'validateMinimumAmount',
'getIsMultiShipping',
'__wakeup'
],
[],
Expand Down Expand Up @@ -185,6 +199,31 @@ public function testValidateBeforeSubmitThrowsExceptionIfPaymentMethodIsNotSelec
$this->quoteValidator->validateBeforeSubmit($this->quoteMock);
}

/**
* @expectedException \Magento\Framework\Exception\LocalizedException
* @expectedExceptionMessage Minimum Order Amount Exceeded.
*/
public function testValidateBeforeSubmitThrowsExceptionIfMinimumOrderAmount()
{
$paymentMock = $this->getMock(\Magento\Quote\Model\Quote\Payment::class, [], [], '', false);
$paymentMock->expects($this->once())->method('getMethod')->willReturn('checkmo');

$billingAddressMock = $this->getMock(\Magento\Quote\Model\Quote\Address::class, [], [], '', false);
$billingAddressMock->expects($this->any())->method('validate')->willReturn(true);

$this->quoteMock->expects($this->any())->method('getBillingAddress')->willReturn($billingAddressMock);
$this->quoteMock->expects($this->any())->method('getPayment')->willReturn($paymentMock);
$this->quoteMock->expects($this->any())->method('isVirtual')->willReturn(true);

$this->quoteMock->expects($this->any())->method('getIsMultiShipping')->willReturn(false);
$this->quoteMock->expects($this->any())->method('validateMinimumAmount')->willReturn(false);

$this->orderAmountValidationMessage->expects($this->once())->method('getMessage')
->willReturn(__("Minimum Order Amount Exceeded."));

$this->quoteValidator->validateBeforeSubmit($this->quoteMock);
}

/**
* Test case when country id not present in allowed countries list.
*
Expand Down
Loading

0 comments on commit 8e21d5a

Please sign in to comment.