This is a module for integration with the Bloomreach service.
- Magento 2.3, 2.4
- PHP 7.3, 7.4, 8.1
- composer config repositories.bloomreach git https://github.com/exponea/bloomreach-magento2-integration.git
- composer require bloomreach/bloomreach-engagement-connector-magento
Check to see if your Magento instance has an app/code directory structure. If not, create it manually.
- Then create 2 more directories with this path:
Bloomreach/EngagementConnector
. The final path should look like:app/code/Bloomreach/EngagementConnector
- Extract the downloaded zip folder and move the content of the extracted folder to this path:
app/code/Bloomreach/EngagementConnector
- bin/magento maintenance:enable
- bin/magento module:enable Bloomreach_EngagementConnector
- bin/magento deploy:mode:set production
- bin/magento cache:clean
- bin/magento maintenance:disable
- bin/magento module:enable Bloomreach_EngagementConnector
- bin/magento setup:upgrade
- bin/magento cache:clean
bloomreach_export_queue
- contains a queue of prepared data waiting to be exported.bloomreach_export_entity
- contains the identifiers of the entities to be added to the export queue.
<project_dir>/var/log/bloomreach/engagement_connector.log
- contains errors information<project_dir>/var/log/bloomreach/debug.log
- contains debugging information
Bloomreach\EngagementConnector\Model\DataMapping\DataMapperResolver
- responsible for map Magento entity data to the Bloomreach data. ReturnsMagento\Framework\DataObject
;
bloomreach_entity_mapping.xml
- allows you to configure field mapping
entity_type
- entity type to map;bloomreach_code
- the name of the key on the Bloomreach side;field
- field to map withbloomreach_code
.
- Add entity configuration to the
bloomreach_entity_mapping.xml
.
<entity_type entity="custom_entity">
<bloomreach_code code="entity_id">
<field code="entity_id" />
</bloomreach_code>
<bloomreach_code code="created_at">
<field code="created_at" />
</bloomreach_code>
<bloomreach_code code="updated_at">
<field code="updated_at" />
</bloomreach_code>
</entity_type>
- Create a class that implements
Bloomreach\EngagementConnector\Model\DataMapping\DataMapper\DataMapperInterface
- Pass your Mapper to the
Bloomreach\EngagementConnector\Model\DataMapping\DataMapperFactory
viadi.xml
<type name="Bloomreach\EngagementConnector\Model\DataMapping\DataMapperFactory">
<arguments>
<argument name="dataMappers" xsi:type="array">
<item name="custom_entity" xsi:type="string">
Vendor\Name\Model\DataMapping\DataMapper\Custom
</item>
</argument>
</arguments>
</type>
Optional. If you want to use a separate renderer for the field you need:
- Create a class that implements
Bloomreach\EngagementConnector\Model\DataMapping\FieldValueRenderer\RenderInterface
- Pass your Renderer to the
Bloomreach\EngagementConnector\Model\DataMapping\FieldValueRendererResolver
viadi.xml
and specify the entity type and field code:
<type name="Bloomreach\EngagementConnector\Model\DataMapping\FieldValueRendererResolver">
<arguments>
<argument name="fieldValueRenderers" xsi:type="array">
<item name="custom_entity" xsi:type="array">
<item name="entity_id" xsi:type="object">
Vendor\Name\Model\DataMapping\FieldValueRenderer\CustomRenderer\EntityIdRenderer
</item>
</item>
</argument>
</arguments>
</type>
- Use
Bloomreach\EngagementConnector\Model\DataMapping\FieldValueRendererResolver
in the mapper class to get field value.
- Create a class that implements
Bloomreach\EngagementConnector\Model\DataMapping\DataMapper\DataMapperInterface
- Pass your Mapper to the
Bloomreach\EngagementConnector\Model\DataMapping\DataMapper\ProductMapperResolver
viadi.xml
and specifyproductTypeId
as the name of the argument
<type name="Bloomreach\EngagementConnector\Model\DataMapping\DataMapper\ProductMapperResolver">
<arguments>
<argument name="dataMappers" xsi:type="array">
<item name="configurable" xsi:type="object">
Vendor\Name\Model\DataMapping\DataMapper\Product\Configurable
</item>
</argument>
</arguments>
</type>
- Create a class that implements
Bloomreach\EngagementConnector\Model\DataMapping\FieldValueRenderer\RenderInterface
- Pass your Renderer to the
Bloomreach\EngagementConnector\Model\DataMapping\FieldValueRendererResolver
viadi.xml
and specify theentity_type
andfield
code as name of items:
<type name="Bloomreach\EngagementConnector\Model\DataMapping\FieldValueRendererResolver">
<arguments>
<argument name="fieldValueRenderers" xsi:type="array">
<item name="catalog_product" xsi:type="array">
<item name="custom_field" xsi:type="object">
Vendor\Name\Model\DataMapping\FieldValueRenderer\Product\CustomRenderer
</item>
</item>
</argument>
</arguments>
</type>
- Create a class that implements
Bloomreach\EngagementConnector\Model\DataMapping\FieldValueRenderer\RenderInterface
- Pass your Renderer to the
Bloomreach\EngagementConnector\Model\DataMapping\FieldValueRenderer\Product\ProductTypeRendererResolver
viadi.xml
and specify theproductTypeId
andfield
code as name of items:
<type name="Bloomreach\EngagementConnector\Model\DataMapping\FieldValueRenderer\Product\ProductTypeRendererResolver">
<arguments>
<argument name="fieldValueRenderers" xsi:type="array">
<item name="simple" xsi:type="array">
<item name="entity_id" xsi:type="object">
Vendor\Name\Model\DataMapping\FieldValueRenderer\Product\Simple\EntityIdRenderer
</item>
</item>
</argument>
</arguments>
</type>
- Create a class that implements
Bloomreach\EngagementConnector\Model\DataMapping\FieldValueRenderer\RenderInterface
- Pass your Renderer to the
Bloomreach\EngagementConnector\Model\DataMapping\FieldValueRendererResolver
viadi.xml
and specify theentity_type
andfield
code as name of items:
<type name="Bloomreach\EngagementConnector\Model\DataMapping\FieldValueRendererResolver">
<arguments>
<argument name="fieldValueRenderers" xsi:type="array">
<item name="catalog_product" xsi:type="array">
<item name="entity_id" xsi:type="object">
Vendor\Name\Model\DataMapping\FieldValueRenderer\Product\\EntityIdRenderer
</item>
</item>
</argument>
</arguments>
</type>
- Create
bloomreach_entity_mapping.xml
in file in your module. - Add a new
bloomreach_code
node toentity_type
that you want to extend
<entity_type entity="catalog_product">
<bloomreach_code code="custom_code">
<field code="custom_field" />
</bloomreach_code>
</entity_type>
- Create
bloomreach_entity_mapping.xml
in file in your module. - Add
disabled
equaltrue
tobloomreach_code
that you want to exclude from mapping
<entity_type entity="catalog_product">
<bloomreach_code code="entity_id" disabled="true" />
</entity_type>
- Create
bloomreach_entity_mapping.xml
in file in your module. - Add a
field
node tobloomreach_code
node that you want to change
<entity_type entity="catalog_product">
<bloomreach_code code="title">
<field code="custom_field" />
</bloomreach_code>
</entity_type>
Bloomreach\EngagementConnector\Observer\CustomerEntitySave
the event customer_save_after
Get customer entity after save.
Bloomreach\EngagementConnector\Observer\OrderEntitySave
the event checkout_submit_all_after
Get order entity after save
Bloomreach\EngagementConnector\Observer\ProductEntitySave
the event catalog_product_save_commit_after
Get product entity after save
Bloomreach\EngagementConnector\Service\Export\PrepareCustomerDataService
Preparing customer entity data after save,
and push it to the mapper.
Bloomreach\EngagementConnector\Service\Export\PrepareOrderDataService
Preparing order entity data after save and
push it to the mapper.
Bloomreach\EngagementConnector\Service\Export\PrepareProductDataService
Prepare product entity data and push it to
the mapper.
Start the API import: Bloomreach\EngagementConnector\Service\Integration\StartApiImportService
class can be used to
start the import by API call. The method receives the import ID and path to the csv file with data. Also, the parameter
test_connection
can be used to testing.
Bloomreach\EngagementConnector\Service\Integration\GetEndpointService
class responsible to preparing URL endpoint
by system config.
Bloomreach\EngagementConnector\Console\Command\AddToExportQueue
can be used to add entities to export queue manually.
The command:
bin/magento bloomreach:add-to-export-queue
Bloomreach\EngagementConnector\Console\Command\StartExport
can be used to start export manually.
The command:
bin/magento bloomreach:export-start --import_id="*********" --csv_file_path="*****" --test_connection="1"
Using the options, you can run the export from a specific csv file.
Where:
- import_id - is ID of necessary import, can be clarify in the bloomreach exponea admin
- csv_file_path - path of CSV file
- test_connection - is not required parameter - set "1" to run rest connection.
Bloomreach\EngagementConnector\Console\Command\GenerateExportFileForExportQueue
can be used to testing or to generating import files manually.
The command:
bin/magento bloomreach:generate-export-files --entity_type="*********" --update_export_status="1"
Where:
- entity_type - is not a required parameter. If not specified, an export file is generated for all entity types. For example:
catalog_product
- update_export_status - is not required parameter. Set
1
to update the status of the export queue item after creating the file.
bloomreach_add_to_export_queue
- prepares entities waiting to be exported and adds them to the export queue.bloomreach_run_export
- exports data from the export queue to the Bloomreach service.
Bloomreach\EngagementConnector\Model\Export\QueueProcessor
- obtains the entities that need to be exported, prepares them and adds them to the export queue.Bloomreach\EngagementConnector\Model\Export\ExportProcessor
- obtaining data from export queue and send them to the Bloomreach service.Bloomreach\EngagementConnector\Model\Export\File\DirectoryProvider
- allows to create and retrieve a directory where the export file should be placed.Bloomreach\EngagementConnector\Model\Export\Transporter\TransporterResolver
- sends data to a specific endpoint, for a specific entity type, to the Bloomreach.
- Pass directory name to the
Bloomreach\EngagementConnector\Model\Export\File\DirectoryProvider
viadi.xml
and specify theentity_type
as name of items:
<type name="Bloomreach\EngagementConnector\Model\Export\File\DirectoryProvider">
<arguments>
<argument name="entityDirectories" xsi:type="array">
<item name="catalog_product" xsi:type="string">catalog_product</item>
</argument>
</arguments>
</type>
- Add your entity type to the Entity Provider:
<type name="Bloomreach\EngagementConnector\Model\DataProvider\EntityType">
<arguments>
<argument name="entityTypes" xsi:type="array">
<item name="catalog_product" xsi:type="string">catalog_product</item>
</argument>
</arguments>
</type>
- Create Data Mapping for the new entity.
- Pass collection class to the
Bloomreach\EngagementConnector\Model\Export\Entity\CollectionFactory
viadi.xml
:
<type name="Bloomreach\EngagementConnector\Model\Export\Entity\CollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="catalog_product" xsi:type="string">
Magento\Catalog\Model\ResourceModel\Product\Collection
</item>
</argument>
</arguments>
</type>
- Create class that implements
Bloomreach\EngagementConnector\Model\Export\Transporter\TransporterInterface
. - Optional If you want to use a separate API to send data to the Bloomreach, you can implement other transporter. Pass your transporter class to the
Bloomreach\EngagementConnector\Model\Export\Transporter\TransporterResolver
viadi.xml
and specify theentity_type
andapi_type
as name of items:
<type name="Bloomreach\EngagementConnector\Model\Export\Transporter\TransporterResolver">
<arguments>
<argument name="transporters" xsi:type="array">
<item name="csv_export" xsi:type="array">
<item name="default" xsi:type="object">
Bloomreach\EngagementConnector\Model\Export\Transporter\InitialExport\DefaultTransporter
</item>
</item>
</argument>
</arguments>
</type>
- Use a
Bloomreach\EngagementConnector\Model\Export\Entity\AddToExport
class to add your entity id to the export.
- Create Data Mapping for the new entity.
- Use a
Bloomreach\EngagementConnector\Model\Export\Queue\AddDataToExportQueue
class to add your entity to the export queue - Create class that implements
Bloomreach\EngagementConnector\Model\Export\Transporter\TransporterInterface
. - Optional If you want to use separate API ot send data to the Bloomreach, you can implement other transporter. Pass your transporter class to the
Bloomreach\EngagementConnector\Model\Export\Transporter\TransporterResolver
viadi.xml
and specify theentity_type
andapi_type
as name of items:
<type name="Bloomreach\EngagementConnector\Model\Export\Transporter\TransporterResolver">
<arguments>
<argument name="transporters" xsi:type="array">
<item name="csv_export" xsi:type="array">
<item name="default" xsi:type="object">
Bloomreach\EngagementConnector\Model\Export\Transporter\InitialExport\DefaultTransporter
</item>
</item>
</argument>
</arguments>
</type>
- Create a class that implements
Bloomreach\EngagementConnector\Model\ExportPreconfiguration\PreconfigurateEntityExportInterface
- Pass your class to the
Bloomreach\EngagementConnector\Model\ExportPreconfiguration\PreconfigurateEntityExport
viadi.xml
:
<type name="Bloomreach\EngagementConnector\Model\ExportPreconfiguration\PreconfigurateEntityExport">
<arguments>
<argument name="entitiesToPreconfigurate" xsi:type="array">
<item name="catalog_product" xsi:type="object">
Bloomreach\EngagementConnector\Model\ExportPreconfiguration\Entity\Product
</item>
</argument>
</arguments>
</type>
- Create a class that implements
Bloomreach\EngagementConnector\Model\InitialExport\InitialEntityExportInterface
. - Pass your class to the
Bloomreach\EngagementConnector\Model\InitialExport\InitialEntityExport
viadi.xml
:
<type name="Bloomreach\EngagementConnector\Model\InitialExport\InitialEntityExport">
<arguments>
<argument name="entitiesToExport" xsi:type="array">
<item name="catalog_product" xsi:type="object">
Bloomreach\EngagementConnector\Model\InitialExport\Entity\Product
</item>
</argument>
</arguments>
</type>
- Create system config for import id
- Pass your config to the class via
di.xml
:
<type name="Bloomreach\EngagementConnector\Service\Integration\ImportIdResolver">
<arguments>
<argument name="importIdsConfigPath" xsi:type="array">
<item name="catalog_product" xsi:type="string">bloomreach_engagement/general/catalog_import_id</item>
</argument>
</arguments>
</type>
- Create a data mapper for your entity type.
- Use a
Bloomreach\EngagementConnector\Model\Export\Queue\AddEventToExportQueue
class to add you event to export queue. - Optional If you want to use a separate API to send data to the Bloomreach, you can implement other transporter. Pass your transporter class to the
Bloomreach\EngagementConnector\Model\Export\Transporter\TransporterResolver
viadi.xml
and specify theentity_type
andapi_type
as name of items:
<type name="Bloomreach\EngagementConnector\Model\Export\Transporter\TransporterResolver">
<arguments>
<argument name="transporters" xsi:type="array">
<item name="event" xsi:type="array">
<item name="custom_entity" xsi:type="object">
Bloomreach\EngagementConnector\Model\Export\Transporter\Event\CustomEntityTransporter
</item>
</item>
</argument>
</arguments>
</type>
{
"eventName": "view_item",
"eventBody": {
"sku": "WS02",
"price": "120.00"
}
}
- Prepare event object:
{
"eventName": "view_item",
"eventBody": {
"sku": "WS02",
"price": "120.00"
}
}
- Use
Bloomreach_EngagementConnector/js/tracking/event-sender
component to send an event.
- Create a class that implements
\Bloomreach\EngagementConnector\Model\Tracking\Event\EventsInterface
and\Magento\Framework\View\Element\Block\ArgumentInterface
interfaces. - Create child block for
bloomreach.engagement.connector.tracking
in the layout. - Use
Bloomreach\EngagementConnector\Block\Tracking\Event
class for event block. - Pass your event class to event block via arguments with name
events
. - Use
Bloomreach_EngagementConnector::tracking/event/default.phtml
template for send event
<referenceBlock name="bloomreach.engagement.connector.tracking">
<block class="Bloomreach\EngagementConnector\Block\Tracking\Event"
name="bloomreach.engagement.connector.custom.event.tracking"
after="-"
template="Bloomreach_EngagementConnector::tracking/event/default.phtml">
<arguments>
<argument name="events" xsi:type="object">
Bloomreach\EngagementConnector\Model\Tracking\Event\ProductPage\ViewItem
</argument>
</arguments>
</block>
</referenceBlock>
- Create a class that implements
\Bloomreach\EngagementConnector\Model\Tracking\Event\EventsInterface
interface. - Pass your class to the
Bloomreach\EngagementConnector\Model\Tracking\Event\Cart\CartUpdateEventsCollector
class viadi.xml
:
<type name="Bloomreach\EngagementConnector\Model\Tracking\Event\Cart\CartUpdateEventsCollector">
<arguments>
<argument name="eventsList" xsi:type="array">
<item name="cart_update" xsi:type="object">Bloomreach\EngagementConnector\Model\Tracking\Event\Cart\CartUpdate</item>
</argument>
</arguments>
</type>