How to Customize SintraPimcoreBundle - Sintraconsulting/pimcore-product-sync-plugin GitHub Wiki

How to Customize SintraPimcoreBundle

The SintraPimcoreBundle provides its own solution for Event Listeners to handle Object Events and Object Synchronization Flow. If you need to customize some functionalities to achieve goals on your project, you can easily extend some natives SintraPimcoreBundle functionalities.

In order to accomplish that, firstly you have to declare your custom bundle name in the BaseEcommerceConfig class. Let's say, for example, that this custom bundle is named "MyCustomBundle":

namespace SintraPimcoreBundle\Resources\Ecommerce;

class BaseEcommerceConfig {

    [...]

    public static function getCustomizationInfo(){
        return array(
            "namespace" => "MyCustomBundle"
        );
    }
}

You are free to develop this bundle as you want. To extend some SintraPimcoreBundle functionalities you need to create the SintraPimcoreBundle subfolder inside the MyCustomBundle folder. Let's see some examples of functionalities extension.

Event Listeners

In order to extend the EventListener flow, you need to create an ObjectListener class in the following path: MyCustomBundle/SintraPimcoreBundle/EventListeners

This class has to extend the AbstractObjectListener class provided by SintraPimcoreBundle

namespace MyCustomBundle\SintraPimcoreBundle\EventListener;

use Pimcore\Logger;
use SintraPimcoreBundle\EventListener\AbstractObjectListener;

class ObjectListener extends AbstractObjectListener{
    
    [...]

    public function preUpdateDispatcher($dataObject) {
        $className = strtolower($dataObject->o_className);

        switch ($className) {

            case "product":
                $productListener = new ProductListener();
                $productListener->preUpdateAction($dataObject);
                break;

            default:
                Logger::debug("MyCustomBundle ObjectListener - Class '".$className."' is not Managed for preUpdate");
                break;
        }
    }

    [...]

}

You are free to create a specific event listener for each class or a common one. These event listeners must implement the InterfaceListener provided by the SintraPimcoreBundle. Let's check the guide in Event Listeners to handle Object Events.

Object Synchronization Flow

The synchronization flow for each class of objects is managed by the BaseSyncController class provided by the SintraPimcoreBundle.

Let's say that, for example, for a specific server you need to customize the condition query used to retrieve objects that must be synchronized. All that you need to do is to create a custom class with the following namespace: MyCustomBundle/SintraPimcoreBundle/Controller/Sync/ServerTypeSyncController

This class must extend the BaseSyncController in order to override or extend its functionalities.

Service for Object Synchronization

The SintraPimcoreBundle provides a set of classes that allow you to properly invoke the server API.

  • The BaseEcommerceService class provides a set of common utils that can be used for kind of server and an abstract function that must be implemented for each type of server to define the API object structure.

  • The InterfaceService interface has to be implemented for each class of object that must be exported on the server.

For each type of server, and for each class that must be exported on those server, it must exists a Service that provides methods to properly generate the object to be sent as body for the API calls that create or update the object on the server. Let's say for example that we want to export object of the "Product" class on a server of type "Shopify"; we must create subfolder named Shopify and, inside of it, the following classes:

  • The BaseShopifyService class, that extend the BaseEcommerceService class.

  • The ShopifyProductService class that extends the BaseShopifyService class and implements the InterfaceService interface.

If you must override some functionalities you just need to extends this classes, properly creating the correct subfolders in MyCustomBundle/SintraPimcoreBundle/Services path.

How to add Integrations with other Server types

Until now, SintraPimcoreBundle provides integrations that permits to synchronize Pimcore objects in "Magento 2" and "Shopify" E-Commerce.

Potentially, it's possible to add integrations to connect with any other kind of E-Commerce. Let's say, for example, that we want to add an integration with an "Amazon" platform. What we should do is:

  • Create or integrate in Pimcore a PHP client for the Amazon APIs. You can check a detailed example of How to implement the Magento2 API services.

  • Create an AmazonServerInfo ObjectBrick to store Amazon server information (for example an API key) and set its reference in the TargetServer class.

  • Implement the BaseAmazonService and the AmazonProductService classes in the SintraPimcoreBundle/Services/Amazon path as described in the previous paragraph

⚠️ **GitHub.com Fallback** ⚠️