Skip to content

Commit 62f4626

Browse files
committed
Merge remote-tracking branch 'origin/MC-29047' into 2.4-develop-pr6
2 parents ab54661 + 70c7918 commit 62f4626

File tree

78 files changed

+1476
-446
lines changed

Some content is hidden

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

78 files changed

+1476
-446
lines changed

app/code/Magento/Backend/Block/Media/Uploader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected function _construct()
8787

8888
$this->setId($this->getId() . '_Uploader');
8989

90-
$uploadUrl = $this->_urlBuilder->addSessionParam()->getUrl('adminhtml/*/upload');
90+
$uploadUrl = $this->_urlBuilder->getUrl('adminhtml/*/upload');
9191
$this->getConfig()->setUrl($uploadUrl);
9292
$this->getConfig()->setParams(['form_key' => $this->getFormKey()]);
9393
$this->getConfig()->setFileField('file');

app/code/Magento/Catalog/Block/Adminhtml/Product/Helper/Form/Gallery/Content.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ protected function _prepareLayout()
9595
);
9696

9797
$this->getUploader()->getConfig()->setUrl(
98-
$this->_urlBuilder->addSessionParam()->getUrl('catalog/product_gallery/upload')
98+
$this->_urlBuilder->getUrl('catalog/product_gallery/upload')
9999
)->setFileField(
100100
'image'
101101
)->setFilters(

app/code/Magento/Catalog/Model/Product/Url.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,10 @@ public function getUrlInStore(\Magento\Catalog\Model\Product $product, $params =
101101
*/
102102
public function getProductUrl($product, $useSid = null)
103103
{
104-
if ($useSid === null) {
105-
$useSid = $this->sidResolver->getUseSessionInUrl();
106-
}
107-
108104
$params = [];
109105
if (!$useSid) {
110106
$params['_nosid'] = true;
111107
}
112-
113108
return $this->getUrl($product, $params);
114109
}
115110

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AssertStorefrontProductDetailPageNameAndUrlActionGroup">
12+
<annotations>
13+
<description>Validates that the Product name and Url are correct.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="productName" defaultValue="{{ApiSimpleProduct.name}}" type="string"/>
17+
<argument name="productUrl" defaultValue="{{ApiSimpleProduct.urlKey}}" type="string"/>
18+
</arguments>
19+
20+
<seeInCurrentUrl url="{{StorefrontProductPage.url(productUrl)}}" stepKey="checkUrl"/>
21+
<seeInTitle userInput="{{productName}}" stepKey="assertProductNameTitle"/>
22+
<see userInput="{{productName}}" selector="{{StorefrontProductInfoMainSection.productName}}" stepKey="assertProductName"/>
23+
</actionGroup>
24+
</actionGroups>

app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontCheckCategorySimpleProductActionGroup.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
<argument name="product"/>
1717
</arguments>
1818

19+
<waitForElementVisible selector="{{StorefrontCategoryProductSection.ProductTitleByName(product.name)}}" stepKey="waitForProduct"/>
1920
<seeElement selector="{{StorefrontCategoryProductSection.ProductTitleByName(product.name)}}" stepKey="assertProductName"/>
2021
<see userInput="${{product.price}}.00" selector="{{StorefrontCategoryProductSection.ProductPriceByName(product.name)}}" stepKey="AssertProductPrice"/>
21-
<!-- @TODO: MAGETWO-80272 Move to Magento_Checkout -->
2222
<moveMouseOver selector="{{StorefrontCategoryProductSection.ProductInfoByName(product.name)}}" stepKey="moveMouseOverProduct"/>
23-
<!-- @TODO: MAGETWO-80272 Move to Magento_Checkout -->
2423
<seeElement selector="{{StorefrontCategoryProductSection.ProductAddToCartByName(product.name)}}" stepKey="AssertAddToCart"/>
2524
</actionGroup>
2625
</actionGroups>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
-->
7+
8+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="StorefrontOpenProductFromCategoryPageActionGroup">
11+
<annotations>
12+
<description>Click on the provided product on category page.</description>
13+
</annotations>
14+
<arguments>
15+
<argument name="productName" type="string" defaultValue="{{ApiSimpleProduct.name}}"/>
16+
</arguments>
17+
18+
<click selector="{{StorefrontCategoryMainSection.specifiedProductItemInfo(productName)}}" stepKey="openProductPage"/>
19+
<waitForPageLoad stepKey="waitForProductPageLoad"/>
20+
</actionGroup>
21+
</actionGroups>

app/code/Magento/Catalog/Test/Unit/Model/Product/UrlTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,11 @@ public function testGetUrl(
159159
$this->assertEquals($requestPathProduct, $this->model->getUrlInStore($product, $routeParams));
160160
break;
161161
case 'getProductUrl':
162-
$this->assertEquals($requestPathProduct, $this->model->getProductUrl($product, true));
162+
$this->assertEquals($requestPathProduct, $this->model->getProductUrl($product, null));
163163
$this->sidResolver
164-
->expects($this->once())
164+
->expects($this->never())
165165
->method('getUseSessionInUrl')
166166
->will($this->returnValue(true));
167-
$this->assertEquals($requestPathProduct, $this->model->getProductUrl($product, null));
168167
break;
169168
}
170169
}
@@ -212,7 +211,7 @@ public function getUrlDataProvider()
212211
1,
213212
1,
214213
[],
215-
['_direct' => '/product/url/path', '_query' => []],
214+
['_direct' => '/product/url/path', '_query' => [], '_nosid' => true],
216215
null,
217216
null,
218217
]

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Magento\CatalogImportExport\Model\Import\Product\ImageTypeProcessor;
1414
use Magento\CatalogImportExport\Model\Import\Product\MediaGalleryProcessor;
1515
use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface as ValidatorInterface;
16+
use Magento\CatalogImportExport\Model\Import\Product\StatusProcessor;
17+
use Magento\CatalogImportExport\Model\Import\Product\StockProcessor;
1618
use Magento\CatalogImportExport\Model\StockItemImporterInterface;
1719
use Magento\CatalogInventory\Api\Data\StockItemInterface;
1820
use Magento\Framework\App\Filesystem\DirectoryList;
@@ -746,6 +748,15 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
746748
*/
747749
private $productRepository;
748750

751+
/**
752+
* @var StatusProcessor
753+
*/
754+
private $statusProcessor;
755+
/**
756+
* @var StockProcessor
757+
*/
758+
private $stockProcessor;
759+
749760
/**
750761
* @param \Magento\Framework\Json\Helper\Data $jsonHelper
751762
* @param \Magento\ImportExport\Helper\Data $importExportData
@@ -791,6 +802,8 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
791802
* @param StockItemImporterInterface|null $stockItemImporter
792803
* @param DateTimeFactory $dateTimeFactory
793804
* @param ProductRepositoryInterface|null $productRepository
805+
* @param StatusProcessor|null $statusProcessor
806+
* @param StockProcessor|null $stockProcessor
794807
* @throws LocalizedException
795808
* @throws \Magento\Framework\Exception\FileSystemException
796809
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -840,7 +853,9 @@ public function __construct(
840853
MediaGalleryProcessor $mediaProcessor = null,
841854
StockItemImporterInterface $stockItemImporter = null,
842855
DateTimeFactory $dateTimeFactory = null,
843-
ProductRepositoryInterface $productRepository = null
856+
ProductRepositoryInterface $productRepository = null,
857+
StatusProcessor $statusProcessor = null,
858+
StockProcessor $stockProcessor = null
844859
) {
845860
$this->_eventManager = $eventManager;
846861
$this->stockRegistry = $stockRegistry;
@@ -876,6 +891,10 @@ public function __construct(
876891
$this->mediaProcessor = $mediaProcessor ?: ObjectManager::getInstance()->get(MediaGalleryProcessor::class);
877892
$this->stockItemImporter = $stockItemImporter ?: ObjectManager::getInstance()
878893
->get(StockItemImporterInterface::class);
894+
$this->statusProcessor = $statusProcessor ?: ObjectManager::getInstance()
895+
->get(StatusProcessor::class);
896+
$this->stockProcessor = $stockProcessor ?: ObjectManager::getInstance()
897+
->get(StockProcessor::class);
879898
parent::__construct(
880899
$jsonHelper,
881900
$importExportData,
@@ -1290,12 +1309,18 @@ protected function _saveLinks()
12901309
protected function _saveProductAttributes(array $attributesData)
12911310
{
12921311
$linkField = $this->getProductEntityLinkField();
1312+
$statusAttributeId = (int) $this->retrieveAttributeByCode('status')->getId();
12931313
foreach ($attributesData as $tableName => $skuData) {
1314+
$linkIdBySkuForStatusChanged = [];
12941315
$tableData = [];
12951316
foreach ($skuData as $sku => $attributes) {
12961317
$linkId = $this->_oldSku[strtolower($sku)][$linkField];
12971318
foreach ($attributes as $attributeId => $storeValues) {
12981319
foreach ($storeValues as $storeId => $storeValue) {
1320+
if ($attributeId === $statusAttributeId) {
1321+
$this->statusProcessor->setStatus($sku, $storeId, $storeValue);
1322+
$linkIdBySkuForStatusChanged[strtolower($sku)] = $linkId;
1323+
}
12991324
$tableData[] = [
13001325
$linkField => $linkId,
13011326
'attribute_id' => $attributeId,
@@ -1305,6 +1330,9 @@ protected function _saveProductAttributes(array $attributesData)
13051330
}
13061331
}
13071332
}
1333+
if ($linkIdBySkuForStatusChanged) {
1334+
$this->statusProcessor->loadOldStatus($linkIdBySkuForStatusChanged);
1335+
}
13081336
$this->_connection->insertOnDuplicate($tableName, $tableData, ['value']);
13091337
}
13101338

@@ -2188,6 +2216,7 @@ protected function _saveStockItem()
21882216
while ($bunch = $this->_dataSourceModel->getNextBunch()) {
21892217
$stockData = [];
21902218
$productIdsToReindex = [];
2219+
$stockChangedProductIds = [];
21912220
// Format bunch to stock data rows
21922221
foreach ($bunch as $rowNum => $rowData) {
21932222
if (!$this->isRowAllowedToImport($rowData, $rowNum)) {
@@ -2197,8 +2226,16 @@ protected function _saveStockItem()
21972226
$row = [];
21982227
$sku = $rowData[self::COL_SKU];
21992228
if ($this->skuProcessor->getNewSku($sku) !== null) {
2229+
$stockItem = $this->getRowExistingStockItem($rowData);
2230+
$existingStockItemData = $stockItem->getData();
22002231
$row = $this->formatStockDataForRow($rowData);
22012232
$productIdsToReindex[] = $row['product_id'];
2233+
$storeId = $this->getRowStoreId($rowData);
2234+
if (!empty(array_diff_assoc($row, $existingStockItemData))
2235+
|| $this->statusProcessor->isStatusChanged($sku, $storeId)
2236+
) {
2237+
$stockChangedProductIds[] = $row['product_id'];
2238+
}
22022239
}
22032240

22042241
if (!isset($stockData[$sku])) {
@@ -2211,11 +2248,24 @@ protected function _saveStockItem()
22112248
$this->stockItemImporter->import($stockData);
22122249
}
22132250

2251+
$this->reindexStockStatus($stockChangedProductIds);
22142252
$this->reindexProducts($productIdsToReindex);
22152253
}
22162254
return $this;
22172255
}
22182256

2257+
/**
2258+
* Reindex stock status for provided product IDs
2259+
*
2260+
* @param array $productIds
2261+
*/
2262+
private function reindexStockStatus(array $productIds): void
2263+
{
2264+
if ($productIds) {
2265+
$this->stockProcessor->reindexList($productIds);
2266+
}
2267+
}
2268+
22192269
/**
22202270
* Initiate product reindex by product ids
22212271
*
@@ -3259,4 +3309,30 @@ private function composeLinkKey(int $productId, int $linkedId, int $linkTypeId)
32593309
{
32603310
return "{$productId}-{$linkedId}-{$linkTypeId}";
32613311
}
3312+
3313+
/**
3314+
* Get row store ID
3315+
*
3316+
* @param array $rowData
3317+
* @return int
3318+
*/
3319+
private function getRowStoreId(array $rowData): int
3320+
{
3321+
return !empty($rowData[self::COL_STORE])
3322+
? (int) $this->getStoreIdByCode($rowData[self::COL_STORE])
3323+
: Store::DEFAULT_STORE_ID;
3324+
}
3325+
3326+
/**
3327+
* Get row stock item model
3328+
*
3329+
* @param array $rowData
3330+
* @return StockItemInterface
3331+
*/
3332+
private function getRowExistingStockItem(array $rowData): StockItemInterface
3333+
{
3334+
$productId = $this->skuProcessor->getNewSku($rowData[self::COL_SKU])['entity_id'];
3335+
$websiteId = $this->stockConfiguration->getDefaultScopeId();
3336+
return $this->stockRegistry->getStockItem($productId, $websiteId);
3337+
}
32623338
}

0 commit comments

Comments
 (0)