Although Magento 2 Data Feed Generator supports all product attributes, sometimes you may need to change the display of a particular attribute or add additional fields to the feed.
All fields are recorded in the feed in the {entity.property} format, which we call tags. You can read more information about them in our Data Feed Generator Tags documentation.
Let’s add a Delivery Time field to a product feed.
{product.delivery_time}
tag to the feed
Step 1. Add For XML feed, add the tag to the Template Editor -> Item Element field.
<item>
...
<delivery_time>{product.delivery_time}</delivery_time>
...
</item>
For CSV feed, add the name of the field to the Template Editor -> Header field, and the tag – to the Template Editor -> Item Element field.
...","delivery_time","...
...},{product.delivery_time},{...
delivery_time
for the product.
Step 2. Create a file that will determine For this, you need to implement the \Plumrocket\Datagenerator\Model\Feed\Resolver\FieldResolverInterface
interface.
<?php
declare(strict_types=1);
namespace Vendor\Module\Model;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Store\Api\Data\StoreInterface;
use Plumrocket\Datagenerator\Model\Feed\Resolver\FieldResolverInterface;
use Plumrocket\Datagenerator\Model\Feed\TagInterface;
class DeliveryTimeResolver implements FieldResolverInterface
{
public function resolve(
TagInterface $tag,
ProductInterface $product,
StoreInterface $store,
array $data,
array $params = []
): string {
return '2 working days';
}
}
delivery_time
tag in di.xml
Step 3. Register the resolver for the <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Plumrocket\Datagenerator\Model\Feed\Resolver\FieldComposite">
<arguments>
<argument name="fieldResolvers" xsi:type="array">
<item name="delivery_time" xsi:type="object">Vendor\Module\Model\DeliveryTimeResolver</item>
</argument>
</arguments>
</type>
</config>
The Delivery Time field is now added to the product.