{"id":313287,"date":"2021-11-26T13:48:38","date_gmt":"2021-11-26T13:48:38","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=313287"},"modified":"2021-11-26T13:49:21","modified_gmt":"2021-11-26T13:49:21","slug":"add-product-variation-in-shopware6","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/add-product-variation-in-shopware6\/","title":{"rendered":"How to add product variation in Shopware6"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p>In this blog, we will discuss how to add a product variation in Shopware6 at the coding end after creating a product. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Coding Overview<\/h2>\n\n\n\n<p>I hope you are aware of product variation in Shopware6.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Sending Product Variation Request<\/h2>\n\n\n\n<p>We need to get a request to have a property option value id with a combination of other option value id. Like we select a Color property value as Blue and another Size property value 30. Then we combine both different property value id in a single array and we can select and create many combinations of property values like this, and pass the parent product id in the request also and other values we can pass which you want to not inherit with parent product. If you choose two options values from every two properties then your combination of variation will be four like matrix calculation.<br>please see the screenshot for better understanding <a href=\"https:\/\/prnt.sc\/20xb5f4\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/prnt.sc\/20xb5f4<\/a> and <a href=\"https:\/\/prnt.sc\/20xb6zi\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/prnt.sc\/20xb6zi<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Handling Variation Request<\/h2>\n\n\n\n<p>we need to get product variation data in our controller. Now we get the HTTP request from the client-side and send it to the server-side. We arrange the option value array with persisting data manner. We loop the over incoming data request. please see the below code.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">foreach ($variantCollection as $variant) {\n            \n            $id = Uuid::randomHex();\n            $variantIds&#091;] = $id;\n\n            $variant&#091;&#039;id&#039;] = $id;\n            $variant&#091;&#039;active&#039;] = true;\n\n            $options = $variant&#091;&#039;options&#039;];\n            $variant&#091;&#039;options&#039;] = &#091;];\n\n            foreach($options as $option) {\n                array_push($variant&#091;&#039;options&#039;], &#091;\n                    &#039;id&#039; =&gt; $option\n                ]);\n            }\n            $productRepository-&gt;create(&#091;$variant], $context);\n        }<\/pre>\n\n\n\n<p>then make an entry for the product_configurator_setting entity, please follow the below code.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">foreach ($options as $option) {\n $productConfiguratorRepository = $this-&gt;container-&gt;get(&#039;product_configurator_setting.repository&#039;);\n $optionData = array(\n               &#039;productId&#039; =&gt; $data&#091;&#039;product_id&#039;],\n               &#039;optionId&#039; =&gt; $option,\n               );\n         try{\n              $productConfiguratorRepository-&gt;create(&#091;$optionData], $context);\n            } catch(Exception $ex){\n                $ex-&gt;getMessage();\n            }\n   }<\/pre>\n\n\n\n<p><a href=\"https:\/\/webkul.com\/blog\/shopware-multi-seller-marketplace\/\" target=\"_blank\" rel=\"noreferrer noopener\">Multi-Seller Marketplace Plugin<\/a><\/p>\n\n\n\n<p>Now we have done. I hope it will help you. Happy coding \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In this blog, we will discuss how to add a product variation in Shopware6 at the coding end after creating a product. Coding Overview I hope you are aware of product variation in Shopware6. Sending Product Variation Request We need to get a request to have a property option value id with a combination <a href=\"https:\/\/webkul.com\/blog\/add-product-variation-in-shopware6\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":325,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-313287","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Add product variation in Shopware6<\/title>\n<meta name=\"description\" content=\"Add product variation in Shopware6 | Adding custom product variation for the product in shopware6| How to add product variation in shopware6\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/add-product-variation-in-shopware6\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Add product variation in Shopware6\" \/>\n<meta property=\"og:description\" content=\"Add product variation in Shopware6 | Adding custom product variation for the product in shopware6| How to add product variation in shopware6\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/add-product-variation-in-shopware6\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-11-26T13:48:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-11-26T13:49:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Prince Gupta\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prince Gupta\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/add-product-variation-in-shopware6\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-product-variation-in-shopware6\/\"},\"author\":{\"name\":\"Prince Gupta\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/669b7c5067f73a7ae2204ff4aca829fd\"},\"headline\":\"How to add product variation in Shopware6\",\"datePublished\":\"2021-11-26T13:48:38+00:00\",\"dateModified\":\"2021-11-26T13:49:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-product-variation-in-shopware6\/\"},\"wordCount\":250,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/add-product-variation-in-shopware6\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/add-product-variation-in-shopware6\/\",\"url\":\"https:\/\/webkul.com\/blog\/add-product-variation-in-shopware6\/\",\"name\":\"Add product variation in Shopware6\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2021-11-26T13:48:38+00:00\",\"dateModified\":\"2021-11-26T13:49:21+00:00\",\"description\":\"Add product variation in Shopware6 | Adding custom product variation for the product in shopware6| How to add product variation in shopware6\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-product-variation-in-shopware6\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/add-product-variation-in-shopware6\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/add-product-variation-in-shopware6\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to add product variation in Shopware6\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/669b7c5067f73a7ae2204ff4aca829fd\",\"name\":\"Prince Gupta\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/dd55a986709c72a714a8135a38f3b2cba1009ea371caec823a8547b2e01df18d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/dd55a986709c72a714a8135a38f3b2cba1009ea371caec823a8547b2e01df18d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Prince Gupta\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/princegupta-wp031\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Add product variation in Shopware6","description":"Add product variation in Shopware6 | Adding custom product variation for the product in shopware6| How to add product variation in shopware6","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:\/\/webkul.com\/blog\/add-product-variation-in-shopware6\/","og_locale":"en_US","og_type":"article","og_title":"Add product variation in Shopware6","og_description":"Add product variation in Shopware6 | Adding custom product variation for the product in shopware6| How to add product variation in shopware6","og_url":"https:\/\/webkul.com\/blog\/add-product-variation-in-shopware6\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2021-11-26T13:48:38+00:00","article_modified_time":"2021-11-26T13:49:21+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png","type":"image\/png"}],"author":"Prince Gupta","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Prince Gupta","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/add-product-variation-in-shopware6\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/add-product-variation-in-shopware6\/"},"author":{"name":"Prince Gupta","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/669b7c5067f73a7ae2204ff4aca829fd"},"headline":"How to add product variation in Shopware6","datePublished":"2021-11-26T13:48:38+00:00","dateModified":"2021-11-26T13:49:21+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/add-product-variation-in-shopware6\/"},"wordCount":250,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/add-product-variation-in-shopware6\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/add-product-variation-in-shopware6\/","url":"https:\/\/webkul.com\/blog\/add-product-variation-in-shopware6\/","name":"Add product variation in Shopware6","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2021-11-26T13:48:38+00:00","dateModified":"2021-11-26T13:49:21+00:00","description":"Add product variation in Shopware6 | Adding custom product variation for the product in shopware6| How to add product variation in shopware6","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/add-product-variation-in-shopware6\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/add-product-variation-in-shopware6\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/add-product-variation-in-shopware6\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to add product variation in Shopware6"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/669b7c5067f73a7ae2204ff4aca829fd","name":"Prince Gupta","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/dd55a986709c72a714a8135a38f3b2cba1009ea371caec823a8547b2e01df18d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/dd55a986709c72a714a8135a38f3b2cba1009ea371caec823a8547b2e01df18d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Prince Gupta"},"url":"https:\/\/webkul.com\/blog\/author\/princegupta-wp031\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/313287","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/325"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=313287"}],"version-history":[{"count":2,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/313287\/revisions"}],"predecessor-version":[{"id":313325,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/313287\/revisions\/313325"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=313287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=313287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=313287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}