Redirect from simple product to parent productHow to reroute simple products to associated configurable...

Is going from continuous data to categorical always wrong?

A curious inequality concerning binomial coefficients

Touchscreen-controlled dentist office snowman collector game

Do I need to leave some extra space available on the disk which my database log files reside, for log backup operations to successfully occur?

Am I not good enough for you?

Life insurance that covers only simultaneous/dual deaths

Is this animal really missing?

Want to switch to tankless, but can I use my existing wiring?

What is the definition of "Natural Selection"?

Good allowance savings plan?

Silly Sally's Movie

Why doesn't the EU now just force the UK to choose between referendum and no-deal?

Rejected in 4th interview round citing insufficient years of experience

The three point beverage

Is "history" a male-biased word ("his+story")?

Potentiometer like component

How does Dispel Magic work against Stoneskin?

Format picture and text with TikZ and minipage

Can you reject a postdoc offer after the PI has paid a large sum for flights/accommodation for your visit?

"One can do his homework in the library"

When were linguistics departments first established

What Happens when Passenger Refuses to Fly Boeing 737 Max?

Giving Plot options defined outside of the Plot expression

It's a yearly task, alright



Redirect from simple product to parent product


How to reroute simple products to associated configurable products - Magento 2.2.5How to add simple product to grouped product as Associated products?Rearrange simple associated products in configurable product optionsProduct grid homepage display category linkGet associated products Price and Size from configurable productCustom page for category parentload configurable product with preselected options of any one of simple productMagento 1: Find products who have a certain associated productProducts not showing in parent categoriesMagento: Delete products and 301 redirect to relevant it's parent categoryMagnto2 Display specific simple products of configurable product in category pages













0
















I want to display all the associated simple products on the category-
pages and link them to the their parent product.




How this can be achieved?



One simple product is associated with only one parent.










share|improve this question
















bumped to the homepage by Community 12 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.




















    0
















    I want to display all the associated simple products on the category-
    pages and link them to the their parent product.




    How this can be achieved?



    One simple product is associated with only one parent.










    share|improve this question
















    bumped to the homepage by Community 12 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      0












      0








      0









      I want to display all the associated simple products on the category-
      pages and link them to the their parent product.




      How this can be achieved?



      One simple product is associated with only one parent.










      share|improve this question

















      I want to display all the associated simple products on the category-
      pages and link them to the their parent product.




      How this can be achieved?



      One simple product is associated with only one parent.







      magento-2.1 product product-association






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 10 at 10:09









      Jai

      3,54382962




      3,54382962










      asked Feb 1 '17 at 9:50









      Anshu MishraAnshu Mishra

      5,46152660




      5,46152660





      bumped to the homepage by Community 12 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 12 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Here I use configurable product as an example. You can pluginize Product View controller.



          Try following way:



          SR/StackExchange/etc/frontend/di.xml




          <?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="MagentoCatalogControllerProductView">
          <plugin name="sr_product_controller_view" type="SRStackExchangePluginCatalogControllerProductView" sortOrder="1"/>
          </type>
          </config>


          If you redirect to Parent Product use following code:



          SR/StackExchange/Plugin/Catalog/Controller/Product/View.php




          namespace SRStackExchangePluginCatalogControllerProduct;

          class View
          {
          /**
          * @var MagentoFrameworkAppResponseHttp
          */
          protected $http;

          /**
          * @var MagentoCatalogHelperProduct
          */
          protected $productHelper;

          /**
          * @var MagentoConfigurableProductModelProductTypeConfigurable
          */
          protected $configurable;

          /**
          * @param MagentoFrameworkAppResponseHttp $http
          * @param MagentoCatalogHelperProduct $productHelper
          * @param MagentoConfigurableProductModelProductTypeConfigurable $configurable
          */
          public function __construct(
          MagentoFrameworkAppResponseHttp $http,
          MagentoCatalogHelperProduct $productHelper,
          MagentoConfigurableProductModelProductTypeConfigurable $configurable
          ) {
          $this->http = $http;
          $this->productHelper =$productHelper;
          $this->configurable = $configurable;
          }

          /**
          * Product view action
          *
          * @return MagentoFrameworkControllerResultForward|MagentoFrameworkControllerResultRedirect
          */
          public function aroundExecute(
          MagentoCatalogControllerProductView $subject,
          Closure $proceed
          )
          {
          $productId = (int) $subject->getRequest()->getParam('id');
          $parentIds = $this->configurable->getParentIdsByChild($productId);
          $parentId = array_shift($parentIds);

          if($parentId) {
          $categoryId = (int)$subject->getRequest()->getParam('category', false);
          $productId = (int)$parentId;

          $params = new MagentoFrameworkDataObject();
          $params->setCategoryId($categoryId);

          /** @var MagentoCatalogHelperProduct $product */
          $product = $this->productHelper->initProduct($productId, $subject, $params);;
          $this->http->setRedirect($product->getProductUrl(), 301);
          }
          return $proceed();
          }
          }


          [Update]



          Instead of redirecting, can I just show the parent product url.



          SR/StackExchange/Plugin/Catalog/Controller/Product/View.php




          namespace SRStackExchangePluginCatalogControllerProduct;

          class View
          {
          /**
          * @var MagentoConfigurableProductModelProductTypeConfigurable
          */
          protected $configurable;

          /**
          * @param MagentoConfigurableProductModelProductTypeConfigurable $configurable
          */
          public function __construct(
          MagentoConfigurableProductModelProductTypeConfigurable $configurable
          ) {
          $this->configurable = $configurable;
          }

          /**
          * Product view action
          *
          * @return MagentoFrameworkControllerResultForward|MagentoFrameworkControllerResultRedirect
          */
          public function aroundExecute(
          MagentoCatalogControllerProductView $subject,
          Closure $proceed
          )
          {
          $productId = (int) $subject->getRequest()->getParam('id');
          $parentIds = $this->configurable->getParentIdsByChild($productId);
          $parentId = array_shift($parentIds);

          if($parentId) {
          $subject->getRequest()->setParam('id', $parentId);
          }

          return $proceed();
          }
          }


          Overwrite following template



          Magento_Swatches::product/view/renderer.phtml
          Magento_ConfigurableProduct::product/view/type/options/configurable.phtml



          Add following code




          <script>
          history.pushState({}, '', '<?php echo $block->getProduct()->getProductUrl();?>');
          </script>





          share|improve this answer


























          • The code is showing parent product page but url is of the child product, I want the redirect i.e url should be of parent product only.

            – Anshu Mishra
            Feb 2 '17 at 6:00











          • Check updated answer.

            – Sohel Rana
            Feb 2 '17 at 6:18











          • Instead of redirecting, can I just show the parent product url on the child product on product list page.

            – Anshu Mishra
            Feb 2 '17 at 7:53











          • @AnshuMishra if you assign parent product url in product list page, then system will be slow. Check updated answer, may be it will help you.

            – Sohel Rana
            Feb 3 '17 at 7:53











          • Can you explain how to overwrite the templates and where to add the script in more detail?

            – Will Cousin
            Aug 11 '18 at 11:51











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "479"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f157429%2fredirect-from-simple-product-to-parent-product%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Here I use configurable product as an example. You can pluginize Product View controller.



          Try following way:



          SR/StackExchange/etc/frontend/di.xml




          <?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="MagentoCatalogControllerProductView">
          <plugin name="sr_product_controller_view" type="SRStackExchangePluginCatalogControllerProductView" sortOrder="1"/>
          </type>
          </config>


          If you redirect to Parent Product use following code:



          SR/StackExchange/Plugin/Catalog/Controller/Product/View.php




          namespace SRStackExchangePluginCatalogControllerProduct;

          class View
          {
          /**
          * @var MagentoFrameworkAppResponseHttp
          */
          protected $http;

          /**
          * @var MagentoCatalogHelperProduct
          */
          protected $productHelper;

          /**
          * @var MagentoConfigurableProductModelProductTypeConfigurable
          */
          protected $configurable;

          /**
          * @param MagentoFrameworkAppResponseHttp $http
          * @param MagentoCatalogHelperProduct $productHelper
          * @param MagentoConfigurableProductModelProductTypeConfigurable $configurable
          */
          public function __construct(
          MagentoFrameworkAppResponseHttp $http,
          MagentoCatalogHelperProduct $productHelper,
          MagentoConfigurableProductModelProductTypeConfigurable $configurable
          ) {
          $this->http = $http;
          $this->productHelper =$productHelper;
          $this->configurable = $configurable;
          }

          /**
          * Product view action
          *
          * @return MagentoFrameworkControllerResultForward|MagentoFrameworkControllerResultRedirect
          */
          public function aroundExecute(
          MagentoCatalogControllerProductView $subject,
          Closure $proceed
          )
          {
          $productId = (int) $subject->getRequest()->getParam('id');
          $parentIds = $this->configurable->getParentIdsByChild($productId);
          $parentId = array_shift($parentIds);

          if($parentId) {
          $categoryId = (int)$subject->getRequest()->getParam('category', false);
          $productId = (int)$parentId;

          $params = new MagentoFrameworkDataObject();
          $params->setCategoryId($categoryId);

          /** @var MagentoCatalogHelperProduct $product */
          $product = $this->productHelper->initProduct($productId, $subject, $params);;
          $this->http->setRedirect($product->getProductUrl(), 301);
          }
          return $proceed();
          }
          }


          [Update]



          Instead of redirecting, can I just show the parent product url.



          SR/StackExchange/Plugin/Catalog/Controller/Product/View.php




          namespace SRStackExchangePluginCatalogControllerProduct;

          class View
          {
          /**
          * @var MagentoConfigurableProductModelProductTypeConfigurable
          */
          protected $configurable;

          /**
          * @param MagentoConfigurableProductModelProductTypeConfigurable $configurable
          */
          public function __construct(
          MagentoConfigurableProductModelProductTypeConfigurable $configurable
          ) {
          $this->configurable = $configurable;
          }

          /**
          * Product view action
          *
          * @return MagentoFrameworkControllerResultForward|MagentoFrameworkControllerResultRedirect
          */
          public function aroundExecute(
          MagentoCatalogControllerProductView $subject,
          Closure $proceed
          )
          {
          $productId = (int) $subject->getRequest()->getParam('id');
          $parentIds = $this->configurable->getParentIdsByChild($productId);
          $parentId = array_shift($parentIds);

          if($parentId) {
          $subject->getRequest()->setParam('id', $parentId);
          }

          return $proceed();
          }
          }


          Overwrite following template



          Magento_Swatches::product/view/renderer.phtml
          Magento_ConfigurableProduct::product/view/type/options/configurable.phtml



          Add following code




          <script>
          history.pushState({}, '', '<?php echo $block->getProduct()->getProductUrl();?>');
          </script>





          share|improve this answer


























          • The code is showing parent product page but url is of the child product, I want the redirect i.e url should be of parent product only.

            – Anshu Mishra
            Feb 2 '17 at 6:00











          • Check updated answer.

            – Sohel Rana
            Feb 2 '17 at 6:18











          • Instead of redirecting, can I just show the parent product url on the child product on product list page.

            – Anshu Mishra
            Feb 2 '17 at 7:53











          • @AnshuMishra if you assign parent product url in product list page, then system will be slow. Check updated answer, may be it will help you.

            – Sohel Rana
            Feb 3 '17 at 7:53











          • Can you explain how to overwrite the templates and where to add the script in more detail?

            – Will Cousin
            Aug 11 '18 at 11:51
















          0














          Here I use configurable product as an example. You can pluginize Product View controller.



          Try following way:



          SR/StackExchange/etc/frontend/di.xml




          <?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="MagentoCatalogControllerProductView">
          <plugin name="sr_product_controller_view" type="SRStackExchangePluginCatalogControllerProductView" sortOrder="1"/>
          </type>
          </config>


          If you redirect to Parent Product use following code:



          SR/StackExchange/Plugin/Catalog/Controller/Product/View.php




          namespace SRStackExchangePluginCatalogControllerProduct;

          class View
          {
          /**
          * @var MagentoFrameworkAppResponseHttp
          */
          protected $http;

          /**
          * @var MagentoCatalogHelperProduct
          */
          protected $productHelper;

          /**
          * @var MagentoConfigurableProductModelProductTypeConfigurable
          */
          protected $configurable;

          /**
          * @param MagentoFrameworkAppResponseHttp $http
          * @param MagentoCatalogHelperProduct $productHelper
          * @param MagentoConfigurableProductModelProductTypeConfigurable $configurable
          */
          public function __construct(
          MagentoFrameworkAppResponseHttp $http,
          MagentoCatalogHelperProduct $productHelper,
          MagentoConfigurableProductModelProductTypeConfigurable $configurable
          ) {
          $this->http = $http;
          $this->productHelper =$productHelper;
          $this->configurable = $configurable;
          }

          /**
          * Product view action
          *
          * @return MagentoFrameworkControllerResultForward|MagentoFrameworkControllerResultRedirect
          */
          public function aroundExecute(
          MagentoCatalogControllerProductView $subject,
          Closure $proceed
          )
          {
          $productId = (int) $subject->getRequest()->getParam('id');
          $parentIds = $this->configurable->getParentIdsByChild($productId);
          $parentId = array_shift($parentIds);

          if($parentId) {
          $categoryId = (int)$subject->getRequest()->getParam('category', false);
          $productId = (int)$parentId;

          $params = new MagentoFrameworkDataObject();
          $params->setCategoryId($categoryId);

          /** @var MagentoCatalogHelperProduct $product */
          $product = $this->productHelper->initProduct($productId, $subject, $params);;
          $this->http->setRedirect($product->getProductUrl(), 301);
          }
          return $proceed();
          }
          }


          [Update]



          Instead of redirecting, can I just show the parent product url.



          SR/StackExchange/Plugin/Catalog/Controller/Product/View.php




          namespace SRStackExchangePluginCatalogControllerProduct;

          class View
          {
          /**
          * @var MagentoConfigurableProductModelProductTypeConfigurable
          */
          protected $configurable;

          /**
          * @param MagentoConfigurableProductModelProductTypeConfigurable $configurable
          */
          public function __construct(
          MagentoConfigurableProductModelProductTypeConfigurable $configurable
          ) {
          $this->configurable = $configurable;
          }

          /**
          * Product view action
          *
          * @return MagentoFrameworkControllerResultForward|MagentoFrameworkControllerResultRedirect
          */
          public function aroundExecute(
          MagentoCatalogControllerProductView $subject,
          Closure $proceed
          )
          {
          $productId = (int) $subject->getRequest()->getParam('id');
          $parentIds = $this->configurable->getParentIdsByChild($productId);
          $parentId = array_shift($parentIds);

          if($parentId) {
          $subject->getRequest()->setParam('id', $parentId);
          }

          return $proceed();
          }
          }


          Overwrite following template



          Magento_Swatches::product/view/renderer.phtml
          Magento_ConfigurableProduct::product/view/type/options/configurable.phtml



          Add following code




          <script>
          history.pushState({}, '', '<?php echo $block->getProduct()->getProductUrl();?>');
          </script>





          share|improve this answer


























          • The code is showing parent product page but url is of the child product, I want the redirect i.e url should be of parent product only.

            – Anshu Mishra
            Feb 2 '17 at 6:00











          • Check updated answer.

            – Sohel Rana
            Feb 2 '17 at 6:18











          • Instead of redirecting, can I just show the parent product url on the child product on product list page.

            – Anshu Mishra
            Feb 2 '17 at 7:53











          • @AnshuMishra if you assign parent product url in product list page, then system will be slow. Check updated answer, may be it will help you.

            – Sohel Rana
            Feb 3 '17 at 7:53











          • Can you explain how to overwrite the templates and where to add the script in more detail?

            – Will Cousin
            Aug 11 '18 at 11:51














          0












          0








          0







          Here I use configurable product as an example. You can pluginize Product View controller.



          Try following way:



          SR/StackExchange/etc/frontend/di.xml




          <?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="MagentoCatalogControllerProductView">
          <plugin name="sr_product_controller_view" type="SRStackExchangePluginCatalogControllerProductView" sortOrder="1"/>
          </type>
          </config>


          If you redirect to Parent Product use following code:



          SR/StackExchange/Plugin/Catalog/Controller/Product/View.php




          namespace SRStackExchangePluginCatalogControllerProduct;

          class View
          {
          /**
          * @var MagentoFrameworkAppResponseHttp
          */
          protected $http;

          /**
          * @var MagentoCatalogHelperProduct
          */
          protected $productHelper;

          /**
          * @var MagentoConfigurableProductModelProductTypeConfigurable
          */
          protected $configurable;

          /**
          * @param MagentoFrameworkAppResponseHttp $http
          * @param MagentoCatalogHelperProduct $productHelper
          * @param MagentoConfigurableProductModelProductTypeConfigurable $configurable
          */
          public function __construct(
          MagentoFrameworkAppResponseHttp $http,
          MagentoCatalogHelperProduct $productHelper,
          MagentoConfigurableProductModelProductTypeConfigurable $configurable
          ) {
          $this->http = $http;
          $this->productHelper =$productHelper;
          $this->configurable = $configurable;
          }

          /**
          * Product view action
          *
          * @return MagentoFrameworkControllerResultForward|MagentoFrameworkControllerResultRedirect
          */
          public function aroundExecute(
          MagentoCatalogControllerProductView $subject,
          Closure $proceed
          )
          {
          $productId = (int) $subject->getRequest()->getParam('id');
          $parentIds = $this->configurable->getParentIdsByChild($productId);
          $parentId = array_shift($parentIds);

          if($parentId) {
          $categoryId = (int)$subject->getRequest()->getParam('category', false);
          $productId = (int)$parentId;

          $params = new MagentoFrameworkDataObject();
          $params->setCategoryId($categoryId);

          /** @var MagentoCatalogHelperProduct $product */
          $product = $this->productHelper->initProduct($productId, $subject, $params);;
          $this->http->setRedirect($product->getProductUrl(), 301);
          }
          return $proceed();
          }
          }


          [Update]



          Instead of redirecting, can I just show the parent product url.



          SR/StackExchange/Plugin/Catalog/Controller/Product/View.php




          namespace SRStackExchangePluginCatalogControllerProduct;

          class View
          {
          /**
          * @var MagentoConfigurableProductModelProductTypeConfigurable
          */
          protected $configurable;

          /**
          * @param MagentoConfigurableProductModelProductTypeConfigurable $configurable
          */
          public function __construct(
          MagentoConfigurableProductModelProductTypeConfigurable $configurable
          ) {
          $this->configurable = $configurable;
          }

          /**
          * Product view action
          *
          * @return MagentoFrameworkControllerResultForward|MagentoFrameworkControllerResultRedirect
          */
          public function aroundExecute(
          MagentoCatalogControllerProductView $subject,
          Closure $proceed
          )
          {
          $productId = (int) $subject->getRequest()->getParam('id');
          $parentIds = $this->configurable->getParentIdsByChild($productId);
          $parentId = array_shift($parentIds);

          if($parentId) {
          $subject->getRequest()->setParam('id', $parentId);
          }

          return $proceed();
          }
          }


          Overwrite following template



          Magento_Swatches::product/view/renderer.phtml
          Magento_ConfigurableProduct::product/view/type/options/configurable.phtml



          Add following code




          <script>
          history.pushState({}, '', '<?php echo $block->getProduct()->getProductUrl();?>');
          </script>





          share|improve this answer















          Here I use configurable product as an example. You can pluginize Product View controller.



          Try following way:



          SR/StackExchange/etc/frontend/di.xml




          <?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="MagentoCatalogControllerProductView">
          <plugin name="sr_product_controller_view" type="SRStackExchangePluginCatalogControllerProductView" sortOrder="1"/>
          </type>
          </config>


          If you redirect to Parent Product use following code:



          SR/StackExchange/Plugin/Catalog/Controller/Product/View.php




          namespace SRStackExchangePluginCatalogControllerProduct;

          class View
          {
          /**
          * @var MagentoFrameworkAppResponseHttp
          */
          protected $http;

          /**
          * @var MagentoCatalogHelperProduct
          */
          protected $productHelper;

          /**
          * @var MagentoConfigurableProductModelProductTypeConfigurable
          */
          protected $configurable;

          /**
          * @param MagentoFrameworkAppResponseHttp $http
          * @param MagentoCatalogHelperProduct $productHelper
          * @param MagentoConfigurableProductModelProductTypeConfigurable $configurable
          */
          public function __construct(
          MagentoFrameworkAppResponseHttp $http,
          MagentoCatalogHelperProduct $productHelper,
          MagentoConfigurableProductModelProductTypeConfigurable $configurable
          ) {
          $this->http = $http;
          $this->productHelper =$productHelper;
          $this->configurable = $configurable;
          }

          /**
          * Product view action
          *
          * @return MagentoFrameworkControllerResultForward|MagentoFrameworkControllerResultRedirect
          */
          public function aroundExecute(
          MagentoCatalogControllerProductView $subject,
          Closure $proceed
          )
          {
          $productId = (int) $subject->getRequest()->getParam('id');
          $parentIds = $this->configurable->getParentIdsByChild($productId);
          $parentId = array_shift($parentIds);

          if($parentId) {
          $categoryId = (int)$subject->getRequest()->getParam('category', false);
          $productId = (int)$parentId;

          $params = new MagentoFrameworkDataObject();
          $params->setCategoryId($categoryId);

          /** @var MagentoCatalogHelperProduct $product */
          $product = $this->productHelper->initProduct($productId, $subject, $params);;
          $this->http->setRedirect($product->getProductUrl(), 301);
          }
          return $proceed();
          }
          }


          [Update]



          Instead of redirecting, can I just show the parent product url.



          SR/StackExchange/Plugin/Catalog/Controller/Product/View.php




          namespace SRStackExchangePluginCatalogControllerProduct;

          class View
          {
          /**
          * @var MagentoConfigurableProductModelProductTypeConfigurable
          */
          protected $configurable;

          /**
          * @param MagentoConfigurableProductModelProductTypeConfigurable $configurable
          */
          public function __construct(
          MagentoConfigurableProductModelProductTypeConfigurable $configurable
          ) {
          $this->configurable = $configurable;
          }

          /**
          * Product view action
          *
          * @return MagentoFrameworkControllerResultForward|MagentoFrameworkControllerResultRedirect
          */
          public function aroundExecute(
          MagentoCatalogControllerProductView $subject,
          Closure $proceed
          )
          {
          $productId = (int) $subject->getRequest()->getParam('id');
          $parentIds = $this->configurable->getParentIdsByChild($productId);
          $parentId = array_shift($parentIds);

          if($parentId) {
          $subject->getRequest()->setParam('id', $parentId);
          }

          return $proceed();
          }
          }


          Overwrite following template



          Magento_Swatches::product/view/renderer.phtml
          Magento_ConfigurableProduct::product/view/type/options/configurable.phtml



          Add following code




          <script>
          history.pushState({}, '', '<?php echo $block->getProduct()->getProductUrl();?>');
          </script>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 3 '17 at 7:52

























          answered Feb 1 '17 at 10:48









          Sohel RanaSohel Rana

          22.6k34460




          22.6k34460













          • The code is showing parent product page but url is of the child product, I want the redirect i.e url should be of parent product only.

            – Anshu Mishra
            Feb 2 '17 at 6:00











          • Check updated answer.

            – Sohel Rana
            Feb 2 '17 at 6:18











          • Instead of redirecting, can I just show the parent product url on the child product on product list page.

            – Anshu Mishra
            Feb 2 '17 at 7:53











          • @AnshuMishra if you assign parent product url in product list page, then system will be slow. Check updated answer, may be it will help you.

            – Sohel Rana
            Feb 3 '17 at 7:53











          • Can you explain how to overwrite the templates and where to add the script in more detail?

            – Will Cousin
            Aug 11 '18 at 11:51



















          • The code is showing parent product page but url is of the child product, I want the redirect i.e url should be of parent product only.

            – Anshu Mishra
            Feb 2 '17 at 6:00











          • Check updated answer.

            – Sohel Rana
            Feb 2 '17 at 6:18











          • Instead of redirecting, can I just show the parent product url on the child product on product list page.

            – Anshu Mishra
            Feb 2 '17 at 7:53











          • @AnshuMishra if you assign parent product url in product list page, then system will be slow. Check updated answer, may be it will help you.

            – Sohel Rana
            Feb 3 '17 at 7:53











          • Can you explain how to overwrite the templates and where to add the script in more detail?

            – Will Cousin
            Aug 11 '18 at 11:51

















          The code is showing parent product page but url is of the child product, I want the redirect i.e url should be of parent product only.

          – Anshu Mishra
          Feb 2 '17 at 6:00





          The code is showing parent product page but url is of the child product, I want the redirect i.e url should be of parent product only.

          – Anshu Mishra
          Feb 2 '17 at 6:00













          Check updated answer.

          – Sohel Rana
          Feb 2 '17 at 6:18





          Check updated answer.

          – Sohel Rana
          Feb 2 '17 at 6:18













          Instead of redirecting, can I just show the parent product url on the child product on product list page.

          – Anshu Mishra
          Feb 2 '17 at 7:53





          Instead of redirecting, can I just show the parent product url on the child product on product list page.

          – Anshu Mishra
          Feb 2 '17 at 7:53













          @AnshuMishra if you assign parent product url in product list page, then system will be slow. Check updated answer, may be it will help you.

          – Sohel Rana
          Feb 3 '17 at 7:53





          @AnshuMishra if you assign parent product url in product list page, then system will be slow. Check updated answer, may be it will help you.

          – Sohel Rana
          Feb 3 '17 at 7:53













          Can you explain how to overwrite the templates and where to add the script in more detail?

          – Will Cousin
          Aug 11 '18 at 11:51





          Can you explain how to overwrite the templates and where to add the script in more detail?

          – Will Cousin
          Aug 11 '18 at 11:51


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f157429%2fredirect-from-simple-product-to-parent-product%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          迭戈·戈丁...

          A phrase ”follow into" in a context The 2019 Stack Overflow Developer Survey Results Are...

          1960s short story making fun of James Bond-style spy fiction The 2019 Stack Overflow Developer...