Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-8198: PIM training #2449

Draft
wants to merge 30 commits into
base: master
Choose a base branch
from
Draft

IBX-8198: PIM training #2449

wants to merge 30 commits into from

Conversation

adriendupuis
Copy link
Contributor

@adriendupuis adriendupuis commented Jul 31, 2024

Question Answer
JIRA Ticket IBX-8198, IBX-7097
Versions master, 4.6
Edition Headless

Test #2372 PoC farther with PIM Training case.

Preview: https://ez-systems-developer-documentation--2449.com.readthedocs.build/en/2449/trainings/commerce/pim/000_syllabus/

Checklist

  • Text renders correctly
  • Text has been checked with vale
  • Description metadata is up to date
  • Redirects cover removed/moved pages
  • Code samples are working
  • PHP code samples have been fixed with PHP CS fixer
  • Added link to this PR in relevant JIRA ticket or code PR

adriendupuis and others added 21 commits October 2, 2024 11:00
```
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires ibexa/product-catalog 5.0.x-dev -> satisfiable by ibexa/product-catalog[5.0.x-dev (alias of dev-main)].
    - ibexa/product-catalog dev-main requires ibexa/core-search ~5.0.x-dev -> found ibexa/core-search[dev-main, 5.0.x-dev (alias of dev-main)] but it does not match your minimum-stability.
    - ibexa/product-catalog 5.0.x-dev is an alias of ibexa/product-catalog dev-main and thus requires it to be installed too.
```
Copy link

code_samples/ change report

Before (on target branch)After (in current PR)

code_samples/trainings/commerce/pim/001_product_modeling/config/packages/ibexa_product_catalog.yaml


code_samples/trainings/commerce/pim/001_product_modeling/config/packages/ibexa_product_catalog.yaml

docs/trainings/commerce/pim/011_product_modeling.md@256:    ```yaml hl_lines="8"
docs/trainings/commerce/pim/011_product_modeling.md@257: [[= include_file('code_samples/trainings/commerce/pim/001_product_modeling/config/packages/ibexa_product_catalog.yaml', 0, None, ' ') =]]
docs/trainings/commerce/pim/011_product_modeling.md@258: ```

001⫶ ibexa_product_catalog:
002⫶ engines:
003⫶ default:
004⫶ type: local
005⫶ options:
006⫶ root_location_remote_id: ibexa_product_catalog_root
007⫶ product_type_group_identifier: 'product'
008⫸ variant_code_generator_strategy: 'per_product_type_code_generator'


code_samples/trainings/commerce/pim/001_product_modeling/config/services.yaml


code_samples/trainings/commerce/pim/001_product_modeling/config/services.yaml

docs/trainings/commerce/pim/011_product_modeling.md@239:    ```yaml
docs/trainings/commerce/pim/011_product_modeling.md@240: [[= include_file('code_samples/trainings/commerce/pim/001_product_modeling/config/services.yaml', 0, None, ' ') =]]
docs/trainings/commerce/pim/011_product_modeling.md@241: ```

001⫶ services:
002⫶ # …
003⫶
004⫶ App\CodeGenerator\Strategy\ProductTypeCodeGeneratorDispatcher:
005⫶ arguments:
006⫶ $defaultCodeGeneratorIdentifier: 'incremental'
007⫶ $productTypeCodeGeneratorMap:
008⫶ bike: 'bike'
009⫶ tags:
010⫶ - { name: 'ibexa.product_catalog.code_generator', type: 'per_product_type_code_generator' }
011⫶
012⫶ App\CodeGenerator\Strategy\BikeCodeGenerator:
013⫶ tags:
014⫶ - { name: 'ibexa.product_catalog.code_generator', type: 'bike' }


code_samples/trainings/commerce/pim/001_product_modeling/src/CodeGenerator/Strategy/BikeCodeGenerator.php


code_samples/trainings/commerce/pim/001_product_modeling/src/CodeGenerator/Strategy/BikeCodeGenerator.php

docs/trainings/commerce/pim/011_product_modeling.md@251:    ```php
docs/trainings/commerce/pim/011_product_modeling.md@252: [[= include_file('code_samples/trainings/commerce/pim/001_product_modeling/src/CodeGenerator/Strategy/BikeCodeGenerator.php', 0, None, ' ') =]]
docs/trainings/commerce/pim/011_product_modeling.md@253: ```

001⫶
002⫶
003⫶ declare(strict_types=1);
004⫶
005⫶ namespace App\CodeGenerator\Strategy;
006⫶
007⫶ use Ibexa\Contracts\Core\Exception\InvalidArgumentException;
008⫶ use Ibexa\Contracts\ProductCatalog\Local\CodeGenerator\CodeGeneratorContext;
009⫶ use Ibexa\Contracts\ProductCatalog\Local\CodeGenerator\CodeGeneratorInterface;
010⫶
011⫶ final class BikeCodeGenerator implements CodeGeneratorInterface
012⫶ {
013⫶ public function generateCode(CodeGeneratorContext $context): string
014⫶ {
015⫶ if (!$context->hasBaseProduct()) {
016⫶ throw new InvalidArgumentException('$context', 'missing base product');
017⫶ }
018⫶
019⫶ $frameSize = $context->getAttributes()['frame_size'];
020⫶ $wheelSize = $context->getAttributes()['wheel_diameter'];
021⫶ $frameShape = $context->getAttributes()['frame_shape'][0];
022⫶ $gearBundle = $context->getAttributes()['gear_bundle'];
023⫶
024⫶ return $context->getBaseProduct()->getCode() . "--$frameSize-$wheelSize-$frameShape-$gearBundle";
025⫶ }
026⫶ }


code_samples/trainings/commerce/pim/001_product_modeling/src/CodeGenerator/Strategy/ProductTypeCodeGeneratorDispatcher.php


code_samples/trainings/commerce/pim/001_product_modeling/src/CodeGenerator/Strategy/ProductTypeCodeGeneratorDispatcher.php

docs/trainings/commerce/pim/011_product_modeling.md@245:    ```php
docs/trainings/commerce/pim/011_product_modeling.md@246: [[= include_file('code_samples/trainings/commerce/pim/001_product_modeling/src/CodeGenerator/Strategy/ProductTypeCodeGeneratorDispatcher.php', 0, None, ' ') =]]
docs/trainings/commerce/pim/011_product_modeling.md@247: ```

001⫶
002⫶
003⫶ declare(strict_types=1);
004⫶
005⫶ namespace App\CodeGenerator\Strategy;
006⫶
007⫶ use Ibexa\Contracts\Core\Exception\InvalidArgumentException;
008⫶ use Ibexa\Contracts\ProductCatalog\Local\CodeGenerator\CodeGeneratorContext;
009⫶ use Ibexa\Contracts\ProductCatalog\Local\CodeGenerator\CodeGeneratorInterface;
010⫶ use Ibexa\ProductCatalog\Local\Repository\CodeGenerator\CodeGeneratorRegistryInterface;
011⫶
012⫶ final class ProductTypeCodeGeneratorDispatcher implements CodeGeneratorInterface
013⫶ {
014⫶ private CodeGeneratorRegistryInterface $codeGeneratorRegistry;
015⫶
016⫶ private string $defaultCodeGeneratorIdentifier;
017⫶
018⫶ private array $productTypeCodeGeneratorMap;
019⫶
020⫶ public function __construct(CodeGeneratorRegistryInterface $codeGeneratorRegistry, string $defaultCodeGeneratorIdentifier = 'incremental', array $productTypeCodeGeneratorMap = [])
021⫶ {
022⫶ $this->codeGeneratorRegistry = $codeGeneratorRegistry;
023⫶ $this->defaultCodeGeneratorIdentifier = $defaultCodeGeneratorIdentifier;
024⫶ $this->productTypeCodeGeneratorMap = $productTypeCodeGeneratorMap;
025⫶ }
026⫶
027⫶ public function generateCode(CodeGeneratorContext $context): string
028⫶ {
029⫶ if (!$context->hasBaseProduct()) {
030⫶ throw new InvalidArgumentException('$context', 'missing base product');
031⫶ }
032⫶
033⫶ $productTypeIdentifier = $context->getBaseProduct()->getProductType()->getIdentifier();
034⫶ $codeGeneratorIdentifier = array_key_exists($productTypeIdentifier, $this->productTypeCodeGeneratorMap) ? $this->productTypeCodeGeneratorMap[$productTypeIdentifier] : $this->defaultCodeGeneratorIdentifier;
035⫶
036⫶ if ($this->codeGeneratorRegistry->hasCodeGenerator($codeGeneratorIdentifier)) {
037⫶ return $this->codeGeneratorRegistry->getCodeGenerator($codeGeneratorIdentifier)->generateCode($context);
038⫶ } else {
039⫶ throw new InvalidArgumentException('$productTypeCodeGeneratorMap', "no code generator '$codeGeneratorIdentifier' registered");
040⫶ }
041⫶ }
042⫶ }

Download colorized diff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant