@@ 10-38 (lines=29) @@ | ||
7 | use Sylius\Component\Core\Model\ProductInterface; |
|
8 | use Sylius\Component\Resource\Repository\RepositoryInterface; |
|
9 | ||
10 | final class ProductBlockInitializer |
|
11 | { |
|
12 | /** |
|
13 | * @var RepositoryInterface |
|
14 | */ |
|
15 | private $productRepository; |
|
16 | ||
17 | /** |
|
18 | * @param RepositoryInterface $productRepository |
|
19 | */ |
|
20 | public function __construct(RepositoryInterface $productRepository) |
|
21 | { |
|
22 | $this->productRepository = $productRepository; |
|
23 | } |
|
24 | ||
25 | public function postLoad(LifecycleEventArgs $event) |
|
26 | { |
|
27 | $productBlock = $event->getObject(); |
|
28 | ||
29 | if (!$productBlock instanceof ProductBlock) { |
|
30 | return; |
|
31 | } |
|
32 | ||
33 | /** @var ProductInterface|null $product */ |
|
34 | $product = $this->productRepository->findOneBy(['code' => $productBlock->getProductCode()]); |
|
35 | ||
36 | $productBlock->setProduct($product); |
|
37 | } |
|
38 | } |
|
39 |
@@ 10-38 (lines=29) @@ | ||
7 | use Sylius\Component\Core\Model\TaxonInterface; |
|
8 | use Sylius\Component\Resource\Repository\RepositoryInterface; |
|
9 | ||
10 | final class TaxonBlockInitializer |
|
11 | { |
|
12 | /** |
|
13 | * @var RepositoryInterface |
|
14 | */ |
|
15 | private $taxonRepository; |
|
16 | ||
17 | /** |
|
18 | * @param RepositoryInterface $taxonRepository |
|
19 | */ |
|
20 | public function __construct(RepositoryInterface $taxonRepository) |
|
21 | { |
|
22 | $this->taxonRepository = $taxonRepository; |
|
23 | } |
|
24 | ||
25 | public function postLoad(LifecycleEventArgs $event) |
|
26 | { |
|
27 | $taxonBlock = $event->getObject(); |
|
28 | ||
29 | if (!$taxonBlock instanceof TaxonBlock) { |
|
30 | return; |
|
31 | } |
|
32 | ||
33 | /** @var TaxonInterface|null $taxon */ |
|
34 | $taxon = $this->taxonRepository->findOneBy(['code' => $taxonBlock->getTaxonCode()]); |
|
35 | ||
36 | $taxonBlock->setTaxon($taxon); |
|
37 | } |
|
38 | } |
|
39 |