Skip to content

Commit 3572266

Browse files
authored
Merge branch 'magento-commerce:2.4-develop' into ACQE-5559-test-fix
2 parents 9df6658 + 0b41085 commit 3572266

File tree

32 files changed

+1504
-157
lines changed

32 files changed

+1504
-157
lines changed

app/code/Magento/Catalog/Helper/Product/Compare.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ public function getItemCollection()
298298

299299
/* update compare items count */
300300
$count = count($this->_itemCollection);
301-
$counts = $this->_catalogSession->getCatalogCompareItemsCountPerWebsite() ?: [];
302301
$counts[$this->_storeManager->getWebsite()->getId()] = $count;
303302
$this->_catalogSession->setCatalogCompareItemsCountPerWebsite($counts);
304303
$this->_catalogSession->setCatalogCompareItemsCount($count); //deprecated
@@ -331,7 +330,6 @@ public function calculate($logout = false)
331330
->setVisibility($this->_catalogProductVisibility->getVisibleInSiteIds());
332331

333332
$count = $collection->getSize();
334-
$counts = $this->_catalogSession->getCatalogCompareItemsCountPerWebsite() ?: [];
335333
$counts[$this->_storeManager->getWebsite()->getId()] = $count;
336334
$this->_catalogSession->setCatalogCompareItemsCountPerWebsite($counts);
337335
$this->_catalogSession->setCatalogCompareItemsCount($count); //deprecated
@@ -349,6 +347,7 @@ public function getItemCount()
349347
$counts = $this->_catalogSession->getCatalogCompareItemsCountPerWebsite() ?: [];
350348
if (!isset($counts[$this->_storeManager->getWebsite()->getId()])) {
351349
$this->calculate();
350+
$counts = $this->_catalogSession->getCatalogCompareItemsCountPerWebsite() ?: [];
352351
}
353352

354353
return $counts[$this->_storeManager->getWebsite()->getId()] ?? 0;

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,34 @@
1313
use Magento\Eav\Model\ResourceModel\AttributeValue;
1414
use Magento\Framework\App\ObjectManager;
1515
use Magento\Framework\EntityManager\MetadataPool;
16+
use Magento\Framework\Exception\FileSystemException;
17+
use Magento\Framework\Exception\LocalizedException;
1618
use Magento\Framework\Filesystem;
1719
use Magento\Framework\Json\Helper\Data;
1820
use Magento\MediaStorage\Helper\File\Storage\Database;
1921
use Magento\Store\Model\Store;
2022
use Magento\Store\Model\StoreManagerInterface;
23+
use Magento\Catalog\Model\Product\Image\RemoveDeletedImagesFromCache;
2124

2225
/**
2326
* Update handler for catalog product gallery.
2427
*
2528
* @api
2629
* @since 101.0.0
30+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
2731
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2832
*/
2933
class UpdateHandler extends CreateHandler
3034
{
3135
/**
3236
* @var AttributeValue
3337
*/
34-
private $attributeValue;
38+
private AttributeValue $attributeValue;
39+
40+
/**
41+
* @var RemoveDeletedImagesFromCache
42+
*/
43+
private RemoveDeletedImagesFromCache $removeDeletedImagesFromCache;
3544

3645
/**
3746
* @param MetadataPool $metadataPool
@@ -43,6 +52,8 @@ class UpdateHandler extends CreateHandler
4352
* @param Database $fileStorageDb
4453
* @param StoreManagerInterface|null $storeManager
4554
* @param AttributeValue|null $attributeValue
55+
* @param RemoveDeletedImagesFromCache|null $removeDeletedImagesFromCache
56+
* @throws FileSystemException
4657
*/
4758
public function __construct(
4859
MetadataPool $metadataPool,
@@ -53,7 +64,8 @@ public function __construct(
5364
Filesystem $filesystem,
5465
Database $fileStorageDb,
5566
StoreManagerInterface $storeManager = null,
56-
?AttributeValue $attributeValue = null
67+
?AttributeValue $attributeValue = null,
68+
?RemoveDeletedImagesFromCache $removeDeletedImagesFromCache = null
5769
) {
5870
parent::__construct(
5971
$metadataPool,
@@ -66,6 +78,8 @@ public function __construct(
6678
$storeManager
6779
);
6880
$this->attributeValue = $attributeValue ?: ObjectManager::getInstance()->get(AttributeValue::class);
81+
$this->removeDeletedImagesFromCache = $removeDeletedImagesFromCache ?:
82+
ObjectManager::getInstance()->get(RemoveDeletedImagesFromCache::class);
6983
}
7084

7185
/**
@@ -102,6 +116,7 @@ protected function processDeletedImages($product, array &$images)
102116
$this->deleteMediaAttributeValues($product, $imagesToDelete);
103117
$this->resourceModel->deleteGallery($recordsToDelete);
104118
$this->removeDeletedImages($filesToDelete);
119+
$this->removeDeletedImagesFromCache->removeDeletedImagesFromCache($filesToDelete);
105120
}
106121

107122
/**
@@ -181,6 +196,7 @@ protected function extractStoreIds($product)
181196
*
182197
* @param array $files
183198
* @return null
199+
* @throws FileSystemException
184200
* @since 101.0.0
185201
*/
186202
protected function removeDeletedImages(array $files)
@@ -198,6 +214,7 @@ protected function removeDeletedImages(array $files)
198214
*
199215
* @param Product $product
200216
* @param string[] $images
217+
* @throws LocalizedException
201218
*/
202219
private function deleteMediaAttributeValues(Product $product, array $images): void
203220
{
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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\Product\Image;
9+
10+
/**
11+
* Convert array into string representation
12+
*/
13+
class ConvertImageMiscParamsToReadableFormat
14+
{
15+
/**
16+
* Converting bool into a string representation
17+
*
18+
* @param array $miscParams
19+
* @return array
20+
*/
21+
public function convertImageMiscParamsToReadableFormat(array $miscParams): array
22+
{
23+
$miscParams['image_height'] = 'h:' . ($miscParams['image_height'] ?? 'empty');
24+
$miscParams['image_width'] = 'w:' . ($miscParams['image_width'] ?? 'empty');
25+
$miscParams['quality'] = 'q:' . ($miscParams['quality'] ?? 'empty');
26+
$miscParams['angle'] = 'r:' . ($miscParams['angle'] ?? 'empty');
27+
$miscParams['keep_aspect_ratio'] = (!empty($miscParams['keep_aspect_ratio']) ? '' : 'non') . 'proportional';
28+
$miscParams['keep_frame'] = (!empty($miscParams['keep_frame']) ? '' : 'no') . 'frame';
29+
$miscParams['keep_transparency'] = (!empty($miscParams['keep_transparency']) ? '' : 'no') . 'transparency';
30+
$miscParams['constrain_only'] = (!empty($miscParams['constrain_only']) ? 'do' : 'not') . 'constrainonly';
31+
$miscParams['background'] = !empty($miscParams['background'])
32+
? 'rgb' . implode(',', $miscParams['background'])
33+
: 'nobackground';
34+
return $miscParams;
35+
}
36+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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\Product\Image;
9+
10+
use Magento\Catalog\Helper\Image;
11+
use Magento\Catalog\Model\Product\Media\Config;
12+
use Magento\Framework\App\Filesystem\DirectoryList;
13+
use Magento\Framework\Encryption\Encryptor;
14+
use Magento\Framework\Encryption\EncryptorInterface;
15+
use Magento\Framework\Filesystem;
16+
use Magento\Framework\Filesystem\Directory\WriteInterface;
17+
use Magento\Framework\View\ConfigInterface;
18+
19+
/**
20+
* Delete image from cache
21+
*/
22+
class RemoveDeletedImagesFromCache
23+
{
24+
/**
25+
* @var ConfigInterface
26+
*/
27+
private ConfigInterface $presentationConfig;
28+
29+
/**
30+
* @var EncryptorInterface
31+
*/
32+
private EncryptorInterface $encryptor;
33+
34+
/**
35+
* @var Config
36+
*/
37+
private Config $mediaConfig;
38+
39+
/**
40+
* @var WriteInterface
41+
*/
42+
private WriteInterface $mediaDirectory;
43+
44+
/**
45+
* @var ParamsBuilder
46+
*/
47+
private ParamsBuilder $imageParamsBuilder;
48+
49+
/**
50+
* @var ConvertImageMiscParamsToReadableFormat
51+
*/
52+
private ConvertImageMiscParamsToReadableFormat $convertImageMiscParamsToReadableFormat;
53+
54+
/**
55+
* @param ConfigInterface $presentationConfig
56+
* @param EncryptorInterface $encryptor
57+
* @param Config $mediaConfig
58+
* @param Filesystem $filesystem
59+
* @param ParamsBuilder $imageParamsBuilder
60+
* @param ConvertImageMiscParamsToReadableFormat $convertImageMiscParamsToReadableFormat
61+
*/
62+
public function __construct(
63+
ConfigInterface $presentationConfig,
64+
EncryptorInterface $encryptor,
65+
Config $mediaConfig,
66+
Filesystem $filesystem,
67+
ParamsBuilder $imageParamsBuilder,
68+
ConvertImageMiscParamsToReadableFormat $convertImageMiscParamsToReadableFormat
69+
) {
70+
$this->presentationConfig = $presentationConfig;
71+
$this->encryptor = $encryptor;
72+
$this->mediaConfig = $mediaConfig;
73+
$this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
74+
$this->imageParamsBuilder = $imageParamsBuilder;
75+
$this->convertImageMiscParamsToReadableFormat = $convertImageMiscParamsToReadableFormat;
76+
}
77+
78+
/**
79+
* Remove deleted images from cache.
80+
*
81+
* @param array $files
82+
*
83+
* @return void
84+
*/
85+
public function removeDeletedImagesFromCache(array $files): void
86+
{
87+
if (count($files) === 0) {
88+
return;
89+
}
90+
$images = $this->presentationConfig
91+
->getViewConfig(['area' => \Magento\Framework\App\Area::AREA_FRONTEND])
92+
->getMediaEntities(
93+
'Magento_Catalog',
94+
Image::MEDIA_TYPE_CONFIG_NODE
95+
);
96+
97+
$catalogPath = $this->mediaConfig->getBaseMediaPath();
98+
99+
foreach ($images as $imageData) {
100+
$imageMiscParams = $this->imageParamsBuilder->build($imageData);
101+
102+
if (isset($imageMiscParams['image_type'])) {
103+
unset($imageMiscParams['image_type']);
104+
}
105+
106+
$cacheId = $this->encryptor->hash(
107+
implode('_', $this->convertImageMiscParamsToReadableFormat
108+
->convertImageMiscParamsToReadableFormat($imageMiscParams)),
109+
Encryptor::HASH_VERSION_MD5
110+
);
111+
112+
foreach ($files as $filePath) {
113+
$this->mediaDirectory->delete(
114+
$catalogPath . '/cache/' . $cacheId . '/' . $filePath
115+
);
116+
}
117+
}
118+
}
119+
}

app/code/Magento/Catalog/Model/ResourceModel/Product/Compare/Item.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,47 @@
55
*/
66
namespace Magento\Catalog\Model\ResourceModel\Product\Compare;
77

8+
use Magento\Customer\Model\Config\Share;
9+
use Magento\Store\Model\StoreManagerInterface;
10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\Model\ResourceModel\Db\Context;
12+
813
/**
914
* Catalog compare item resource model
1015
*
1116
* @author Magento Core Team <[email protected]>
1217
*/
1318
class Item extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
1419
{
20+
/**
21+
* @var Share
22+
*/
23+
private $share;
24+
25+
/**
26+
* @var StoreManagerInterface
27+
*/
28+
private $storeManager;
29+
30+
/**
31+
* Class constructor
32+
*
33+
* @param Context $context
34+
* @param string $connectionName
35+
* @param Share|null $share
36+
* @param StoreManagerInterface|null $storeManager
37+
*/
38+
public function __construct(
39+
Context $context,
40+
$connectionName = null,
41+
?Share $share = null,
42+
?StoreManagerInterface $storeManager = null
43+
) {
44+
$this->share = $share ?? ObjectManager::getInstance()->get(Share::class);
45+
$this->storeManager = $storeManager ?? ObjectManager::getInstance()->get(StoreManagerInterface::class);
46+
parent::__construct($context, $connectionName);
47+
}
48+
1549
/**
1650
* Initialize connection
1751
*
@@ -41,8 +75,12 @@ public function loadByProduct(\Magento\Catalog\Model\Product\Compare\Item $objec
4175

4276
if ($object->getCustomerId()) {
4377
$select->where('customer_id = ?', (int)$object->getCustomerId());
78+
if (!$this->share->isGlobalScope()) {
79+
$select->where('store_id = ?', $this->storeManager->getStore()->getId());
80+
}
4481
} else {
4582
$select->where('visitor_id = ?', (int)$object->getVisitorId());
83+
$select->where('store_id = ?', $this->storeManager->getStore()->getId());
4684
}
4785

4886
if ($object->getListId()) {
@@ -236,10 +274,15 @@ public function clearItems($visitorId = null, $customerId = null)
236274
if ($customerId) {
237275
$customerId = (int)$customerId;
238276
$where[] = $this->getConnection()->quoteInto('customer_id = ?', $customerId);
277+
if (!$this->share->isGlobalScope()) {
278+
$where[] = $this->getConnection()
279+
->quoteInto('store_id = ?', $this->storeManager->getStore()->getId());
280+
}
239281
}
240282
if ($visitorId) {
241283
$visitorId = (int)$visitorId;
242284
$where[] = $this->getConnection()->quoteInto('visitor_id = ?', $visitorId);
285+
$where[] = $this->getConnection()->quoteInto('store_id = ?', $this->storeManager->getStore()->getId());
243286
}
244287
if (!$where) {
245288
return $this;

0 commit comments

Comments
 (0)