Skip to content

Commit 2f9032b

Browse files
Merge pull request #448 from magento-folks/bugfix
Fixed issues: - MAGETWO-56866: [GITHUB] Custom option prices unexpectedly change after save #6116 #6342 - MAGETWO-58873: Cannot receive shipping quotes via the admin panel or front end - MAGETWO-55216: Reference by name to non existing plugin lead to Di compilation failure - MAGETWO-58958: Fatal error in console in flow for apply new Scheduled Staging Update using CRON - MAGETWO-55924: [FT] Test fails because of unexpected alert window - MAGETWO-58664: [GitHub] Free shipping rule with table shipping method breaks checkout #6346 - MAGETWO-58849: [GitHub] Error in product edit page after disable Review module #6704
2 parents 10ff4f8 + b5ab1ee commit 2f9032b

File tree

24 files changed

+595
-109
lines changed

24 files changed

+595
-109
lines changed

app/code/Magento/Catalog/Helper/Product/Compare.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ public function getPostDataRemove($product)
231231
$data = [
232232
\Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED => '',
233233
'product' => $product->getId(),
234+
'confirmation' => true,
235+
'confirmationMessage' => __('Are you sure you want to remove this item from your Compare Products list?')
234236
];
235237
return $this->postHelper->getPostData($this->getRemoveUrl(), $data);
236238
}
@@ -254,6 +256,8 @@ public function getPostDataClearList()
254256
{
255257
$params = [
256258
\Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED => '',
259+
'confirmation' => true,
260+
'confirmationMessage' => __('Are you sure you want to remove all items from your Compare Products list?'),
257261
];
258262
return $this->postHelper->getPostData($this->getClearListUrl(), $params);
259263
}

app/code/Magento/Catalog/Model/ResourceModel/Product/Option/Value.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class Value extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
3333
*/
3434
protected $_config;
3535

36+
/**
37+
* @var \Magento\Framework\Locale\FormatInterface
38+
*/
39+
private $localeFormat;
40+
3641
/**
3742
* Class constructor
3843
*
@@ -91,8 +96,9 @@ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
9196
protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $object)
9297
{
9398
$priceTable = $this->getTable('catalog_product_option_type_price');
99+
$formattedPrice = $this->getLocaleFormatter()->getNumber($object->getPrice());
94100

95-
$price = (double)sprintf('%F', $object->getPrice());
101+
$price = (double)sprintf('%F', $formattedPrice);
96102
$priceType = $object->getPriceType();
97103

98104
if ($object->getPrice() && $priceType) {
@@ -410,4 +416,19 @@ public function duplicate(\Magento\Catalog\Model\Product\Option\Value $object, $
410416

411417
return $object;
412418
}
419+
420+
/**
421+
* Get FormatInterface to convert price from string to number format
422+
*
423+
* @return \Magento\Framework\Locale\FormatInterface
424+
* @deprecated
425+
*/
426+
private function getLocaleFormatter()
427+
{
428+
if ($this->localeFormat === null) {
429+
$this->localeFormat = \Magento\Framework\App\ObjectManager::getInstance()
430+
->get(\Magento\Framework\Locale\FormatInterface::class);
431+
}
432+
return $this->localeFormat;
433+
}
413434
}

app/code/Magento/Catalog/Test/Unit/Helper/Product/CompareTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ public function testGetPostDataRemove()
115115
$removeUrl = 'catalog/product_compare/remove';
116116
$postParams = [
117117
Action::PARAM_NAME_URL_ENCODED => '',
118-
'product' => $productId
118+
'product' => $productId,
119+
'confirmation' => true,
120+
'confirmationMessage' => __('Are you sure you want to remove this item from your Compare Products list?'),
119121
];
120122

121123
//Verification
@@ -156,7 +158,9 @@ public function testGetPostDataClearList()
156158
//Data
157159
$clearUrl = 'catalog/product_compare/clear';
158160
$postParams = [
159-
Action::PARAM_NAME_URL_ENCODED => ''
161+
Action::PARAM_NAME_URL_ENCODED => '',
162+
'confirmation' => true,
163+
'confirmationMessage' => __('Are you sure you want to remove all items from your Compare Products list?'),
160164
];
161165

162166
//Verification

app/code/Magento/Catalog/view/frontend/requirejs-config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
var config = {
77
map: {
88
'*': {
9-
compareItems: 'Magento_Catalog/js/compare',
109
compareList: 'Magento_Catalog/js/list',
1110
relatedProducts: 'Magento_Catalog/js/related-products',
1211
upsellProducts: 'Magento_Catalog/js/upsell-products',

app/code/Magento/Catalog/view/frontend/web/js/compare.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

app/code/Magento/Catalog/view/frontend/web/js/view/compare-products.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,32 @@
22
* Copyright © 2016 Magento. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5+
56
define([
67
'uiComponent',
78
'Magento_Customer/js/customer-data',
8-
'mage/translate'
9-
], function (Component, customerData) {
9+
'jquery',
10+
'mage/mage',
11+
'mage/decorate'
12+
], function (Component, customerData, $) {
1013
'use strict';
1114

1215
var sidebarInitialized = false;
1316

17+
/**
18+
* Initialize sidebar
19+
*/
1420
function initSidebar() {
1521
if (sidebarInitialized) {
1622
return;
1723
}
18-
sidebarInitialized = true;
19-
require([
20-
'jquery',
21-
'mage/mage'
22-
], function ($) {
23-
/*eslint-disable max-len*/
24-
$('[data-role=compare-products-sidebar]').mage('compareItems', {
25-
'removeConfirmMessage': $.mage.__('Are you sure you want to remove this item from your Compare Products list?'),
26-
'removeSelector': '#compare-items a.action.delete',
27-
'clearAllConfirmMessage': $.mage.__('Are you sure you want to remove all items from your Compare Products list?'),
28-
'clearAllSelector': '#compare-clear-all'
29-
});
3024

31-
/*eslint-enable max-len*/
32-
});
25+
sidebarInitialized = true;
26+
$('[data-role=compare-products-sidebar]').decorate('list', true);
3327
}
3428

3529
return Component.extend({
30+
/** @inheritdoc */
3631
initialize: function () {
3732
this._super();
3833
this.compareProducts = customerData.get('compare-products');

app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,25 +151,28 @@ public function collectRates(RateRequest $request)
151151
$request->setPackageQty($oldQty);
152152

153153
if (!empty($rate) && $rate['price'] >= 0) {
154-
/** @var \Magento\Quote\Model\Quote\Address\RateResult\Method $method */
155-
$method = $this->_resultMethodFactory->create();
156-
157-
$method->setCarrier('tablerate');
158-
$method->setCarrierTitle($this->getConfigData('title'));
159-
160-
$method->setMethod('bestway');
161-
$method->setMethodTitle($this->getConfigData('name'));
162-
163154
if ($request->getFreeShipping() === true || $request->getPackageQty() == $freeQty) {
164155
$shippingPrice = 0;
165156
} else {
166157
$shippingPrice = $this->getFinalPriceWithHandlingFee($rate['price']);
167158
}
168-
169-
$method->setPrice($shippingPrice);
170-
$method->setCost($rate['cost']);
171-
159+
$method = $this->createShippingMethod($shippingPrice, $rate['cost']);
172160
$result->append($method);
161+
} elseif (empty($rate) && $request->getFreeShipping() === true || $request->getPackageQty() == $freeQty) {
162+
163+
/**
164+
* Promotion rule was applied for the whole cart.
165+
* In this case all other shipping methods could be omitted
166+
* Table rate shipping method with 0$ price must be shown if grand total is more than minimal value.
167+
* Free package weight has been already taken into account.
168+
*/
169+
$request->setPackageValue($freePackageValue);
170+
$request->setPackageQty($freeQty);
171+
$rate = $this->getRate($request);
172+
if (!empty($rate) && $rate['price'] >= 0) {
173+
$method = $this->createShippingMethod(0, 0);
174+
$result->append($method);
175+
}
173176
} else {
174177
/** @var \Magento\Quote\Model\Quote\Address\RateResult\Error $error */
175178
$error = $this->_rateErrorFactory->create(
@@ -241,4 +244,27 @@ public function getAllowedMethods()
241244
{
242245
return ['bestway' => $this->getConfigData('name')];
243246
}
247+
248+
/**
249+
* Get the method object based on the shipping price and cost
250+
*
251+
* @param float $shippingPrice
252+
* @param float $cost
253+
* @return \Magento\Quote\Model\Quote\Address\RateResult\Method
254+
*/
255+
private function createShippingMethod($shippingPrice, $cost)
256+
{
257+
/** @var \Magento\Quote\Model\Quote\Address\RateResult\Method $method */
258+
$method = $this->_resultMethodFactory->create();
259+
260+
$method->setCarrier('tablerate');
261+
$method->setCarrierTitle($this->getConfigData('title'));
262+
263+
$method->setMethod('bestway');
264+
$method->setMethodTitle($this->getConfigData('name'));
265+
266+
$method->setPrice($shippingPrice);
267+
$method->setCost($cost);
268+
return $method;
269+
}
244270
}

app/code/Magento/Review/Test/Unit/Ui/DataProvider/Product/Form/Modifier/ReviewTest.php

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Magento\Catalog\Test\Unit\Ui\DataProvider\Product\Form\Modifier\AbstractModifierTest;
99
use Magento\Framework\UrlInterface;
1010
use Magento\Review\Ui\DataProvider\Product\Form\Modifier\Review;
11+
use Magento\Framework\Module\Manager as ModuleManager;
12+
use Magento\Ui\DataProvider\Modifier\ModifierInterface;
1113

1214
/**
1315
* Class ReviewTest
@@ -19,36 +21,73 @@ class ReviewTest extends AbstractModifierTest
1921
*/
2022
protected $urlBuilderMock;
2123

24+
/**
25+
* @var \PHPUnit_Framework_MockObject_MockObject
26+
*/
27+
private $moduleManagerMock;
28+
2229
protected function setUp()
2330
{
2431
parent::setUp();
2532
$this->urlBuilderMock = $this->getMockBuilder(UrlInterface::class)
2633
->getMockForAbstractClass();
34+
$this->moduleManagerMock = $this->getMock(ModuleManager::class, [], [], '', false);
2735
}
2836

37+
/**
38+
* @return ModifierInterface
39+
*/
2940
protected function createModel()
3041
{
31-
return $this->objectManager->getObject(Review::class, [
42+
$model = $this->objectManager->getObject(Review::class, [
3243
'locator' => $this->locatorMock,
3344
'urlBuilder' => $this->urlBuilderMock,
3445
]);
46+
47+
$reviewClass = new \ReflectionClass(Review::class);
48+
$moduleManagerProperty = $reviewClass->getProperty('moduleManager');
49+
$moduleManagerProperty->setAccessible(true);
50+
$moduleManagerProperty->setValue(
51+
$model,
52+
$this->moduleManagerMock
53+
);
54+
55+
return $model;
3556
}
3657

37-
public function testModifyMetaToBeEmpty()
58+
public function testModifyMetaDoesNotAddReviewSectionForNewProduct()
59+
{
60+
$this->productMock->expects($this->once())
61+
->method('getId');
62+
63+
$this->assertSame([], $this->getModel()->modifyMeta([]));
64+
}
65+
66+
public function testModifyMetaDoesNotAddReviewSectionIfReviewModuleOutputIsDisabled()
3867
{
3968
$this->productMock->expects($this->once())
4069
->method('getId')
41-
->willReturn(0);
70+
->willReturn(1);
71+
72+
$this->moduleManagerMock->expects($this->any())
73+
->method('isOutputEnabled')
74+
->with('Magento_Review')
75+
->willReturn(false);
4276

4377
$this->assertSame([], $this->getModel()->modifyMeta([]));
4478
}
4579

46-
public function testModifyMeta()
80+
public function testModifyMetaAddsReviewSectionForExistingProductIfReviewModuleOutputIsEnabled()
4781
{
4882
$this->productMock->expects($this->once())
4983
->method('getId')
5084
->willReturn(1);
5185

86+
$this->moduleManagerMock->expects($this->any())
87+
->method('isOutputEnabled')
88+
->with('Magento_Review')
89+
->willReturn(true);
90+
5291
$this->assertArrayHasKey(Review::GROUP_REVIEW, $this->getModel()->modifyMeta([]));
5392
}
5493

app/code/Magento/Review/Ui/DataProvider/Product/Form/Modifier/Review.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
1313
use Magento\Ui\Component\Form;
1414
use Magento\Framework\UrlInterface;
15+
use Magento\Framework\Module\Manager as ModuleManager;
16+
use Magento\Framework\App\ObjectManager;
1517

1618
/**
1719
* Class Review
@@ -34,6 +36,11 @@ class Review extends AbstractModifier
3436
*/
3537
protected $urlBuilder;
3638

39+
/**
40+
* @var ModuleManager
41+
*/
42+
private $moduleManager;
43+
3744
/**
3845
* @param LocatorInterface $locator
3946
* @param UrlInterface $urlBuilder
@@ -51,7 +58,7 @@ public function __construct(
5158
*/
5259
public function modifyMeta(array $meta)
5360
{
54-
if (!$this->locator->getProduct()->getId()) {
61+
if (!$this->locator->getProduct()->getId() || !$this->getModuleManager()->isOutputEnabled('Magento_Review')) {
5562
return $meta;
5663
}
5764

@@ -114,4 +121,19 @@ public function modifyData(array $data)
114121

115122
return $data;
116123
}
124+
125+
/**
126+
* Retrieve module manager instance using dependency lookup to keep this class backward compatible.
127+
*
128+
* @return ModuleManager
129+
*
130+
* @deprecated
131+
*/
132+
private function getModuleManager()
133+
{
134+
if ($this->moduleManager === null) {
135+
$this->moduleManager = ObjectManager::getInstance()->get(ModuleManager::class);
136+
}
137+
return $this->moduleManager;
138+
}
117139
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
/** @var \Magento\Sales\Block\Adminhtml\Order\Create\Form $block */
1010
?>
11-
<form id="edit_form" data-order-config='<?php /* @escapeNotVerified */ echo $block->getOrderDataJson() ?>' data-load-base-url="<?php /* @escapeNotVerified */ echo $block->getLoadBlockUrl() ?>" action="<?php /* @escapeNotVerified */ echo $block->getSaveUrl() ?>" method="post" enctype="multipart/form-data">
11+
<form id="edit_form" data-order-config='<?php echo $block->escapeHtml($block->getOrderDataJson()) ?>' data-load-base-url="<?php /* @escapeNotVerified */ echo $block->getLoadBlockUrl() ?>" action="<?php /* @escapeNotVerified */ echo $block->getSaveUrl() ?>" method="post" enctype="multipart/form-data">
1212
<?php echo $block->getBlockHtml('formkey')?>
1313
<div id="order-message">
1414
<?php echo $block->getChildHtml('message') ?>

0 commit comments

Comments
 (0)