Skip to content

Commit 1a9a75f

Browse files
authored
Merge pull request #1135 from magento-engcom/develop-prs
[EngCom] Public Pull Requests
2 parents 85def59 + c3059d6 commit 1a9a75f

File tree

5 files changed

+119
-16
lines changed

5 files changed

+119
-16
lines changed

app/code/Magento/Cms/Block/Page.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,26 @@ protected function _prepareLayout()
126126
*/
127127
protected function _addBreadcrumbs(\Magento\Cms\Model\Page $page)
128128
{
129+
$homePageIdentifier = $this->_scopeConfig->getValue(
130+
'web/default/cms_home_page',
131+
ScopeInterface::SCOPE_STORE
132+
);
133+
$homePageDelimiterPosition = strrpos($homePageIdentifier, '|');
134+
if ($homePageDelimiterPosition) {
135+
$homePageIdentifier = substr($homePageIdentifier, 0, $homePageDelimiterPosition);
136+
}
137+
$noRouteIdentifier = $this->_scopeConfig->getValue(
138+
'web/default/cms_no_route',
139+
ScopeInterface::SCOPE_STORE
140+
);
141+
$noRouteDelimiterPosition = strrpos($noRouteIdentifier, '|');
142+
if ($noRouteDelimiterPosition) {
143+
$noRouteIdentifier = substr($noRouteIdentifier, 0, $noRouteDelimiterPosition);
144+
}
129145
if ($this->_scopeConfig->getValue('web/default/show_cms_breadcrumbs', ScopeInterface::SCOPE_STORE)
130146
&& ($breadcrumbsBlock = $this->getLayout()->getBlock('breadcrumbs'))
131-
&& $page->getIdentifier() !== $this->_scopeConfig->getValue(
132-
'web/default/cms_home_page',
133-
ScopeInterface::SCOPE_STORE
134-
)
135-
&& $page->getIdentifier() !== $this->_scopeConfig->getValue(
136-
'web/default/cms_no_route',
137-
ScopeInterface::SCOPE_STORE
138-
)
147+
&& $page->getIdentifier() !== $homePageIdentifier
148+
&& $page->getIdentifier() !== $noRouteIdentifier
139149
) {
140150
$breadcrumbsBlock->addCrumb(
141151
'home',

app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,16 +344,14 @@ define([
344344
_determineProductData: function () {
345345
// Check if product is in a list of products.
346346
var productId,
347-
product,
348347
isInProductView = false;
349348

350349
productId = this.element.parents('.product-item-details')
351350
.find('.price-box.price-final_price').attr('data-product-id');
352351

353352
if (!productId) {
354353
// Check individual product.
355-
product = document.getElementsByName('product')[0];
356-
productId = product ? product.value : undefined;
354+
productId = $('[name=product]').val();
357355
isInProductView = productId > 0;
358356
}
359357

lib/internal/Magento/Framework/Data/Collection.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,17 +514,29 @@ public function walk($callback, array $args = [])
514514
}
515515

516516
/**
517-
* @param string|array $objMethod
517+
* Call method or callback on each item in the collection.
518+
*
519+
* @param string|array|\Closure $objMethod
518520
* @param array $args
519521
* @return void
520522
*/
521523
public function each($objMethod, $args = [])
522524
{
523-
foreach ($args->_items as $k => $item) {
524-
$args->_items[$k] = call_user_func($objMethod, $item);
525+
if ($objMethod instanceof \Closure) {
526+
foreach ($this->getItems() as $item) {
527+
$objMethod($item, ...$args);
528+
}
529+
} elseif (is_array($objMethod)) {
530+
foreach ($this->getItems() as $item) {
531+
call_user_func($objMethod, $item, ...$args);
532+
}
533+
} else {
534+
foreach ($this->getItems() as $item) {
535+
$item->$objMethod(...$args);
536+
}
525537
}
526538
}
527-
539+
528540
/**
529541
* Setting data for all collection items
530542
*

lib/internal/Magento/Framework/Data/Test/Unit/CollectionTest.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Framework\Data\Test\Unit;
77

8+
// @codingStandardsIgnoreFile
9+
810
class CollectionTest extends \PHPUnit_Framework_TestCase
911
{
1012
/**
@@ -173,4 +175,85 @@ public function testPossibleFlowWithItem()
173175
$this->_model->removeAllItems();
174176
$this->assertEquals([], $this->_model->getItems());
175177
}
178+
179+
public function testEachCallsMethodOnEachItemWithNoArgs()
180+
{
181+
for ($i = 0; $i < 3; $i++) {
182+
$item = $this->getMock(\Magento\Framework\DataObject::class, ['testCallback']);
183+
$item->expects($this->once())->method('testCallback')->with();
184+
$this->_model->addItem($item);
185+
}
186+
$this->_model->each('testCallback');
187+
}
188+
189+
public function testEachCallsMethodOnEachItemWithArgs()
190+
{
191+
for ($i = 0; $i < 3; $i++) {
192+
$item = $this->getMock(\Magento\Framework\DataObject::class, ['testCallback']);
193+
$item->expects($this->once())->method('testCallback')->with('a', 'b', 'c');
194+
$this->_model->addItem($item);
195+
}
196+
$this->_model->each('testCallback', ['a', 'b', 'c']);
197+
}
198+
199+
public function testCallsClosureWithEachItemAndNoArgs()
200+
{
201+
for ($i = 0; $i < 3; $i++) {
202+
$item = $this->getMock(\Magento\Framework\DataObject::class, ['testCallback']);
203+
$item->expects($this->once())->method('testCallback')->with();
204+
$this->_model->addItem($item);
205+
}
206+
$this->_model->each(function ($item) {
207+
$item->testCallback();
208+
});
209+
}
210+
211+
public function testCallsClosureWithEachItemAndArgs()
212+
{
213+
for ($i = 0; $i < 3; $i++) {
214+
$item = $this->getMock(\Magento\Framework\DataObject::class, ['testItemCallback']);
215+
$item->expects($this->once())->method('testItemCallback')->with('a', 'b', 'c');
216+
$this->_model->addItem($item);
217+
}
218+
$this->_model->each(function ($item, ...$args) {
219+
$item->testItemCallback(...$args);
220+
}, ['a', 'b', 'c']);
221+
}
222+
223+
public function testCallsCallableArrayWithEachItemNoArgs()
224+
{
225+
$mockCallbackObject = $this->getMockBuilder('DummyEachCallbackInstance')
226+
->setMethods(['testObjCallback'])
227+
->getMock();
228+
$mockCallbackObject->method('testObjCallback')->willReturnCallback(function ($item, ...$args) {
229+
$item->testItemCallback(...$args);
230+
});
231+
232+
for ($i = 0; $i < 3; $i++) {
233+
$item = $this->getMock(\Magento\Framework\DataObject::class, ['testItemCallback']);
234+
$item->expects($this->once())->method('testItemCallback')->with();
235+
$this->_model->addItem($item);
236+
}
237+
238+
$this->_model->each([$mockCallbackObject, 'testObjCallback']);
239+
}
240+
241+
public function testCallsCallableArrayWithEachItemAndArgs()
242+
{
243+
$mockCallbackObject = $this->getMockBuilder('DummyEachCallbackInstance')
244+
->setMethods(['testObjCallback'])
245+
->getMock();
246+
$mockCallbackObject->method('testObjCallback')->willReturnCallback(function ($item, ...$args) {
247+
$item->testItemCallback(...$args);
248+
});
249+
250+
for ($i = 0; $i < 3; $i++) {
251+
$item = $this->getMock(\Magento\Framework\DataObject::class, ['testItemCallback']);
252+
$item->expects($this->once())->method('testItemCallback')->with('a', 'b', 'c');
253+
$this->_model->addItem($item);
254+
}
255+
256+
$callback = [$mockCallbackObject, 'testObjCallback'];
257+
$this->_model->each($callback, ['a', 'b', 'c']);
258+
}
176259
}

lib/internal/Magento/Framework/Session/SaveHandlerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
namespace Magento\Framework\Session;
99

10-
interface SaveHandlerInterface extends \Zend_Session_SaveHandler_Interface
10+
interface SaveHandlerInterface extends \SessionHandlerInterface
1111
{
1212
/**
1313
* Default session save handler

0 commit comments

Comments
 (0)