Skip to content

Commit 500727c

Browse files
author
Stanislav Idolov
committed
MAGETWO-53793: Minicart Maximum Display Recently Added Item is broken #4750
1 parent 32eda5c commit 500727c

File tree

4 files changed

+84
-41
lines changed

4 files changed

+84
-41
lines changed

app/code/Magento/Checkout/Block/Cart/Sidebar.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@
1313
class Sidebar extends AbstractCart
1414
{
1515
/**
16-
* Xml pah to checkout sidebar count value
16+
* Xml pah to checkout sidebar display value
1717
*/
1818
const XML_PATH_CHECKOUT_SIDEBAR_DISPLAY = 'checkout/sidebar/display';
1919

20+
/**
21+
* Xml pah to checkout sidebar count value
22+
*/
23+
const XML_PATH_CHECKOUT_SIDEBAR_COUNT = 'checkout/sidebar/count';
24+
2025
/**
2126
* @var \Magento\Catalog\Helper\Image
2227
*/
@@ -63,7 +68,8 @@ public function getConfig()
6368
'updateItemQtyUrl' => $this->getUpdateItemQtyUrl(),
6469
'removeItemUrl' => $this->getRemoveItemUrl(),
6570
'imageTemplate' => $this->getImageHtmlTemplate(),
66-
'baseUrl' => $this->getBaseUrl()
71+
'baseUrl' => $this->getBaseUrl(),
72+
'minicartMaxItemsVisible' => $this->getMiniCartMaxItemsCount()
6773
];
6874
}
6975

@@ -171,4 +177,15 @@ public function getBaseUrl()
171177
{
172178
return $this->_storeManager->getStore()->getBaseUrl();
173179
}
180+
181+
/**
182+
* Return max visible item count for minicart
183+
*
184+
* @codeCoverageIgnore
185+
* @return int
186+
*/
187+
protected function getMiniCartMaxItemsCount()
188+
{
189+
return (int)$this->_scopeConfig->getValue('checkout/sidebar/count', ScopeInterface::SCOPE_STORE);
190+
}
174191
}

app/code/Magento/Checkout/Test/Unit/Block/Cart/SidebarTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ public function testGetConfig()
138138
'updateItemQtyUrl' => $updateItemQtyUrl,
139139
'removeItemUrl' => $removeItemUrl,
140140
'imageTemplate' => $imageTemplate,
141-
'baseUrl' => $baseUrl
141+
'baseUrl' => $baseUrl,
142+
'minicartMaxItemsVisible' => 3
142143
];
143144

144145
$valueMap = [
@@ -159,6 +160,13 @@ public function testGetConfig()
159160
$storeMock->expects($this->once())->method('getBaseUrl')->willReturn($baseUrl);
160161
$this->imageHelper->expects($this->once())->method('getFrame')->willReturn(false);
161162

163+
$this->scopeConfigMock->expects($this->once())
164+
->method('getValue')
165+
->with(
166+
\Magento\Checkout\Block\Cart\Sidebar::XML_PATH_CHECKOUT_SIDEBAR_COUNT,
167+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
168+
)->willReturn(3);
169+
162170
$this->assertEquals($expectedResult, $this->model->getConfig());
163171
}
164172

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ define([
1919
$.widget('mage.sidebar', {
2020
options: {
2121
isRecursive: true,
22-
maxItemsVisible: 3
22+
minicart: {
23+
maxItemsVisible: 3
24+
}
2325
},
2426
scrollHeight: 0,
2527

@@ -240,7 +242,7 @@ define([
240242
_calcHeight: function () {
241243
var self = this,
242244
height = 0,
243-
counter = this.options.maxItemsVisible,
245+
counter = this.options.minicart.maxItemsVisible,
244246
target = $(this.options.minicart.list),
245247
outerHeight;
246248

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

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,57 +12,63 @@ define([
1212
], function (Component, customerData, $, ko, _) {
1313
'use strict';
1414

15-
var sidebarInitialized = false;
16-
var addToCartCalls = 0;
15+
var sidebarInitialized = false,
16+
addToCartCalls = 0,
17+
miniCart;
1718

18-
var minicart = $("[data-block='minicart']");
19-
minicart.on('dropdowndialogopen', function () {
19+
miniCart = $('[data-block=\'minicart\']');
20+
miniCart.on('dropdowndialogopen', function () {
2021
initSidebar();
2122
});
2223

24+
/**
25+
* @return {Boolean}
26+
*/
2327
function initSidebar() {
24-
if (minicart.data('mageSidebar')) {
25-
minicart.sidebar('update');
28+
if (miniCart.data('mageSidebar')) {
29+
miniCart.sidebar('update');
2630
}
2731

2832
if (!$('[data-role=product-item]').length) {
2933
return false;
3034
}
31-
minicart.trigger('contentUpdated');
35+
miniCart.trigger('contentUpdated');
36+
3237
if (sidebarInitialized) {
3338
return false;
3439
}
3540
sidebarInitialized = true;
36-
minicart.sidebar({
37-
"targetElement": "div.block.block-minicart",
38-
"url": {
39-
"checkout": window.checkout.checkoutUrl,
40-
"update": window.checkout.updateItemQtyUrl,
41-
"remove": window.checkout.removeItemUrl,
42-
"loginUrl": window.checkout.customerLoginUrl,
43-
"isRedirectRequired": window.checkout.isRedirectRequired
41+
miniCart.sidebar({
42+
'targetElement': 'div.block.block-minicart',
43+
'url': {
44+
'checkout': window.checkout.checkoutUrl,
45+
'update': window.checkout.updateItemQtyUrl,
46+
'remove': window.checkout.removeItemUrl,
47+
'loginUrl': window.checkout.customerLoginUrl,
48+
'isRedirectRequired': window.checkout.isRedirectRequired
4449
},
45-
"button": {
46-
"checkout": "#top-cart-btn-checkout",
47-
"remove": "#mini-cart a.action.delete",
48-
"close": "#btn-minicart-close"
50+
'button': {
51+
'checkout': '#top-cart-btn-checkout',
52+
'remove': '#mini-cart a.action.delete',
53+
'close': '#btn-minicart-close'
4954
},
50-
"showcart": {
51-
"parent": "span.counter",
52-
"qty": "span.counter-number",
53-
"label": "span.counter-label"
55+
'showcart': {
56+
'parent': 'span.counter',
57+
'qty': 'span.counter-number',
58+
'label': 'span.counter-label'
5459
},
55-
"minicart": {
56-
"list": "#mini-cart",
57-
"content": "#minicart-content-wrapper",
58-
"qty": "div.items-total",
59-
"subtotal": "div.subtotal span.price"
60+
'minicart': {
61+
'list': '#mini-cart',
62+
'content': '#minicart-content-wrapper',
63+
'qty': 'div.items-total',
64+
'subtotal': 'div.subtotal span.price',
65+
'maxItemsVisible': window.checkout.minicartMaxItemsVisible
6066
},
61-
"item": {
62-
"qty": ":input.cart-item-qty",
63-
"button": ":button.update-cart-item"
67+
'item': {
68+
'qty': ':input.cart-item-qty',
69+
'button': ':button.update-cart-item'
6470
},
65-
"confirmMessage": $.mage.__(
71+
'confirmMessage': $.mage.__(
6672
'Are you sure you would like to remove this item from the shopping cart?'
6773
)
6874
});
@@ -87,7 +93,7 @@ define([
8793
this.update(updatedCart);
8894
initSidebar();
8995
}, this);
90-
$('[data-block="minicart"]').on('contentLoading', function(event) {
96+
$('[data-block="minicart"]').on('contentLoading', function (event) {
9197
addToCartCalls++;
9298
self.isLoading(true);
9399
});
@@ -96,14 +102,24 @@ define([
96102
},
97103
isLoading: ko.observable(false),
98104
initSidebar: initSidebar,
99-
closeSidebar: function() {
105+
106+
/**
107+
* @return {Boolean}
108+
*/
109+
closeSidebar: function () {
100110
var minicart = $('[data-block="minicart"]');
101-
minicart.on('click', '[data-action="close"]', function(event) {
111+
minicart.on('click', '[data-action="close"]', function (event) {
102112
event.stopPropagation();
103-
minicart.find('[data-role="dropdownDialog"]').dropdownDialog("close");
113+
minicart.find('[data-role="dropdownDialog"]').dropdownDialog('close');
104114
});
115+
105116
return true;
106117
},
118+
119+
/**
120+
* @param {String} productType
121+
* @return {*|String}
122+
*/
107123
getItemRenderer: function (productType) {
108124
return this.itemRenderer[productType] || 'defaultRenderer';
109125
},

0 commit comments

Comments
 (0)