Skip to content

Commit f7dd335

Browse files
committed
Add traits for controllers
1 parent ecda845 commit f7dd335

File tree

10 files changed

+414
-282
lines changed

10 files changed

+414
-282
lines changed

README.md

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,59 @@ fos_rest:
6060
- { path: '^/', stop: true }
6161
```
6262

63-
### 3. Update UI Configuration
63+
### 3. Configure Order Controllers
64+
65+
Configure the Sylius order controllers to use the legacy bridge functionality:
66+
67+
**Option A: If you have NOT overridden Order/OrderItem controllers in your project**
68+
69+
Add the following to your `config/packages/_sylius.yaml`:
70+
71+
```yaml
72+
sylius_order:
73+
resources:
74+
order:
75+
classes:
76+
controller: Sylius\LegacyBridgePlugin\Controller\OrderController
77+
order_item:
78+
classes:
79+
controller: Sylius\LegacyBridgePlugin\Controller\OrderItemController
80+
```
81+
82+
**Option B: If you HAVE already overridden Order/OrderItem controllers in your project**
83+
84+
Add the appropriate traits to your existing controllers:
85+
86+
```php
87+
// src/Controller/OrderController.php
88+
namespace App\Controller;
89+
90+
use Sylius\LegacyBridgePlugin\Controller\Trait\OrderTrait;
91+
92+
class OrderController extends \Sylius\Bundle\CoreBundle\Controller\OrderController
93+
{
94+
use OrderTrait; // Adds: widgetAction(), clearAction()
95+
96+
// ... your existing custom methods
97+
}
98+
```
99+
100+
```php
101+
// src/Controller/OrderItemController.php
102+
namespace App\Controller;
103+
104+
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
105+
use Sylius\LegacyBridgePlugin\Controller\Trait\OrderItemTrait;
106+
107+
class OrderItemController extends ResourceController
108+
{
109+
use OrderItemTrait; // Adds: addAction(), removeAction() and helper methods
110+
111+
// ... your existing custom methods
112+
}
113+
```
114+
115+
### 4. Update UI Configuration
64116

65117
Replace `sylius_ui` configuration with `sylius_legacy_bridge` in your `config/packages/sylius_ui.yaml` (or wherever your UI events are configured):
66118

@@ -76,7 +128,7 @@ sylius_legacy_bridge:
76128
# ...
77129
```
78130

79-
### 4. Configure Twig Paths
131+
### 5. Configure Twig Paths
80132

81133
Add the following Twig paths configuration to your `config/packages/twig.yaml`:
82134

@@ -94,7 +146,7 @@ twig:
94146

95147
**Note:** The first two lines are only needed if you have customized `SyliusShopBundle` or `SyliusUiBundle` templates in your `templates/bundles/` directory. The last two lines pointing to the plugin's templates are always required.
96148

97-
### 5. Add Routes
149+
### 6. Add Routes
98150

99151
Add the plugin routes to your `config/routes.yaml` file. **Important:** These routes must be loaded after the shop routes:
100152

@@ -111,7 +163,7 @@ sylius_legacy_bridge:
111163
resource: "@SyliusLegacyBridgePlugin/config/routes.yaml"
112164
```
113165

114-
### 6. Update Encore Entry Points (Shop)
166+
### 7. Update Encore Entry Points (Shop)
115167

116168
Update your shop template base file to use legacy Encore entries:
117169

@@ -125,7 +177,7 @@ Update your shop template base file to use legacy Encore entries:
125177
{{ encore_entry_script_tags('legacy-shop-entry', null, 'legacy.shop') }}
126178
```
127179

128-
### 7. Update Asset Paths
180+
### 8. Update Asset Paths
129181

130182
Replace asset references to use the legacy paths:
131183

@@ -155,7 +207,7 @@ Replace:
155207
{{ asset($1build/legacy/shop/$2$1, $3legacy.shop$3) }}
156208
```
157209

158-
### 8. Configure Webpack
210+
### 9. Configure Webpack
159211

160212
Add the legacy bridge configuration to your `webpack.config.js`:
161213

@@ -190,7 +242,7 @@ module.exports = [
190242
];
191243
```
192244

193-
### 9. Install Frontend Dependencies
245+
### 10. Install Frontend Dependencies
194246

195247
Add the following legacy dependencies to your `package.json`:
196248

@@ -213,7 +265,7 @@ npm install
213265
yarn install
214266
```
215267

216-
### 10. Build Assets
268+
### 11. Build Assets
217269

218270
Build your frontend assets:
219271

config/config.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@ twig:
88
globals:
99
use_webpack: '%sylius_ui.use_webpack%'
1010

11-
sylius_order:
12-
resources:
13-
order:
14-
classes:
15-
controller: Sylius\LegacyBridgePlugin\Controller\OrderController
16-
order_item:
17-
classes:
18-
controller: Sylius\LegacyBridgePlugin\Controller\OrderItemController
19-
2011
liip_imagine:
2112
filter_sets:
2213
sylius_shop_product_tiny_thumbnail:

ecs.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22

33
declare(strict_types=1);
44

5-
use PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer;
65
use Symplify\EasyCodingStandard\Config\ECSConfig;
76

87
return static function (ECSConfig $ecsConfig): void {
98
$ecsConfig->paths([
109
__DIR__ . '/src',
11-
__DIR__ . '/tests/Behat',
1210
__DIR__ . '/ecs.php',
1311
]);
1412

1513
$ecsConfig->import('vendor/sylius-labs/coding-standard/ecs.php');
1614
};
17-

phpstan.neon

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,12 @@ parameters:
22
level: max
33
reportUnmatchedIgnoredErrors: false
44
paths:
5-
- src
6-
- tests/Behat
5+
- 'src/'
76

87
excludePaths:
98
# Makes PHPStan crash
109
- 'src/DependencyInjection/Configuration.php'
1110

12-
# Test dependencies
13-
- 'tests/Application/app/**.php'
14-
- 'tests/Application/src/**.php'
15-
1611
ignoreErrors:
1712
- '/Parameter #1 \$configuration of method Symfony\\Component\\DependencyInjection\\Extension\\Extension::processConfiguration\(\) expects Symfony\\Component\\Config\\Definition\\ConfigurationInterface, Symfony\\Component\\Config\\Definition\\ConfigurationInterface\|null given\./'
1813
-

src/Controller/CurrencySwitchController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace Sylius\LegacyBridgePlugin\Controller;
1515

16-
use Sylius\Bundle\ShopBundle\Controller\CurrencySwitchController as DecoratorCurrencySwitchControllerAlias;
1716
use Sylius\Component\Channel\Context\ChannelContextInterface;
1817
use Sylius\Component\Core\Currency\CurrencyStorageInterface;
1918
use Sylius\Component\Core\Model\ChannelInterface;

src/Controller/OrderController.php

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,9 @@
1313

1414
namespace Sylius\LegacyBridgePlugin\Controller;
1515

16-
use FOS\RestBundle\View\View;
17-
use Symfony\Component\HttpFoundation\Request;
18-
use Symfony\Component\HttpFoundation\Response;
19-
16+
use Sylius\LegacyBridgePlugin\Controller\Trait\OrderTrait;
2017

2118
class OrderController extends \Sylius\Bundle\CoreBundle\Controller\OrderController
2219
{
23-
public function widgetAction(Request $request): Response
24-
{
25-
$configuration = $this->requestConfigurationFactory->create($this->metadata, $request);
26-
27-
$cart = $this->getCurrentCart();
28-
29-
if (!$configuration->isHtmlRequest()) {
30-
return $this->viewHandler->handle($configuration, View::create($cart));
31-
}
32-
33-
return $this->render(
34-
$configuration->getTemplate('summary.html'),
35-
[
36-
'cart' => $cart,
37-
],
38-
);
39-
}
20+
use OrderTrait;
4021
}

0 commit comments

Comments
 (0)