Skip to content

Commit

Permalink
Merge pull request #167 from synolia/feature/new-set-of-fixtures
Browse files Browse the repository at this point in the history
[DX] New set of fixtures
  • Loading branch information
oallain authored Oct 23, 2023
2 parents 625cb97 + 627e2ba commit 68b8047
Show file tree
Hide file tree
Showing 20 changed files with 739 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@
* See [How to contribute](CONTRIBUTING.md)
* See [How to customize your import using processors](docs/customize/PROCESSORS.md)
* See [How to use fixtures](docs/FIXTURE.md)
## Akeneo Enterprise Edition
Expand Down
284 changes: 284 additions & 0 deletions docs/FIXTURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
# Developers - Using fixtures

This plugin provides multiples fixtures to help you start your shop from scratch.

## Category Configurations - `akeneo_category_configuration`

This fixture allow to define the root category you want to import from Akeneo, and also if you want to exclude somes.

```yaml
# config/packages/sylius_fixtures.yaml

sylius_fixtures:
suites:
app:
fixtures:
akeneo_category_configuration:
options:
root_categories_to_import:
- 'root_category'
- 'another_root_category'
categories_to_exclude:
- 'excluded_category'
- 'another_excluded_category'
```
## Categories - `akeneo_categories`

This fixture allow you to trigger the `akeneo:import:categories` command.

> [!IMPORTANT]
> Remember that the `akeneo_category_configuration` fixture must be configured and loaded before this one.

```yaml
# config/packages/sylius_fixtures.yaml
sylius_fixtures:
suites:
app:
fixtures:
akeneo_category_configuration:
# ...
akeneo_categories: ~
```

You can also provide a custom filter to reduce the number of categories you want to import.

> [!IMPORTANT]
> If you want to get only some children categories, make sure that all parents are also included in your search.

Inside `custom` node option, you can provide any query parameter supported by [Akeneo API](https://api.akeneo.com/documentation/filter.html#filter-categories).

```yaml
# config/packages/sylius_fixtures.yaml
sylius_fixtures:
suites:
app:
fixtures:
akeneo_category_configuration:
# ...
akeneo_categories:
options:
custom:
search:
code:
-
operator: 'IN'
value:
- 'root_category'
- 'child_category'
- 'another_child_category'
```

## Attributes - `akeneo_attributes`

This fixture allow you to trigger the `akeneo:import:attributes` command.

You can specify the batch size, if you allow parallel import, and max concurrency.

```yaml
# config/packages/sylius_fixtures.yaml
sylius_fixtures:
suites:
app:
fixtures:
akeneo_attributes:
options:
batch_size: 100
allow_parallel: true
max_concurrency: 4
```

If you have too many attributes, you can also provide a custom filter to reduce the number of attributes you want to import.

```yaml
# config/packages/sylius_fixtures.yaml
sylius_fixtures:
suites:
app:
fixtures:
akeneo_attributes:
options:
custom:
search:
code:
-
operator: 'IN'
value:
- 'attribute_code'
- 'another_attribute_code'
```
Inside `custom` node option, you can provide any query parameter supported by [Akeneo API](https://api.akeneo.com/documentation/filter.html#filter-attributes).

## Association Types - `akeneo_association_types`

This fixture allow you to trigger the `akeneo:import:association-type` command.

You can specify the batch size, if you allow parallel import, and max concurrency.

```yaml
# config/packages/sylius_fixtures.yaml
sylius_fixtures:
suites:
app:
fixtures:
akeneo_association_types:
options:
batch_size: 100
allow_parallel: true
max_concurrency: 4
```

> [!NOTE]
> Given [Akeneo API](https://api.akeneo.com/api-reference.html#Associationtype) don't provide any search filter for association types,
> it's not currently possible de reduce the number of association types to import.

## Families - `akeneo_families`

This fixture allow you to trigger the `akeneo:import:families` command.

You can specify the batch size, if you allow parallel import, and max concurrency.

```yaml
# config/packages/sylius_fixtures.yaml
sylius_fixtures:
suites:
app:
fixtures:
akeneo_families:
options:
batch_size: 100
allow_parallel: true
max_concurrency: 4
```

You can also provide a custom filter to reduce the number of families you want to import.

Inside `custom` node option, you can provide any query parameter supported by [Akeneo API](https://api.akeneo.com/documentation/filter.html#filter-on-product-model-properties).

```yaml
# config/packages/sylius_fixtures.yaml
sylius_fixtures:
suites:
app:
fixtures:
akeneo_families:
options:
custom:
search:
categories:
-
operator: 'IN'
value:
- 'root_category'
```

> [!NOTE]
> The API call made is on ProductModel endpoint, so be careful to only use filters available for this endpoint.

## Product Models - `akeneo_product_models`

This fixture allow you to trigger the `akeneo:import:product-models` command.

You can specify the batch size, if you allow parallel import, and max concurrency.

```yaml
# config/packages/sylius_fixtures.yaml
sylius_fixtures:
suites:
app:
fixtures:
akeneo_product_models:
options:
batch_size: 100
allow_parallel: true
max_concurrency: 4
```

> [!IMPORTANT]
> Before this fixture, you need to create a [Product Filter rule](https://github.com/synolia/SyliusAkeneoPlugin/blob/master/docs/CONFIGURE_DETAIL.md#product-filter-rules).

You can also provide a custom filter to reduce the number of product-models you want to import.

Inside `custom` node option, you can provide any query parameter supported by [Akeneo API](https://api.akeneo.com/documentation/filter.html#filter-on-product-model-properties).

```yaml
sylius_fixtures:
suites:
app:
fixtures:
akeneo_product_models:
options:
custom:
search:
categories:
-
operator: 'IN'
value:
- 'root_category'
- 'another_category'
parent:
-
operator: 'NOT EMPTY'
```

> [!NOTE]
> Adding NOT EMPTY filter for parent will avoid warning while importing product models.
> We actually don't import productModel without parents.


## Products - `akeneo_products`

This fixture allow you to trigger the `akeneo:import:products` command.

You can specify the batch size, if you allow parallel import, and max concurrency.

```yaml
# config/packages/sylius_fixtures.yaml
sylius_fixtures:
suites:
app:
fixtures:
akeneo_products:
options:
batch_size: 100
allow_parallel: true
max_concurrency: 4
```

Like others fixtures, you can reduce amount of product to import by adding filters.
Inside `custom` node option, you can provide any query parameter supported by [Akeneo API](https://api.akeneo.com/documentation/filter.html#filter-on-product-properties).


```yaml
# config/packages/sylius_fixtures.yaml
sylius_fixtures:
suites:
app:
fixtures:
akeneo_products:
options:
custom:
search:
code:
-
operator: 'IN'
value:
- 'awesome_product'
```

> [!NOTE]
> While launching this fixture, the [Product Filter rule](https://github.com/synolia/SyliusAkeneoPlugin/blob/master/docs/CONFIGURE_DETAIL.md#product-filter-rules) will be applied too.
> Custom search can override those values.




3 changes: 1 addition & 2 deletions install/Application/config/packages/test/akeneo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:

Akeneo\Pim\ApiClient\AkeneoPimClientInterface:
factory: ['@Tests\Synolia\SyliusAkeneoPlugin\PHPUnit\Client\ClientFactory', 'createFromApiCredentials']

lazy: true
Synolia\SyliusAkeneoPlugin\Builder\Attribute\ProductAttributeValueValueBuilder: ~
Synolia\SyliusAkeneoPlugin\Factory\AttributePipelineFactory: ~
Synolia\SyliusAkeneoPlugin\Factory\CategoryPipelineFactory: ~
Expand All @@ -25,7 +25,6 @@ services:
Synolia\SyliusAkeneoPlugin\Factory\AssociationTypePipelineFactory: ~
Synolia\SyliusAkeneoPlugin\Filter\ProductFilter: ~
Synolia\SyliusAkeneoPlugin\Provider\AkeneoAttributePropertiesProvider: ~
Synolia\SyliusAkeneoPlugin\Provider\SyliusAkeneoLocaleCodeProvider: ~
Synolia\SyliusAkeneoPlugin\Provider\TaskProvider: ~
Synolia\SyliusAkeneoPlugin\Retriever\FamilyRetriever: ~
Synolia\SyliusAkeneoPlugin\Repository\ProductAttributeRepository: ~
Expand Down
4 changes: 2 additions & 2 deletions src/Entity/ProductGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ class ProductGroup implements ProductGroupInterface
/**
* @ORM\ManyToOne(targetEntity="Synolia\SyliusAkeneoPlugin\Entity\ProductGroupInterface")
*
* @ORM\JoinColumn(referencedColumnName="id", nullable=true)
* @ORM\JoinColumn(referencedColumnName="id", nullable=true, onDelete="CASCADE")
*/
#[ORM\ManyToOne(targetEntity: ProductGroupInterface::class)]
#[ORM\JoinColumn(referencedColumnName: 'id', nullable: true)]
#[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'CASCADE')]
private ?ProductGroupInterface $parent = null;

/** @ORM\Column(type="string", length=255, nullable=false, unique=true) */
Expand Down
57 changes: 57 additions & 0 deletions src/Fixture/AssociationTypesFixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace Synolia\SyliusAkeneoPlugin\Fixture;

use Sylius\Bundle\FixturesBundle\Fixture\AbstractFixture;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Synolia\SyliusAkeneoPlugin\Factory\AssociationTypePipelineFactory;
use Synolia\SyliusAkeneoPlugin\Factory\PayloadFactoryInterface;
use Synolia\SyliusAkeneoPlugin\Payload\Association\AssociationTypePayload;

final class AssociationTypesFixture extends AbstractFixture
{
public function __construct(
private AssociationTypePipelineFactory $associationTypePipelineFactory,
private PayloadFactoryInterface $payloadFactory,
) {
}

/**
* @param array{
* batch_size: int,
* allow_parallel: bool,
* max_concurrency: int,
* } $options
*/
public function load(array $options): void
{
$pipeline = $this->associationTypePipelineFactory->create();
$payload = $this->payloadFactory->create(
AssociationTypePayload::class,
);

$payload->setBatchSize($options['batch_size']);
$payload->setAllowParallel($options['allow_parallel']);
$payload->setMaxRunningProcessQueueSize($options['max_concurrency']);

$pipeline->process($payload);
}

public function getName(): string
{
return 'akeneo_association_types';
}

protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void
{
$optionsNode
->children()
->integerNode('batch_size')->defaultValue(100)->end()
->booleanNode('allow_parallel')->defaultTrue()->end()
->integerNode('max_concurrency')->defaultValue(4)->end()
->end()
;
}
}
Loading

0 comments on commit 68b8047

Please sign in to comment.