Skip to content

Commit 9d6930c

Browse files
authored
Merge pull request #2618 from magento-mpi/MPI-PR
[MPI] Bug Fixes
2 parents 323994f + 97606ec commit 9d6930c

File tree

15 files changed

+435
-61
lines changed

15 files changed

+435
-61
lines changed

app/code/Magento/Checkout/view/frontend/web/js/sidebar.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ define([
99
'Magento_Customer/js/customer-data',
1010
'Magento_Ui/js/modal/alert',
1111
'Magento_Ui/js/modal/confirm',
12+
'underscore',
1213
'jquery/ui',
1314
'mage/decorate',
1415
'mage/collapsible',
1516
'mage/cookies'
16-
], function ($, authenticationPopup, customerData, alert, confirm) {
17+
], function ($, authenticationPopup, customerData, alert, confirm, _) {
1718
'use strict';
1819

1920
$.widget('mage.sidebar', {
@@ -219,6 +220,11 @@ define([
219220
* @param {HTMLElement} elem
220221
*/
221222
_updateItemQtyAfter: function (elem) {
223+
var productData = this._getProductById(Number(elem.data('cart-item')));
224+
225+
if (!_.isUndefined(productData)) {
226+
$(document).trigger('ajax:updateCartItemQty', productData['product_sku']);
227+
}
222228
this._hideItemButton(elem);
223229
},
224230

@@ -241,11 +247,24 @@ define([
241247
* @private
242248
*/
243249
_removeItemAfter: function (elem) {
244-
var productData = customerData.get('cart')().items.find(function (item) {
245-
return Number(elem.data('cart-item')) === Number(item['item_id']);
246-
});
250+
var productData = this._getProductById(Number(elem.data('cart-item')));
251+
252+
if (!_.isUndefined(productData)) {
253+
$(document).trigger('ajax:removeFromCart', productData['product_sku']);
254+
}
255+
},
247256

248-
$(document).trigger('ajax:removeFromCart', productData['product_sku']);
257+
/**
258+
* Retrieves product data by Id.
259+
*
260+
* @param {Number} productId - product Id
261+
* @returns {Object|undefined}
262+
* @private
263+
*/
264+
_getProductById: function (productId) {
265+
return _.find(customerData.get('cart')().items, function (item) {
266+
return productId === Number(item['item_id']);
267+
});
249268
},
250269

251270
/**

app/code/Magento/Checkout/view/frontend/web/js/view/configure/product-customer-data.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
require([
22
'jquery',
33
'Magento_Customer/js/customer-data',
4+
'underscore',
45
'domReady!'
5-
], function ($, customerData) {
6+
], function ($, customerData, _) {
67
'use strict';
78

89
var selectors = {
@@ -41,7 +42,7 @@ require([
4142
if (!(data && data.items && data.items.length && productId)) {
4243
return;
4344
}
44-
product = data.items.find(function (item) {
45+
product = _.find(data.items, function (item) {
4546
if (item['item_id'] === itemId) {
4647
return item['product_id'] === productId ||
4748
item['item_id'] === productId;

app/code/Magento/Customer/Model/Metadata/AttributeMetadataHydrator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Customer\Api\Data\OptionInterfaceFactory;
1212
use Magento\Customer\Api\Data\ValidationRuleInterface;
1313
use Magento\Customer\Api\Data\ValidationRuleInterfaceFactory;
14+
use Magento\Customer\Model\Data\AttributeMetadata;
1415
use Magento\Framework\Reflection\DataObjectProcessor;
1516

1617
/**
@@ -120,7 +121,7 @@ public function extract($attributeMetadata)
120121
{
121122
return $this->dataObjectProcessor->buildOutputDataArray(
122123
$attributeMetadata,
123-
AttributeMetadataInterface::class
124+
AttributeMetadata::class
124125
);
125126
}
126127
}

app/code/Magento/Customer/Test/Unit/Model/Metadata/AttributeMetadataHydratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public function testExtract()
205205
->method('buildOutputDataArray')
206206
->with(
207207
$this->attributeMetadataMock,
208-
AttributeMetadataInterface::class
208+
AttributeMetadata::class
209209
)
210210
->willReturn($data);
211211
$this->assertSame(

app/code/Magento/Fedex/Model/Carrier.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
namespace Magento\Fedex\Model;
1010

1111
use Magento\Framework\App\ObjectManager;
12+
use Magento\Framework\DataObject;
1213
use Magento\Framework\Module\Dir;
1314
use Magento\Framework\Serialize\Serializer\Json;
15+
use Magento\Framework\Webapi\Soap\ClientFactory;
1416
use Magento\Framework\Xml\Security;
1517
use Magento\Quote\Model\Quote\Address\RateRequest;
1618
use Magento\Shipping\Model\Carrier\AbstractCarrierOnline;
@@ -19,7 +21,6 @@
1921
/**
2022
* Fedex shipping implementation
2123
*
22-
* @author Magento Core Team <[email protected]>
2324
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
2425
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2526
*/
@@ -145,6 +146,11 @@ class Carrier extends AbstractCarrierOnline implements \Magento\Shipping\Model\C
145146
*/
146147
private $serializer;
147148

149+
/**
150+
* @var ClientFactory
151+
*/
152+
private $soapClientFactory;
153+
148154
/**
149155
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
150156
* @param \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory
@@ -166,7 +172,7 @@ class Carrier extends AbstractCarrierOnline implements \Magento\Shipping\Model\C
166172
* @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
167173
* @param array $data
168174
* @param Json|null $serializer
169-
*
175+
* @param ClientFactory|null $soapClientFactory
170176
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
171177
*/
172178
public function __construct(
@@ -189,7 +195,8 @@ public function __construct(
189195
\Magento\Framework\Module\Dir\Reader $configReader,
190196
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
191197
array $data = [],
192-
Json $serializer = null
198+
Json $serializer = null,
199+
ClientFactory $soapClientFactory = null
193200
) {
194201
$this->_storeManager = $storeManager;
195202
$this->_productCollectionFactory = $productCollectionFactory;
@@ -216,6 +223,7 @@ public function __construct(
216223
$this->_rateServiceWsdl = $wsdlBasePath . 'RateService_v10.wsdl';
217224
$this->_trackServiceWsdl = $wsdlBasePath . 'TrackService_v' . self::$trackServiceVersion . '.wsdl';
218225
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
226+
$this->soapClientFactory = $soapClientFactory ?: ObjectManager::getInstance()->get(ClientFactory::class);
219227
}
220228

221229
/**
@@ -227,7 +235,7 @@ public function __construct(
227235
*/
228236
protected function _createSoapClient($wsdl, $trace = false)
229237
{
230-
$client = new \SoapClient($wsdl, ['trace' => $trace]);
238+
$client = $this->soapClientFactory->create($wsdl, ['trace' => $trace]);
231239
$client->__setLocation(
232240
$this->getConfigFlag(
233241
'sandbox_mode'
@@ -1264,7 +1272,7 @@ protected function _formShipmentRequest(\Magento\Framework\DataObject $request)
12641272
$countriesOfManufacture[] = $product->getCountryOfManufacture();
12651273
}
12661274

1267-
$paymentType = $request->getIsReturn() ? 'RECIPIENT' : 'SENDER';
1275+
$paymentType = $this->getPaymentType($request);
12681276
$optionType = $request->getShippingMethod() == self::RATE_REQUEST_SMARTPOST
12691277
? 'SERVICE_DEFAULT' : $packageParams->getDeliveryConfirmation();
12701278
$requestClient = [
@@ -1750,4 +1758,18 @@ private function parseDate($timestamp)
17501758

17511759
return false;
17521760
}
1761+
1762+
/**
1763+
* Defines payment type by request.
1764+
* Two values are available: RECIPIENT or SENDER.
1765+
*
1766+
* @param DataObject $request
1767+
* @return string
1768+
*/
1769+
private function getPaymentType(DataObject $request): string
1770+
{
1771+
return $request->getIsReturn() && $request->getShippingMethod() !== self::RATE_REQUEST_SMARTPOST
1772+
? 'RECIPIENT'
1773+
: 'SENDER';
1774+
}
17531775
}

app/code/Magento/Sales/Block/Adminhtml/Order/Create/Form/Account.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,15 @@ protected function _prepareForm()
134134
$this->_addAttributesToForm($attributes, $fieldset);
135135

136136
$this->_form->addFieldNameSuffix('order[account]');
137-
$this->_form->setValues($this->getFormValues());
137+
138+
$formValues = $this->getFormValues();
139+
foreach ($attributes as $code => $attribute) {
140+
$defaultValue = $attribute->getDefaultValue();
141+
if (isset($defaultValue) && !isset($formValues[$code])) {
142+
$formValues[$code] = $defaultValue;
143+
}
144+
}
145+
$this->_form->setValues($formValues);
138146

139147
return $this;
140148
}

dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Creditmemo/Form/Items.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public function getItemProductBlock($productSku)
5151
*/
5252
public function clickUpdateQty()
5353
{
54-
$this->_rootElement->find($this->updateQty)->click();
54+
$button = $this->_rootElement->find($this->updateQty);
55+
if (!$button->isDisabled()) {
56+
$button->click();
57+
}
5558
}
5659
}

dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Creditmemo/Totals.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ public function getAdjustmentFeeElement()
123123
*/
124124
public function clickUpdateTotals()
125125
{
126-
$this->_rootElement->find($this->updateTotalsSelector)->click();
126+
$button = $this->_rootElement->find($this->updateTotalsSelector);
127+
if (!$button->isDisabled()) {
128+
$button->click();
129+
}
127130
}
128131
}

dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertNoCreditMemoButton.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function processAssert(SalesOrderView $salesOrderView, OrderIndex $orderI
3030
$orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $order->getId()]);
3131
\PHPUnit_Framework_Assert::assertFalse(
3232
$salesOrderView->getPageActions()->isActionButtonVisible('Credit Memo'),
33-
'Credit memo button is present on order view page.'
33+
'Credit memo button should not be present on order view page.'
3434
);
3535
}
3636

dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/CreateCreditMemoStep.php

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,8 @@ public function run()
9696
$this->orderCreditMemoNew->getFormBlock()->updateQty();
9797
}
9898

99-
$hasChangeTotals = $this->compareRefundTotalsData($refundData);
10099
$this->orderCreditMemoNew->getFormBlock()->fillFormData($refundData);
101-
if ($hasChangeTotals) {
102-
$this->orderCreditMemoNew->getTotalsBlock()->clickUpdateTotals();
103-
}
100+
$this->orderCreditMemoNew->getTotalsBlock()->clickUpdateTotals();
104101

105102
$this->orderCreditMemoNew->getFormBlock()->submit();
106103
}
@@ -121,31 +118,4 @@ protected function getCreditMemoIds()
121118
$this->salesOrderView->getOrderForm()->openTab('creditmemos');
122119
return $this->salesOrderView->getOrderForm()->getTab('creditmemos')->getGridBlock()->getIds();
123120
}
124-
125-
/**
126-
* Compare refund total items.
127-
*
128-
* @param array $data
129-
* @return int
130-
*/
131-
private function compareRefundTotalsData($data)
132-
{
133-
$compareData = [
134-
'shipping_amount' =>
135-
$this->orderCreditMemoNew->getTotalsBlock()->getRefundShippingElement()->getValue(),
136-
'adjustment_positive' =>
137-
$this->orderCreditMemoNew->getTotalsBlock()->getAdjustmentRefundElement()->getValue(),
138-
'adjustment_negative' =>
139-
$this->orderCreditMemoNew->getTotalsBlock()->getAdjustmentFeeElement()->getValue(),
140-
];
141-
142-
$count = 0;
143-
foreach ($compareData as $key => $val) {
144-
if (isset($data['form_data'][$key])) {
145-
$count += ($val != $data['form_data'][$key] ? 1 : 0);
146-
}
147-
}
148-
149-
return $count;
150-
}
151121
}

0 commit comments

Comments
 (0)