Skip to content

Commit 4559910

Browse files
🔃 [Magento Community Engineering] Community Contributions - 2.4-develop latest changes
Accepted Community Pull Requests: - #32186: Customers that have unsubscribed to the newsletter in the time span from when the queue was created and the actual sending of the newsletter still receive newsletters (by @engcom-Charlie) - #32273: `catalog_product_entity_media_gallery` not cleared when related products deleted. (by @engcom-Charlie) - #30755: MC-38592 Fixed load regions for scope (by @bogutskyy) - #31961: Removed CliCacheFlushActionGroup usage for Wishlist module (by @sergiy-v) - #32212: Magento_Authorization model Rules/Role calling a resource model function update, that is not exist in resource model(Rules/Role) (by @engcom-Charlie) - #28973: Scheduled price rule time zone correction (by @AntonEvers) - #32389: Update ListProduct.php (by @mamsincl) Fixed GitHub Issues: - #32116: Customers that have unsubscribed to the newsletter in the time span from when the queue was created and the actual sending of the newsletter still receive newsletters (reported by @victortodoran) has been fixed in #32186 by @engcom-Charlie in 2.4-develop branch Related commits: 1. 35468fc 2. 23bfcdd 3. d594fa7 4. 0ecec5d 5. d98dc43 6. ec464f5 7. 64066c4 8. f3c3a1d - #17727: `catalog_product_entity_media_gallery` not cleared when related products deleted. (reported by @likemusic) has been fixed in #32273 by @engcom-Charlie in 2.4-develop branch Related commits: 1. b2c47af 2. b40d857 3. 98237f1 - #30577: Can't place order on admin: "regionId" is required (reported by @kassner) has been fixed in #30755 by @bogutskyy in 2.4-develop branch Related commits: 1. e8507db 2. 228cb68 3. 4e48a7a 4. 165a1c1 5. 3bfc316 6. b611bae 7. cbe1cd9 8. ef066ad 9. 95bf7dc 10. ee50311 11. 9e061d1 - #31962: [Issue] Removed CliCacheFlushActionGroup usage for Wishlist module (reported by @m2-assistant[bot]) has been fixed in #31961 by @sergiy-v in 2.4-develop branch Related commits: 1. 020bc36 2. 9437843 3. b629ddb 4. f1fdf84 - #30756: Magento_Authorization model Rules/Role calling a resource model function update, that is not exist in resource model(Rules/Role) (reported by @narendrarwt) has been fixed in #32212 by @engcom-Charlie in 2.4-develop branch Related commits: 1. 8615941 - #29549: [Issue] Scheduled price rule time zone correction (reported by @m2-assistant[bot]) has been fixed in #28973 by @AntonEvers in 2.4-develop branch Related commits: 1. 5972daa 2. 0e68e70 3. c7def24 4. c614f89 5. 3cbc4f6 6. 46a769f 7. d9a0f6f 8. 6bf3dfc 9. f2d7be3 10. 6eef782 11. d6b3c40 12. fa821da 13. ee7176f - #32088: ArrayIterator incompatible method current() php 7.4 (reported by @jeroenkosse) has been fixed in #32389 by @mamsincl in 2.4-develop branch Related commits: 1. e5b3bb3 2. b13fcbb
2 parents 69f3cd0 + 933663d commit 4559910

File tree

39 files changed

+694
-193
lines changed

39 files changed

+694
-193
lines changed

app/code/Magento/Authorization/Model/Role.php

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,32 @@
55
*/
66
namespace Magento\Authorization\Model;
77

8+
use Magento\Authorization\Model\ResourceModel\Role\Collection;
9+
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\Model\AbstractModel;
11+
812
/**
913
* Admin Role Model
1014
*
1115
* @api
1216
* @method int getParentId()
13-
* @method \Magento\Authorization\Model\Role setParentId(int $value)
17+
* @method Role setParentId(int $value)
1418
* @method int getTreeLevel()
15-
* @method \Magento\Authorization\Model\Role setTreeLevel(int $value)
19+
* @method Role setTreeLevel(int $value)
1620
* @method int getSortOrder()
17-
* @method \Magento\Authorization\Model\Role setSortOrder(int $value)
21+
* @method Role setSortOrder(int $value)
1822
* @method string getRoleType()
19-
* @method \Magento\Authorization\Model\Role setRoleType(string $value)
23+
* @method Role setRoleType(string $value)
2024
* @method int getUserId()
21-
* @method \Magento\Authorization\Model\Role setUserId(int $value)
25+
* @method Role setUserId(int $value)
2226
* @method string getUserType()
23-
* @method \Magento\Authorization\Model\Role setUserType(string $value)
27+
* @method Role setUserType(string $value)
2428
* @method string getRoleName()
25-
* @method \Magento\Authorization\Model\Role setRoleName(string $value)
29+
* @method Role setRoleName(string $value)
2630
* @api
2731
* @since 100.0.2
2832
*/
29-
class Role extends \Magento\Framework\Model\AbstractModel
33+
class Role extends AbstractModel
3034
{
3135
/**
3236
* @var string
@@ -38,23 +42,6 @@ class Role extends \Magento\Framework\Model\AbstractModel
3842
*/
3943
protected $_cacheTag = 'user_assigned_role';
4044

41-
/**
42-
* @param \Magento\Framework\Model\Context $context
43-
* @param \Magento\Framework\Registry $registry
44-
* @param \Magento\Authorization\Model\ResourceModel\Role $resource
45-
* @param \Magento\Authorization\Model\ResourceModel\Role\Collection $resourceCollection
46-
* @param array $data
47-
*/
48-
public function __construct( //phpcs:ignore Generic.CodeAnalysis.UselessOverridingMethod
49-
\Magento\Framework\Model\Context $context,
50-
\Magento\Framework\Registry $registry,
51-
\Magento\Authorization\Model\ResourceModel\Role $resource,
52-
\Magento\Authorization\Model\ResourceModel\Role\Collection $resourceCollection,
53-
array $data = []
54-
) {
55-
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
56-
}
57-
5845
/**
5946
* @inheritDoc
6047
*/
@@ -70,31 +57,30 @@ public function __sleep()
7057
public function __wakeup()
7158
{
7259
parent::__wakeup();
73-
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
74-
$this->_resource = $objectManager->get(\Magento\Authorization\Model\ResourceModel\Role::class);
75-
$this->_resourceCollection = $objectManager->get(
76-
\Magento\Authorization\Model\ResourceModel\Role\Collection::class
77-
);
60+
$objectManager = ObjectManager::getInstance();
61+
$this->_resource = $objectManager->get(ResourceModel\Role::class);
62+
$this->_resourceCollection = $objectManager->get(Collection::class);
7863
}
7964

8065
/**
81-
* Class constructor
82-
*
83-
* @return void
66+
* @inheritdoc
8467
*/
8568
protected function _construct()
8669
{
87-
$this->_init(\Magento\Authorization\Model\ResourceModel\Role::class);
70+
$this->_init(ResourceModel\Role::class);
8871
}
8972

9073
/**
91-
* Update object into database
74+
* Obsolete method of update
9275
*
9376
* @return $this
77+
* @deprecated Method was never implemented and used.
9478
*/
9579
public function update()
9680
{
97-
$this->getResource()->update($this);
81+
// phpcs:disable Magento2.Functions.DiscouragedFunction
82+
trigger_error('Method was never implemented and used.', E_USER_DEPRECATED);
83+
9884
return $this;
9985
}
10086

app/code/Magento/Catalog/Block/Product/ListProduct.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ private function initializeProductCollection()
461461
// if the product is associated with any category
462462
if ($categories->count()) {
463463
// show products from this category
464-
$this->setCategoryId(current($categories->getIterator())->getId());
464+
$this->setCategoryId($categories->getIterator()->current()->getId());
465465
}
466466
}
467467

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Catalog\Plugin;
10+
11+
use Magento\Catalog\Api\Data\ProductInterface;
12+
use Magento\Catalog\Api\ProductRepositoryInterface;
13+
use Magento\Catalog\Model\Product\Gallery\ReadHandler;
14+
use Magento\Catalog\Model\ResourceModel\Product\Gallery;
15+
16+
/**
17+
* Responsible for deleting images from media gallery after deleting product
18+
*/
19+
class RemoveImagesFromGalleryAfterRemovingProduct
20+
{
21+
/**
22+
* @var Gallery
23+
*/
24+
private $galleryResource;
25+
26+
/**
27+
* @var ReadHandler
28+
*/
29+
private $mediaGalleryReadHandler;
30+
31+
/**
32+
* @param Gallery $galleryResource
33+
* @param ReadHandler $mediaGalleryReadHandler
34+
*/
35+
public function __construct(Gallery $galleryResource, ReadHandler $mediaGalleryReadHandler)
36+
{
37+
$this->galleryResource = $galleryResource;
38+
$this->mediaGalleryReadHandler = $mediaGalleryReadHandler;
39+
}
40+
41+
/**
42+
* Delete media gallery after deleting product
43+
*
44+
* @param ProductRepositoryInterface $subject
45+
* @param callable $proceed
46+
* @param ProductInterface $product
47+
* @return bool
48+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
49+
*/
50+
public function aroundDelete(
51+
ProductRepositoryInterface $subject,
52+
callable $proceed,
53+
ProductInterface $product
54+
): bool {
55+
$mediaGalleryAttributeId = $this->mediaGalleryReadHandler->getAttribute()->getAttributeId();
56+
$mediaGallery = $this->galleryResource->loadProductGalleryByAttributeId($product, $mediaGalleryAttributeId);
57+
58+
$result = $proceed($product);
59+
60+
if ($mediaGallery) {
61+
$this->galleryResource->deleteGallery(array_column($mediaGallery, 'value_id'));
62+
}
63+
64+
return $result;
65+
}
66+
}

app/code/Magento/Catalog/Test/Unit/Block/Product/ListProductTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public function testGetIdentities()
195195

196196
$this->catCollectionMock->expects($this->once())
197197
->method('getIterator')
198-
->willReturn([$currentCategory]);
198+
->willReturn(new \ArrayIterator([$currentCategory]));
199199

200200
$this->prodCollectionMock->expects($this->any())
201201
->method('getIterator')

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,4 +1319,8 @@
13191319
</argument>
13201320
</arguments>
13211321
</type>
1322+
<type name="Magento\Catalog\Api\ProductRepositoryInterface">
1323+
<plugin name="remove_images_from_gallery_after_removing_product"
1324+
type="Magento\Catalog\Plugin\RemoveImagesFromGalleryAfterRemovingProduct"/>
1325+
</type>
13221326
</config>

0 commit comments

Comments
 (0)