{"id":25132,"date":"2021-12-02T05:46:05","date_gmt":"2021-12-02T10:46:05","guid":{"rendered":"https:\/\/plumrocket.com\/docs\/?p=25132"},"modified":"2021-12-02T05:46:07","modified_gmt":"2021-12-02T10:46:07","slug":"how-to-add-custom-fields-to-a-product-feed-in-magento-2","status":"publish","type":"post","link":"https:\/\/plumrocket.com\/docs\/magento-data-feed\/v2\/devguide\/custom-product-fields","title":{"rendered":"How to Add Custom Fields to a Product Feed in Magento 2"},"content":{"rendered":"\n<p>Although <a href=\"\/magento-data-feed\">Magento 2 Data Feed Generator<\/a> supports all product attributes, sometimes you may need to change the display of a particular attribute or add additional fields to the feed.<\/p>\n\n\n\n<p>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 <a href=\"\/docs\/magento-data-feed\/v2\/devguide\/tags\">Data Feed Generator Tags<\/a> documentation. <\/p>\n\n\n\n<p>Let&#8217;s add a Delivery Time field to a product feed.<\/p>\n\n\n\n<h3 id=\"h-step-1-add-product-delivery_time-tag-to-the-feed\">Step 1. Add <code>{product.delivery_time}<\/code> tag to the feed<\/h3>\n\n\n\n<p>For XML feed, add the tag to the <strong>Template Editor<\/strong> -&gt; <strong>Item Element<\/strong> field.<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-markup\">&lt;item>\n    ...\n    &lt;delivery_time>{product.delivery_time}&lt;\/delivery_time>\n    ...\n&lt;\/item><\/code><\/pre><\/div>\n\n\n\n<p>For CSV feed, add the name of the field to the <strong>Template Editor<\/strong> -&gt; <strong>Header <\/strong>field, and the tag &#8211; to the <strong>Template Editor<\/strong> -&gt; <strong>Item Element<\/strong> field.<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div class=\"prism-title\">Template Editor -> Header<\/div><pre><code class=\"language-\">...\",\"delivery_time\",\"...<\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div class=\"prism-title\">Template Editor -> Item Element<\/div><pre><code class=\"language-\">...},{product.delivery_time},{...<\/code><\/pre><\/div>\n\n\n\n<h3 id=\"h-step-2-create-a-file-that-will-determine-delivery_time-for-the-product\">Step 2. Create a file that will determine <code>delivery_time<\/code> for the product.<\/h3>\n\n\n\n<p>For this, you need to implement the <code>\\Plumrocket\\Datagenerator\\Model\\Feed\\Resolver\\FieldResolverInterface<\/code> interface.<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div class=\"prism-title\">app\/code\/Vendor\/Module\/Model\/DeliveryTimeResolver.php<\/div><pre><code class=\"language-php\">&lt;?php\ndeclare(strict_types=1);\n\nnamespace Vendor\\Module\\Model;\n\nuse Magento\\Catalog\\Api\\Data\\ProductInterface;\nuse Magento\\Store\\Api\\Data\\StoreInterface;\nuse Plumrocket\\Datagenerator\\Model\\Feed\\Resolver\\FieldResolverInterface;\nuse Plumrocket\\Datagenerator\\Model\\Feed\\TagInterface;\n\nclass DeliveryTimeResolver implements FieldResolverInterface\n{\n    public function resolve(\n        TagInterface $tag,\n        ProductInterface $product,\n        StoreInterface $store,\n        array $data,\n        array $params = []\n    ): string {\n        return '2 working days';\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<h3 id=\"h-step-3-register-the-resolver-for-the-delivery_time-tag-in-di-xml\">Step 3. Register the resolver for the <code>delivery_time<\/code> tag in <code>di.xml<\/code><\/h3>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div class=\"prism-title\">app\/code\/Vendor\/Module\/etc\/di.xml<\/div><pre><code class=\"language-markup\">&lt;?xml version=\"1.0\"?>\n&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:ObjectManager\/etc\/config.xsd\">\n    &lt;type name=\"Plumrocket\\Datagenerator\\Model\\Feed\\Resolver\\FieldComposite\">\n        &lt;arguments>\n            &lt;argument name=\"fieldResolvers\" xsi:type=\"array\">\n                &lt;item name=\"delivery_time\" xsi:type=\"object\">Vendor\\Module\\Model\\DeliveryTimeResolver&lt;\/item>\n            &lt;\/argument>\n        &lt;\/arguments>\n    &lt;\/type>\n&lt;\/config><\/code><\/pre><\/div>\n\n\n\n<p>The Delivery Time field is now added to the product.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/plumrocket.com\/docs\/magento-data-feed\/v2\/devguide\/custom-product-fields\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Add Custom Fields to a Product Feed in Magento 2&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[287],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v17.2 (Yoast SEO v17.2) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Add Custom Fields to a Product Feed in Magento 2 - Plumrocket Documentation<\/title>\n<meta name=\"description\" content=\"Although Magento 2 Data Feed Generator supports all product attributes, sometimes you may need to change the display of a particular attribute or add\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/plumrocket.com\/docs\/magento-data-feed\/v2\/devguide\/custom-product-fields\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Add Custom Fields to a Product Feed in Magento 2\" \/>\n<meta property=\"og:description\" content=\"Although Magento 2 Data Feed Generator supports all product attributes, sometimes you may need to change the display of a particular attribute or add\" \/>\n<meta property=\"og:url\" content=\"https:\/\/plumrocket.com\/docs\/magento-data-feed\/v2\/devguide\/custom-product-fields\" \/>\n<meta property=\"og:site_name\" content=\"Plumrocket Documentation\" \/>\n<meta property=\"article:published_time\" content=\"2021-12-02T10:46:05+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-02T10:46:07+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Admin Docs\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Add Custom Fields to a Product Feed in Magento 2 - Plumrocket Documentation","description":"Although Magento 2 Data Feed Generator supports all product attributes, sometimes you may need to change the display of a particular attribute or add","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/plumrocket.com\/docs\/magento-data-feed\/v2\/devguide\/custom-product-fields","og_locale":"en_US","og_type":"article","og_title":"How to Add Custom Fields to a Product Feed in Magento 2","og_description":"Although Magento 2 Data Feed Generator supports all product attributes, sometimes you may need to change the display of a particular attribute or add","og_url":"https:\/\/plumrocket.com\/docs\/magento-data-feed\/v2\/devguide\/custom-product-fields","og_site_name":"Plumrocket Documentation","article_published_time":"2021-12-02T10:46:05+00:00","article_modified_time":"2021-12-02T10:46:07+00:00","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Admin Docs","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/plumrocket.com\/docs\/#website","url":"https:\/\/plumrocket.com\/docs\/","name":"Plumrocket Documentation","description":"Extensions docs, troubleshootings etc.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/plumrocket.com\/docs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/plumrocket.com\/docs\/magento-data-feed\/v2\/devguide\/custom-product-fields#webpage","url":"https:\/\/plumrocket.com\/docs\/magento-data-feed\/v2\/devguide\/custom-product-fields","name":"How to Add Custom Fields to a Product Feed in Magento 2 - Plumrocket Documentation","isPartOf":{"@id":"https:\/\/plumrocket.com\/docs\/#website"},"datePublished":"2021-12-02T10:46:05+00:00","dateModified":"2021-12-02T10:46:07+00:00","author":{"@id":"https:\/\/plumrocket.com\/docs\/#\/schema\/person\/015cbe7d3eb39051359cab3a634456a2"},"description":"Although Magento 2 Data Feed Generator supports all product attributes, sometimes you may need to change the display of a particular attribute or add","breadcrumb":{"@id":"https:\/\/plumrocket.com\/docs\/magento-data-feed\/v2\/devguide\/custom-product-fields#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/plumrocket.com\/docs\/magento-data-feed\/v2\/devguide\/custom-product-fields"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/plumrocket.com\/docs\/magento-data-feed\/v2\/devguide\/custom-product-fields#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Magento 2 Extensions","item":"https:\/\/plumrocket.com\/magento-extensions"},{"@type":"ListItem","position":2,"name":"Magento 2 Data Feed Generator","item":"https:\/\/plumrocket.com\/magento-data-feed"},{"@type":"ListItem","position":3,"name":"Documentation","item":"https:\/\/plumrocket.com\/docs\/magento-data-feed"},{"@type":"ListItem","position":4,"name":"v2","item":"https:\/\/plumrocket.com\/docs\/magento-data-feed\/v2"},{"@type":"ListItem","position":5,"name":"Developer Guide","item":"https:\/\/plumrocket.com\/docs\/magento-data-feed\/v2\/devguide"},{"@type":"ListItem","position":6,"name":"How to Add Custom Fields to a Product Feed in Magento 2"}]},{"@type":"Person","@id":"https:\/\/plumrocket.com\/docs\/#\/schema\/person\/015cbe7d3eb39051359cab3a634456a2","name":"Admin Docs","image":{"@type":"ImageObject","@id":"https:\/\/plumrocket.com\/docs\/#personlogo","inLanguage":"en-US","url":"https:\/\/secure.gravatar.com\/avatar\/51791b4b0fb12be6e5bced98930993ed?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/51791b4b0fb12be6e5bced98930993ed?s=96&d=mm&r=g","caption":"Admin Docs"}}]}},"_links":{"self":[{"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/posts\/25132"}],"collection":[{"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/comments?post=25132"}],"version-history":[{"count":10,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/posts\/25132\/revisions"}],"predecessor-version":[{"id":25151,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/posts\/25132\/revisions\/25151"}],"wp:attachment":[{"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/media?parent=25132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/categories?post=25132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/tags?post=25132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}