Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Classification Rule Bundle Laravel Package

akeneo-labs/classification-rule-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    composer require akeneo-labs/classification-rule-bundle:1.2.*
    

    Enable the bundle in AppKernel.php:

    new PimEnterprise\Bundle\ClassificationRuleBundle\PimEnterpriseClassificationRuleBundle(),
    

    Clear cache and reinstall assets:

    php app/console cache:clear --env=prod
    php app/console pim:installer:assets --env=prod
    
  2. First Use Case: Define a rule to unclassify products from a category tree. Example rule (resources/config/rules.yml):

    classification_rule_unclassify_example:
        conditions:
            - condition: "product.attribute.text == 'example'"
        actions:
            - action: "unclassify"
              category_tree: "ecommerce"
              category_code: "electronics"
    
  3. Trigger the Rule: Use Akeneo’s rule engine to apply the rule to products:

    php app/console pim:rule:execute classification_rule_unclassify_example
    

Implementation Patterns

Workflows

  1. Rule-Based Declassification:

    • Use the unclassify action to remove products from categories based on conditions (e.g., attribute values, product families).
    • Example: Declassify products with is_discontinued = true from the "promotions" category tree.
  2. Integration with Akeneo’s Rule Engine:

    • Leverage Akeneo’s existing rule conditions (e.g., product.attribute, product.family).
    • Combine with other actions (e.g., classify, set_attribute) for complex workflows.
  3. Batch Processing:

    • Apply rules to large product sets via CLI:
      php app/console pim:rule:execute rule_name --products=1,2,3
      
  4. Dynamic Category Trees:

    • Use category_tree in actions to target specific category hierarchies (e.g., "apparel", "electronics").

Integration Tips

  • Extend Existing Rules: Modify existing CatalogRuleBundle rules to include unclassify actions. Example:

    conditions:
        - condition: "product.family == 'apparel'"
    actions:
        - action: "unclassify"
          category_tree: "ecommerce"
        - action: "classify"
          category_code: "sale_items"
    
  • Event Listeners: Trigger rules on product updates via Akeneo’s event system:

    // src/Akeneo/YourBundle/EventListener/RuleListener.php
    public function onProductUpdate(ProductUpdateEvent $event) {
        $this->ruleEngine->execute('classification_rule_unclassify_example', [$event->getProduct()]);
    }
    
  • API Integration: Use Akeneo’s REST API to fetch products and apply rules programmatically:

    $client = new Client();
    $response = $client->get('/api/rest/v1/products');
    $products = json_decode($response->getBody(), true);
    $this->ruleEngine->execute('rule_name', $products);
    

Gotchas and Tips

Pitfalls

  1. Deprecated Interfaces:

    • The bundle uses updated interfaces (e.g., Akeneo\Component\Classification\Repository\CategoryRepositoryInterface). Ensure your codebase aligns with Akeneo PIM Enterprise’s latest dependencies.
    • Fix: Update service definitions in config.yml to use the new interfaces.
  2. Rule Engine Compatibility:

    • Rules must be compatible with Akeneo’s rule engine. Test conditions/actions in a staging environment first.
    • Debugging: Use pim:rule:debug to validate rule syntax:
      php app/console pim:rule:debug classification_rule_unclassify_example
      
  3. Category Tree Scope:

    • The unclassify action only affects categories within the specified category_tree. Products may remain classified in other trees.
    • Tip: Use category_code: null to declassify from all categories in the tree.
  4. Performance:

    • Batch processing large product sets may time out. Use chunked execution:
      php app/console pim:rule:execute rule_name --limit=100
      

Debugging

  • Logs: Enable debug mode (APP_DEBUG=true) and check var/log/dev.log for rule execution errors. Example log entry:

    [2023-01-01 12:00:00] pim.rule.ERROR: Failed to unclassify product SKU-123: Category "electronics" not found in tree "ecommerce" []
    
  • Dry Runs: Test rules without saving changes by mocking the ProductUpdater service in tests.

Extension Points

  1. Custom Actions: Extend the rule engine to add new actions (e.g., reclassify):

    // src/Akeneo/YourBundle/Rule/Action/ReclassifyAction.php
    class ReclassifyAction implements ActionInterface {
        public function execute(ProductInterface $product, array $parameters) {
            // Logic to reclassify product to a new category
        }
    }
    
  2. Condition Providers: Add custom conditions (e.g., product.price > 100):

    // src/Akeneo/YourBundle/Rule/Condition/PriceCondition.php
    class PriceCondition implements ConditionInterface {
        public function isValid(ProductInterface $product, array $parameters) {
            return $product->getPrice() > $parameters['threshold'];
        }
    }
    
  3. Configuration: Override default rule configurations in config/packages/pim_enterprise_classification_rule.yaml:

    pim_enterprise_classification_rule:
        default_category_tree: "custom_tree"
    

Config Quirks

  • Environment-Specific Rules: Use environment variables to dynamically set category_tree or category_code:

    actions:
        - action: "unclassify"
          category_tree: "%env(CLASSIFICATION_TREE)%"
    
  • Rule Inheritance: Rules defined in child bundles (e.g., YourBundle) override those in parent bundles (e.g., ClassificationRuleBundle). Use explicit bundle ordering in AppKernel.php.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle
dmstr/api-platform-utils-bundle
dmstr/api-configuration-bundle
chrisdev/ux-components
baks-dev/finances
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle