-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Don't load all customer options to filter in PHP 2. Rename the class to have a more descriptive name and fixing the tests
- Loading branch information
Showing
6 changed files
with
94 additions
and
82 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,48 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Brille24 customer options plugin. | ||
* | ||
* (c) Brille24 GmbH | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Brille24\SyliusCustomerOptionsPlugin\EventListener; | ||
|
||
use Brille24\SyliusCustomerOptionsPlugin\Entity\CustomerOptions\CustomerOptionValuePriceInterface; | ||
use Brille24\SyliusCustomerOptionsPlugin\Factory\CustomerOptionValuePriceFactoryInterface; | ||
use Brille24\SyliusCustomerOptionsPlugin\Repository\CustomerOptionValueRepositoryInterface; | ||
use Doctrine\ORM\Event\LifecycleEventArgs; | ||
use Doctrine\ORM\Event\PrePersistEventArgs; | ||
use Sylius\Component\Core\Model\ChannelInterface; | ||
|
||
final class ChannelPersistListener | ||
{ | ||
public function __construct( | ||
private CustomerOptionValuePriceFactoryInterface $customerOptionValuePriceFactory, | ||
private CustomerOptionValueRepositoryInterface $customerOptionValueRepository | ||
) { | ||
} | ||
|
||
public function prePersist(LifecycleEventArgs $args): void | ||
{ | ||
$channel = $args->getObject(); | ||
|
||
if (!$channel instanceof ChannelInterface) { | ||
return; | ||
} | ||
|
||
$customerOptionValues = $this->customerOptionValueRepository->findValuesWithoutPricingInChannel($channel); | ||
|
||
foreach ($customerOptionValues as $customerOptionValue) { | ||
/** @var CustomerOptionValuePriceInterface $newPrice */ | ||
$newPrice = $this->customerOptionValuePriceFactory->createNew(); | ||
$newPrice->setChannel($channel); | ||
$customerOptionValue->addPrice($newPrice); | ||
$args->getObjectManager()->persist($customerOptionValue); | ||
} | ||
} | ||
} |
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
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