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

Cnet Connector Laravel Package

akeneo/cnet-connector

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps to Begin

  1. Install Dependencies Run:

    composer require akeneo/cnet-connector:2.0.*
    composer require akeneo-labs/custom-entity-bundle:2.*
    composer require akeneo/extended-attribute-type:2.0.*
    
  2. Enable Bundles Add to app/AppKernel.php:

    new Pim\Bundle\CustomEntityBundle\PimCustomEntityBundle(),
    new Pim\Bundle\ExtendedAttributeTypeBundle\PimExtendedAttributeTypeBundle(),
    new Pim\Bundle\CnetConnectorBundle\PimCnetConnectorBundle(),
    
  3. Configure Brand Reference Data Update app/config/config.yml:

    pim_reference_data:
        brand:
            class: Pim\Bundle\CnetConnectorBundle\Entity\Brand
            type: simple
    
  4. Update Database & Assets

    php bin/console cache:clear --env=prod --no-warmup
    php bin/console doctrine:schema:update --env=prod --force
    php bin/console --env=prod pim:installer:assets --symlink --clean
    yarn run webpack
    
  5. First Use Case: Import CNET Data

    • Download CNET CSV files (e.g., products.csv, reviews.csv).
    • Place them in var/import/cnet/.
    • Trigger import via CLI:
      php bin/console pim:cnet-connector:import
      

Implementation Patterns

Workflows

  1. Data Enrichment Workflow

    • Fetch CNET Data: Use CNET’s API or manually download CSV files (e.g., product specs, reviews, ratings).
    • Map Fields: Align CNET fields (e.g., cnet_product_id, brand, specs) to Akeneo’s attribute structure. Example: Extend Product entity to include CNET-specific attributes:
      // config/akeneo_pim.yml
      pim_enrich:
          product:
              attributes:
                  cnet_rating:
                      type: pim_catalog_enum
                      enum:
                          values:
                              - "1"
                              - "2"
                              - "3"
                              - "4"
                              - "5"
      
    • Import: Run the connector’s import command to merge CNET data into Akeneo:
      php bin/console pim:cnet-connector:import --file=products.csv
      
  2. Scheduled Syncs

    • Automate imports via Cron (e.g., daily syncs):
      0 3 * * * php /path/to/akeneo/bin/console pim:cnet-connector:import >> /var/log/cnet_import.log 2>&1
      
    • Log output to debug failures (e.g., missing fields, duplicates).
  3. Attribute Customization

    • Extend Attributes: Use ExtendedAttributeTypeBundle to add CNET-specific fields (e.g., cnet_review_url, cnet_category). Example:
      # config/akeneo_pim.yml
      pim_enrich:
          extended_attribute_type:
              cnet_review_url:
                  type: pim_catalog_text
      
  4. Brand Management

    • Use the Brand entity (from pim_reference_data) to categorize products by manufacturer.
    • Example CLI to add a brand:
      php bin/console pim:reference-data:create brand "Sony" --locale=en_US
      

Integration Tips

  • CSV Format: Ensure CNET CSV files match Akeneo’s expected format (e.g., headers must align with attribute codes). Example products.csv:
    sku,cnet_product_id,brand,cnet_rating,specs
    PROD-001,CN12345,Sony,4,"Resolution: 4K"
    
  • Error Handling: Validate imports with:
    php bin/console pim:cnet-connector:validate --file=products.csv
    
  • API Integration: For dynamic data, extend the connector to call CNET’s API instead of CSV files. Override the CnetImportCommand class to fetch data via HTTP.

Gotchas and Tips

Pitfalls

  1. Schema Mismatches

    • Issue: CNET CSV headers don’t match Akeneo attribute codes.
    • Fix: Map fields explicitly in the connector’s configuration or override the CnetImporter service to transform headers. Example override:
      # config/services.yml
      services:
          pim_cnet_connector.importer:
              class: AppBundle\Service\CustomCnetImporter
              arguments:
                  - '@pim_cnet_connector.importer.default'
      
      // src/Service/CustomCnetImporter.php
      class CustomCnetImporter extends \Pim\Bundle\CnetConnectorBundle\Importer\CnetImporter
      {
          protected function getFieldMappings()
          {
              return [
                  'cnet_product_id' => 'reference',
                  'brand' => 'brand', // Maps to reference data
                  'specs' => 'specs_text', // Custom attribute
              ];
          }
      }
      
  2. Duplicate Entries

    • Issue: CNET data may contain duplicate sku or cnet_product_id values.
    • Fix: Use Akeneo’s ProductUpdater to merge duplicates or skip updates with a flag:
      php bin/console pim:cnet-connector:import --skip-duplicates
      
  3. Locale Conflicts

    • Issue: CNET data may include non-supported locales (e.g., fr_FR).
    • Fix: Filter or translate locales in the importer:
      // Override getSupportedLocales()
      public function getSupportedLocales()
      {
          return ['en_US', 'fr_FR']; // Whitelist locales
      }
      
  4. Dependency Conflicts

    • Issue: CustomEntityBundle or ExtendedAttributeTypeBundle may conflict with other Akeneo extensions.
    • Fix: Test in a staging environment first. Isolate the connector in a separate bundle if needed.

Debugging

  1. Log Imports Enable debug mode in config/packages/dev/monolog.yaml:

    handlers:
        main:
            type: stream
            path: "%kernel.logs_dir%/%kernel.environment%.log"
            level: debug
    

    Check logs for failed imports or missing fields.

  2. Validate CSV Use the validate command to catch format errors early:

    php bin/console pim:cnet-connector:validate --file=products.csv --dry-run
    
  3. Database Constraints If imports fail with IntegrityConstraintViolationException, check:

    • Unique constraints on sku or cnet_product_id.
    • Required attributes (e.g., family, categories) are populated.

Extension Points

  1. Custom Importers Extend CnetImporter to support additional CNET data sources (e.g., videos, news):

    class VideoCnetImporter extends CnetImporter
    {
        protected function importFile($filePath)
        {
            // Custom logic for video data
        }
    }
    
  2. Webhooks Trigger Akeneo workflows post-import (e.g., publish products):

    // src/EventListener/CnetImportListener.php
    class CnetImportListener implements EventSubscriberInterface
    {
        public static function getSubscribedEvents()
        {
            return [
                'pim_cnet_connector.import.post' => 'onPostImport',
            ];
        }
    
        public function onPostImport(PostImportEvent $event)
        {
            $this->publishProducts($event->getProducts());
        }
    }
    
  3. UI Integration Add CNET-specific tabs to the Akeneo product grid using the pim_enrich_datagrid event:

    # config/packages/pim_enrich.yaml
    pim_enrich:
        datagrid:
            cnet:
                label: CNET Data
                fields:
                    - cnet_rating
                    - cnet_review_url
    
  4. Testing Use PHPUnit to test importers:

    public function testImportValidCsv()
    {
        $importer = $this->getImporter();
        $result = $importer->import($this->getValidCsvPath());
        $this->assertCount(1, $result->getProducts());
    }
    
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor