Skip to content

Commit 2841088

Browse files
authored
Merge pull request #5899 from magento-tsg-csl3/2.4-develop-pr35
[TSG-CSL3] For 2.4 (pr35)
2 parents 25772e6 + 84610b2 commit 2841088

File tree

14 files changed

+320
-11
lines changed

14 files changed

+320
-11
lines changed

app/code/Magento/Catalog/Model/Category.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class Category extends \Magento\Catalog\Model\AbstractModel implements
8787
*
8888
* @var string
8989
*/
90-
protected $_cacheTag = self::CACHE_TAG;
90+
protected $_cacheTag = false;
9191

9292
/**
9393
* URL Model instance
@@ -1111,6 +1111,17 @@ public function afterSave()
11111111
return $result;
11121112
}
11131113

1114+
/**
1115+
* @inheritDoc
1116+
*/
1117+
public function getCacheTags()
1118+
{
1119+
$identities = $this->getIdentities();
1120+
$cacheTags = !empty($identities) ? (array) $identities : parent::getCacheTags();
1121+
1122+
return $cacheTags;
1123+
}
1124+
11141125
/**
11151126
* Init indexing process after category save
11161127
*

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Magento\Catalog\Api\ProductLinkRepositoryInterface;
1212
use Magento\Catalog\Model\Product\Attribute\Backend\Media\EntryConverterPool;
1313
use Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface;
14-
use Magento\Catalog\Model\FilterProductCustomAttribute;
1514
use Magento\Framework\Api\AttributeValueFactory;
1615
use Magento\Framework\App\Filesystem\DirectoryList;
1716
use Magento\Framework\App\ObjectManager;
@@ -977,6 +976,17 @@ public function afterSave()
977976
return $result;
978977
}
979978

979+
/**
980+
* @inheritDoc
981+
*/
982+
public function getCacheTags()
983+
{
984+
$identities = $this->getIdentities();
985+
$cacheTags = !empty($identities) ? (array) $identities : parent::getCacheTags();
986+
987+
return $cacheTags;
988+
}
989+
980990
/**
981991
* Set quantity for product
982992
*
@@ -2158,7 +2168,7 @@ public function reset()
21582168
*/
21592169
public function getCacheIdTags()
21602170
{
2161-
// phpstan:ignore
2171+
// phpstan:ignore "Call to an undefined static method"
21622172
$tags = parent::getCacheIdTags();
21632173
$affectedCategoryIds = $this->getAffectedCategoryIds();
21642174
if (!$affectedCategoryIds) {
@@ -2339,7 +2349,8 @@ public function isDisabled()
23392349
public function getImage()
23402350
{
23412351
$this->getTypeInstance()->setImageFromChildProduct($this);
2342-
// phpstan:ignore
2352+
2353+
// phpstan:ignore "Call to an undefined static method"
23432354
return parent::getImage();
23442355
}
23452356

@@ -2403,6 +2414,8 @@ public function reloadPriceInfo()
24032414
}
24042415
}
24052416

2417+
//phpcs:disable PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.MethodDoubleUnderscore
2418+
24062419
/**
24072420
* Return Data Object data in array format.
24082421
*
@@ -2430,6 +2443,8 @@ public function __toArray() //phpcs:ignore PHPCompatibility.FunctionNameRestrict
24302443
return $data;
24312444
}
24322445

2446+
//phpcs:enable PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.MethodDoubleUnderscore
2447+
24332448
/**
24342449
* Convert Category model into flat array.
24352450
*
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Model;
9+
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Framework\App\RequestInterface;
12+
use Magento\Framework\Exception\NoSuchEntityException;
13+
use Magento\PageCache\Model\Spi\PageCacheTagsPreprocessorInterface;
14+
use Magento\Store\Model\StoreManagerInterface;
15+
16+
/**
17+
* Add product identities to "noroute" page
18+
*
19+
* Ensure that "noroute" page has necessary product tags
20+
* so it can be invalidated once the product becomes visible again
21+
*/
22+
class ProductNotFoundPageCacheTags implements PageCacheTagsPreprocessorInterface
23+
{
24+
private const NOROUTE_ACTION_NAME = 'cms_noroute_index';
25+
/**
26+
* @var ProductRepositoryInterface
27+
*/
28+
private $productRepository;
29+
/**
30+
* @var StoreManagerInterface
31+
*/
32+
private $storeManager;
33+
/**
34+
* @var RequestInterface
35+
*/
36+
private $request;
37+
38+
/**
39+
* @param RequestInterface $request
40+
* @param ProductRepositoryInterface $productRepository
41+
* @param StoreManagerInterface $storeManager
42+
*/
43+
public function __construct(
44+
RequestInterface $request,
45+
ProductRepositoryInterface $productRepository,
46+
StoreManagerInterface $storeManager
47+
) {
48+
$this->productRepository = $productRepository;
49+
$this->storeManager = $storeManager;
50+
$this->request = $request;
51+
}
52+
53+
/**
54+
* @inheritDoc
55+
*/
56+
public function process(array $tags): array
57+
{
58+
if ($this->request->getFullActionName() === self::NOROUTE_ACTION_NAME) {
59+
try {
60+
$productId = (int) $this->request->getParam('id');
61+
$product = $this->productRepository->getById(
62+
$productId,
63+
false,
64+
$this->storeManager->getStore()->getId()
65+
);
66+
} catch (NoSuchEntityException $e) {
67+
$product = null;
68+
}
69+
if ($product) {
70+
$tags = array_merge($tags, $product->getIdentities());
71+
}
72+
}
73+
return $tags;
74+
}
75+
}

app/code/Magento/Catalog/etc/frontend/di.xml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
</argument>
1414
</arguments>
1515
</virtualType>
16-
<type name="Magento\Catalog\Model\ResourceModel\Category\Collection">
17-
<arguments>
18-
<argument name="fetchStrategy" xsi:type="object">Magento\Catalog\Model\ResourceModel\Category\Collection\FetchStrategy</argument>
19-
</arguments>
20-
</type>
2116
<type name="Magento\Catalog\Model\Indexer\AbstractFlatState">
2217
<arguments>
2318
<argument name="isAvailable" xsi:type="boolean">true</argument>
@@ -120,4 +115,13 @@
120115
<plugin name="catalog_app_action_dispatch_controller_context_plugin"
121116
type="Magento\Catalog\Plugin\Framework\App\Action\ContextPlugin" />
122117
</type>
118+
<type name="\Magento\PageCache\Model\PageCacheTagsPreprocessorComposite">
119+
<arguments>
120+
<argument name="preprocessors" xsi:type="array">
121+
<item name="catalog_product_view" xsi:type="array">
122+
<item name="product_not_found" xsi:type="object">Magento\Catalog\Model\ProductNotFoundPageCacheTags</item>
123+
</item>
124+
</argument>
125+
</arguments>
126+
</type>
123127
</config>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3079,6 +3079,9 @@ private function formatStockDataForRow(array $rowData): array
30793079
);
30803080

30813081
if ($this->stockConfiguration->isQty($this->skuProcessor->getNewSku($sku)['type_id'])) {
3082+
if (isset($rowData['qty']) && $rowData['qty'] == 0) {
3083+
$row['is_in_stock'] = 0;
3084+
}
30823085
$stockItemDo->setData($row);
30833086
$row['is_in_stock'] = $row['is_in_stock'] ?? $this->stockStateProvider->verifyStock($stockItemDo);
30843087
if ($this->stockStateProvider->verifyNotification($stockItemDo)) {

app/code/Magento/Checkout/view/frontend/web/js/model/address-converter.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ define([
8484
quoteAddressToFormAddressData: function (addrs) {
8585
var self = this,
8686
output = {},
87-
streetObject;
87+
streetObject,
88+
customAttributesObject;
8889

8990
$.each(addrs, function (key) {
9091
if (addrs.hasOwnProperty(key) && !$.isFunction(addrs[key])) {
@@ -100,6 +101,16 @@ define([
100101
output.street = streetObject;
101102
}
102103

104+
//jscs:disable requireCamelCaseOrUpperCaseIdentifiers
105+
if ($.isArray(addrs.customAttributes)) {
106+
customAttributesObject = {};
107+
addrs.customAttributes.forEach(function (value) {
108+
customAttributesObject[value.attribute_code] = value.value;
109+
});
110+
output.custom_attributes = customAttributesObject;
111+
}
112+
//jscs:enable requireCamelCaseOrUpperCaseIdentifiers
113+
103114
return output;
104115
},
105116

app/code/Magento/PageCache/Model/Layout/LayoutPlugin.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
namespace Magento\PageCache\Model\Layout;
99

1010
use Magento\Framework\App\MaintenanceMode;
11+
use Magento\Framework\App\ObjectManager;
1112
use Magento\Framework\App\ResponseInterface;
1213
use Magento\Framework\DataObject\IdentityInterface;
1314
use Magento\Framework\View\Layout;
1415
use Magento\PageCache\Model\Config;
16+
use Magento\PageCache\Model\Spi\PageCacheTagsPreprocessorInterface;
1517

1618
/**
1719
* Append cacheable pages response headers.
@@ -28,6 +30,11 @@ class LayoutPlugin
2830
*/
2931
private $response;
3032

33+
/**
34+
* @var PageCacheTagsPreprocessorInterface
35+
*/
36+
private $pageCacheTagsPreprocessor;
37+
3138
/**
3239
* @var MaintenanceMode
3340
*/
@@ -37,15 +44,19 @@ class LayoutPlugin
3744
* @param ResponseInterface $response
3845
* @param Config $config
3946
* @param MaintenanceMode $maintenanceMode
47+
* @param PageCacheTagsPreprocessorInterface|null $pageCacheTagsPreprocessor
4048
*/
4149
public function __construct(
4250
ResponseInterface $response,
4351
Config $config,
44-
MaintenanceMode $maintenanceMode
52+
MaintenanceMode $maintenanceMode,
53+
?PageCacheTagsPreprocessorInterface $pageCacheTagsPreprocessor = null
4554
) {
4655
$this->response = $response;
4756
$this->config = $config;
4857
$this->maintenanceMode = $maintenanceMode;
58+
$this->pageCacheTagsPreprocessor = $pageCacheTagsPreprocessor
59+
?? ObjectManager::getInstance()->get(PageCacheTagsPreprocessorInterface::class);
4960
}
5061

5162
/**
@@ -85,6 +96,7 @@ public function afterGetOutput(Layout $subject, $result)
8596
}
8697
}
8798
$tags = array_unique(array_merge(...$tags));
99+
$tags = $this->pageCacheTagsPreprocessor->process($tags);
88100
$this->response->setHeader('X-Magento-Tags', implode(',', $tags));
89101
}
90102

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\PageCache\Model;
9+
10+
use InvalidArgumentException;
11+
use Magento\Framework\App\RequestInterface;
12+
use Magento\PageCache\Model\Spi\PageCacheTagsPreprocessorInterface;
13+
14+
/**
15+
* Composite page cache preprocessors
16+
*/
17+
class PageCacheTagsPreprocessorComposite implements PageCacheTagsPreprocessorInterface
18+
{
19+
/**
20+
* @var PageCacheTagsPreprocessorInterface[][]
21+
*/
22+
private $preprocessors;
23+
/**
24+
* @var RequestInterface
25+
*/
26+
private $request;
27+
28+
/**
29+
* @param RequestInterface $request
30+
* @param PageCacheTagsPreprocessorInterface[][] $preprocessors
31+
*/
32+
public function __construct(
33+
RequestInterface $request,
34+
array $preprocessors = []
35+
) {
36+
foreach ($preprocessors as $group) {
37+
foreach ($group as $preprocessor) {
38+
if (!$preprocessor instanceof PageCacheTagsPreprocessorInterface) {
39+
throw new InvalidArgumentException(
40+
sprintf(
41+
'Instance of %s is expected, got %s instead.',
42+
PageCacheTagsPreprocessorInterface::class,
43+
get_class($preprocessor)
44+
)
45+
);
46+
}
47+
}
48+
}
49+
$this->preprocessors = $preprocessors;
50+
$this->request = $request;
51+
}
52+
53+
/**
54+
* @inheritDoc
55+
*/
56+
public function process(array $tags): array
57+
{
58+
$forwardInfo = $this->request->getBeforeForwardInfo();
59+
$actionName = $forwardInfo
60+
? implode('_', [$forwardInfo['route_name'], $forwardInfo['controller_name'], $forwardInfo['action_name']])
61+
: $this->request->getFullActionName();
62+
if (isset($this->preprocessors[$actionName])) {
63+
foreach ($this->preprocessors[$actionName] as $preprocessor) {
64+
$tags = $preprocessor->process($tags);
65+
}
66+
}
67+
return $tags;
68+
}
69+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\PageCache\Model\Spi;
9+
10+
/**
11+
* Interface for page tags preprocessors
12+
*/
13+
interface PageCacheTagsPreprocessorInterface
14+
{
15+
/**
16+
* Change page tags and returned the modified tags
17+
*
18+
* @param array $tags
19+
* @return array
20+
*/
21+
public function process(array $tags): array;
22+
}

0 commit comments

Comments
 (0)