This article is aimed at developers looking to extend the PureClarity feed process in the Magento 2.x extension.
Extending the feed could be required if you have custom data that needs to be sent in the feed, or you'd like to override/change the data being sent already.
Extension points
Each feed type has 2 main classes you can extend upon.
Feed Data Handler - This gathers the data from Magento, using collections
Row Data Handler - This turns the Magento data into an array in the format required by the PureClarity Feeds process.
How to Extend
We recommend that you use plugins to extend the feed process.
Class names & relevant functions
Product Feed
Feed Data Handler - Pureclarity\Core\Model\Feed\Type\Product\FeedData
buildCollection - returns the collection used to gather data
Row Data Handler - Pureclarity\Core\Model\Feed\Type\Product\RowData
getRowData - returns the array of data sent to PureClarity
Category Feed
Feed Data Handler - Pureclarity\Core\Model\Feed\Type\Category\FeedData
buildCategoryCollection - returns the collection used to gather data
Row Data Handler - Pureclarity\Core\Model\Feed\Type\Category\RowData
getRowData - returns the array of data sent to PureClarity
Brand Feed
Feed Data Handler - Pureclarity\Core\Model\Feed\Type\Brand\FeedData
buildBrandCollection - returns the collection used to gather data
Row Data Handler - Pureclarity\Core\Model\Feed\Type\Brand\RowData
getRowData - returns the array of data sent to PureClarity
User Feed
Feed Data Handler - Pureclarity\Core\Model\Feed\Type\User\FeedData
buildCustomerCollection - returns the collection used to gather data
Row Data Handler - Pureclarity\Core\Model\Feed\Type\User\RowData
getRowData - returns the array of data sent to PureClarity
Order History Feed
Feed Data Handler - Pureclarity\Core\Model\Feed\Type\Order\FeedData
buildOrderCollection - returns the collection used to gather data
Row Data Handler - Pureclarity\Core\Model\Feed\Type\Order\RowData
getRowData - returns the array of data sent to PureClarity
The product feed row processing is also broken out into a few different child row data handlers, so that there isn't too much code in one class. These can also be extended individually if required.
These all live in the Pureclarity\Core\Model\Feed\Type\Product\RowDataHandlers namespace
Example
This example add a custom field of data to the product feed.
di.xml
<config>
<type name="">
<plugin name="\Pureclarity\Core\Model\Feed\Type\Product\RowData" type="\My\Module\Plugin\PureClarity\Product\RowDataPlugin" sortOrder="1" disabled="false" />
</type>
</config>
RowDataPlugin.php
namespace My\Module\Plugin\PureClarity\Product;
use \Pureclarity\Core\Model\Feed\Type\Product\RowData;
class RowDataPlugin
{
public function afterGetRowData(RowData $subject, $data)
{
// $data is the row of data for a product, to be sent to PureClarity
$data['MyCustomField'] = 'My Custom Value';
return $data;
}
}