Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions concepts/framework/data-abstraction-layer.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ This is the recommended way for developers to interface with the DAL or the data
Before using the repositories, you will need to get them from the [Dependency Injection Container (DIC)](../../guides/plugins/plugins/plugin-fundamentals/dependency-injection).
This is done with [Constructor injection](https://symfony.com/doc/current/service_container/injection_types.html#constructor-injection), so you will need to extend your services constructor by expecting an EntityRepository:

```php
```PHP
// <plugin root>/src/Service/DalExampleService.php
public function __construct (EntityRepository $productRepository)
{
Expand All @@ -47,11 +47,10 @@ If you are using [Service autowiring](https://symfony.com/doc/current/service_co

Alternatively, configure the `product.repository` service to be injected explicitly:

```html
// <plugin root>src/Resources/config/service.xml
<service id="Swag\ExamplePlugin\Service\DalExampleService">
<argument type="service" id="product.repository"/>
</service>
```PHP
// <plugin root>src/Resources/config/services.php
$services->set(Swag\ExamplePlugin\Service\DalExampleService::class)
->args([service('product.repository')]);
```

You can read more about dependency injection and service registration in Shopware in the services guides:
Expand Down
11 changes: 5 additions & 6 deletions guides/hosting/configurations/observability/profiling.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The OpenTelemetry profiler is not installed by default. Checkout the [OpenTeleme

To add custom spans to the profiler, you can use the `Shopware\Core\Profiling\Profiler::trace` method:

```php
```PHP
use Shopware\Core\Profiling\Profiler;

$value = Profiler::trace('my-example-trace', function () {
Expand All @@ -50,7 +50,7 @@ To add a custom profiler backend, you need to implement the `Shopware\Core\Profi

The following example shows a custom profiler backend that logs the traces to the console:

```php
```PHP

namespace App\Profiler;

Expand All @@ -70,10 +70,9 @@ class ConsoleProfiler implements ProfilerInterface
}
```

```XML
<service id="App\Profiler">
<tag name="shopware.profiler" integration="Console"/>
</service>
```PHP
$services->set(App\Profiler::class)
->tag('shopware.profiler', ['integration' => 'Console']);
```

The attribute `integration` is used to identify the profiler backend in the configuration.
9 changes: 4 additions & 5 deletions guides/hosting/performance/session.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,14 @@ To use one of these handlers, you must create a new service in the dependency in

Example service definition:

```xml
<service id="session.db" class="Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler">
<argument ....></argument>
</service>
```PHP
$services->set('session.db', Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler::class)
->args([/* ... */]);
```

Example session configuration:

```yaml
```YAML
# config/packages/redis.yml
framework:
session:
Expand Down
18 changes: 9 additions & 9 deletions guides/plugins/plugins/bundle.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ project-root/
│ │ └── Migration1234567890YourMigration.php
│ └── Resources/
│ ├── config/
│ │ ├── services.xml
│ │ └── routes.xml
│ │ ├── services.php
│ │ └── routes.php
│ ├── views/
│ │ └── storefront/
│ │ └── page/
Expand Down Expand Up @@ -67,7 +67,7 @@ If you don't need these features, you can use the Symfony bundle class instead.

By default, The namespace `App\` is registered to the `src` folder in any Shopware project to be used for customizations. We recommend using this namespace, if you like to change the project structure, you can change the `App\` namespace in the `composer.json` file of your project.

```php
```PHP
// <project root>/src/YourBundleName.php
<?php declare(strict_types=1);

Expand All @@ -82,7 +82,7 @@ class YourBundleName extends Bundle

The bundle class needs to be registered in the `config/bundles.php` file of your project.

```php
```PHP
// <project root>/config/bundles.php
//...
App\YourBundleName\YourBundleName::class => ['all' => true],
Expand All @@ -92,7 +92,7 @@ App\YourBundleName\YourBundleName::class => ['all' => true],
## Adding services, twig templates, routes, theme, etc

You can add services, twig templates, routes, etc. to your bundle like you would do in a plugin.
Just create `Resources/config/services.xml` and `Resources/config/routes.xml` files or `Resources/views` for twig templates.
Just create `Resources/config/services.php` and `Resources/config/routes.php` files or `Resources/views` for twig templates.
The bundle will be automatically detected and the files will be loaded.

To mark your bundle as a theme, it's enough to implement the `Shopware\Core\Framework\ThemeInterface` interface in your bundle class.
Expand All @@ -104,7 +104,7 @@ You can also add a `theme.json` file to define the theme configuration like [des
Migrations are not automatically detected in bundles.
To enable migrations, you need to overwrite the `build` method in your bundle class like this:

```php
```PHP
// <project root>/src/YourBundleName.php
<?php declare(strict_types=1);

Expand All @@ -126,13 +126,13 @@ class YourBundleName extends Bundle
As Bundles don't have a lifecycle, the migrations are not automatically executed.
You need to execute them manually via the console command:

```bash
```BASH
bin/console database:migrate <BundleName> --all
```

If you use [Deployment Helper](../../hosting/installation-updates/deployments/deployment-helper.md), you can add it to the `.shopware-project.yaml` file like this:

```yaml
```YAML
deployment:
hooks:
pre-update: |
Expand All @@ -145,7 +145,7 @@ Shopware-CLI cannot detect bundles automatically, therefore the assets of the bu
You will need to adjust the `composer.json` file of your project to specify the path to the bundle.
This is done by adding the `extra` section to the `composer.json` file:

```json
```JSON
{
"extra": {
"shopware-bundles": {
Expand Down
4 changes: 2 additions & 2 deletions guides/plugins/plugins/checkout/cart/add-cart-discounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ To add a discount to the cart, you should use the processor pattern. For this yo

Let's start with the actual example code:

```php
```PHP
// <plugin root>/src/Core/Checkout/ExampleProcessor.php
<?php declare(strict_types=1);

Expand Down Expand Up @@ -120,4 +120,4 @@ Shopware comes with a called `LineItemRule`, which requires two parameters:

After adding the definition to the line item, we have to calculate the current price of the discount. Therefore we can use the `PercentagePriceCalculator` of the core. The last step is to add the discount to the new cart which is provided as `Cart $toCalculate`.

That's it for the main code of our custom `CartProcessor`. Now we only have to register it in our `services.xml` using the tag `shopware.cart.processor` and priority `4500`, which is used to get access to the calculation after the [product processor](https://github.com/shopware/shopware/blob/v6.3.4.1/src/Core/Checkout/DependencyInjection/cart.xml#L223-L231) handled the products.
That's it for the main code of our custom `CartProcessor`. Now we only have to register it in our `services.php` using the tag `shopware.cart.processor` and priority `4500`, which is used to get access to the calculation after the [product processor](https://github.com/shopware/shopware/blob/v6.3.4.1/src/Core/Checkout/DependencyInjection/cart.xml#L223-L231) handled the products.
58 changes: 31 additions & 27 deletions guides/plugins/plugins/checkout/cart/add-cart-items.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ So let's add an example product to the cart using code. For that case, you'll ne

Let's have a look at an example.

```php
```PHP
// <plugin root>/src/Service/ExampleController.php
<?php declare(strict_types=1);

Expand Down Expand Up @@ -100,24 +100,24 @@ Sometimes you really want to have a custom line item handler, e.g. for your own

You need to create a new class which implements the interface `\Shopware\Core\Checkout\Cart\LineItemFactoryHandler\LineItemFactoryInterface` and it needs to be registered in the DI container with the tag `shopware.cart.line_item.factory`.

```xml
// <plugin root>/src/Resources/config/services.xml
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="Swag\BasicExample\Service\ExampleHandler">
<tag name="shopware.cart.line_item.factory" />
</service>
</services>
</container>
```PHP
// <plugin root>/src/Resources/config/services.php
<?php declare(strict_types=1);

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Swag\BasicExample\Service\ExampleHandler;

return static function (ContainerConfigurator $configurator): void {
$services = $configurator->services();

$services->set(ExampleHandler::class)
->tag('shopware.cart.line_item.factory');
};
```

Let's first have a look at an example handler:

```php
```PHP
// <plugin root>/src/Service/ExampleHandler.php
<?php declare(strict_types=1);

Expand Down Expand Up @@ -168,7 +168,7 @@ Implementing the `LineItemFactoryInterface` will force you to also implement thr

Now you'll need to add a processor for your type. Otherwise your item won't be persisted in the cart. A simple processor for our ExampleHandler could look like this:

```php
```PHP
// <plugin root>/Core/Checkout/Cart/ExampleProcessor.php
<?php declare(strict_types=1);

Expand Down Expand Up @@ -199,17 +199,21 @@ As you can see, this processor takes an "original cart" as an input and adds all

Of course you can use processors to do much more than this. Have a look at [adding cart processors and collectors](./add-cart-processor-collector).

Now register this processor in your `services.xml` like this:

```html
// <plugin root>/Resources/config/services.xml
...
<services>
...
<service id="Swag\BasicExample\Core\Checkout\Cart\ExampleProcessor">
<tag name="shopware.cart.processor" priority="4800"/>
</service>
</services>
Now register this processor in your `services.php` like this:

```PHP
// <plugin root>/src/Resources/config/services.php
<?php declare(strict_types=1);

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Swag\BasicExample\Core\Checkout\Cart\ExampleProcessor;

return static function (ContainerConfigurator $configurator): void {
$services = $configurator->services();

$services->set(ExampleProcessor::class)
->tag('shopware.cart.processor', ['priority' => 4800]);
};
```

And that's it. You should now be able to create line items of type `example`.
Expand Down
32 changes: 16 additions & 16 deletions guides/plugins/plugins/checkout/cart/add-cart-validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Your validator has to implement the interface `Shopware\Core\Checkout\Cart\CartV

But let's have a look at the example validator first:

```php
```PHP
// <plugin root>/src/Core/Checkout/Cart/Custom/CustomCartValidator.php
<?php declare(strict_types=1);

Expand Down Expand Up @@ -76,19 +76,19 @@ One more thing to do is to register your new validator to the [dependency inject

Your validator has to be registered using the tag `shopware.cart.validator`:

```xml
// <plugin root>/src/Resources/config/services.xml
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="Swag\BasicExample\Core\Checkout\Cart\Custom\CustomCartValidator">
<tag name="shopware.cart.validator"/>
</service>
</services>
</container>
```PHP
// <plugin root>/src/Resources/config/services.php
<?php declare(strict_types=1);

use Swag\BasicExample\Core\Checkout\Cart\Custom\CustomCartValidator;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $configurator): void {
$services = $configurator->services();

$services->set(CustomCartValidator::class)
->tag('shopware.cart.validator');
};
```

### Adding the custom cart error
Expand Down Expand Up @@ -121,7 +121,7 @@ It has to extend from the abstract class `Shopware\Core\Checkout\Cart\Error\Erro

So now let's have a look at the example error class:

```php
```PHP
// <plugin root>/src/Core/Checkout/Cart/Custom/Error/CustomCartBlockedError.php
<?php declare(strict_types=1);

Expand Down Expand Up @@ -182,7 +182,7 @@ You've defined the error key to be `custom-line-item-blocked` in your custom err

Now let's have a look at an example snippet file:

```javascript
```JAVASCRIPT
// <plugin root>/src/Resources/snippet/en\_GB/example.en-GB.json
{
"checkout": {
Expand Down
42 changes: 23 additions & 19 deletions guides/plugins/plugins/checkout/cart/change-price-of-item.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Your collector class has to implement the interface `Shopware\Core\Checkout\Cart

Let's have a look at an example:

```php
```PHP
// <plugin root>/src/Core/Checkout/Cart/OverwritePriceCollector.php
<?php declare(strict_types=1);

Expand Down Expand Up @@ -137,7 +137,7 @@ Your processor has to implement the interface `Shopware\Core\Checkout\Cart\CartP

But once, again, let's have a look at the example:

```php
```PHP
// <plugin root>/src/Core/Checkout/Cart/OverwritePriceCollector.php
<?php declare(strict_types=1);

Expand Down Expand Up @@ -263,23 +263,27 @@ One last thing, we need to register our processor and collector to the DI contai

Let's have a look at it:

```xml
// <plugin root>/src/Resources/config/services.xml
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="Swag\BasicExample\Core\Checkout\Cart\OverwritePriceCollector">
<argument type="service" id="Shopware\Core\Checkout\Cart\Price\QuantityPriceCalculator"/>

<!-- after product collector/processor -->
<tag name="shopware.cart.processor" priority="4500" />
<tag name="shopware.cart.collector" priority="4500" />
</service>
</services>
</container>
```PHP
// <plugin root>/src/Resources/config/services.php
<?php declare(strict_types=1);

use Shopware\Core\Checkout\Cart\Price\QuantityPriceCalculator;
use Swag\BasicExample\Core\Checkout\Cart\OverwritePriceCollector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

return static function (ContainerConfigurator $configurator): void {
$services = $configurator->services();

$services->set(OverwritePriceCollector::class)
->args([
service(QuantityPriceCalculator::class),
])
// after product collector/processor
->tag('shopware.cart.processor', ['priority' => 4500])
->tag('shopware.cart.collector', ['priority' => 4500]);
};
```

And that's it. Your processor / collector should now be working.
Loading