-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa5e1d4
commit 8f0ea9e
Showing
3 changed files
with
68 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Diglin\AutoCustomerGroupBundle\EventListener; | ||
|
||
use Doctrine\Persistence\ManagerRegistry; | ||
use Diglin\AutoCustomerGroupBundle\DependencyInjection\AutoCustomerGroupExtension; | ||
use Diglin\AutoCustomerGroupBundle\DependencyInjection\Configuration; | ||
use Oro\Bundle\ConfigBundle\Config\ConfigManager; | ||
use Oro\Bundle\ConfigBundle\Event\ConfigSettingsUpdateEvent; | ||
use Oro\Bundle\CustomerBundle\Entity\CustomerGroup; | ||
|
||
class SystemConfigListener | ||
{ | ||
protected ManagerRegistry $registry; | ||
|
||
protected string $ownerClass; | ||
|
||
public function __construct(ManagerRegistry $registry) | ||
{ | ||
$this->registry = $registry; | ||
} | ||
|
||
public function onFormPreSetData(ConfigSettingsUpdateEvent $event): void | ||
{ | ||
$settingsKey = implode(ConfigManager::SECTION_VIEW_SEPARATOR, [AutoCustomerGroupExtension::ALIAS, Configuration::ASSIGNMENT_CUSTOMER_GROUP]); | ||
$settings = $event->getSettings(); | ||
if (is_array($settings) | ||
&& !empty($settings[$settingsKey]['value']) | ||
) { | ||
$settings[$settingsKey]['value'] = $this->registry | ||
->getManagerForClass(CustomerGroup::class) | ||
->find(CustomerGroup::class, $settings[$settingsKey]['value']); | ||
$event->setSettings($settings); | ||
} | ||
} | ||
|
||
public function onSettingsSaveBefore(ConfigSettingsUpdateEvent $event): void | ||
{ | ||
$settings = $event->getSettings(); | ||
|
||
if (!array_key_exists('value', $settings)) { | ||
return; | ||
} | ||
|
||
if (!is_a($settings['value'], CustomerGroup::class)) { | ||
return; | ||
} | ||
|
||
/** @var object $owner */ | ||
$owner = $settings['value']; | ||
$settings['value'] = $owner->getId(); | ||
$event->setSettings($settings); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters