Skip to content

Commit

Permalink
Merge branch '2.4-develop' of github.com:magento/magento2 into 2.4-de…
Browse files Browse the repository at this point in the history
…velop
  • Loading branch information
woutk88 committed Jul 20, 2020
2 parents 82d60a3 + 2841088 commit f1758db
Show file tree
Hide file tree
Showing 14 changed files with 320 additions and 11 deletions.
13 changes: 12 additions & 1 deletion app/code/Magento/Catalog/Model/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class Category extends \Magento\Catalog\Model\AbstractModel implements
*
* @var string
*/
protected $_cacheTag = self::CACHE_TAG;
protected $_cacheTag = false;

/**
* URL Model instance
Expand Down Expand Up @@ -1111,6 +1111,17 @@ public function afterSave()
return $result;
}

/**
* @inheritDoc
*/
public function getCacheTags()
{
$identities = $this->getIdentities();
$cacheTags = !empty($identities) ? (array) $identities : parent::getCacheTags();

return $cacheTags;
}

/**
* Init indexing process after category save
*
Expand Down
21 changes: 18 additions & 3 deletions app/code/Magento/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Magento\Catalog\Api\ProductLinkRepositoryInterface;
use Magento\Catalog\Model\Product\Attribute\Backend\Media\EntryConverterPool;
use Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface;
use Magento\Catalog\Model\FilterProductCustomAttribute;
use Magento\Framework\Api\AttributeValueFactory;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\ObjectManager;
Expand Down Expand Up @@ -977,6 +976,17 @@ public function afterSave()
return $result;
}

/**
* @inheritDoc
*/
public function getCacheTags()
{
$identities = $this->getIdentities();
$cacheTags = !empty($identities) ? (array) $identities : parent::getCacheTags();

return $cacheTags;
}

/**
* Set quantity for product
*
Expand Down Expand Up @@ -2158,7 +2168,7 @@ public function reset()
*/
public function getCacheIdTags()
{
// phpstan:ignore
// phpstan:ignore "Call to an undefined static method"
$tags = parent::getCacheIdTags();
$affectedCategoryIds = $this->getAffectedCategoryIds();
if (!$affectedCategoryIds) {
Expand Down Expand Up @@ -2339,7 +2349,8 @@ public function isDisabled()
public function getImage()
{
$this->getTypeInstance()->setImageFromChildProduct($this);
// phpstan:ignore

// phpstan:ignore "Call to an undefined static method"
return parent::getImage();
}

Expand Down Expand Up @@ -2403,6 +2414,8 @@ public function reloadPriceInfo()
}
}

//phpcs:disable PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.MethodDoubleUnderscore

/**
* Return Data Object data in array format.
*
Expand Down Expand Up @@ -2430,6 +2443,8 @@ public function __toArray() //phpcs:ignore PHPCompatibility.FunctionNameRestrict
return $data;
}

//phpcs:enable PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.MethodDoubleUnderscore

/**
* Convert Category model into flat array.
*
Expand Down
75 changes: 75 additions & 0 deletions app/code/Magento/Catalog/Model/ProductNotFoundPageCacheTags.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Model;

use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\PageCache\Model\Spi\PageCacheTagsPreprocessorInterface;
use Magento\Store\Model\StoreManagerInterface;

/**
* Add product identities to "noroute" page
*
* Ensure that "noroute" page has necessary product tags
* so it can be invalidated once the product becomes visible again
*/
class ProductNotFoundPageCacheTags implements PageCacheTagsPreprocessorInterface
{
private const NOROUTE_ACTION_NAME = 'cms_noroute_index';
/**
* @var ProductRepositoryInterface
*/
private $productRepository;
/**
* @var StoreManagerInterface
*/
private $storeManager;
/**
* @var RequestInterface
*/
private $request;

/**
* @param RequestInterface $request
* @param ProductRepositoryInterface $productRepository
* @param StoreManagerInterface $storeManager
*/
public function __construct(
RequestInterface $request,
ProductRepositoryInterface $productRepository,
StoreManagerInterface $storeManager
) {
$this->productRepository = $productRepository;
$this->storeManager = $storeManager;
$this->request = $request;
}

/**
* @inheritDoc
*/
public function process(array $tags): array
{
if ($this->request->getFullActionName() === self::NOROUTE_ACTION_NAME) {
try {
$productId = (int) $this->request->getParam('id');
$product = $this->productRepository->getById(
$productId,
false,
$this->storeManager->getStore()->getId()
);
} catch (NoSuchEntityException $e) {
$product = null;
}
if ($product) {
$tags = array_merge($tags, $product->getIdentities());
}
}
return $tags;
}
}
14 changes: 9 additions & 5 deletions app/code/Magento/Catalog/etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
</argument>
</arguments>
</virtualType>
<type name="Magento\Catalog\Model\ResourceModel\Category\Collection">
<arguments>
<argument name="fetchStrategy" xsi:type="object">Magento\Catalog\Model\ResourceModel\Category\Collection\FetchStrategy</argument>
</arguments>
</type>
<type name="Magento\Catalog\Model\Indexer\AbstractFlatState">
<arguments>
<argument name="isAvailable" xsi:type="boolean">true</argument>
Expand Down Expand Up @@ -120,4 +115,13 @@
<plugin name="catalog_app_action_dispatch_controller_context_plugin"
type="Magento\Catalog\Plugin\Framework\App\Action\ContextPlugin" />
</type>
<type name="\Magento\PageCache\Model\PageCacheTagsPreprocessorComposite">
<arguments>
<argument name="preprocessors" xsi:type="array">
<item name="catalog_product_view" xsi:type="array">
<item name="product_not_found" xsi:type="object">Magento\Catalog\Model\ProductNotFoundPageCacheTags</item>
</item>
</argument>
</arguments>
</type>
</config>
3 changes: 3 additions & 0 deletions app/code/Magento/CatalogImportExport/Model/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -3079,6 +3079,9 @@ private function formatStockDataForRow(array $rowData): array
);

if ($this->stockConfiguration->isQty($this->skuProcessor->getNewSku($sku)['type_id'])) {
if (isset($rowData['qty']) && $rowData['qty'] == 0) {
$row['is_in_stock'] = 0;
}
$stockItemDo->setData($row);
$row['is_in_stock'] = $row['is_in_stock'] ?? $this->stockStateProvider->verifyStock($stockItemDo);
if ($this->stockStateProvider->verifyNotification($stockItemDo)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ define([
quoteAddressToFormAddressData: function (addrs) {
var self = this,
output = {},
streetObject;
streetObject,
customAttributesObject;

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

//jscs:disable requireCamelCaseOrUpperCaseIdentifiers
if ($.isArray(addrs.customAttributes)) {
customAttributesObject = {};
addrs.customAttributes.forEach(function (value) {
customAttributesObject[value.attribute_code] = value.value;
});
output.custom_attributes = customAttributesObject;
}
//jscs:enable requireCamelCaseOrUpperCaseIdentifiers

return output;
},

Expand Down
14 changes: 13 additions & 1 deletion app/code/Magento/PageCache/Model/Layout/LayoutPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
namespace Magento\PageCache\Model\Layout;

use Magento\Framework\App\MaintenanceMode;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\DataObject\IdentityInterface;
use Magento\Framework\View\Layout;
use Magento\PageCache\Model\Config;
use Magento\PageCache\Model\Spi\PageCacheTagsPreprocessorInterface;

/**
* Append cacheable pages response headers.
Expand All @@ -28,6 +30,11 @@ class LayoutPlugin
*/
private $response;

/**
* @var PageCacheTagsPreprocessorInterface
*/
private $pageCacheTagsPreprocessor;

/**
* @var MaintenanceMode
*/
Expand All @@ -37,15 +44,19 @@ class LayoutPlugin
* @param ResponseInterface $response
* @param Config $config
* @param MaintenanceMode $maintenanceMode
* @param PageCacheTagsPreprocessorInterface|null $pageCacheTagsPreprocessor
*/
public function __construct(
ResponseInterface $response,
Config $config,
MaintenanceMode $maintenanceMode
MaintenanceMode $maintenanceMode,
?PageCacheTagsPreprocessorInterface $pageCacheTagsPreprocessor = null
) {
$this->response = $response;
$this->config = $config;
$this->maintenanceMode = $maintenanceMode;
$this->pageCacheTagsPreprocessor = $pageCacheTagsPreprocessor
?? ObjectManager::getInstance()->get(PageCacheTagsPreprocessorInterface::class);
}

/**
Expand Down Expand Up @@ -85,6 +96,7 @@ public function afterGetOutput(Layout $subject, $result)
}
}
$tags = array_unique(array_merge(...$tags));
$tags = $this->pageCacheTagsPreprocessor->process($tags);
$this->response->setHeader('X-Magento-Tags', implode(',', $tags));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\PageCache\Model;

use InvalidArgumentException;
use Magento\Framework\App\RequestInterface;
use Magento\PageCache\Model\Spi\PageCacheTagsPreprocessorInterface;

/**
* Composite page cache preprocessors
*/
class PageCacheTagsPreprocessorComposite implements PageCacheTagsPreprocessorInterface
{
/**
* @var PageCacheTagsPreprocessorInterface[][]
*/
private $preprocessors;
/**
* @var RequestInterface
*/
private $request;

/**
* @param RequestInterface $request
* @param PageCacheTagsPreprocessorInterface[][] $preprocessors
*/
public function __construct(
RequestInterface $request,
array $preprocessors = []
) {
foreach ($preprocessors as $group) {
foreach ($group as $preprocessor) {
if (!$preprocessor instanceof PageCacheTagsPreprocessorInterface) {
throw new InvalidArgumentException(
sprintf(
'Instance of %s is expected, got %s instead.',
PageCacheTagsPreprocessorInterface::class,
get_class($preprocessor)
)
);
}
}
}
$this->preprocessors = $preprocessors;
$this->request = $request;
}

/**
* @inheritDoc
*/
public function process(array $tags): array
{
$forwardInfo = $this->request->getBeforeForwardInfo();
$actionName = $forwardInfo
? implode('_', [$forwardInfo['route_name'], $forwardInfo['controller_name'], $forwardInfo['action_name']])
: $this->request->getFullActionName();
if (isset($this->preprocessors[$actionName])) {
foreach ($this->preprocessors[$actionName] as $preprocessor) {
$tags = $preprocessor->process($tags);
}
}
return $tags;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\PageCache\Model\Spi;

/**
* Interface for page tags preprocessors
*/
interface PageCacheTagsPreprocessorInterface
{
/**
* Change page tags and returned the modified tags
*
* @param array $tags
* @return array
*/
public function process(array $tags): array;
}
Loading

0 comments on commit f1758db

Please sign in to comment.