Skip to content

Commit

Permalink
Use main image options defined in plugin configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
lruozzi9 committed Jul 4, 2024
1 parent 806d200 commit 1dcfe13
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/Converter/CommonOrderConverterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ abstract private function getCacheManager(): CacheManager;

abstract private function getTranslator(): TranslatorInterface;

abstract private function getSchema(): string;

abstract private function getImageFilter(): string;

abstract private function getMainImageType(): string;

private function getCustomer(OrderInterface $order): ?Customer
{
$customer = $order->getCustomer();
Expand Down Expand Up @@ -106,7 +112,7 @@ private function createOrderLineFromOrderItem(OrderInterface $order, OrderItemIn
'',
'GET',
$hostname,
'https',
$this->getSchema(),
));
}
$slug = $orderItem->getProduct()?->getSlug();
Expand All @@ -123,7 +129,7 @@ private function createOrderLineFromOrderItem(OrderInterface $order, OrderItemIn
if ($productImagePath !== null) {
$imageUrl = $this->getCacheManager()->getBrowserPath(
$productImagePath,
'sylius_shop_product_thumbnail',
$this->getImageFilter(),
);
}
$this->getUrlGenerator()->setContext($previousContext);
Expand Down Expand Up @@ -206,7 +212,7 @@ private function getProductImagePath(?ProductInterface $product): ?string
if ($product === null) {
return null;
}
$images = $product->getImagesByType('main_image');
$images = $product->getImagesByType($this->getMainImageType());
foreach ($images as $image) {
return $image->getPath();
}
Expand Down
17 changes: 17 additions & 0 deletions src/Converter/OrderConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public function __construct(
private TranslatorInterface $translator,
private UrlGeneratorInterface $urlGenerator,
private CacheManager $cacheManager,
private string $mainImageType,
private string $imageFilter,
) {
}

Expand Down Expand Up @@ -78,4 +80,19 @@ private function getTranslator(): TranslatorInterface
{
return $this->translator;
}

private function getSchema(): string
{
return 'https';
}

private function getImageFilter(): string
{
return $this->imageFilter;
}

private function getMainImageType(): string
{
return $this->mainImageType;
}
}
17 changes: 17 additions & 0 deletions src/Converter/PaymentConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public function __construct(
private TranslatorInterface $translator,
private UrlGeneratorInterface $urlGenerator,
private CacheManager $cacheManager,
private string $mainImageType,
private string $imageFilter,
) {
}

Expand Down Expand Up @@ -96,4 +98,19 @@ private function getTranslator(): TranslatorInterface
{
return $this->translator;
}

private function getSchema(): string
{
return 'https';
}

private function getImageFilter(): string
{
return $this->imageFilter;
}

private function getMainImageType(): string
{
return $this->mainImageType;
}
}
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('acme_sylius_example_plugin');
$treeBuilder = new TreeBuilder('webgriffe_sylius_klarna_plugin');
$rootNode = $treeBuilder->getRootNode();

$rootNode
Expand Down
11 changes: 9 additions & 2 deletions src/DependencyInjection/WebgriffeSyliusKlarnaExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function load(array $configs, ContainerBuilder $container): void

$loader->load('services.php');

$this->addImageOptionsConverters($container, $config);
$this->addImageOptionsOnConverters($container, $config);
}

public function prepend(ContainerBuilder $container): void
Expand All @@ -50,7 +50,14 @@ protected function getNamespacesOfMigrationsExecutedBefore(): array
];
}

private function addImageOptionsConverters(ContainerBuilder $container, array $config): void
private function addImageOptionsOnConverters(ContainerBuilder $container, array $config): void
{
$definition = $container->getDefinition('webgriffe_sylius_klarna.converter.order');
$definition->setArgument('$mainImageType', $config['product_images']['type']);
$definition->setArgument('$imageFilter', $config['product_images']['filter']);

$definition = $container->getDefinition('webgriffe_sylius_klarna.converter.payment');
$definition->setArgument('$mainImageType', $config['product_images']['type']);
$definition->setArgument('$imageFilter', $config['product_images']['filter']);
}
}

0 comments on commit 1dcfe13

Please sign in to comment.