Page 1 of 1

Fetch product url from drop down

Posted: Wed Jul 27, 2022 12:40 pm
by radhavallabh
Hi dear;
I am trying to assign a related product url to each product so-
I am trying to fetch a product url in the a href tag using a drop down in admin-
like below fetches a id
<?= Products::select('products_id', ['id' => 'fProduct'])->require() ?>
Can you pls help me figure out how to fetch the url using this type of select function?

I am trying to fetch a URL using the above in place of ENTRY ANSWER so it will automatically fetch the URL in each language

-

Code: Select all

<div class="form-group row">
    <label for="fProduct" class="col-form-label col-sm-3 text-left text-sm-right"><?= ENTRY_PRODUCT ?></label>
    <div class="col-sm-9"><?= Products::select('products_id', ['id' => 'fProduct'])->require() ?></div>
  </div>

  <div class="form-group row">
    <label class="col-form-label col-sm-3 text-left text-sm-right"><?= ENTRY_QUESTION ?></label>
    <div class="col-sm-9"><?= $question_input_string ?></div>
  </div>

  <div class="form-group row">
    <label class="col-form-label col-sm-3 text-left text-sm-right"><?= ENTRY_ANSWER ?></label>
    <div class="col-sm-9"><?= $answer_input_string ?></div>
  </div>
Please your help will be deeply appreciated;
Thank you in advance;
Very Warm Regds./
radhavallabh
radhavallabh

Re: Fetch product url from drop down

Posted: Wed Jul 27, 2022 2:24 pm
by ecartz
radhavallabh wrote: Wed Jul 27, 2022 12:40 pm I am trying to fetch a product url in the a href tag using a drop down in admin-
I don't know what this means.

If you just want to associate a product with a different product, just work with the IDs. You can then use the ID to generate a URL:

Code: Select all

$href = $Admin->catalog('product_info.php', ['products_id' => $product->get('associated_product_id')]);
or in catalog

Code: Select all

$href = $Linker->build('product_info.php', ['products_id' => $product->get('associated_product_id')]);
You can set the associated_product_id on the Product object with a hook listener on productCapabilities.

If you want to change the URL in admin based on a select menu, then you'll need Javascript.

Re: Fetch product url from drop down

Posted: Thu Jul 28, 2022 1:49 am
by radhavallabh
ecartz wrote: Wed Jul 27, 2022 2:24 pm
radhavallabh wrote: Wed Jul 27, 2022 12:40 pm I am trying to fetch a product url in the a href tag using a drop down in admin-
I don't know what this means.
Sorry for not being precise.
I am trying to make a tabbed module in admin on each product where I could select a URL to associate it with the product.
On catalog size it shall appear as a Button link with text I assign in the module.

Will try the method you suggested and report back , Am also trying to replicate Soft redirect into this module so will come back as and when I hit a block :)

Thank you;
Very Warm Regds./
radhavallabh