Magento 2 get Simple product url from configurableHow to redirect to a product page from a path such as mymagento.com/path?barcode=123Programmatically create a configurable product and assign the simple product to configurable product in Magento2 productConfigurable product returning itself and simple productCan not update configurable products, price of simples suddenly become 0,00Magento2 Get parent image from a simple product (configurable)Magento 2 Get selected simple product id in configurable productHow to create a custom product view page in a custom url in Magento 2Get Regular Price of Configurable Simple ProductCreate configurable product using rest api magento 2.2.6Get current product detail in the product alert module in magento 2

Thread Pool C++ Implementation

Difference between > and >> when used with a named pipe

Should I give professor gift at the beginning of my PhD?

What is the actual quality of machine translations?

Is it a problem if <h4>, <h5> and <h6> are smaller than regular text?

Why is one of Madera Municipal's runways labelled with only "R" on both sides?

Is the term 'open source' a trademark?

This riddle is not to see but to solve

How to return a security deposit to a tenant

Were Alexander the Great and Hephaestion lovers?

Character descriptions

How does an ordinary object become radioactive?

How to tell your grandparent to not come to fetch you with their car?

At what point in time did Dumbledore ask Snape for this favor?

What is wrong with this proof that symmetric matrices commute?

How can this tool find out registered domains from an IP?

How to signal to my players that the following part is supposed to be played on fast forward?

Why did the Herschel Space Telescope need helium coolant?

Inward extrusion is not working

What makes Ada the language of choice for the ISS's safety-critical systems?

How to construct an hbox with negative height?

Confusion around using "des" in sentences

How come the nude protesters were not arrested?

What can I, as a user, do about offensive reviews in App Store?



Magento 2 get Simple product url from configurable


How to redirect to a product page from a path such as mymagento.com/path?barcode=123Programmatically create a configurable product and assign the simple product to configurable product in Magento2 productConfigurable product returning itself and simple productCan not update configurable products, price of simples suddenly become 0,00Magento2 Get parent image from a simple product (configurable)Magento 2 Get selected simple product id in configurable productHow to create a custom product view page in a custom url in Magento 2Get Regular Price of Configurable Simple ProductCreate configurable product using rest api magento 2.2.6Get current product detail in the product alert module in magento 2






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I am extending Magento_ProductAlert module. By default when subscribing to product it saves configurable product id but I have managed to get selected simple product ID. And later I know that I can get my product url by $product->getProductUrl() but in this case it doesn't work for me because simple products are not visible individually, only in configurable products and using that it returns me link to simple product like this - http://mysite/myproduct-123 but is there a way how can I retrieve configurable product url but with attributes that respond to my simple product? I mean like this - http://mysite/myconfigurableproduct#123=12



Thank you!



When sending email to user that he has subscribed to product I am using this -



<?php if ($_products = $block->getProducts()): ?>
<?php foreach ($_products as $_product): ?>
<p><?= __('Hello!') ?></p>
<p>
<?= __(
'You have subscribed for product: <strong class="product name"><a href="%1">%2</a></strong>',
$_product->getProductUrl(),
$block->escapeHtml($_product->getName())
)
?>
</p>
<p>
<a href="<?= $block->getUserUnsubscribeUrl() ?>">
<?= __('Click here to stop alerts for this product.') ?>
</a>
</p>
<?php endforeach ?>
<?php endif ?>









share|improve this question
























  • Share your code

    – Asad Khan
    May 30 at 8:03











  • @AsadKhan not sure what exactly you wanted to see, but updated with example to email template I am sending to user. It gets productUrl but not exactly how I want to. Currently it retrieves simple product id but I want to retrieve configurable with attributes that when opening it selects my simple product

    – Mee
    May 30 at 8:07


















1















I am extending Magento_ProductAlert module. By default when subscribing to product it saves configurable product id but I have managed to get selected simple product ID. And later I know that I can get my product url by $product->getProductUrl() but in this case it doesn't work for me because simple products are not visible individually, only in configurable products and using that it returns me link to simple product like this - http://mysite/myproduct-123 but is there a way how can I retrieve configurable product url but with attributes that respond to my simple product? I mean like this - http://mysite/myconfigurableproduct#123=12



Thank you!



When sending email to user that he has subscribed to product I am using this -



<?php if ($_products = $block->getProducts()): ?>
<?php foreach ($_products as $_product): ?>
<p><?= __('Hello!') ?></p>
<p>
<?= __(
'You have subscribed for product: <strong class="product name"><a href="%1">%2</a></strong>',
$_product->getProductUrl(),
$block->escapeHtml($_product->getName())
)
?>
</p>
<p>
<a href="<?= $block->getUserUnsubscribeUrl() ?>">
<?= __('Click here to stop alerts for this product.') ?>
</a>
</p>
<?php endforeach ?>
<?php endif ?>









share|improve this question
























  • Share your code

    – Asad Khan
    May 30 at 8:03











  • @AsadKhan not sure what exactly you wanted to see, but updated with example to email template I am sending to user. It gets productUrl but not exactly how I want to. Currently it retrieves simple product id but I want to retrieve configurable with attributes that when opening it selects my simple product

    – Mee
    May 30 at 8:07














1












1








1








I am extending Magento_ProductAlert module. By default when subscribing to product it saves configurable product id but I have managed to get selected simple product ID. And later I know that I can get my product url by $product->getProductUrl() but in this case it doesn't work for me because simple products are not visible individually, only in configurable products and using that it returns me link to simple product like this - http://mysite/myproduct-123 but is there a way how can I retrieve configurable product url but with attributes that respond to my simple product? I mean like this - http://mysite/myconfigurableproduct#123=12



Thank you!



When sending email to user that he has subscribed to product I am using this -



<?php if ($_products = $block->getProducts()): ?>
<?php foreach ($_products as $_product): ?>
<p><?= __('Hello!') ?></p>
<p>
<?= __(
'You have subscribed for product: <strong class="product name"><a href="%1">%2</a></strong>',
$_product->getProductUrl(),
$block->escapeHtml($_product->getName())
)
?>
</p>
<p>
<a href="<?= $block->getUserUnsubscribeUrl() ?>">
<?= __('Click here to stop alerts for this product.') ?>
</a>
</p>
<?php endforeach ?>
<?php endif ?>









share|improve this question
















I am extending Magento_ProductAlert module. By default when subscribing to product it saves configurable product id but I have managed to get selected simple product ID. And later I know that I can get my product url by $product->getProductUrl() but in this case it doesn't work for me because simple products are not visible individually, only in configurable products and using that it returns me link to simple product like this - http://mysite/myproduct-123 but is there a way how can I retrieve configurable product url but with attributes that respond to my simple product? I mean like this - http://mysite/myconfigurableproduct#123=12



Thank you!



When sending email to user that he has subscribed to product I am using this -



<?php if ($_products = $block->getProducts()): ?>
<?php foreach ($_products as $_product): ?>
<p><?= __('Hello!') ?></p>
<p>
<?= __(
'You have subscribed for product: <strong class="product name"><a href="%1">%2</a></strong>',
$_product->getProductUrl(),
$block->escapeHtml($_product->getName())
)
?>
</p>
<p>
<a href="<?= $block->getUserUnsubscribeUrl() ?>">
<?= __('Click here to stop alerts for this product.') ?>
</a>
</p>
<?php endforeach ?>
<?php endif ?>






magento2 php product-alert






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 30 at 8:07







Mee

















asked May 30 at 7:54









MeeMee

285




285












  • Share your code

    – Asad Khan
    May 30 at 8:03











  • @AsadKhan not sure what exactly you wanted to see, but updated with example to email template I am sending to user. It gets productUrl but not exactly how I want to. Currently it retrieves simple product id but I want to retrieve configurable with attributes that when opening it selects my simple product

    – Mee
    May 30 at 8:07


















  • Share your code

    – Asad Khan
    May 30 at 8:03











  • @AsadKhan not sure what exactly you wanted to see, but updated with example to email template I am sending to user. It gets productUrl but not exactly how I want to. Currently it retrieves simple product id but I want to retrieve configurable with attributes that when opening it selects my simple product

    – Mee
    May 30 at 8:07

















Share your code

– Asad Khan
May 30 at 8:03





Share your code

– Asad Khan
May 30 at 8:03













@AsadKhan not sure what exactly you wanted to see, but updated with example to email template I am sending to user. It gets productUrl but not exactly how I want to. Currently it retrieves simple product id but I want to retrieve configurable with attributes that when opening it selects my simple product

– Mee
May 30 at 8:07






@AsadKhan not sure what exactly you wanted to see, but updated with example to email template I am sending to user. It gets productUrl but not exactly how I want to. Currently it retrieves simple product id but I want to retrieve configurable with attributes that when opening it selects my simple product

– Mee
May 30 at 8:07











2 Answers
2






active

oldest

votes


















2














This article by Daan van den Bergh explains how you can do exactly what you need:
https://daan.dev/magento/2/redirect-simple-products-configurable-parent-attributes-pre-selected/



And if the image doesn't update when the simple product is selected check this article:
https://daan.dev/how-to/uncaught-typeerror-updatedata-undefined/



Regards






share|improve this answer






























    0














    Create a custom module which has helper class and it has a method which gives a Configurable product URl.



    Helper class



    <?php

    namespace StackExchangeMagentoHelper;

    use MagentoCatalogModelProductVisibility;
    class Product extends MagentoFrameworkAppHelperAbstractHelper


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

    /**
    * @var MagentoCatalogApiProductRepositoryInterface
    */
    private $productRepository;

    public function __construct(
    MagentoFrameworkAppHelperContext $context,
    MagentoCatalogApiProductRepositoryInterface $productRepository,
    MagentoConfigurableProductModelProductTypeConfigurable $configurable
    )
    parent::__construct($context);
    $this->productRepository = $productRepository;
    $this->configurable = $configurable;

    public function getConfigurableProductUrl($product)


    if($product->getVisibility() != Visibility::VISIBILITY_NOT_VISIBLE)
    return false;


    $configProductIds = $this->configurable->getParentIdsByChild($product->getId());

    if(is_array($configProductIds) && empty($configProductIds))
    return '#';


    if(is_array($configProductIds) && !empty($configProductIds))
    $configProductId = $configProductIds[0];

    if(is_int($configProductIds))
    $configProductId = $configProductIds;


    try
    $configurablProduct =$this->productRepository
    ->getById($configProductId, false, $product->getStoreId());
    catch (MagentoFrameworkExceptionNoSuchEntityException $ex)
    return false;


    return $configurablProduct->getUrlModel()->getUrl($configurablProduct);




    Call this helper to your phtml files
    using



    $configHelper = $this->helper('StackExchangeMagentoHelperProduct');


    PHTML code looks like:



    <?php
    $configHelper = $this->helper('StackExchangeMagentoHelperProduct');
    ?>
    <?php if ($_products = $block->getProducts()): ?>
    <?php foreach ($_products as $_product): ?>
    <p><?= __('Hello!') ?></p>
    <?php $isConigProduct = $configHelper->getConfigurableProductUrl($product); ?>
    <p>
    <?php if($isConigProduct): ?>
    <?= __(
    'You have subscribed for product: <strong class="product name"><a href="%1">%2</a></strong>',
    $isConigProduct,
    $block->escapeHtml($_product->getName())
    )
    ?>
    <?php else: ?>
    <?= __(
    'You have subscribed for product: <strong class="product name"><a href="%1">%2</a></strong>',
    $_product->getProductUrl(),
    $block->escapeHtml($_product->getName())
    )
    ?>
    <?php endif; ?>
    </p>
    <p>
    <a href="<?= $block->getUserUnsubscribeUrl() ?>">
    <?= __('Click here to stop alerts for this product.') ?>
    </a>
    </p>
    <?php endforeach ?>
    <?php endif ?>


    Code is not tested given base on Idea.






    share|improve this answer























      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%2f276693%2fmagento-2-get-simple-product-url-from-configurable%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      This article by Daan van den Bergh explains how you can do exactly what you need:
      https://daan.dev/magento/2/redirect-simple-products-configurable-parent-attributes-pre-selected/



      And if the image doesn't update when the simple product is selected check this article:
      https://daan.dev/how-to/uncaught-typeerror-updatedata-undefined/



      Regards






      share|improve this answer



























        2














        This article by Daan van den Bergh explains how you can do exactly what you need:
        https://daan.dev/magento/2/redirect-simple-products-configurable-parent-attributes-pre-selected/



        And if the image doesn't update when the simple product is selected check this article:
        https://daan.dev/how-to/uncaught-typeerror-updatedata-undefined/



        Regards






        share|improve this answer

























          2












          2








          2







          This article by Daan van den Bergh explains how you can do exactly what you need:
          https://daan.dev/magento/2/redirect-simple-products-configurable-parent-attributes-pre-selected/



          And if the image doesn't update when the simple product is selected check this article:
          https://daan.dev/how-to/uncaught-typeerror-updatedata-undefined/



          Regards






          share|improve this answer













          This article by Daan van den Bergh explains how you can do exactly what you need:
          https://daan.dev/magento/2/redirect-simple-products-configurable-parent-attributes-pre-selected/



          And if the image doesn't update when the simple product is selected check this article:
          https://daan.dev/how-to/uncaught-typeerror-updatedata-undefined/



          Regards







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 30 at 8:43









          SantiBMSantiBM

          1015




          1015























              0














              Create a custom module which has helper class and it has a method which gives a Configurable product URl.



              Helper class



              <?php

              namespace StackExchangeMagentoHelper;

              use MagentoCatalogModelProductVisibility;
              class Product extends MagentoFrameworkAppHelperAbstractHelper


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

              /**
              * @var MagentoCatalogApiProductRepositoryInterface
              */
              private $productRepository;

              public function __construct(
              MagentoFrameworkAppHelperContext $context,
              MagentoCatalogApiProductRepositoryInterface $productRepository,
              MagentoConfigurableProductModelProductTypeConfigurable $configurable
              )
              parent::__construct($context);
              $this->productRepository = $productRepository;
              $this->configurable = $configurable;

              public function getConfigurableProductUrl($product)


              if($product->getVisibility() != Visibility::VISIBILITY_NOT_VISIBLE)
              return false;


              $configProductIds = $this->configurable->getParentIdsByChild($product->getId());

              if(is_array($configProductIds) && empty($configProductIds))
              return '#';


              if(is_array($configProductIds) && !empty($configProductIds))
              $configProductId = $configProductIds[0];

              if(is_int($configProductIds))
              $configProductId = $configProductIds;


              try
              $configurablProduct =$this->productRepository
              ->getById($configProductId, false, $product->getStoreId());
              catch (MagentoFrameworkExceptionNoSuchEntityException $ex)
              return false;


              return $configurablProduct->getUrlModel()->getUrl($configurablProduct);




              Call this helper to your phtml files
              using



              $configHelper = $this->helper('StackExchangeMagentoHelperProduct');


              PHTML code looks like:



              <?php
              $configHelper = $this->helper('StackExchangeMagentoHelperProduct');
              ?>
              <?php if ($_products = $block->getProducts()): ?>
              <?php foreach ($_products as $_product): ?>
              <p><?= __('Hello!') ?></p>
              <?php $isConigProduct = $configHelper->getConfigurableProductUrl($product); ?>
              <p>
              <?php if($isConigProduct): ?>
              <?= __(
              'You have subscribed for product: <strong class="product name"><a href="%1">%2</a></strong>',
              $isConigProduct,
              $block->escapeHtml($_product->getName())
              )
              ?>
              <?php else: ?>
              <?= __(
              'You have subscribed for product: <strong class="product name"><a href="%1">%2</a></strong>',
              $_product->getProductUrl(),
              $block->escapeHtml($_product->getName())
              )
              ?>
              <?php endif; ?>
              </p>
              <p>
              <a href="<?= $block->getUserUnsubscribeUrl() ?>">
              <?= __('Click here to stop alerts for this product.') ?>
              </a>
              </p>
              <?php endforeach ?>
              <?php endif ?>


              Code is not tested given base on Idea.






              share|improve this answer



























                0














                Create a custom module which has helper class and it has a method which gives a Configurable product URl.



                Helper class



                <?php

                namespace StackExchangeMagentoHelper;

                use MagentoCatalogModelProductVisibility;
                class Product extends MagentoFrameworkAppHelperAbstractHelper


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

                /**
                * @var MagentoCatalogApiProductRepositoryInterface
                */
                private $productRepository;

                public function __construct(
                MagentoFrameworkAppHelperContext $context,
                MagentoCatalogApiProductRepositoryInterface $productRepository,
                MagentoConfigurableProductModelProductTypeConfigurable $configurable
                )
                parent::__construct($context);
                $this->productRepository = $productRepository;
                $this->configurable = $configurable;

                public function getConfigurableProductUrl($product)


                if($product->getVisibility() != Visibility::VISIBILITY_NOT_VISIBLE)
                return false;


                $configProductIds = $this->configurable->getParentIdsByChild($product->getId());

                if(is_array($configProductIds) && empty($configProductIds))
                return '#';


                if(is_array($configProductIds) && !empty($configProductIds))
                $configProductId = $configProductIds[0];

                if(is_int($configProductIds))
                $configProductId = $configProductIds;


                try
                $configurablProduct =$this->productRepository
                ->getById($configProductId, false, $product->getStoreId());
                catch (MagentoFrameworkExceptionNoSuchEntityException $ex)
                return false;


                return $configurablProduct->getUrlModel()->getUrl($configurablProduct);




                Call this helper to your phtml files
                using



                $configHelper = $this->helper('StackExchangeMagentoHelperProduct');


                PHTML code looks like:



                <?php
                $configHelper = $this->helper('StackExchangeMagentoHelperProduct');
                ?>
                <?php if ($_products = $block->getProducts()): ?>
                <?php foreach ($_products as $_product): ?>
                <p><?= __('Hello!') ?></p>
                <?php $isConigProduct = $configHelper->getConfigurableProductUrl($product); ?>
                <p>
                <?php if($isConigProduct): ?>
                <?= __(
                'You have subscribed for product: <strong class="product name"><a href="%1">%2</a></strong>',
                $isConigProduct,
                $block->escapeHtml($_product->getName())
                )
                ?>
                <?php else: ?>
                <?= __(
                'You have subscribed for product: <strong class="product name"><a href="%1">%2</a></strong>',
                $_product->getProductUrl(),
                $block->escapeHtml($_product->getName())
                )
                ?>
                <?php endif; ?>
                </p>
                <p>
                <a href="<?= $block->getUserUnsubscribeUrl() ?>">
                <?= __('Click here to stop alerts for this product.') ?>
                </a>
                </p>
                <?php endforeach ?>
                <?php endif ?>


                Code is not tested given base on Idea.






                share|improve this answer

























                  0












                  0








                  0







                  Create a custom module which has helper class and it has a method which gives a Configurable product URl.



                  Helper class



                  <?php

                  namespace StackExchangeMagentoHelper;

                  use MagentoCatalogModelProductVisibility;
                  class Product extends MagentoFrameworkAppHelperAbstractHelper


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

                  /**
                  * @var MagentoCatalogApiProductRepositoryInterface
                  */
                  private $productRepository;

                  public function __construct(
                  MagentoFrameworkAppHelperContext $context,
                  MagentoCatalogApiProductRepositoryInterface $productRepository,
                  MagentoConfigurableProductModelProductTypeConfigurable $configurable
                  )
                  parent::__construct($context);
                  $this->productRepository = $productRepository;
                  $this->configurable = $configurable;

                  public function getConfigurableProductUrl($product)


                  if($product->getVisibility() != Visibility::VISIBILITY_NOT_VISIBLE)
                  return false;


                  $configProductIds = $this->configurable->getParentIdsByChild($product->getId());

                  if(is_array($configProductIds) && empty($configProductIds))
                  return '#';


                  if(is_array($configProductIds) && !empty($configProductIds))
                  $configProductId = $configProductIds[0];

                  if(is_int($configProductIds))
                  $configProductId = $configProductIds;


                  try
                  $configurablProduct =$this->productRepository
                  ->getById($configProductId, false, $product->getStoreId());
                  catch (MagentoFrameworkExceptionNoSuchEntityException $ex)
                  return false;


                  return $configurablProduct->getUrlModel()->getUrl($configurablProduct);




                  Call this helper to your phtml files
                  using



                  $configHelper = $this->helper('StackExchangeMagentoHelperProduct');


                  PHTML code looks like:



                  <?php
                  $configHelper = $this->helper('StackExchangeMagentoHelperProduct');
                  ?>
                  <?php if ($_products = $block->getProducts()): ?>
                  <?php foreach ($_products as $_product): ?>
                  <p><?= __('Hello!') ?></p>
                  <?php $isConigProduct = $configHelper->getConfigurableProductUrl($product); ?>
                  <p>
                  <?php if($isConigProduct): ?>
                  <?= __(
                  'You have subscribed for product: <strong class="product name"><a href="%1">%2</a></strong>',
                  $isConigProduct,
                  $block->escapeHtml($_product->getName())
                  )
                  ?>
                  <?php else: ?>
                  <?= __(
                  'You have subscribed for product: <strong class="product name"><a href="%1">%2</a></strong>',
                  $_product->getProductUrl(),
                  $block->escapeHtml($_product->getName())
                  )
                  ?>
                  <?php endif; ?>
                  </p>
                  <p>
                  <a href="<?= $block->getUserUnsubscribeUrl() ?>">
                  <?= __('Click here to stop alerts for this product.') ?>
                  </a>
                  </p>
                  <?php endforeach ?>
                  <?php endif ?>


                  Code is not tested given base on Idea.






                  share|improve this answer













                  Create a custom module which has helper class and it has a method which gives a Configurable product URl.



                  Helper class



                  <?php

                  namespace StackExchangeMagentoHelper;

                  use MagentoCatalogModelProductVisibility;
                  class Product extends MagentoFrameworkAppHelperAbstractHelper


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

                  /**
                  * @var MagentoCatalogApiProductRepositoryInterface
                  */
                  private $productRepository;

                  public function __construct(
                  MagentoFrameworkAppHelperContext $context,
                  MagentoCatalogApiProductRepositoryInterface $productRepository,
                  MagentoConfigurableProductModelProductTypeConfigurable $configurable
                  )
                  parent::__construct($context);
                  $this->productRepository = $productRepository;
                  $this->configurable = $configurable;

                  public function getConfigurableProductUrl($product)


                  if($product->getVisibility() != Visibility::VISIBILITY_NOT_VISIBLE)
                  return false;


                  $configProductIds = $this->configurable->getParentIdsByChild($product->getId());

                  if(is_array($configProductIds) && empty($configProductIds))
                  return '#';


                  if(is_array($configProductIds) && !empty($configProductIds))
                  $configProductId = $configProductIds[0];

                  if(is_int($configProductIds))
                  $configProductId = $configProductIds;


                  try
                  $configurablProduct =$this->productRepository
                  ->getById($configProductId, false, $product->getStoreId());
                  catch (MagentoFrameworkExceptionNoSuchEntityException $ex)
                  return false;


                  return $configurablProduct->getUrlModel()->getUrl($configurablProduct);




                  Call this helper to your phtml files
                  using



                  $configHelper = $this->helper('StackExchangeMagentoHelperProduct');


                  PHTML code looks like:



                  <?php
                  $configHelper = $this->helper('StackExchangeMagentoHelperProduct');
                  ?>
                  <?php if ($_products = $block->getProducts()): ?>
                  <?php foreach ($_products as $_product): ?>
                  <p><?= __('Hello!') ?></p>
                  <?php $isConigProduct = $configHelper->getConfigurableProductUrl($product); ?>
                  <p>
                  <?php if($isConigProduct): ?>
                  <?= __(
                  'You have subscribed for product: <strong class="product name"><a href="%1">%2</a></strong>',
                  $isConigProduct,
                  $block->escapeHtml($_product->getName())
                  )
                  ?>
                  <?php else: ?>
                  <?= __(
                  'You have subscribed for product: <strong class="product name"><a href="%1">%2</a></strong>',
                  $_product->getProductUrl(),
                  $block->escapeHtml($_product->getName())
                  )
                  ?>
                  <?php endif; ?>
                  </p>
                  <p>
                  <a href="<?= $block->getUserUnsubscribeUrl() ?>">
                  <?= __('Click here to stop alerts for this product.') ?>
                  </a>
                  </p>
                  <?php endforeach ?>
                  <?php endif ?>


                  Code is not tested given base on Idea.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered May 30 at 8:51









                  Amit BeraAmit Bera

                  60.9k1682181




                  60.9k1682181



























                      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%2f276693%2fmagento-2-get-simple-product-url-from-configurable%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

                      Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                      Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

                      Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?