Skip to content

Commit 100af87

Browse files
authored
Merge pull request #1204 from magento-okapis/Okapis-develop-pr
[Okapis] P1 P2
2 parents 5f7f226 + 7a094be commit 100af87

File tree

17 files changed

+319
-49
lines changed

17 files changed

+319
-49
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/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/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');

app/code/Magento/User/Setup/UpgradeSchema.php

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,27 @@ class UpgradeSchema implements UpgradeSchemaInterface
2121
*/
2222
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
2323
{
24-
$installer = $setup;
25-
$installer->startSetup();
26-
$tableAdmins = $installer->getTable('admin_user');
24+
$setup->startSetup();
2725

28-
$installer->getConnection()->addColumn(
26+
if (version_compare($context->getVersion(), '2.0.1', '<')) {
27+
$this->addFailuresToAdminUserTable($setup);
28+
$this->createAdminPasswordsTable($setup);
29+
}
30+
31+
$setup->endSetup();
32+
}
33+
34+
/**
35+
* Adds 'failures_num', 'first_failure', and 'lock_expires' columns to 'admin_user' table
36+
*
37+
* @param SchemaSetupInterface $setup
38+
* @return void
39+
*/
40+
private function addFailuresToAdminUserTable(SchemaSetupInterface $setup)
41+
{
42+
$tableAdmins = $setup->getTable('admin_user');
43+
44+
$setup->getConnection()->addColumn(
2945
$tableAdmins,
3046
'failures_num',
3147
[
@@ -35,28 +51,38 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
3551
'comment' => 'Failure Number'
3652
]
3753
);
38-
$installer->getConnection()->addColumn(
54+
$setup->getConnection()->addColumn(
3955
$tableAdmins,
4056
'first_failure',
4157
[
4258
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
4359
'comment' => 'First Failure'
4460
]
4561
);
46-
$installer->getConnection()->addColumn(
62+
$setup->getConnection()->addColumn(
4763
$tableAdmins,
4864
'lock_expires',
4965
[
5066
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
5167
'comment' => 'Expiration Lock Dates'
5268
]
5369
);
70+
}
71+
72+
/**
73+
* Create table 'admin_passwords'
74+
*
75+
* @param SchemaSetupInterface $setup
76+
* @return void
77+
*/
78+
private function createAdminPasswordsTable(SchemaSetupInterface $setup)
79+
{
80+
if ($setup->tableExists($setup->getTable('admin_passwords'))) {
81+
return;
82+
}
5483

55-
/**
56-
* Create table 'admin_passwords'
57-
*/
58-
$table = $installer->getConnection()->newTable(
59-
$installer->getTable('admin_passwords')
84+
$table = $setup->getConnection()->newTable(
85+
$setup->getTable('admin_passwords')
6086
)->addColumn(
6187
'password_id',
6288
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
@@ -88,19 +114,17 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
88114
['unsigned' => true, 'nullable' => false, 'default' => '0'],
89115
'Last Updated'
90116
)->addIndex(
91-
$installer->getIdxName('admin_passwords', ['user_id']),
117+
$setup->getIdxName('admin_passwords', ['user_id']),
92118
['user_id']
93119
)->addForeignKey(
94-
$installer->getFkName('admin_passwords', 'user_id', 'admin_user', 'user_id'),
120+
$setup->getFkName('admin_passwords', 'user_id', 'admin_user', 'user_id'),
95121
'user_id',
96-
$installer->getTable('admin_user'),
122+
$setup->getTable('admin_user'),
97123
'user_id',
98124
\Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
99125
)->setComment(
100126
'Admin Passwords'
101127
);
102-
$installer->getConnection()->createTable($table);
103-
104-
$installer->endSetup();
128+
$setup->getConnection()->createTable($table);
105129
}
106130
}

dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Edit/Section/ProductDetails/CategoryIds.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@ class CategoryIds extends MultisuggestElement
4646
*/
4747
protected $advancedInventoryButton = '[data-index="advanced_inventory_button"]';
4848

49-
/**
50-
* Locator for MultiSelect element.
51-
*
52-
* @var string
53-
*/
54-
private $multiSelectElement = '.admin__action-multiselect-menu-inner-item';
55-
5649
/**
5750
* @constructor
5851
* @param BrowserInterface $browser
@@ -93,14 +86,15 @@ public function setValue($values)
9386
if ($value == '') {
9487
continue;
9588
}
96-
$this->keys([$value]);
97-
98-
// wait when some element of multiSelect will be visible.
99-
$this->waitUntil(function () {
100-
return $this->find($this->multiSelectElement)->isVisible() ? true : null;
101-
});
10289

90+
$this->keys([$value]);
10391
$searchedItem = $this->find(sprintf($this->resultItem, $value), Locator::SELECTOR_XPATH);
92+
$searchedCountElements = $this->find($this->searchedCount);
93+
$this->waitUntil(
94+
function () use ($searchedCountElements) {
95+
return $searchedCountElements->isVisible() ? true : null;
96+
}
97+
);
10498
$searchedItem->click();
10599

106100
$closeButton = $this->find($this->closeButton);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\ConfigurableProduct\Test\Constraint;
8+
9+
use Magento\Catalog\Test\Constraint\AssertProductPage;
10+
11+
class AssertConfigurableProductOutOfStockPage extends AssertProductPage
12+
{
13+
/**
14+
* Verifies that all relevant product data will be shown for an out of stock configurable product.
15+
*
16+
* @return array
17+
*/
18+
protected function verify()
19+
{
20+
$errors = parent::verify();
21+
22+
return array_filter($errors);
23+
}
24+
25+
/**
26+
* Verify displayed product price on product page (front-end) equals passed from fixture
27+
*
28+
* @return string|null
29+
*/
30+
protected function verifyPrice()
31+
{
32+
$priceBlock = $this->productView->getPriceBlock();
33+
if (!$priceBlock->isVisible()) {
34+
return "Price block for '{$this->product->getName()}' product' is not visible.";
35+
}
36+
$formPrice = $priceBlock->isOldPriceVisible() ? $priceBlock->getOldPrice() : $priceBlock->getPrice();
37+
$fixturePrice = $this->getLowestConfigurablePrice();
38+
39+
if ($fixturePrice != $formPrice) {
40+
return "Displayed product price on product page (front-end) not equals passed from fixture. "
41+
. "Actual: {$formPrice}, expected: {$fixturePrice}.";
42+
}
43+
return null;
44+
}
45+
46+
/**
47+
* Returns lowest possible price of configurable product.
48+
*
49+
* @return string
50+
*/
51+
protected function getLowestConfigurablePrice()
52+
{
53+
$price = null;
54+
$priceDataConfig = $this->product->getDataFieldConfig('price');
55+
if (isset($priceDataConfig['source'])) {
56+
$priceData = $priceDataConfig['source']->getPriceData();
57+
if (isset($priceData['price_from'])) {
58+
$price = $priceData['price_from'];
59+
}
60+
}
61+
62+
if (null === $price) {
63+
$configurableOptions = $this->product->getConfigurableAttributesData();
64+
foreach ($configurableOptions['matrix'] as $option) {
65+
$price = $price === null ? $option['price'] : $price;
66+
if ($price > $option['price']) {
67+
$price = $option['price'];
68+
}
69+
}
70+
}
71+
return $price;
72+
}
73+
}

dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/CreateConfigurableProductEntityTest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@
186186
<constraint name="Magento\ConfigurableProduct\Test\Constraint\AssertConfigurableAttributesBlockIsAbsentOnProductPage" />
187187
<constraint name="Magento\Catalog\Test\Constraint\AssertProductOutOfStock" />
188188
<constraint name="Magento\Catalog\Test\Constraint\AssertProductVisibleInCategory" />
189+
<constraint name="Magento\ConfigurableProduct\Test\Constraint\AssertConfigurableProductOutOfStockPage" />
189190
</variation>
190191
<variation name="CreateConfigurableProductEntityTestVariation12" summary="Create Configurable Product with disabled child" ticketId="MAGETWO-65661">
191192
<data name="tag" xsi:type="string">test_type:acceptance_test, test_type:extended_acceptance_test</data>

dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/SourceTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ public function testReindexMultiselectAttribute()
114114
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attr **/
115115
$attr = $objectManager->get(\Magento\Eav\Model\Config::class)
116116
->getAttribute('catalog_product', 'multiselect_attribute');
117-
$attr->setIsFilterable(1)->save();
118117

119118
/** @var $options \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection */
120119
$options = $objectManager->create(\Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection::class);

0 commit comments

Comments
 (0)