Skip to content

Commit 42c7265

Browse files
FIX: fixing dependency injection for installation
1 parent e5537ec commit 42c7265

2 files changed

Lines changed: 183 additions & 17 deletions

File tree

README.md

Lines changed: 164 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,161 @@ In local environment, the plugin will not work properly because you will not be
3838

3939
## Installation
4040

41-
### 1. Require the **payplug/sylius-payplug-plugin** :
41+
Choose the installation method that matches your setup:
42+
43+
- [With Symfony Flex](#with-symfony-flex-recommended) (recommended)
44+
- [Without Symfony Flex](#without-symfony-flex-manual)
45+
46+
---
47+
48+
### With Symfony Flex (recommended)
49+
50+
#### 1. Allow contrib recipes and require the plugin
4251

4352
```bash
4453
composer config extra.symfony.allow-contrib true
4554
composer require payplug/sylius-payplug-plugin
4655
```
4756

48-
### 3. Register Sylius resources
57+
#### 2. Install the Flex recipe
58+
59+
```bash
60+
composer recipes:install payplug/sylius-payplug-plugin --force
61+
```
62+
63+
This automatically registers the bundle, copies configuration files, and sets up assets (on Sylius 2.1+).
64+
65+
#### 3. Apply migrations to your database
66+
67+
```shell
68+
bin/console doctrine:migrations:migrate
69+
```
70+
71+
#### 4. Add Payplug to refundable payment methods for Sylius Refund Plugin in `config/services.yaml`
72+
73+
```yaml
74+
parameters:
75+
locale: fr_FR
76+
sylius_refund.supported_gateways:
77+
- payplug
78+
- payplug_oney
79+
- payplug_bancontact
80+
- payplug_apple_pay
81+
- payplug_american_express
82+
```
83+
84+
#### 5. Add Traits for Customer and PaymentMethod entities
85+
86+
* App\Entity\Customer\Customer
87+
88+
```php
89+
<?php
90+
91+
declare(strict_types=1);
92+
93+
namespace App\Entity\Customer;
94+
95+
use Doctrine\ORM\Mapping as ORM;
96+
use PayPlug\SyliusPayPlugPlugin\Entity\CardsOwnerInterface;
97+
use PayPlug\SyliusPayPlugPlugin\Entity\Traits\CustomerTrait;
98+
use Sylius\Component\Core\Model\Customer as BaseCustomer;
99+
100+
/**
101+
* @ORM\Entity
102+
* @ORM\Table(name="sylius_customer")
103+
*/
104+
#[ORM\Entity]
105+
#[ORM\Table(name: 'sylius_customer')]
106+
class Customer extends BaseCustomer implements CardsOwnerInterface
107+
{
108+
use CustomerTrait;
109+
}
110+
```
111+
112+
* App\Entity\Payment\PaymentMethod
113+
114+
```php
115+
<?php
116+
117+
declare(strict_types=1);
118+
119+
namespace App\Entity\Payment;
120+
121+
use Doctrine\ORM\Mapping as ORM;
122+
use PayPlug\SyliusPayPlugPlugin\Entity\Traits\PaymentMethodTrait;
123+
use Sylius\Component\Core\Model\PaymentMethod as BasePaymentMethod;
124+
use Sylius\Component\Payment\Model\PaymentMethodTranslationInterface;
125+
126+
/**
127+
* @ORM\Entity
128+
* @ORM\Table(name="sylius_payment_method")
129+
*/
130+
#[ORM\Entity]
131+
#[ORM\Table(name: 'sylius_payment_method')]
132+
class PaymentMethod extends BasePaymentMethod
133+
{
134+
use PaymentMethodTrait;
135+
136+
protected function createTranslation(): PaymentMethodTranslationInterface
137+
{
138+
return new PaymentMethodTranslation();
139+
}
140+
}
141+
```
142+
143+
* App\Entity\Payment\Payment
144+
145+
```php
146+
<?php
147+
148+
declare(strict_types=1);
149+
150+
namespace App\Entity\Payment;
151+
152+
use Doctrine\Common\Collections\ArrayCollection;
153+
use Doctrine\ORM\Mapping as ORM;
154+
use PayPlug\SyliusPayPlugPlugin\Entity\Traits\PaymentTrait;
155+
use Sylius\Component\Core\Model\Payment as BasePayment;
156+
157+
/**
158+
* @ORM\Entity
159+
* @ORM\Table(name="sylius_payment")
160+
*/
161+
#[ORM\Entity]
162+
#[ORM\Table(name: 'sylius_payment')]
163+
class Payment extends BasePayment
164+
{
165+
use PaymentTrait;
166+
}
167+
```
168+
169+
#### 6. Process translations
170+
171+
```bash
172+
php bin/console translation:extract en PayPlugSyliusPayPlugPlugin --dump-messages
173+
php bin/console translation:extract fr PayPlugSyliusPayPlugPlugin --dump-messages
174+
```
175+
176+
#### 7. Clear cache
177+
178+
```bash
179+
bin/console cache:clear
180+
```
181+
182+
🎉 You are now ready to add Payplug Payment method.
183+
In your back-office, go to `Configuration > Payment methods`, then click on `Create` and choose "**Payplug**".
184+
185+
---
186+
187+
### Without Symfony Flex (manual)
188+
189+
#### 1. Require the **payplug/sylius-payplug-plugin**
190+
191+
```bash
192+
composer require payplug/sylius-payplug-plugin
193+
```
194+
195+
#### 2. Register Sylius resources
49196

50197
The plugin's extension does not prepend its `resources.yaml`, so the Sylius resource services for the Card and RefundHistory entities are never created. Add them manually in `config/packages/sylius_resource.yaml`:
51198

@@ -63,7 +210,7 @@ sylius_resource:
63210
repository: PayPlug\SyliusPayPlugPlugin\Repository\RefundHistoryRepository
64211
```
65212
66-
### 4. Fix service autowiring
213+
#### 3. Fix service autowiring
67214
68215
The plugin uses `#[Autoconfigure]` on some actions and relies on named constructor arguments that Symfony cannot resolve automatically. Add the following to `config/services.yaml`:
69216

@@ -77,13 +224,13 @@ services:
77224
alias: payplug.repository.payplug_refund_history
78225
```
79226

80-
### 5. Apply migrations to your database:
227+
#### 4. Apply migrations to your database
81228

82229
```shell
83230
bin/console doctrine:migrations:migrate
84-
```
231+
```
85232

86-
### 6. Add Payplug to refundable payment method for Sylius Refund Plugin in `config/services.yaml`
233+
#### 5. Add Payplug to refundable payment methods for Sylius Refund Plugin in `config/services.yaml`
87234

88235
```yaml
89236
parameters:
@@ -96,7 +243,7 @@ parameters:
96243
- payplug_american_express
97244
```
98245

99-
### 7. Add Traits for Customer and PaymentMethod entities
246+
#### 6. Add Traits for Customer and PaymentMethod entities
100247

101248
* App\Entity\Customer\Customer
102249

@@ -153,7 +300,7 @@ class PaymentMethod extends BasePaymentMethod
153300
return new PaymentMethodTranslation();
154301
}
155302
}
156-
```
303+
```
157304

158305
* App\Entity\Payment\Payment
159306

@@ -179,27 +326,27 @@ class Payment extends BasePayment
179326
{
180327
use PaymentTrait;
181328
}
182-
```
329+
```
183330

184-
### 8. Process translations
331+
#### 7. Process translations
185332

186333
```bash
187334
php bin/console translation:extract en PayPlugSyliusPayPlugPlugin --dump-messages
188335
php bin/console translation:extract fr PayPlugSyliusPayPlugPlugin --dump-messages
189336
```
190337

191-
### 9. Clear cache:
338+
#### 8. Clear cache
192339

193-
```bash
194-
bin/console cache:clear
195-
```
340+
```bash
341+
bin/console cache:clear
342+
```
196343

197344
🎉 You are now ready to add Payplug Payment method.
198345
In your back-office, go to `Configuration > Payment methods`, then click on `Create` and choose "**Payplug**".
199346

200-
### Assets installation (only for Sylius 2.0.x)
347+
#### Assets installation (only for Sylius 2.0.x)
201348

202-
On sylius 2.0.x, there is no automatic load of assets.
349+
On Sylius 2.0.x, there is no automatic load of assets.
203350
You need to add the following lines in `assets/shop/controllers.json` to allow Sylius to use our assets:
204351

205352
```json
@@ -247,7 +394,7 @@ You need to add the following lines in `assets/shop/controllers.json` to allow S
247394
```
248395

249396
> [!NOTE]
250-
> On Sylius Standard >= 2.1, assets are automatically loaded when you install the plugin with flex.
397+
> On Sylius Standard >= 2.1, assets are automatically loaded when you install the plugin with Flex.
251398
> If you are upgrading from a 2.0.x version, read the [upgrade guide](https://github.com/Sylius/Sylius/blob/2.1/UPGRADE-2.1.md#assets)
252399

253400

src/DependencyInjection/PayPlugSyliusPayPlugExtension.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
1212
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
1313
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
14+
use Symfony\Component\Yaml\Parser as YamlParser;
1415

1516
final class PayPlugSyliusPayPlugExtension extends Extension implements PrependExtensionInterface
1617
{
@@ -33,6 +34,24 @@ public function prepend(ContainerBuilder $container): void
3334
$this->prependTwigExtension($container);
3435
$this->prependDoctrineMigrations($container);
3536
$this->prependMonologExtension($container);
37+
$this->prependTwigHooks($container);
38+
}
39+
40+
private function prependTwigHooks(ContainerBuilder $container): void
41+
{
42+
if (!$container->hasExtension('sylius_twig_hooks')) {
43+
return;
44+
}
45+
46+
$yaml = new YamlParser();
47+
$configDir = dirname(__DIR__, 2) . '/config/twig_hooks';
48+
49+
foreach (['admin.yaml', 'shop.yaml'] as $file) {
50+
$config = $yaml->parseFile($configDir . '/' . $file);
51+
if (isset($config['sylius_twig_hooks'])) {
52+
$container->prependExtensionConfig('sylius_twig_hooks', $config['sylius_twig_hooks']);
53+
}
54+
}
3655
}
3756

3857
private function prependTwigExtension(ContainerBuilder $container): void

0 commit comments

Comments
 (0)