2017 © Pedro Peláez
 

lib commercetools-odm-bundle

Makes the commercetools database accessible with the doctrine commons api.

image

bestit/commercetools-odm-bundle

Makes the commercetools database accessible with the doctrine commons api.

  • Wednesday, January 17, 2018
  • by WBLKonzept
  • Repository
  • 2 Watchers
  • 0 Stars
  • 7,622 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 2 Versions
  • 7 % Grown

The README.md

bestit/commercetools-odm-bundle

Makes the commercetools database accessible with the doctrine commons api. It still uses the commmercetools/php-sdk under the hood., (*1)

Installation

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:, (*2)

$ composer require bestit/commercetools-odm-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation., (*3)

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:, (*4)

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new BestIt\CommercetoolsODMBundle\BestItCommercetoolsODMBundle(),
        );

        // ...
    }

    // ...
}

Step 3: Configure the Bundle

# Default configuration for "BestItCommercetoolsODMBundle"
bestit_commercetools_odm:

    # Please provide the service id for your commercetools client.
    client_service_id:    ~ # Required

    # Please provide the service id for your commercetools request async pool.
    pool_service_id:      ~

This bundle ships a client factory which you can use to create a client. Example:, (*5)

services:
    Commercetools\Core\Client:
        factory: 'BestIt\CommercetoolsODMBundle\Factory\ClientFactory:create'
        arguments:
            - {client_id: '%env(COMMERCETOOLS_CLIENT_ID)%', client_secret: '%env(COMMERCETOOLS_CLIENT_SECRET)%', project: '%env(COMMERCETOOLS_PROJECT)%', scope: ['manage_project'] }
            - {locale: 'de', languages: ['de'] }

    BestIt\CommercetoolsODMBundle\Factory\ClientFactory:
        class: BestIt\CommercetoolsODMBundle\Factory\ClientFactory
        arguments: ['@cache.app', '@logger']

Usage

Event Listener with the sercice container

You can add an event listener to the typical live cycle events if you tag your service with the name best_it_commercetools_odm.event_listener. But don't forget the name of the event with the key event on your tag., (*6)

Example:, (*7)

# app/config/services.yml
services:
    app.tokens.action_listener:
        class: AppBundle\EventListener\TokenListener
        arguments: ['%tokens%']
        tags:
            - { name: best_it_commercetools_odm.event_listener, event: postPersist }

the method of the service should match the event name., (*8)

Services

The service best_it.commercetools_odm.manager provices you with an extended Doctrine\Common\Persistence\ObjectManager., (*9)

the method of the service should match the event name., (*10)

Filters

You can add multiple filters to apply on requests. Just create one filter, implement the FilterInterface and tag the service with best_it_commercetools_odm.filter. The filter get the raw created request and will be applied just before the request will be send., (*11)

Example:, (*12)

// ProductFilter.php
class ProductFilter implements FilterInterface
{
    /**
     * {@inheritdoc}
     */
    public function getKey()
    {
        return 'product';
    }

    /**
     * {@inheritdoc}
     */
    public function apply($request)
    {
        $request->setExpands(['masterVariant.attributes[*].value', 'productType', 'categories[*].ancestors[*]']);

        $request->channel('xyz');
        $request->currency('EUR');
    }
}
# app/config/services.yml
services:
    app.filter.product_filter:
        class: AppBundle\Filter\ProductFilter
        tags:
            - { name: best_it_commercetools_odm.filter }

Now you can apply the one or more filter whenever you want:, (*13)

    app.repository.product_projection:
        class: BestIt\CommercetoolsODM\Model\ProductProjectionRepository
        factory: ["@best_it.commercetools_odm.manager", getRepository]
        arguments:
            - Commercetools\Core\Model\Product\ProductProjection
        calls:
            - [filter, ['projection', 'projection-categories']]

The Versions

17/01 2018

dev-master

9999999-dev

Makes the commercetools database accessible with the doctrine commons api.

  Sources   Download

MIT

The Requires

 

The Development Requires

17/01 2018

dev-feature/clear-dependencies

dev-feature/clear-dependencies

Makes the commercetools database accessible with the doctrine commons api.

  Sources   Download

MIT

The Requires

 

The Development Requires