The plugin \Magento\Customer\Model\Plugin\GetListCustomerGroupExcludedWebsite always created a new extension object for customer group lists, regardless of if one already exists. So it overwrote other extension attributes. This change checks if an extension object already exists.
Manual testing scenarios (*)
Create your own module, introducing another extension attribute for the customer group entity. In this example, an extension attribute named "discount_percentage" is used.
<?php
declare(strict_types=1);
namespace Custom\CustomerGroupDiscount\Plugin;
use Magento\Customer\Api\Data\GroupExtensionInterfaceFactory;
use Magento\Customer\Api\Data\GroupInterface;
use Magento\Framework\Api\ExtensibleDataInterface;
use Magento\Framework\Api\ExtensionAttribute\JoinProcessor;
class ExtensionAttributeJoinProcessorPlugin
{
public function __construct(
private readonly GroupExtensionInterfaceFactory $groupExtensionInterfaceFactory
) {
}
/**
* Set "discount_percentage" extension attribute based on raw data from database
*/
public function afterExtractExtensionAttributes(
JoinProcessor $subject,
array $result,
string $extensibleEntityClass,
array $data
): array {
if ($extensibleEntityClass != ltrim(GroupInterface::class, '\\')) {
return $result;
}
if (!isset($result[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY])) {
$extensionAttributes = $this->groupExtensionInterfaceFactory->create();
$result[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY] = $extensionAttributes;
}
$result[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]->setDiscountPercentage($data['discount_percentage']);
return $result;
}
}
Without this PR, the customer group list doesn't contain the extension attribute discount_percentage.
Contribution checklist
[ ] Pull request has a meaningful description of its purpose
[ ] All commits are accompanied by meaningful commit messages
[ ] All new or changed code is covered with unit/integration tests (if applicable)
[ ] README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
[ ] All automated tests passed successfully (all builds are green)
Description
The plugin
\Magento\Customer\Model\Plugin\GetListCustomerGroupExcludedWebsite
always created a new extension object for customer group lists, regardless of if one already exists. So it overwrote other extension attributes. This change checks if an extension object already exists.Manual testing scenarios (*)
Create your own module, introducing another extension attribute for the customer group entity. In this example, an extension attribute named "discount_percentage" is used.
etc/db_schema.xml:
etc/extension_attributes.xml:
etc/di.xml:
Plugin/ExtensionAttributeJoinProcessorPlugin.php:
Without this PR, the customer group list doesn't contain the extension attribute discount_percentage.
Contribution checklist