Skip to content

Commit cd4a59b

Browse files
committed
Merge branch 'develop' of github.com:magento/magento2ce into MAGETWO-68795
2 parents c4c0cf8 + 100af87 commit cd4a59b

File tree

60 files changed

+1114
-297
lines changed

Some content is hidden

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

60 files changed

+1114
-297
lines changed

app/code/Magento/Catalog/Block/Product/View/Options/Type/Date.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ public function getCalendarDateHtml()
8181
$yearStart = $this->_catalogProductOptionTypeDate->getYearStart();
8282
$yearEnd = $this->_catalogProductOptionTypeDate->getYearEnd();
8383

84+
$dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT);
85+
/** Escape RTL characters which are present in some locales and corrupt formatting */
86+
$escapedDateFormat = preg_replace('/[^MmDdYy\/\.\-]/', '', $dateFormat);
8487
$calendar = $this->getLayout()->createBlock(
8588
\Magento\Framework\View\Element\Html\Date::class
8689
)->setId(
@@ -92,7 +95,7 @@ public function getCalendarDateHtml()
9295
)->setImage(
9396
$this->getViewFileUrl('Magento_Theme::calendar.png')
9497
)->setDateFormat(
95-
$this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT)
98+
$escapedDateFormat
9699
)->setValue(
97100
$value
98101
)->setYearsRange(

app/code/Magento/Catalog/Model/Product/Option/Type/Date.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function prepareForCart()
155155

156156
if ($this->_dateExists()) {
157157
if ($this->useCalendar()) {
158-
$timestamp += (new \DateTime($value['date']))->getTimestamp();
158+
$timestamp += $this->_localeDate->date($value['date'], null, true, false)->getTimestamp();
159159
} else {
160160
$timestamp += mktime(0, 0, 0, $value['month'], $value['day'], $value['year']);
161161
}

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/AbstractModifierTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ protected function setUp()
5656
$this->productMock = $this->getMockBuilder(ProductInterface::class)
5757
->setMethods([
5858
'getId',
59+
'getTypeId',
5960
'getStoreId',
6061
'getResource',
6162
'getData',

app/code/Magento/CatalogInventory/Model/ResourceModel/Product/StockStatusBaseSelectProcessor.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ class StockStatusBaseSelectProcessor implements BaseSelectProcessorInterface
2222
*/
2323
private $resource;
2424

25+
/**
26+
* @var \Magento\CatalogInventory\Api\StockConfigurationInterface
27+
*/
28+
private $stockConfig;
29+
2530
/**
2631
* @var \Magento\Indexer\Model\ResourceModel\FrontendResource
2732
*/
@@ -30,14 +35,18 @@ class StockStatusBaseSelectProcessor implements BaseSelectProcessorInterface
3035
/**
3136
* @param ResourceConnection $resource
3237
* @param null|\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource
38+
* @param \Magento\CatalogInventory\Api\StockConfigurationInterface|null $stockConfig
3339
*/
3440
public function __construct(
3541
ResourceConnection $resource,
36-
\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource = null
42+
\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource = null,
43+
\Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfig = null
3744
) {
3845
$this->resource = $resource;
3946
$this->indexerStockFrontendResource = $indexerStockFrontendResource ?: ObjectManager::getInstance()
4047
->get(\Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource::class);
48+
$this->stockConfig = $stockConfig ?: ObjectManager::getInstance()
49+
->get(\Magento\CatalogInventory\Api\StockConfigurationInterface::class);
4150
}
4251

4352
/**
@@ -50,13 +59,15 @@ public function process(Select $select)
5059
{
5160
$stockStatusTable = $this->indexerStockFrontendResource->getMainTable();
5261

53-
/** @var Select $select */
54-
$select->join(
55-
['stock' => $stockStatusTable],
56-
sprintf('stock.product_id = %s.entity_id', BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS),
57-
[]
58-
)
59-
->where('stock.stock_status = ?', Stock::STOCK_IN_STOCK);
62+
if (!$this->stockConfig->isShowOutOfStock()) {
63+
/** @var Select $select */
64+
$select->join(
65+
['stock' => $stockStatusTable],
66+
sprintf('stock.product_id = %s.entity_id', BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS),
67+
[]
68+
)->where('stock.stock_status = ?', Stock::STOCK_IN_STOCK);
69+
}
70+
6071
return $select;
6172
}
6273
}

app/code/Magento/CatalogInventory/Model/Stock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Stock extends AbstractExtensibleModel implements StockInterface
3232
*
3333
* @var string
3434
*/
35-
protected $eventObject = 'stock';
35+
protected $_eventObject = 'stock';
3636

3737
const BACKORDERS_NO = 0;
3838

app/code/Magento/CatalogInventory/Model/Stock/Item.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Item extends AbstractExtensibleModel implements StockItemInterface
4343
*
4444
* @var string
4545
*/
46-
protected $eventObject = 'item';
46+
protected $_eventObject = 'item';
4747

4848
/**
4949
* Store model manager

app/code/Magento/CatalogInventory/Test/Unit/Model/Stock/ItemTest.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -477,33 +477,37 @@ public function getQtyIncrementsDataProvider()
477477
*
478478
* @param $eventName
479479
* @param $methodName
480+
* @param $objectName
480481
*
481482
* @dataProvider eventsDataProvider
482483
*/
483-
public function testDispatchEvents($eventName, $methodName)
484+
public function testDispatchEvents($eventName, $methodName, $objectName)
484485
{
485486
$isCalledWithRightPrefix = 0;
487+
$isObjectNameRight = 0;
486488
$this->eventDispatcher->expects($this->any())->method('dispatch')->with(
487489
$this->callback(function ($arg) use (&$isCalledWithRightPrefix, $eventName) {
488490
$isCalledWithRightPrefix |= ($arg === $eventName);
489491
return true;
490492
}),
491-
$this->anything()
493+
$this->callback(function ($data) use (&$isObjectNameRight, $objectName) {
494+
$isObjectNameRight |= isset($data[$objectName]);
495+
return true;
496+
})
492497
);
493498

494499
$this->item->$methodName();
495-
$this->assertEquals(
496-
1,
497-
(int) $isCalledWithRightPrefix,
498-
sprintf("Event %s doesn't dispatched", $eventName)
500+
$this->assertTrue(
501+
($isCalledWithRightPrefix && $isObjectNameRight),
502+
sprintf('Event "%s" with object name "%s" doesn\'t dispatched properly', $eventName, $objectName)
499503
);
500504
}
501505

502506
public function eventsDataProvider()
503507
{
504508
return [
505-
['cataloginventory_stock_item_save_before', 'beforeSave'],
506-
['cataloginventory_stock_item_save_after', 'afterSave'],
509+
['cataloginventory_stock_item_save_before', 'beforeSave', 'item'],
510+
['cataloginventory_stock_item_save_after', 'afterSave', 'item'],
507511
];
508512
}
509513
}

app/code/Magento/CatalogInventory/Test/Unit/Model/StockTest.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,33 +100,37 @@ public function setUp()
100100
*
101101
* @param $eventName
102102
* @param $methodName
103+
* @param $objectName
103104
*
104105
* @dataProvider eventsDataProvider
105106
*/
106-
public function testDispatchEvents($eventName, $methodName)
107+
public function testDispatchEvents($eventName, $methodName, $objectName)
107108
{
108109
$isCalledWithRightPrefix = 0;
110+
$isObjectNameRight = 0;
109111
$this->eventDispatcher->expects($this->any())->method('dispatch')->with(
110112
$this->callback(function ($arg) use (&$isCalledWithRightPrefix, $eventName) {
111113
$isCalledWithRightPrefix |= ($arg === $eventName);
112114
return true;
113115
}),
114-
$this->anything()
116+
$this->callback(function ($data) use (&$isObjectNameRight, $objectName) {
117+
$isObjectNameRight |= isset($data[$objectName]);
118+
return true;
119+
})
115120
);
116121

117122
$this->stockModel->$methodName();
118-
$this->assertEquals(
119-
1,
120-
(int) $isCalledWithRightPrefix,
121-
sprintf("Event %s doesn't dispatched", $eventName)
123+
$this->assertTrue(
124+
($isCalledWithRightPrefix && $isObjectNameRight),
125+
sprintf('Event "%s" with object name "%s" doesn\'t dispatched properly', $eventName, $objectName)
122126
);
123127
}
124128

125129
public function eventsDataProvider()
126130
{
127131
return [
128-
['cataloginventory_stock_save_before', 'beforeSave'],
129-
['cataloginventory_stock_save_after', 'afterSave'],
132+
['cataloginventory_stock_save_before', 'beforeSave', 'stock'],
133+
['cataloginventory_stock_save_after', 'afterSave', 'stock'],
130134
];
131135
}
132136
}

app/code/Magento/CatalogWidget/Block/Product/ProductsList.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ public function createCollection()
237237
$conditions->collectValidatedAttributes($collection);
238238
$this->sqlBuilder->attachConditionToCollection($collection, $conditions);
239239

240+
/**
241+
* Prevent retrieval of duplicate records. This may occur when multiselect product attribute matches
242+
* several allowed values from condition simultaneously
243+
*/
244+
$collection->distinct(true);
245+
240246
return $collection;
241247
}
242248

app/code/Magento/CatalogWidget/Test/Unit/Block/Product/ProductsListTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ public function testCreateCollection($pagerEnable, $productsCount, $productsPerP
269269
'addStoreFilter',
270270
'setPageSize',
271271
'setCurPage',
272+
'distinct'
272273
])->disableOriginalConstructor()
273274
->getMock();
274275
$collection->expects($this->once())->method('setVisibility')
@@ -282,6 +283,7 @@ public function testCreateCollection($pagerEnable, $productsCount, $productsPerP
282283
$collection->expects($this->once())->method('addStoreFilter')->willReturnSelf();
283284
$collection->expects($this->once())->method('setPageSize')->with($expectedPageSize)->willReturnSelf();
284285
$collection->expects($this->once())->method('setCurPage')->willReturnSelf();
286+
$collection->expects($this->once())->method('distinct')->willReturnSelf();
285287

286288
$this->collectionFactory->expects($this->once())->method('create')->willReturn($collection);
287289
$this->productsList->setData('conditions_encoded', 'some_serialized_conditions');

0 commit comments

Comments
 (0)