Skip to content

Commit 3cf1a10

Browse files
authored
Merge pull request #10161 from magento-gl/spartans_pr_29102025
[Spartans] BugFixes Delivery
2 parents 044d35d + e24a9dc commit 3cf1a10

File tree

13 files changed

+2006
-56
lines changed

13 files changed

+2006
-56
lines changed

app/code/Magento/Catalog/Block/Adminhtml/Category/Tab/Product.php

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Magento\Catalog\Model\Product\Attribute\Source\Status;
1818
use Magento\Catalog\Model\Product\Visibility;
1919
use Magento\Catalog\Model\ProductFactory;
20+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
2021
use Magento\Framework\App\ObjectManager;
2122
use Magento\Framework\Registry;
2223

@@ -42,6 +43,11 @@ class Product extends Extended
4243
*/
4344
private $visibility;
4445

46+
/**
47+
* @var ProductCollectionFactory|mixed
48+
*/
49+
private ProductCollectionFactory $productCollectionFactory;
50+
4551
/**
4652
* @param Context $context
4753
* @param Data $backendHelper
@@ -50,6 +56,7 @@ class Product extends Extended
5056
* @param array $data
5157
* @param Visibility|null $visibility
5258
* @param Status|null $status
59+
* @param ProductCollectionFactory|null $productCollectionFactory
5360
*/
5461
public function __construct(
5562
Context $context,
@@ -58,12 +65,16 @@ public function __construct(
5865
Registry $coreRegistry,
5966
array $data = [],
6067
?Visibility $visibility = null,
61-
?Status $status = null
68+
?Status $status = null,
69+
?ProductCollectionFactory $productCollectionFactory = null
6270
) {
6371
$this->_productFactory = $productFactory;
6472
$this->_coreRegistry = $coreRegistry;
6573
$this->visibility = $visibility ?: ObjectManager::getInstance()->get(Visibility::class);
6674
$this->status = $status ?: ObjectManager::getInstance()->get(Status::class);
75+
$this->productCollectionFactory = $productCollectionFactory ?: ObjectManager::getInstance()->get(
76+
ProductCollectionFactory::class
77+
);
6778
parent::__construct($context, $backendHelper, $data);
6879
}
6980

@@ -125,31 +136,30 @@ protected function _prepareCollection()
125136
if ($this->getCategory()->getId()) {
126137
$this->setDefaultFilter(['in_category' => 1]);
127138
}
128-
129-
$collection = $this->_productFactory->create()->getCollection()->addAttributeToSelect(
130-
'name'
131-
)->addAttributeToSelect(
132-
'sku'
133-
)->addAttributeToSelect(
134-
'visibility'
135-
)->addAttributeToSelect(
136-
'status'
137-
)->addAttributeToSelect(
138-
'price'
139-
)->joinField(
139+
$collection = $this->productCollectionFactory->create();
140+
$storeId = (int)$this->getRequest()->getParam('store', 0);
141+
if ($storeId > 0) {
142+
$collection->addStoreFilter($storeId);
143+
}
144+
$collection->addAttributeToSelect(
145+
[
146+
'name',
147+
'sku',
148+
'visibility',
149+
'status',
150+
'price'
151+
],
152+
'left'
153+
);
154+
$collection->joinField(
140155
'position',
141156
'catalog_category_product',
142157
'position',
143158
'product_id=entity_id',
144159
'category_id=' . (int)$this->getRequest()->getParam('id', 0),
145160
'left'
146161
);
147-
$storeId = (int)$this->getRequest()->getParam('store', 0);
148-
$collection->setStoreId($storeId);
149-
if ($storeId > 0) {
150-
$collection->addStoreFilter($storeId);
151-
}
152-
162+
$collection->getSelect()->group('e.entity_id');
153163
$this->setCollection($collection);
154164

155165
if ($this->getCategory()->getProductsReadonly()) {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Plugin\Model;
9+
10+
use Magento\Catalog\Model\Config as Subject;
11+
use Magento\Catalog\Model\Product;
12+
use Magento\Eav\Model\Config as EavConfig;
13+
14+
/**
15+
* Plugin to ensure special_price attribute is always loaded in product listings even when used_in_product_listing = 0
16+
*/
17+
class ConfigPlugin
18+
{
19+
private const SPECIAL_PRICE_ATTR_CODE = 'special_price';
20+
21+
/**
22+
* @param EavConfig $eavConfig
23+
*/
24+
public function __construct(
25+
private readonly EavConfig $eavConfig
26+
) {
27+
}
28+
29+
/**
30+
* Add special_price attribute to the list of attributes used in product listing
31+
*
32+
* @param Subject $subject
33+
* @param array $result
34+
* @return array
35+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
36+
*/
37+
public function afterGetAttributesUsedInProductListing(Subject $subject, array $result): array
38+
{
39+
// Check if special_price is already in the result
40+
if (!isset($result[self::SPECIAL_PRICE_ATTR_CODE])) {
41+
// Get the special_price attribute
42+
$specialPriceAttribute = $this->eavConfig->getAttribute(
43+
Product::ENTITY,
44+
self::SPECIAL_PRICE_ATTR_CODE
45+
);
46+
47+
if ($specialPriceAttribute && $specialPriceAttribute->getId()) {
48+
// Add it to the result
49+
$result[self::SPECIAL_PRICE_ATTR_CODE] = $specialPriceAttribute;
50+
}
51+
}
52+
return $result;
53+
}
54+
}

0 commit comments

Comments
 (0)