Skip to content

Commit 78028f0

Browse files
authored
🔃 [EngCom] Public Pull Requests - 2.2-develop
Accepted Public Pull Requests: - magento-engcom/magento2ce#1215: The function "isUsingStaticUrlsAllowed" (configuration setting "cms/wysiwyg/use_static_urls_in_catalog") doesn't have any effect with the WYSIWYG editor image insertion (by @nmalevanec) - magento-engcom/magento2ce#1050: 11897: Catalog product list widget not working with multiple sku. (by @nmalevanec) - magento-engcom/magento2ce#955: 8624: Stock status not coming back after qty update (by @RomaKis) Fixed GitHub Issues: - #12147: The function "isUsingStaticUrlsAllowed" (configuration setting "cms/wysiwyg/use_static_urls_in_catalog") doesn't have any effect with the WYSIWYG editor image insertion (reported by @andrewhowdencom) has been fixed in magento-engcom/magento2ce#1215 by @nmalevanec in 2.2-develop branch Related commits: 1. 26a83d5 2. 94fdca7 - #11897: Catalog product list widget not working with multiple sku (reported by @hemendraajmera) has been fixed in magento-engcom/magento2ce#1050 by @nmalevanec in 2.2-develop branch Related commits: 1. 8d62341 2. d5b596a - #8624: Stock status not coming back after qty update (reported by @oroskodias) has been fixed in magento-engcom/magento2ce#955 by @RomaKis in 2.2-develop branch Related commits: 1. 15928fb 2. 188ecb3 3. 546a0bb 4. 4b585d4 5. a9a3c19
2 parents 83a9b9c + f13beab commit 78028f0

File tree

19 files changed

+252
-19
lines changed

19 files changed

+252
-19
lines changed

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

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function __construct(
145145
/**
146146
* @inheritdoc
147147
*/
148-
public function save(\Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem)
148+
public function save(StockItemInterface $stockItem)
149149
{
150150
try {
151151
/** @var \Magento\Catalog\Model\Product $product */
@@ -161,10 +161,7 @@ public function save(\Magento\CatalogInventory\Api\Data\StockItemInterface $stoc
161161
$typeId = $product->getTypeId() ?: $product->getTypeInstance()->getTypeId();
162162
$isQty = $this->stockConfiguration->isQty($typeId);
163163
if ($isQty) {
164-
$isInStock = $this->stockStateProvider->verifyStock($stockItem);
165-
if ($stockItem->getManageStock() && !$isInStock) {
166-
$stockItem->setIsInStock(false)->setStockStatusChangedAutomaticallyFlag(true);
167-
}
164+
$this->changeIsInStockIfNecessary($stockItem);
168165
// if qty is below notify qty, update the low stock date to today date otherwise set null
169166
$stockItem->setLowStockDate(null);
170167
if ($this->stockStateProvider->verifyNotification($stockItem)) {
@@ -260,4 +257,28 @@ private function getStockRegistryStorage()
260257
}
261258
return $this->stockRegistryStorage;
262259
}
260+
261+
/**
262+
* Change is_in_stock value if necessary.
263+
*
264+
* @param StockItemInterface $stockItem
265+
*
266+
* @return void
267+
*/
268+
private function changeIsInStockIfNecessary(StockItemInterface $stockItem)
269+
{
270+
$isInStock = $this->stockStateProvider->verifyStock($stockItem);
271+
if ($stockItem->getManageStock() && !$isInStock) {
272+
$stockItem->setIsInStock(false)->setStockStatusChangedAutomaticallyFlag(true);
273+
}
274+
275+
if ($stockItem->getManageStock()
276+
&& $isInStock
277+
&& !$stockItem->getIsInStock()
278+
&& $stockItem->getOrigData(\Magento\CatalogInventory\Api\Data\StockItemInterface::QTY) == 0
279+
&& $stockItem->getOrigData(\Magento\CatalogInventory\Api\Data\StockItemInterface::QTY) !== null
280+
) {
281+
$stockItem->setIsInStock(true)->setStockStatusChangedAutomaticallyFlag(true);
282+
}
283+
}
263284
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public function testSave()
276276
->method('verifyStock')
277277
->with($this->stockItemMock)
278278
->willReturn(false);
279-
$this->stockItemMock->expects($this->once())->method('getManageStock')->willReturn(true);
279+
$this->stockItemMock->expects($this->exactly(2))->method('getManageStock')->willReturn(true);
280280
$this->stockItemMock->expects($this->once())->method('setIsInStock')->with(false)->willReturnSelf();
281281
$this->stockItemMock->expects($this->once())
282282
->method('setStockStatusChangedAutomaticallyFlag')

app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/OnInsert.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(
3535
public function execute()
3636
{
3737
$helper = $this->_objectManager->get(\Magento\Cms\Helper\Wysiwyg\Images::class);
38-
$storeId = $this->getRequest()->getParam('store');
38+
$storeId = (int)$this->getRequest()->getParam('store');
3939

4040
$filename = $this->getRequest()->getParam('filename');
4141
$filename = $helper->idDecode($filename);

app/code/Magento/Rule/Model/Condition/Product/AbstractProduct.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public function getDefaultOperatorInputByType()
137137
*/
138138
$this->_defaultOperatorInputByType['category'] = ['==', '!=', '{}', '!{}', '()', '!()'];
139139
$this->_arrayInputTypes[] = 'category';
140+
$this->_defaultOperatorInputByType['sku'] = ['==', '!=', '{}', '!{}', '()', '!()'];
140141
}
141142
return $this->_defaultOperatorInputByType;
142143
}
@@ -382,6 +383,9 @@ public function getInputType()
382383
if ($this->getAttributeObject()->getAttributeCode() == 'category_ids') {
383384
return 'category';
384385
}
386+
if ($this->getAttributeObject()->getAttributeCode() == 'sku') {
387+
return 'sku';
388+
}
385389
switch ($this->getAttributeObject()->getFrontendInput()) {
386390
case 'select':
387391
return 'select';
@@ -606,7 +610,12 @@ public function getBindArgumentValue()
606610
$this->getValueParsed()
607611
)->__toString()
608612
);
613+
} elseif ($this->getAttribute() === 'sku') {
614+
$value = $this->getData('value');
615+
$value = preg_split('#\s*[,;]\s*#', $value, null, PREG_SPLIT_NO_EMPTY);
616+
$this->setValueParsed($value);
609617
}
618+
610619
return parent::getBindArgumentValue();
611620
}
612621

@@ -704,7 +713,7 @@ protected function _getAttributeSetId($productId)
704713
public function getOperatorForValidate()
705714
{
706715
$operator = $this->getOperator();
707-
if ($this->getInputType() == 'category') {
716+
if (in_array($this->getInputType(), ['category', 'sku'])) {
708717
if ($operator == '==') {
709718
$operator = '{}';
710719
} elseif ($operator == '!=') {

dev/tests/integration/testsuite/Magento/Catalog/Model/ProductTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,4 +549,41 @@ public function testGetOptions()
549549
}
550550
}
551551
}
552+
553+
/**
554+
* @magentoDataFixture Magento/Catalog/_files/product_simple_out_of_stock.php
555+
*/
556+
public function testSaveWithDifferentQty()
557+
{
558+
//if save (out of stock product with qty 0) with new qty > 0 it should become in stock.
559+
//if set out of stock for product with qty > 0 it should become out of stock
560+
$product = $this->productRepository->get('simple-out-of-stock', true, null, true);
561+
$stockItem = $product->getExtensionAttributes()->getStockItem();
562+
$this->assertEquals(false, $stockItem->getIsInStock());
563+
$stockData = [
564+
'qty' => 5,
565+
'is_in_stock' => 0,
566+
];
567+
$product->setStockData($stockData);
568+
$product->save();
569+
570+
/** @var \Magento\CatalogInventory\Model\StockRegistryStorage $stockRegistryStorage */
571+
$stockRegistryStorage = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
572+
->get(\Magento\CatalogInventory\Model\StockRegistryStorage::class);
573+
$stockRegistryStorage->removeStockItem($product->getId());
574+
$product = $this->productRepository->get('simple-out-of-stock', true, null, true);
575+
$stockItem = $product->getExtensionAttributes()->getStockItem();
576+
$this->assertEquals(true, $stockItem->getIsInStock());
577+
$stockData = [
578+
'qty' => 3,
579+
'is_in_stock' => 0,
580+
];
581+
$product->setStockData($stockData);
582+
$product->save();
583+
584+
$stockRegistryStorage->removeStockItem($product->getId());
585+
$product = $this->productRepository->get('simple-out-of-stock', true, null, true);
586+
$stockItem = $product->getExtensionAttributes()->getStockItem();
587+
$this->assertEquals(false, $stockItem->getIsInStock());
588+
}
552589
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
\Magento\TestFramework\Helper\Bootstrap::getInstance()->reinitialize();
8+
9+
/** @var \Magento\TestFramework\ObjectManager $objectManager */
10+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
11+
12+
/** @var \Magento\Catalog\Api\CategoryLinkManagementInterface $categoryLinkManagement */
13+
$categoryLinkManagement = $objectManager->get(\Magento\Catalog\Api\CategoryLinkManagementInterface::class);
14+
15+
/** @var $product \Magento\Catalog\Model\Product */
16+
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
17+
$product->isObjectNew(true);
18+
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
19+
->setId(1)
20+
->setAttributeSetId(4)
21+
->setWebsiteIds([1])
22+
->setName('Simple Product')
23+
->setSku('simple-out-of-stock')
24+
->setPrice(10)
25+
->setWeight(1)
26+
->setShortDescription("Short description")
27+
->setTaxClassId(0)
28+
->setDescription('Description with <b>html tag</b>')
29+
->setMetaTitle('meta title')
30+
->setMetaKeyword('meta keyword')
31+
->setMetaDescription('meta description')
32+
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
33+
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
34+
->setStockData(
35+
[
36+
'use_config_manage_stock' => 1,
37+
'qty' => 0,
38+
'is_qty_decimal' => 0,
39+
'is_in_stock' => 0,
40+
]
41+
)->setCanSaveCustomOptions(true)
42+
->setHasOptions(true);
43+
44+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepositoryFactory */
45+
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
46+
$productRepository->save($product);
47+
48+
$categoryLinkManagement->assignProductToCategories(
49+
$product->getSku(),
50+
[2]
51+
);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
use Magento\Framework\Exception\NoSuchEntityException;
7+
8+
\Magento\TestFramework\Helper\Bootstrap::getInstance()->getInstance()->reinitialize();
9+
10+
/** @var \Magento\Framework\Registry $registry */
11+
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
12+
13+
$registry->unregister('isSecureArea');
14+
$registry->register('isSecureArea', true);
15+
16+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
17+
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
18+
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
19+
try {
20+
$product = $productRepository->get('simple-out-of-stock', false, null, true);
21+
$productRepository->delete($product);
22+
} catch (NoSuchEntityException $e) {
23+
}
24+
$registry->unregister('isSecureArea');
25+
$registry->register('isSecureArea', false);

dev/tests/integration/testsuite/Magento/CatalogInventory/Model/StockItemSave/ByStockItemRepositoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class ByStockItemRepositoryTest extends \PHPUnit\Framework\TestCase
4040
private $stockItemData = [
4141
StockItemInterface::QTY => 555,
4242
StockItemInterface::MANAGE_STOCK => true,
43-
StockItemInterface::IS_IN_STOCK => false,
43+
StockItemInterface::IS_IN_STOCK => true,
4444
];
4545

4646
public function setUp()

dev/tests/integration/testsuite/Magento/CatalogInventory/Model/StockItemSave/OnProductCreate/ByProductModel/ByQuantityAndStockStatusTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class ByQuantityAndStockStatusTest extends \PHPUnit\Framework\TestCase
5353
private $stockItemData = [
5454
StockItemInterface::QTY => 555,
5555
StockItemInterface::MANAGE_STOCK => true,
56-
StockItemInterface::IS_IN_STOCK => false,
56+
StockItemInterface::IS_IN_STOCK => true,
5757
];
5858

5959
public function setUp()

dev/tests/integration/testsuite/Magento/CatalogInventory/Model/StockItemSave/OnProductCreate/ByProductModel/ByStockDataTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class ByStockDataTest extends \PHPUnit\Framework\TestCase
5353
private $stockItemData = [
5454
StockItemInterface::QTY => 555,
5555
StockItemInterface::MANAGE_STOCK => true,
56-
StockItemInterface::IS_IN_STOCK => false,
56+
StockItemInterface::IS_IN_STOCK => true,
5757
];
5858

5959
public function setUp()

0 commit comments

Comments
 (0)