Skip to content

Commit 01a9241

Browse files
committed
Introduce Liip imagine filter to apply to product images (#83)
1 parent 08c4282 commit 01a9241

18 files changed

+122
-58
lines changed

composer.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@
8888
"cache:clear": "symfony-cmd",
8989
"assets:install %PUBLIC_DIR%": "symfony-cmd",
9090
"security-checker security:check": "script"
91-
}
91+
},
92+
"ecs": "vendor/bin/ecs check",
93+
"phpstan": "vendor/bin/phpstan analyse",
94+
"psalm": "vendor/bin/psalm",
95+
"phpspec": "vendor/bin/phpspec run --ansi -f progress --no-interaction",
96+
"unit": "vendor/bin/phpunit --colors=always",
97+
"behat": "vendor/bin/behat --colors --strict -vvv --no-interaction || vendor/bin/behat --colors --strict -vvv --no-interaction --rerun",
98+
"tests": [
99+
"composer validate --ansi --strict",
100+
"@ecs",
101+
"@phpstan",
102+
"@psalm",
103+
"@phpspec",
104+
"@unit",
105+
"@behat"
106+
]
92107
}
93108
}

config/services/generator.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
4-
<parameters>
5-
<parameter key="webgriffe_sylius_active_campaign.scheme">https</parameter>
6-
</parameters>
74
<services>
85
<service id="webgriffe.sylius_active_campaign_plugin.generator.channel_hostname_url"
96
class="Webgriffe\SyliusActiveCampaignPlugin\Generator\ChannelHostnameUrlGenerator">
107
<argument type="service" id="router"/>
8+
<argument type="service" id="liip_imagine.cache.manager"/>
119
</service>
1210
</services>
1311
</container>

config/services/mapper.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.factory.active_campaign.ecommerce_order_product"/>
3333
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.generator.channel_hostname_url"/>
3434
<argument type="string">%kernel.default_locale%</argument>
35-
<argument type="string">%webgriffe_sylius_active_campaign.scheme%</argument>
36-
<argument type="string">%webgriffe_sylius_active_campaign.mapper.ecommerce_order_product.image_type%</argument>
3735
</service>
3836

3937
<service id="webgriffe.sylius_active_campaign_plugin.mapper.ecommerce_order_discount"

docs/usage/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,16 @@ But what if you need to export to ActiveCampaign only some Sylius Orders? Simply
191191
The EcommerceOrderProductMapper service set the product image url needed to show it in the ActiveCampaign admin
192192
dashboard but also for the email template. By default, the service will take the first image for the product, but you can
193193
specify a Sylius image type to use for this purpose (for example you could have a `main` type used to specify the first
194-
image of the product). Set this parameter in the `webgriffe_sylius_active_campaign_plugin.yaml` file:
194+
image of the product). You could also set the Liip imagine filter to apply to the image to be loaded more easily. Set
195+
these parameters in the `webgriffe_sylius_active_campaign_plugin.yaml` file:
195196

196197
```yaml
197198
webgriffe_sylius_active_campaign:
198199
...
199200
mapper:
200201
ecommerce_order_product:
201202
image_type: 'main'
203+
image_filter: 'sylius_medium'
202204
```
203205
204206
Before creating the resource on ActiveCampaign, the EcommerceOrderEnqueuer queries for a corresponding ecommerce order

spec/Enqueuer/WebhookEnqueuerSpec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function let(
2929
$channel->getId()->willReturn(3);
3030
$channel->getActiveCampaignListId()->willReturn(4);
3131

32-
$channelHostnameUrlGenerator->generate($channel, 'webgriffe_sylius_active_campaign_list_status_webhook')->willReturn('https://localhost/webhook');
32+
$channelHostnameUrlGenerator->generateForRoute($channel, 'webgriffe_sylius_active_campaign_list_status_webhook')->willReturn('https://localhost/webhook');
3333

3434
$this->beConstructedWith($messageBus, $activeCampaignWebhookClient, $channelHostnameUrlGenerator);
3535
}

spec/Generator/ChannelHostnameUrlGeneratorSpec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ public function it_should_returns_a_url(
4545
$context->setHost('domain.com')->shouldBeCalledOnce()->willReturn($context);
4646
$context->setHost('otherdomain.com')->shouldBeCalledOnce()->willReturn($context);
4747

48-
$this->generate($channel, 'route', [])->shouldReturn('/route');
48+
$this->generateForRoute($channel, 'route', [])->shouldReturn('/route');
4949
}
5050
}

spec/Mapper/EcommerceOrderMapperSpec.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function let(
5555
ChannelHostnameUrlGeneratorInterface $channelHostnameUrlGenerator,
5656
LocaleInterface $frenchLocale
5757
): void {
58-
$channelHostnameUrlGenerator->generate($channel, 'sylius_shop_order_show', ['tokenValue' => 'sD4ew_w4s5T', '_locale' => 'it_IT'])->willReturn('https://localhost/order/sD4ew_w4s5T');
58+
$channelHostnameUrlGenerator->generateForRoute($channel, 'sylius_shop_order_show', ['tokenValue' => 'sD4ew_w4s5T', '_locale' => 'it_IT'])->willReturn('https://localhost/order/sD4ew_w4s5T');
5959

6060
$ecommerceOrderProductMapper->mapFromOrderItem($firstOrderItem)->willReturn($firstOrderProduct);
6161

@@ -250,7 +250,7 @@ public function it_maps_ecommerce_order_product_with_default_channel_locale_if_n
250250
EcommerceOrderInterface $ecommerceOrder
251251
): void {
252252
$order->getLocaleCode()->willReturn(null);
253-
$channelHostnameUrlGenerator->generate($channel, 'sylius_shop_order_show', ['tokenValue' => 'sD4ew_w4s5T', '_locale' => 'fr_FR'])->shouldBeCalledOnce()->willReturn('https://localhost/order/sD4ew_w4s5T');
253+
$channelHostnameUrlGenerator->generateForRoute($channel, 'sylius_shop_order_show', ['tokenValue' => 'sD4ew_w4s5T', '_locale' => 'fr_FR'])->shouldBeCalledOnce()->willReturn('https://localhost/order/sD4ew_w4s5T');
254254

255255
$this->mapFromOrder($order, true)->shouldReturn($ecommerceOrder);
256256
}
@@ -263,7 +263,7 @@ public function it_maps_ecommerce_order_with_default_app_locale_if_not_existing_
263263
): void {
264264
$order->getLocaleCode()->willReturn(null);
265265
$channel->getDefaultLocale()->willReturn(null);
266-
$channelHostnameUrlGenerator->generate($channel, 'sylius_shop_order_show', ['tokenValue' => 'sD4ew_w4s5T', '_locale' => 'en_US'])->shouldBeCalledOnce()->willReturn('https://localhost/order/sD4ew_w4s5T');
266+
$channelHostnameUrlGenerator->generateForRoute($channel, 'sylius_shop_order_show', ['tokenValue' => 'sD4ew_w4s5T', '_locale' => 'en_US'])->shouldBeCalledOnce()->willReturn('https://localhost/order/sD4ew_w4s5T');
267267

268268
$this->mapFromOrder($order, true)->shouldReturn($ecommerceOrder);
269269
}
@@ -277,7 +277,7 @@ public function it_maps_ecommerce_order_product_with_default_app_locale_if_not_e
277277
): void {
278278
$order->getLocaleCode()->willReturn(null);
279279
$frenchLocale->getCode()->willReturn(null);
280-
$channelHostnameUrlGenerator->generate($channel, 'sylius_shop_order_show', ['tokenValue' => 'sD4ew_w4s5T', '_locale' => 'en_US'])->shouldBeCalledOnce()->willReturn('https://localhost/order/sD4ew_w4s5T');
280+
$channelHostnameUrlGenerator->generateForRoute($channel, 'sylius_shop_order_show', ['tokenValue' => 'sD4ew_w4s5T', '_locale' => 'en_US'])->shouldBeCalledOnce()->willReturn('https://localhost/order/sD4ew_w4s5T');
281281

282282
$this->mapFromOrder($order, true)->shouldReturn($ecommerceOrder);
283283
}
@@ -289,7 +289,7 @@ public function it_maps_ecommerce_abandoned_cart_from_order(
289289
EcommerceOrderFactoryInterface $ecommerceOrderFactory,
290290
ChannelHostnameUrlGeneratorInterface $channelHostnameUrlGenerator
291291
): void {
292-
$channelHostnameUrlGenerator->generate($channel, 'sylius_shop_cart_summary', ['_locale' => 'it_IT'])->shouldBeCalledOnce()->willReturn('https://localhost/cart');
292+
$channelHostnameUrlGenerator->generateForRoute($channel, 'sylius_shop_cart_summary', ['_locale' => 'it_IT'])->shouldBeCalledOnce()->willReturn('https://localhost/cart');
293293
$ecommerceOrder->setOrderUrl('https://localhost/cart')->shouldBeCalledOnce();
294294
$order->getState()->willReturn(OrderInterface::STATE_CART);
295295
$ecommerceOrderFactory->createNew(

spec/Mapper/EcommerceOrderProductMapperSpec.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function let(
3636
): void {
3737
$ecommerceOrderProductFactory->createNew('Wine bottle', 1200, 2, '432')->willReturn($ecommerceOrderProduct);
3838

39-
$channelHostnameUrlGenerator->generate($channel, 'sylius_shop_product_show', ['_locale' => 'it_IT', 'slug' => 'wine-bottle'])->willReturn('https://localhost/products/wine-bottle');
39+
$channelHostnameUrlGenerator->generateForRoute($channel, 'sylius_shop_product_show', ['_locale' => 'it_IT', 'slug' => 'wine-bottle'])->willReturn('https://localhost/products/wine-bottle');
4040

4141
$frenchLocale->getCode()->willReturn('fr_FR');
4242

@@ -203,7 +203,7 @@ public function it_maps_ecommerce_order_product_with_default_channel_locale_if_n
203203
EcommerceOrderProductInterface $ecommerceOrderProduct
204204
): void {
205205
$order->getLocaleCode()->willReturn(null);
206-
$channelHostnameUrlGenerator->generate($channel, 'sylius_shop_product_show', ['_locale' => 'fr_FR', 'slug' => 'wine-bottle'])->shouldBeCalledOnce()->willReturn('https://localhost/products/wine-bottle');
206+
$channelHostnameUrlGenerator->generateForRoute($channel, 'sylius_shop_product_show', ['_locale' => 'fr_FR', 'slug' => 'wine-bottle'])->shouldBeCalledOnce()->willReturn('https://localhost/products/wine-bottle');
207207

208208
$this->mapFromOrderItem($orderItem)->shouldReturn($ecommerceOrderProduct);
209209
}
@@ -217,7 +217,7 @@ public function it_maps_ecommerce_order_product_with_default_app_locale_if_not_e
217217
): void {
218218
$order->getLocaleCode()->willReturn(null);
219219
$channel->getDefaultLocale()->willReturn(null);
220-
$channelHostnameUrlGenerator->generate($channel, 'sylius_shop_product_show', ['_locale' => 'en_US', 'slug' => 'wine-bottle'])->shouldBeCalledOnce()->willReturn('https://localhost/products/wine-bottle');
220+
$channelHostnameUrlGenerator->generateForRoute($channel, 'sylius_shop_product_show', ['_locale' => 'en_US', 'slug' => 'wine-bottle'])->shouldBeCalledOnce()->willReturn('https://localhost/products/wine-bottle');
221221

222222
$this->mapFromOrderItem($orderItem)->shouldReturn($ecommerceOrderProduct);
223223
}
@@ -232,7 +232,7 @@ public function it_maps_ecommerce_order_product_with_default_app_locale_if_not_e
232232
): void {
233233
$order->getLocaleCode()->willReturn(null);
234234
$frenchLocale->getCode()->willReturn(null);
235-
$channelHostnameUrlGenerator->generate($channel, 'sylius_shop_product_show', ['_locale' => 'en_US', 'slug' => 'wine-bottle'])->shouldBeCalledOnce()->willReturn('https://localhost/products/wine-bottle');
235+
$channelHostnameUrlGenerator->generateForRoute($channel, 'sylius_shop_product_show', ['_locale' => 'en_US', 'slug' => 'wine-bottle'])->shouldBeCalledOnce()->willReturn('https://localhost/products/wine-bottle');
236236

237237
$this->mapFromOrderItem($orderItem)->shouldReturn($ecommerceOrderProduct);
238238
}

spec/MessageHandler/Webhook/WebhookCreateHandlerSpec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function let(
2929
$channel->getId()->willReturn(1);
3030
$channel->getActiveCampaignListId()->willReturn(4);
3131

32-
$channelHostnameUrlGenerator->generate($channel, 'webgriffe_sylius_active_campaign_list_status_webhook')->willReturn('https://localhost/webhook');
32+
$channelHostnameUrlGenerator->generateForRoute($channel, 'webgriffe_sylius_active_campaign_list_status_webhook')->willReturn('https://localhost/webhook');
3333

3434
$channelRepository->find(1)->willReturn($channel);
3535

src/DependencyInjection/Configuration.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,14 @@ private function buildMapperNode(ArrayNodeDefinition $rootNode): void
5858
->children()
5959
->arrayNode('ecommerce_order_product')
6060
->children()
61-
->scalarNode('image_type')->defaultNull()->end()
61+
->scalarNode('image_type')
62+
->defaultValue('main')
63+
->info('Type of the product image to send to ActiveCampaign. If none is specified or the type does not exists on current product then the first image will be used.')
64+
->end()
65+
->scalarNode('image_filter')
66+
->defaultValue('sylius_medium')
67+
->info('Liip filter to apply to the image. If none is specified then the original image will be used.')
68+
->end()
6269
->end()
6370
->end()
6471
->end()

0 commit comments

Comments
 (0)