-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Synolia\SyliusAkeneoPlugin\Component\Cache; | ||
|
||
class CacheKey | ||
{ | ||
public const FAMILIES = 'akeneo:families'; | ||
|
||
public const FAMILY = 'akeneo:family:%s'; | ||
|
||
public const FAMILY_BY_VARIANT_CODE = 'akeneo:family_by_variant_code:%s'; | ||
|
||
public const FAMILY_VARIANTS = 'akeneo:family_variants:%s'; | ||
|
||
public const ATTRIBUTES = 'akeneo:attributes'; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Synolia\SyliusAkeneoPlugin\Processor\ProductGroup; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use Psr\Log\LoggerInterface; | ||
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; | ||
use Sylius\Component\Resource\Factory\FactoryInterface; | ||
use Synolia\SyliusAkeneoPlugin\Entity\ProductGroupInterface; | ||
|
||
class ProductGroupProcessor | ||
{ | ||
public function __construct( | ||
private EntityManagerInterface $entityManager, | ||
private LoggerInterface $logger, | ||
private FamilyVariationAxeProcessor $familyVariationAxeProcessor, | ||
private EntityRepository $productGroupRepository, | ||
private FactoryInterface $productGroupFactory, | ||
) { | ||
} | ||
|
||
public function process(array $resource): void | ||
{ | ||
$this->createProductGroups($resource); | ||
$this->familyVariationAxeProcessor->process($resource); | ||
} | ||
|
||
private function createGroupForCodeAndFamily( | ||
string $code, | ||
string $family, | ||
string $familyVariant, | ||
?string $parent = null, | ||
): ProductGroupInterface { | ||
if (isset($this->productGroupsMapping[$code])) { | ||
Check failure on line 36 in src/Processor/ProductGroup/ProductGroupProcessor.php GitHub Actions / PHP 8.2 Symfony 5.4.*
Check failure on line 36 in src/Processor/ProductGroup/ProductGroupProcessor.php GitHub Actions / PHP 8.2 Symfony 5.4.*
Check failure on line 36 in src/Processor/ProductGroup/ProductGroupProcessor.php GitHub Actions / PHP 8.2 Symfony 6.2.*
|
||
return $this->productGroupsMapping[$code]; | ||
} | ||
|
||
$productGroup = $this->productGroupRepository->findOneBy(['model' => $code]); | ||
|
||
if ($productGroup instanceof ProductGroupInterface) { | ||
$this->productGroupsMapping[$code] = $productGroup; | ||
Check failure on line 43 in src/Processor/ProductGroup/ProductGroupProcessor.php GitHub Actions / PHP 8 Symfony 5.4.*
Check failure on line 43 in src/Processor/ProductGroup/ProductGroupProcessor.php GitHub Actions / PHP 8 Symfony 5.4.*
Check failure on line 43 in src/Processor/ProductGroup/ProductGroupProcessor.php GitHub Actions / PHP 8 Symfony 6.2.*
Check failure on line 43 in src/Processor/ProductGroup/ProductGroupProcessor.php GitHub Actions / PHP 8 Symfony 6.2.*
Check failure on line 43 in src/Processor/ProductGroup/ProductGroupProcessor.php GitHub Actions / PHP 8.2 Symfony 5.4.*
Check failure on line 43 in src/Processor/ProductGroup/ProductGroupProcessor.php GitHub Actions / PHP 8.2 Symfony 5.4.*
Check failure on line 43 in src/Processor/ProductGroup/ProductGroupProcessor.php GitHub Actions / PHP 8.2 Symfony 6.2.*
|
||
|
||
$this->logger->info(sprintf( | ||
'Skipping ProductGroup "%s" for family "%s" as it already exists.', | ||
$code, | ||
$family, | ||
)); | ||
|
||
$productGroup->setParent($this->productGroupsMapping[$parent] ?? null); | ||
$productGroup->setModel($code); | ||
$productGroup->setFamily($family); | ||
$productGroup->setFamilyVariant($familyVariant); | ||
$this->entityManager->persist($productGroup); | ||
|
||
return $productGroup; | ||
} | ||
|
||
$this->logger->info(sprintf( | ||
'Creating ProductGroup "%s" for family "%s"', | ||
$code, | ||
$family, | ||
)); | ||
|
||
/** @var ProductGroupInterface $productGroup */ | ||
$productGroup = $this->productGroupFactory->createNew(); | ||
$productGroup->setParent($this->productGroupsMapping[$parent] ?? null); | ||
Check failure on line 68 in src/Processor/ProductGroup/ProductGroupProcessor.php GitHub Actions / PHP 8.2 Symfony 5.4.*
Check failure on line 68 in src/Processor/ProductGroup/ProductGroupProcessor.php GitHub Actions / PHP 8.2 Symfony 5.4.*
Check failure on line 68 in src/Processor/ProductGroup/ProductGroupProcessor.php GitHub Actions / PHP 8.2 Symfony 6.2.*
|
||
$productGroup->setModel($code); | ||
$productGroup->setFamily($family); | ||
$productGroup->setFamilyVariant($familyVariant); | ||
$this->entityManager->persist($productGroup); | ||
$this->productGroupsMapping[$code] = $productGroup; | ||
Check failure on line 73 in src/Processor/ProductGroup/ProductGroupProcessor.php GitHub Actions / PHP 8 Symfony 5.4.*
Check failure on line 73 in src/Processor/ProductGroup/ProductGroupProcessor.php GitHub Actions / PHP 8 Symfony 5.4.*
Check failure on line 73 in src/Processor/ProductGroup/ProductGroupProcessor.php GitHub Actions / PHP 8 Symfony 6.2.*
Check failure on line 73 in src/Processor/ProductGroup/ProductGroupProcessor.php GitHub Actions / PHP 8 Symfony 6.2.*
Check failure on line 73 in src/Processor/ProductGroup/ProductGroupProcessor.php GitHub Actions / PHP 8.2 Symfony 5.4.*
Check failure on line 73 in src/Processor/ProductGroup/ProductGroupProcessor.php GitHub Actions / PHP 8.2 Symfony 5.4.*
Check failure on line 73 in src/Processor/ProductGroup/ProductGroupProcessor.php GitHub Actions / PHP 8.2 Symfony 6.2.*
|
||
|
||
return $productGroup; | ||
} | ||
|
||
private function createProductGroups(array $resource): void | ||
{ | ||
if (null !== $resource['parent']) { | ||
$this->createGroupForCodeAndFamily($resource['parent'], $resource['family'], $resource['family_variant']); | ||
} | ||
|
||
if (null !== $resource['code']) { | ||
$this->createGroupForCodeAndFamily($resource['code'], $resource['family'], $resource['family_variant'], $resource['parent']); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Synolia\SyliusAkeneoPlugin\Retriever; | ||
|
||
interface FamilyVariantRetrieverInterface | ||
{ | ||
public function getVariants(string $familyCode): array; | ||
} |