Skip to content

Commit 64fe924

Browse files
authored
Merge pull request #1303 from magento-tsg/2.1.8-develop-pr22
[TSG] Backporting for 2.1 (pr22) (2.1.8)
2 parents 3a2292e + 824d031 commit 64fe924

File tree

83 files changed

+4702
-400
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+4702
-400
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,14 @@ public function getItemsCount()
232232
{
233233
return $this->getQuote()->getItemsCount();
234234
}
235+
236+
/**
237+
* Render pagination HTML.
238+
*
239+
* @return string
240+
*/
241+
public function getPagerHtml()
242+
{
243+
return $this->getChildHtml('pager');
244+
}
235245
}
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Checkout\Block\Cart;
8+
9+
/**
10+
* Block on checkout/cart/index page to display a pager on the cart items grid.
11+
* The pager will be displayed if items quantity in the shopping cart > than number from
12+
* Store->Configuration->Sales->Checkout->Shopping Cart->Number of items to display pager and
13+
* custom_items weren't set to cart block.
14+
*/
15+
class Grid extends \Magento\Checkout\Block\Cart
16+
{
17+
/**
18+
* Config settings path to determine when pager on checkout/cart/index will be visible.
19+
*/
20+
const XPATH_CONFIG_NUMBER_ITEMS_TO_DISPLAY_PAGER = 'checkout/cart/number_items_to_display_pager';
21+
22+
/**
23+
* Quote item resource collection.
24+
*
25+
* @var \Magento\Quote\Model\ResourceModel\Quote\Item\Collection
26+
*/
27+
private $itemsCollection;
28+
29+
/**
30+
* Quote item resource collection factory.
31+
*
32+
* @var \Magento\Quote\Model\ResourceModel\Quote\Item\CollectionFactory
33+
*
34+
*/
35+
private $itemCollectionFactory;
36+
37+
/**
38+
* Join extension attributes processor.
39+
*
40+
* @var \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface
41+
*/
42+
private $joinAttributeProcessor;
43+
44+
/**
45+
* Is pager displayed on shopping cart page.
46+
*
47+
* @var bool
48+
*/
49+
private $isPagerDisplayed;
50+
51+
/**
52+
* @param \Magento\Framework\View\Element\Template\Context $context
53+
* @param \Magento\Customer\Model\Session $customerSession
54+
* @param \Magento\Checkout\Model\Session $checkoutSession
55+
* @param \Magento\Catalog\Model\ResourceModel\Url $catalogUrlBuilder
56+
* @param \Magento\Checkout\Helper\Cart $cartHelper
57+
* @param \Magento\Framework\App\Http\Context $httpContext
58+
* @param \Magento\Quote\Model\ResourceModel\Quote\Item\CollectionFactory $itemCollectionFactory
59+
* @param \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $joinProcessor
60+
* @param array $data
61+
*/
62+
public function __construct(
63+
\Magento\Framework\View\Element\Template\Context $context,
64+
\Magento\Customer\Model\Session $customerSession,
65+
\Magento\Checkout\Model\Session $checkoutSession,
66+
\Magento\Catalog\Model\ResourceModel\Url $catalogUrlBuilder,
67+
\Magento\Checkout\Helper\Cart $cartHelper,
68+
\Magento\Framework\App\Http\Context $httpContext,
69+
\Magento\Quote\Model\ResourceModel\Quote\Item\CollectionFactory $itemCollectionFactory,
70+
\Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $joinProcessor,
71+
array $data = []
72+
) {
73+
$this->itemCollectionFactory = $itemCollectionFactory;
74+
$this->joinAttributeProcessor = $joinProcessor;
75+
parent::__construct(
76+
$context,
77+
$customerSession,
78+
$checkoutSession,
79+
$catalogUrlBuilder,
80+
$cartHelper,
81+
$httpContext,
82+
$data
83+
);
84+
}
85+
86+
/**
87+
* Prepare Quote Item Product URLs.
88+
* When we don't have custom_items, items URLs will be collected for Collection limited by pager.
89+
* Pager limit on checkout/cart/index is determined by configuration.
90+
* Configuration path is Store->Configuration->Sales->Checkout->Shopping Cart->Number of items to display pager.
91+
*
92+
* @return void
93+
*/
94+
protected function _construct()
95+
{
96+
if (!$this->isPagerDisplayedOnPage()) {
97+
parent::_construct();
98+
}
99+
if ($this->hasData('template')) {
100+
$this->setTemplate($this->getData('template'));
101+
}
102+
}
103+
104+
/**
105+
* {@inheritdoc}
106+
*/
107+
protected function _prepareLayout()
108+
{
109+
parent::_prepareLayout();
110+
if ($this->isPagerDisplayedOnPage()) {
111+
$availableLimit = (int)$this->_scopeConfig->getValue(
112+
self::XPATH_CONFIG_NUMBER_ITEMS_TO_DISPLAY_PAGER,
113+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
114+
);
115+
$itemsCollection = $this->getItemsForGrid();
116+
/** @var \Magento\Theme\Block\Html\Pager $pager */
117+
$pager = $this->getLayout()->createBlock(\Magento\Theme\Block\Html\Pager::class);
118+
$pager->setAvailableLimit([$availableLimit => $availableLimit])->setCollection($itemsCollection);
119+
$this->setChild('pager', $pager);
120+
$itemsCollection->load();
121+
$this->prepareItemUrls();
122+
}
123+
124+
return $this;
125+
}
126+
127+
/**
128+
* Prepare quote items collection for pager.
129+
*
130+
* @return \Magento\Quote\Model\ResourceModel\Quote\Item\Collection
131+
*/
132+
public function getItemsForGrid()
133+
{
134+
if (!$this->itemsCollection) {
135+
/** @var \Magento\Quote\Model\ResourceModel\Quote\Item\Collection $itemCollection */
136+
$itemCollection = $this->itemCollectionFactory->create();
137+
$itemCollection->setQuote($this->getQuote());
138+
$itemCollection->addFieldToFilter('parent_item_id', ['null' => true]);
139+
$this->joinAttributeProcessor->process($itemCollection);
140+
$this->itemsCollection = $itemCollection;
141+
}
142+
143+
return $this->itemsCollection;
144+
}
145+
146+
/**
147+
* {@inheritdoc}
148+
*/
149+
public function getItems()
150+
{
151+
if (!$this->isPagerDisplayedOnPage()) {
152+
return parent::getItems();
153+
}
154+
155+
return $this->getItemsForGrid()->getItems();
156+
}
157+
158+
/**
159+
* Verify pager visibility.
160+
* If cart block has custom_items and items qty in the shopping cart < limit from stores configuration.
161+
*
162+
* @return bool
163+
*/
164+
private function isPagerDisplayedOnPage()
165+
{
166+
if (!$this->isPagerDisplayed) {
167+
$availableLimit = (int)$this->_scopeConfig->getValue(
168+
self::XPATH_CONFIG_NUMBER_ITEMS_TO_DISPLAY_PAGER,
169+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
170+
);
171+
$this->isPagerDisplayed = !$this->getCustomItems() && $availableLimit < $this->getItemsCount();
172+
}
173+
174+
return $this->isPagerDisplayed;
175+
}
176+
}

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

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@
88
use Magento\Store\Model\ScopeInterface;
99

1010
/**
11-
* Cart sidebar block
11+
* Cart sidebar block.
1212
*/
1313
class Sidebar extends AbstractCart
1414
{
1515
/**
16-
* Xml pah to checkout sidebar display value
16+
* Xml pah to checkout sidebar display value.
1717
*/
1818
const XML_PATH_CHECKOUT_SIDEBAR_DISPLAY = 'checkout/sidebar/display';
1919

2020
/**
21-
* Xml pah to checkout sidebar count value
21+
* Xml pah to checkout sidebar count value.
2222
*/
2323
const XML_PATH_CHECKOUT_SIDEBAR_COUNT = 'checkout/sidebar/count';
2424

2525
/**
26-
* @var \Magento\Catalog\Helper\Image
26+
* @var \Magento\Catalog\Helper\Image.
2727
*/
2828
protected $imageHelper;
2929

@@ -56,7 +56,7 @@ public function __construct(
5656
}
5757

5858
/**
59-
* Returns minicart config
59+
* Returns minicart config.
6060
*
6161
* @return array
6262
*/
@@ -70,7 +70,8 @@ public function getConfig()
7070
'imageTemplate' => $this->getImageHtmlTemplate(),
7171
'baseUrl' => $this->getBaseUrl(),
7272
'minicartMaxItemsVisible' => $this->getMiniCartMaxItemsCount(),
73-
'websiteId' => $this->_storeManager->getStore()->getWebsiteId()
73+
'websiteId' => $this->_storeManager->getStore()->getWebsiteId(),
74+
'maxItemsToDisplay' => $this->getMaxItemsToDisplay(),
7475
];
7576
}
7677

@@ -85,7 +86,7 @@ public function getImageHtmlTemplate()
8586
}
8687

8788
/**
88-
* Get one page checkout page url
89+
* Get one page checkout page url.
8990
*
9091
* @codeCoverageIgnore
9192
* @return string
@@ -96,7 +97,7 @@ public function getCheckoutUrl()
9697
}
9798

9899
/**
99-
* Get shopping cart page url
100+
* Get shopping cart page url.
100101
*
101102
* @return string
102103
* @codeCoverageIgnore
@@ -107,7 +108,7 @@ public function getShoppingCartUrl()
107108
}
108109

109110
/**
110-
* Get update cart item url
111+
* Get update cart item url.
111112
*
112113
* @return string
113114
* @codeCoverageIgnore
@@ -118,7 +119,7 @@ public function getUpdateItemQtyUrl()
118119
}
119120

120121
/**
121-
* Get remove cart item url
122+
* Get remove cart item url.
122123
*
123124
* @return string
124125
* @codeCoverageIgnore
@@ -129,7 +130,7 @@ public function getRemoveItemUrl()
129130
}
130131

131132
/**
132-
* Define if Mini Shopping Cart Pop-Up Menu enabled
133+
* Define if Mini Shopping Cart Pop-Up Menu enabled.
133134
*
134135
* @return bool
135136
* @codeCoverageIgnore
@@ -144,7 +145,7 @@ public function getIsNeedToDisplaySideBar()
144145
}
145146

146147
/**
147-
* Return totals from custom quote if needed
148+
* Return totals from custom quote if needed.
148149
*
149150
* @return array
150151
*/
@@ -158,7 +159,7 @@ public function getTotalsCache()
158159
}
159160

160161
/**
161-
* Retrieve subtotal block html
162+
* Retrieve subtotal block html.
162163
*
163164
* @codeCoverageIgnore
164165
* @return string
@@ -180,12 +181,26 @@ public function getBaseUrl()
180181
}
181182

182183
/**
183-
* Return max visible item count for minicart
184+
* Return max visible item count for minicart.
184185
*
185186
* @return int
186187
*/
187188
private function getMiniCartMaxItemsCount()
188189
{
189190
return (int)$this->_scopeConfig->getValue('checkout/sidebar/count', ScopeInterface::SCOPE_STORE);
190191
}
192+
193+
/**
194+
* Returns maximum cart items to display.
195+
* This setting regulates how many items will be displayed in minicart.
196+
*
197+
* @return int
198+
*/
199+
private function getMaxItemsToDisplay()
200+
{
201+
return (int)$this->_scopeConfig->getValue(
202+
'checkout/sidebar/max_items_display_count',
203+
ScopeInterface::SCOPE_STORE
204+
);
205+
}
191206
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Checkout\Model\Cart;
8+
9+
use Magento\Checkout\Model\ConfigProviderInterface;
10+
use Magento\Framework\UrlInterface;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Store\Model\ScopeInterface;
13+
14+
/**
15+
* Class CheckoutSummaryConfigProvider provides configuration for checkout summary block.
16+
*/
17+
class CheckoutSummaryConfigProvider implements ConfigProviderInterface
18+
{
19+
/**
20+
* Url builder interface.
21+
*
22+
* @var UrlInterface
23+
*/
24+
private $urlBuilder;
25+
26+
/**
27+
* Scope config data interface.
28+
*
29+
* @var ScopeConfigInterface
30+
*/
31+
private $scopeConfig;
32+
33+
/**
34+
* @param UrlInterface $urlBuilder
35+
* @param ScopeConfigInterface $scopeConfig
36+
*/
37+
public function __construct(
38+
UrlInterface $urlBuilder,
39+
ScopeConfigInterface $scopeConfig
40+
) {
41+
$this->urlBuilder = $urlBuilder;
42+
$this->scopeConfig = $scopeConfig;
43+
}
44+
45+
/**
46+
* {@inheritdoc}
47+
*/
48+
public function getConfig()
49+
{
50+
return [
51+
'maxCartItemsToDisplay' => $this->getMaxCartItemsToDisplay(),
52+
'cartUrl' => $this->urlBuilder->getUrl('checkout/cart')
53+
];
54+
}
55+
56+
/**
57+
* Returns maximum cart items to display.
58+
* This setting regulates how many items will be displayed in checkout summary block.
59+
*
60+
* @return int
61+
*/
62+
private function getMaxCartItemsToDisplay()
63+
{
64+
return (int)$this->scopeConfig->getValue(
65+
'checkout/options/max_items_display_count',
66+
ScopeInterface::SCOPE_STORE
67+
);
68+
}
69+
}

0 commit comments

Comments
 (0)