Skip to content

Commit 8c33f94

Browse files
author
Alexander Akimov
authored
Merge pull request #345 from magento-folks/bugfix
[Folks] Bug Fixing Fixes: - Select box shown per page in customer's my account pages is not visible - JS validation errors are displayed not per option groups for Product with custom options on create Order Admin page - JS validation is absent if Merchant does not specify Shipping Method while creating Order in Admin - Wrong initialization sequence in mage.priceBox widget - Issues with minicart in multiwebsite - Selected category is not added to Cart Price Rule condition due to JS error - Coupon code override cart rules with no coupon code
2 parents 21d4316 + 6af30d6 commit 8c33f94

File tree

18 files changed

+73
-61
lines changed

18 files changed

+73
-61
lines changed

app/code/Magento/Catalog/view/base/web/js/price-box.js

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright © 2016 Magento. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5+
56
define([
67
'jquery',
78
'Magento_Catalog/js/price-utils',
@@ -29,6 +30,7 @@ define([
2930
*/
3031
_init: function initPriceBox() {
3132
var box = this.element;
33+
3234
box.trigger('updatePrice');
3335
this.cache.displayPrices = utils.deepClone(this.options.prices);
3436
},
@@ -70,7 +72,8 @@ define([
7072
updatePrice: function updatePrice(newPrices) {
7173
var prices = this.cache.displayPrices,
7274
additionalPrice = {},
73-
pricesCode = [];
75+
pricesCode = [],
76+
priceValue, origin, finalPrice;
7477

7578
this.cache.additionalPriceObject = this.cache.additionalPriceObject || {};
7679

@@ -89,19 +92,19 @@ define([
8992
pricesCode = _.keys(additional);
9093
}
9194
_.each(pricesCode, function (priceCode) {
92-
var priceValue = additional[priceCode] || {};
95+
priceValue = additional[priceCode] || {};
9396
priceValue.amount = +priceValue.amount || 0;
9497
priceValue.adjustments = priceValue.adjustments || {};
9598

9699
additionalPrice[priceCode] = additionalPrice[priceCode] || {
97-
'amount': 0,
98-
'adjustments': {}
99-
};
100-
additionalPrice[priceCode].amount = 0 + (additionalPrice[priceCode].amount || 0)
101-
+ priceValue.amount;
100+
'amount': 0,
101+
'adjustments': {}
102+
};
103+
additionalPrice[priceCode].amount = 0 + (additionalPrice[priceCode].amount || 0) +
104+
priceValue.amount;
102105
_.each(priceValue.adjustments, function (adValue, adCode) {
103-
additionalPrice[priceCode].adjustments[adCode] = 0
104-
+ (additionalPrice[priceCode].adjustments[adCode] || 0) + adValue;
106+
additionalPrice[priceCode].adjustments[adCode] = 0 +
107+
(additionalPrice[priceCode].adjustments[adCode] || 0) + adValue;
105108
});
106109
});
107110
});
@@ -110,23 +113,24 @@ define([
110113
this.cache.displayPrices = utils.deepClone(this.options.prices);
111114
} else {
112115
_.each(additionalPrice, function (option, priceCode) {
113-
var origin = this.options.prices[priceCode] || {},
114-
final = prices[priceCode] || {};
116+
origin = this.options.prices[priceCode] || {};
117+
finalPrice = prices[priceCode] || {};
115118
option.amount = option.amount || 0;
116119
origin.amount = origin.amount || 0;
117120
origin.adjustments = origin.adjustments || {};
118-
final.adjustments = final.adjustments || {};
121+
finalPrice.adjustments = finalPrice.adjustments || {};
119122

120-
final.amount = 0 + origin.amount + option.amount;
123+
finalPrice.amount = 0 + origin.amount + option.amount;
121124
_.each(option.adjustments, function (pa, paCode) {
122-
final.adjustments[paCode] = 0 + (origin.adjustments[paCode] || 0) + pa;
125+
finalPrice.adjustments[paCode] = 0 + (origin.adjustments[paCode] || 0) + pa;
123126
});
124127
}, this);
125128
}
126129

127130
this.element.trigger('reloadPrice');
128131
},
129132

133+
/*eslint-disable no-extra-parens*/
130134
/**
131135
* Render price unit block.
132136
*/
@@ -135,16 +139,19 @@ define([
135139
priceTemplate = mageTemplate(this.options.priceTemplate);
136140

137141
_.each(this.cache.displayPrices, function (price, priceCode) {
138-
price.final = _.reduce(price.adjustments, function(memo, amount) {
142+
price.final = _.reduce(price.adjustments, function (memo, amount) {
139143
return memo + amount;
140144
}, price.amount);
141145

142146
price.formatted = utils.formatPrice(price.final, priceFormat);
143147

144-
$('[data-price-type="' + priceCode + '"]', this.element).html(priceTemplate({data: price}));
148+
$('[data-price-type="' + priceCode + '"]', this.element).html(priceTemplate({
149+
data: price
150+
}));
145151
}, this);
146152
},
147153

154+
/*eslint-enable no-extra-parens*/
148155
/**
149156
* Overwrites initial (default) prices object.
150157
* @param {Object} prices
@@ -177,6 +184,7 @@ define([
177184
var box = this.element,
178185
priceHolders = $('[data-price-type]', box),
179186
prices = this.options.prices;
187+
180188
this.options.productId = box.data('productId');
181189

182190
if (_.isEmpty(prices)) {
@@ -199,10 +207,7 @@ define([
199207
_setDefaultsFromPriceConfig: function _setDefaultsFromPriceConfig() {
200208
var config = this.options.priceConfig;
201209

202-
if (config) {
203-
if (+config.productId !== +this.options.productId) {
204-
return;
205-
}
210+
if (config && config.prices) {
206211
this.options.prices = config.prices;
207212
}
208213
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ define([
9797
addToCartCalls++;
9898
self.isLoading(true);
9999
});
100-
101-
if (cartData().websiteId !== window.checkout.websiteId) {
100+
if (cartData().website_id !== window.checkout.websiteId) {
102101
customerData.reload(['cart'], false);
103102
}
104103

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<?php /** @var $block \Magento\Sales\Block\Adminhtml\Order\Create\Shipping\Method\Form */ ?>
1111
<?php $_shippingRateGroups = $block->getShippingRates(); ?>
1212
<?php if ($_shippingRateGroups): ?>
13-
<div id="order-shipping-method-choose" style="display:none">
13+
<div id="order-shipping-method-choose" class="control" style="display:none">
1414
<dl class="admin__order-shipment-methods">
1515
<?php foreach ($_shippingRateGroups as $code => $_rates): ?>
1616
<dt class="admin__order-shipment-methods-title"><?php echo $block->escapeHtml($block->getCarrierName($code)) ?></dt>
@@ -30,7 +30,7 @@
3030
<?php $_checked = $block->isMethodActive($_code) ? 'checked="checked"' : '' ?>
3131
<input <?php /* @escapeNotVerified */ echo $_radioProperty ?> value="<?php /* @escapeNotVerified */ echo $_code ?>"
3232
id="s_method_<?php /* @escapeNotVerified */ echo $_code ?>" <?php /* @escapeNotVerified */ echo $_checked ?>
33-
class="admin__control-radio"/>
33+
class="admin__control-radio required-entry"/>
3434
<label class="admin__field-label" for="s_method_<?php /* @escapeNotVerified */ echo $_code ?>">
3535
<?php echo $block->escapeHtml($_rate->getMethodTitle() ? $_rate->getMethodTitle() : $_rate->getMethodDescription()) ?> -
3636
<strong>

app/code/Magento/SalesRule/Block/Adminhtml/Promo/Quote/Edit/Tab/Actions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ protected function addTabToForm($model, $fieldsetId = 'actions_fieldset', $formN
176176
$actionsFieldSetId = $model->getActionsFieldSetId($formName);
177177

178178
$newChildUrl = $this->getUrl(
179-
'sales_rule/promo_quote/newActionHtml/form/rule_actions_fieldset_' . $actionsFieldSetId,
179+
'sales_rule/promo_quote/newActionHtml/form/' . $actionsFieldSetId,
180180
['form_namespace' => $formName]
181181
);
182182

app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Edit.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ public function execute()
5555
$this->_redirect('sales_rule/*');
5656
return;
5757
}
58+
$model->getConditions()->setFormName('sales_rule_form');
59+
$model->getConditions()->setJsFormObject(
60+
$model->getConditionsFieldSetId($model->getConditions()->getFormName())
61+
);
62+
$model->getActions()->setFormName('sales_rule_form');
63+
$model->getActions()->setJsFormObject(
64+
$model->getActionsFieldSetId($model->getActions()->getFormName())
65+
);
5866

5967
$resultPage->getLayout()->getBlock('promo_sales_rule_edit_tab_coupons')->setCanShow(true);
6068
}
@@ -65,15 +73,6 @@ public function execute()
6573
$model->addData($data);
6674
}
6775

68-
$model->getConditions()->setFormName('sales_rule_form');
69-
$model->getConditions()->setJsFormObject(
70-
$model->getConditionsFieldSetId($model->getConditions()->getFormName())
71-
);
72-
$model->getActions()->setFormName('sales_rule_form');
73-
$model->getActions()->setJsFormObject(
74-
$model->getActionsFieldSetId($model->getActions()->getFormName())
75-
);
76-
7776
$this->_initAction();
7877

7978
$this->_addBreadcrumb($id ? __('Edit Rule') : __('New Rule'), $id ? __('Edit Rule') : __('New Rule'));

app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/NewActionHtml.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class NewActionHtml extends \Magento\SalesRule\Controller\Adminhtml\Promo\Quote
1616
public function execute()
1717
{
1818
$id = $this->getRequest()->getParam('id');
19-
$formName = $this->getRequest()->getParam('form_namespace');
19+
$formName = $this->getRequest()->getParam('form');
2020
$typeArr = explode('|', str_replace('-', '/', $this->getRequest()->getParam('type')));
2121
$type = $typeArr[0];
2222

app/code/Magento/SalesRule/Model/ResourceModel/Rule/Collection.php

Lines changed: 14 additions & 9 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\SalesRule\Model\ResourceModel\Rule;
108

119
use Magento\Quote\Model\Quote\Address;
@@ -153,11 +151,12 @@ public function setValidationFilter(
153151
['code']
154152
);
155153

154+
$noCouponWhereCondition = $connection->quoteInto(
155+
'main_table.coupon_type = ? ',
156+
\Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON
157+
);
158+
156159
$orWhereConditions = [
157-
$connection->quoteInto(
158-
'main_table.coupon_type = ? ',
159-
\Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON
160-
),
161160
$connection->quoteInto(
162161
'(main_table.coupon_type = ? AND rule_coupons.type = 0)',
163162
\Magento\SalesRule\Model\Rule::COUPON_TYPE_AUTO
@@ -186,7 +185,9 @@ public function setValidationFilter(
186185
$orWhereCondition = implode(' OR ', $orWhereConditions);
187186
$andWhereCondition = implode(' AND ', $andWhereConditions);
188187

189-
$select->where('(' . $orWhereCondition . ') AND ' . $andWhereCondition);
188+
$select->where(
189+
$noCouponWhereCondition . ' OR ((' . $orWhereCondition . ') AND ' . $andWhereCondition . ')'
190+
);
190191
} else {
191192
$this->addFieldToFilter(
192193
'main_table.coupon_type',
@@ -214,7 +215,7 @@ public function setValidationFilter(
214215
public function addWebsiteGroupDateFilter($websiteId, $customerGroupId, $now = null)
215216
{
216217
if (!$this->getFlag('website_group_date_filter')) {
217-
if (is_null($now)) {
218+
if ($now === null) {
218219
$now = $this->_date->date()->format('Y-m-d');
219220
}
220221

@@ -277,7 +278,11 @@ public function addAttributeInConditionFilter($attributeCode)
277278
$field = $this->_getMappedField('actions_serialized');
278279
$aCond = $this->_getConditionSql($field, ['like' => $match]);
279280

280-
$this->getSelect()->where(sprintf('(%s OR %s)', $cCond, $aCond), null, \Magento\Framework\DB\Select::TYPE_CONDITION);
281+
$this->getSelect()->where(
282+
sprintf('(%s OR %s)', $cCond, $aCond),
283+
null,
284+
\Magento\Framework\DB\Select::TYPE_CONDITION
285+
);
281286

282287
return $this;
283288
}

app/code/Magento/SalesRule/Model/Rule/Condition/Product/Combine.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public function getNewChildSelectOptions()
4242
foreach ($productAttributes as $code => $label) {
4343
if (strpos($code, 'quote_item_') === 0) {
4444
$iAttributes[] = [
45-
'value' => \Magento\SalesRule\Model\Rule\Condition\Product::class . $code,
45+
'value' => \Magento\SalesRule\Model\Rule\Condition\Product::class . '|' . $code,
4646
'label' => $label,
4747
];
4848
} else {
4949
$pAttributes[] = [
50-
'value' => \Magento\SalesRule\Model\Rule\Condition\Product::class . $code,
50+
'value' => \Magento\SalesRule\Model\Rule\Condition\Product::class . '|' . $code,
5151
'label' => $label,
5252
];
5353
}

app/design/adminhtml/Magento/backend/Magento_Sales/web/css/source/module/order/_payment-shipping.less

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@
7575
}
7676
}
7777

78+
.order-shipping-method {
79+
.admin__page-section-title > span {
80+
&:extend(.validation-symbol all);
81+
}
82+
}
83+
7884
.shipping-description-wrapper {
7985
.price {
8086
font-weight: @font-weight__bold;

app/design/adminhtml/Magento/backend/web/css/source/forms/_fields.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@
227227
._required > & {
228228
> span {
229229
&:after {
230-
color: @field-label__required__color;
230+
color: @validation__color;
231231
content: '*';
232232
display: inline-block;
233233
font-size: @font-size__l;

app/design/adminhtml/Magento/backend/web/css/source/forms/fields/_control-table.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
&._required {
132132
span {
133133
&:after {
134-
color: @field-label__required__color;
134+
color: @validation__color;
135135
content: '*';
136136
}
137137
}

app/design/adminhtml/Magento/backend/web/css/source/variables/_forms.less

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
@field-label__disabled__color: @color-gray65-almost;
1717
@field-label__font-size: @font-size__base;
1818
@field-label__line-height: @line-height__s;
19-
@field-label__required__color: @color-phoenix;
2019
@field-note__color: @color-very-dark-gray-black;
2120
@field-note__font-size: @font-size__s;
2221
@field-scope__color: @color-dark-gray;
@@ -69,7 +68,6 @@
6968

7069
@field-label__indent: 1rem;
7170
@field-label__disabled__color: @color-gray60;
72-
@field-label__required__color: @color-phoenix;
7371

7472
@field-collapsible__border-color: @color-gray80;
7573

app/design/adminhtml/Magento/backend/web/css/styles-old.less

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

14131413
span {
14141414
&:after {
1415-
color: #eb5202;
1415+
color: #e22626;
14161416
content: '*';
14171417
display: inline-block;
14181418
font-size: 1.6rem;

app/design/frontend/Magento/blank/Magento_Catalog/web/css/source/module/_toolbar.less

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@
5050
}
5151

5252
.limiter {
53-
display: none;
54-
5553
.control {
5654
display: inline-block;
5755
}

app/design/frontend/Magento/luma/Magento_Catalog/web/css/source/module/_toolbar.less

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@
115115
}
116116

117117
.limiter {
118-
display: none;
119-
120118
&-options {
121119
margin: 0 5px 0 7px;
122120
width: auto;

dev/tests/integration/testsuite/Magento/SalesRule/Model/ResourceModel/Rule/CollectionTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ public function testSetValidationFilter($couponCode, $expectedItems)
4242
public function setValidationFilterDataProvider()
4343
{
4444
return [
45-
'Check type COUPON' => ['coupon_code', ['#1', '#5']],
45+
'Check type COUPON' => ['coupon_code', ['#1', '#2', '#5']],
4646
'Check type NO_COUPON' => ['', ['#2', '#5']],
47-
'Check type COUPON_AUTO' => ['coupon_code_auto', ['#4', '#5']],
48-
'Check result with auto generated coupon' => ['autogenerated_3_1', ['#3', '#5']],
47+
'Check type COUPON_AUTO' => ['coupon_code_auto', ['#2', '#4', '#5']],
48+
'Check result with auto generated coupon' => ['autogenerated_3_1', ['#2', '#3', '#5']],
4949
'Check result with non actual previously generated coupon' => [
5050
'autogenerated_2_1',
5151
['#2', '#5'],
5252
],
53-
'Check result with wrong code' => ['wrong_code', ['#5']]
53+
'Check result with wrong code' => ['wrong_code', ['#2', '#5']]
5454
];
5555
}
5656

dev/tests/static/testsuite/Magento/Test/Js/_files/blacklist/magento.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ app/code/Magento/Catalog/view/adminhtml/web/js/category-tree.js
3434
app/code/Magento/Catalog/view/adminhtml/web/js/custom-options.js
3535
app/code/Magento/Catalog/view/adminhtml/web/js/new-category-dialog.js
3636
app/code/Magento/Catalog/view/adminhtml/web/js/product-gallery.js
37-
app/code/Magento/Catalog/view/base/web/js/price-box.js
3837
app/code/Magento/Catalog/view/base/web/js/price-option-date.js
3938
app/code/Magento/Catalog/view/base/web/js/price-option-file.js
4039
app/code/Magento/Catalog/view/base/web/js/price-options.js

lib/web/mage/validation.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,12 @@
15131513
}
15141514
//logic for checkboxes/radio
15151515
if (element.is(':checkbox') || element.is(':radio')) {
1516-
errorPlacement = element.siblings('label').last();
1516+
errorPlacement = element.parents('.control').children().last();
1517+
1518+
//fallback if group does not have .control parent
1519+
if (!errorPlacement.length) {
1520+
errorPlacement = element.siblings('label').last();
1521+
}
15171522
}
15181523
//logic for control with tooltip
15191524
if (element.siblings('.tooltip').length) {

0 commit comments

Comments
 (0)