Skip to content

Commit c6cdc33

Browse files
committed
Add installation adjustments
1 parent 8aa0dc6 commit c6cdc33

10 files changed

Lines changed: 97 additions & 20 deletions

File tree

config/config.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
1+
spinbits_sylius_google_analytics4:
2+
id: '%env(TAG_MANAGER_ID)%'
3+
4+
parameters:
5+
user_com.frontend_api_key: '%env(USER_COM_FRONTEND_API_KEY)%'
6+
7+
twig:
8+
globals:
9+
user_com_frontend_api_key: '%user_com.frontend_api_key%'
10+
111
imports:
212
- { resource: "state_machine/*" }
13+
- { resource: "events.yaml" }
14+

config/events.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
sylius_ui:
2+
events:
3+
sylius.admin.channel.form.first_column_content:
4+
blocks:
5+
user_com_configuration:
6+
template: '@BitBagSyliusUserComPlugin/UserApiResource/_userComCredentials.html.twig'
7+
priority: 25
8+
sylius.shop.layout.stylesheets:
9+
blocks:
10+
user_com:
11+
template: '@BitBagSyliusUserComPlugin/_userComScripts.html.twig'
12+
priority: 25

config/services/form.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@
99
<argument type="service" id="sylius.context.customer"/>
1010
<tag name="form.type_extension" />
1111
</service>
12+
13+
<service id="bit_bag.sylius_user_com_plugin.form.extension.user_com_api_aware_type_extension" class="BitBag\SyliusUserComPlugin\Form\Extension\UserComApiAwareTypeExtension">
14+
<argument type="service" id="bit_bag.sylius_user_com_plugin.provider.user_com_api_aware_resource_provider"/>
15+
<tag name="form.type_extension" extended-type="Sylius\Bundle\ChannelBundle\Form\Type\ChannelType" priority="200" />
16+
</service>
1217
</services>
1318
</container>

doc/installation.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Installation
2+
1. Add package to your project via composer:
3+
```bash
4+
composer require bitbag/user-com-plugin
5+
```
6+
>If `bitbag/user-com-plugin` is not found by composer, try adding repository to your `composer.json` file:
7+
> ```json
8+
> "repositories": [
9+
> {
10+
> "type": "vcs",
11+
> "url": "https://github.com/BitBagCommerce/SyliusUserComPlugin.git"
12+
> }
13+
> ]
14+
> ```
15+
2. Add plugin dependencies to config/bundles.php file:
16+
```php
17+
return [
18+
...
19+
BitBag\SyliusUserComPlugin\BitBagSyliusUserComPlugin::class => ['all' => true],
20+
Spinbits\SyliusGoogleAnalytics4Plugin\SpinbitsSyliusGoogleAnalytics4Plugin::class => ['all' => true],
21+
...
22+
];
23+
```
24+
3. Import required config in your `config/packages/_sylius.yaml` file:
25+
```yaml
26+
imports:
27+
...
28+
- { resource: "@BitBagSyliusUserComPlugin/config/config.yml" }
29+
...
30+
```
31+
4. Extend `Channel` entity `UserComApiAwareTrait` and implement `UserComApiAwareInterface`
32+
```php
33+
class Channel extends BaseChannel implements ChannelInterface
34+
{
35+
use UserComApiAwareTrait;
36+
}
37+
```
38+
39+
```php
40+
interface ChannelInterface extends BaseChannelInterface, UserComApiAwareInterface
41+
{
42+
}
43+
```
44+
>`UserComApiAwareTrait` contains mapping for annotations and for attributes which are required by UserCom integration.
45+
> If you're using xml mapping, you should add mapping for those properties in your `Channel.orm.xml` file.
46+
47+
5. Add required environment variables to your `.env` file:
48+
```dotenv
49+
USER_COM_FRONTEND_API_KEY=""
50+
TAG_MANAGER_ID=""
51+
```
52+
53+
6. *Optional* - take advantage of channel based configuration of Google Tag Manager ID:
54+
```yaml
55+
spinbits_sylius_google_analytics4:
56+
id: "%env(TAG_MANAGER_ID)%"
57+
channels_ids:
58+
FASHION_WEB: "G-DF1P3RRJ8S"
59+
OTHER_CHANNEL: "G-WX1RJ8SP3R"
60+
```

src/Trait/UserComApiAwareTrait.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@
1111

1212
namespace BitBag\SyliusUserComPlugin\Trait;
1313

14+
use Doctrine\ORM\Mapping as ORM;
15+
1416
trait UserComApiAwareTrait
1517
{
18+
#[ORM\Column(name: 'user_com_url', type: 'string', nullable: true)]
19+
/** @ORM\Column(name="user_com_url", type="string", nullable=true) */
1620
private ?string $userComUrl;
1721

22+
#[ORM\Column(name: 'user_com_url', type: 'string', nullable: true)]
23+
/** @ORM\Column(name="user_com_url", type="string", nullable=true) */
1824
private ?string $userComApiKey;
1925

2026
public function getUserComUrl(): ?string

templates/_userComScripts.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{% set channel = sylius.channel %}
2+
23
{% if null != channel.userComApiKey and null != channel.userComUrl%}
34
{% set customer = sylius.customer|default(null) %}
45
{% set genderMap = constant('BitBag\\SyliusUserComPlugin\\Builder\\Payload\\CustomerPayloadBuilderInterface::GENDER_MAP')%}

tests/Application/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ SYLIUS_MESSENGER_TRANSPORT_CATALOG_PROMOTION_REMOVAL_FAILED_DSN=doctrine://defau
3434

3535
###> UserCom
3636
USER_COM_FRONTEND_API_KEY=""
37+
TAG_MANAGER_ID=""
3738
###< UserCom

tests/Application/config/services.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,3 @@ spinbits_sylius_google_analytics4:
66

77
parameters:
88
locale: en_US
9-
10-
imports:
11-
- { resource: ./services/** }

tests/Application/config/services/form.xml

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/Application/src/Entity/Channel.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,4 @@
1717
class Channel extends BaseChannel implements ChannelInterface
1818
{
1919
use UserComApiAwareTrait;
20-
21-
public function getId(): ?int
22-
{
23-
return $this->id;
24-
}
2520
}

0 commit comments

Comments
 (0)