- Posts: 17
- Thank you received: 0
Custom link on product page (with variants)
5 years 1 week ago #336056
by netica
Custom link on product page (with variants) was created by netica
-- HikaShop version -- : 4.4.3
-- Joomla version -- : 3.9.5
-- PHP version -- : 7.4.14
Hi, I need to make custom link (to demo site) for product and it's variants. What it the better solution: use some standard field or maybe custom field?
I've try do use "product_code" but it shows code in a strange way - while open product page it takes code form php but while switching on variants it takes code from java script (at least that's how I understood the action).
I want to past code to view like it:
<div class="button_cont" align="center">
<a class="butdemo" href=" mywebiste.com/ element->product_code; ?>" target="_blank" rel="nofollow">See demo on-line
</div>
Thank you in advance
Greg
-- Joomla version -- : 3.9.5
-- PHP version -- : 7.4.14
Hi, I need to make custom link (to demo site) for product and it's variants. What it the better solution: use some standard field or maybe custom field?
I've try do use "product_code" but it shows code in a strange way - while open product page it takes code form php but while switching on variants it takes code from java script (at least that's how I understood the action).
I want to past code to view like it:
<div class="button_cont" align="center">
<a class="butdemo" href=" mywebiste.com/ element->product_code; ?>" target="_blank" rel="nofollow">See demo on-line
</div>
Thank you in advance
Greg
Please Log in or Create an account to join the conversation.
5 years 1 week ago #336057
by nicolas
Replied by nicolas on topic Custom link on product page (with variants)
Hi,
If it's the same URL with only the product_code being different for each product, you'll want to add your HTML/PHP to the show_default.php view file as a view file override, via the menu Display>Views.
And regarding the product code, you'll want to do something like that :
Otherwise, for products with variants, $this->element->product_code contains the product code of the default variant and not the one of the main product.
If it's the same URL with only the product_code being different for each product, you'll want to add your HTML/PHP to the show_default.php view file as a view file override, via the menu Display>Views.
And regarding the product code, you'll want to do something like that :
Code:
<?php
if(!empty($this->element->main))
echo $this->element->main->product_code,
else
echo $this->element->product_code;
?>
Please Log in or Create an account to join the conversation.
5 years 1 week ago #336075
by netica
Replied by netica on topic Custom link on product page (with variants)
Thank you for your replay, problem is that your code is not dynamic - it doesn't change while choosing variants (at least on my website).
When I use this code:
<span id="hikashop_product_code_main">
<?php echo $this->element->product_code;?>
</span>
it works perfectly but don't know how make a link from it. - after switching to variant link is breaking. Also notice that without id="hikashop_product_code_main" it's also not dynamic so it works like your code.
Please look on my site: opop.pl/product/43-cosmetica and try to choose color variant, your code doesn't switch.
I'v put there all 3 codes that we are talking about so can touch the problem.
Ps.: I'm new to HikaShop and made many changes in configuration and few in views... is it possible that I'm the reason
?
Regards
Greg
When I use this code:
<span id="hikashop_product_code_main">
<?php echo $this->element->product_code;?>
</span>
it works perfectly but don't know how make a link from it. - after switching to variant link is breaking. Also notice that without id="hikashop_product_code_main" it's also not dynamic so it works like your code.
Please look on my site: opop.pl/product/43-cosmetica and try to choose color variant, your code doesn't switch.
I'v put there all 3 codes that we are talking about so can touch the problem.
Ps.: I'm new to HikaShop and made many changes in configuration and few in views... is it possible that I'm the reason
Regards
Greg
Please Log in or Create an account to join the conversation.
5 years 1 week ago #336077
by nicolas
Replied by nicolas on topic Custom link on product page (with variants)
Hi,
My code is fine for what you want as long as you put it somewhere outside of a div with an id finishing by _main in show_default.php
If you add it inside a div with an id finishing by _main, then you have also to make a similar modification in product / show.php where you have a big foreach for the variants of the product to display their own HTML in _variant_xxx divs. And when you change the selected variant, the HTML in the _main divs will be replaced by the HTML in the corresponding _variant_xxx divs. So you want to make the modifications in both places so that the HTML can be replaced with HTML that you modified too.
My code is fine for what you want as long as you put it somewhere outside of a div with an id finishing by _main in show_default.php
If you add it inside a div with an id finishing by _main, then you have also to make a similar modification in product / show.php where you have a big foreach for the variants of the product to display their own HTML in _variant_xxx divs. And when you change the selected variant, the HTML in the _main divs will be replaced by the HTML in the corresponding _variant_xxx divs. So you want to make the modifications in both places so that the HTML can be replaced with HTML that you modified too.
Please Log in or Create an account to join the conversation.
5 years 1 week ago #336094
by netica
Replied by netica on topic Custom link on product page (with variants)
Hi Nicolas, did you look at my webiste? Please notice that your code is now odded outside of a div with an id finishing by _main and it's not changeing while choosing variants. To explain how it's done on example page here is the code:
<p> Hika Support 1st:
<?php
if(!empty($this->element->main))
echo $this->element->main->product_code;
else
echo $this->element->product_code;
?>
</p>
<p> Hika Support 2nd:
<?php
echo $this->element->product_code;
?>
</p>
<p>Good one, with id="hikashop_product_code_main"
<span id="hikashop_product_code_main">
<?php echo $this->element->product_code;?>
</span>
</p>
Whole problem is that I don't want to use div with an id finishing by _main but only then product code is changing as I want. Hope it's clear now
Regards
Greg
<p> Hika Support 1st:
<?php
if(!empty($this->element->main))
echo $this->element->main->product_code;
else
echo $this->element->product_code;
?>
</p>
<p> Hika Support 2nd:
<?php
echo $this->element->product_code;
?>
</p>
<p>Good one, with id="hikashop_product_code_main"
<span id="hikashop_product_code_main">
<?php echo $this->element->product_code;?>
</span>
</p>
Whole problem is that I don't want to use div with an id finishing by _main but only then product code is changing as I want. Hope it's clear now
Regards
Greg
Please Log in or Create an account to join the conversation.
5 years 1 week ago #336095
by nicolas
Replied by nicolas on topic Custom link on product page (with variants)
Hi,
Well, I thought that you didn't want the product code to change.
If you want the product code of the link to change to the product code of the currently selected variant, then you need to have your code inside of a div with a _main id, and similar code in the product / show.php view file in the corresponding div with the _variant_xxx id. There is no alternative to that.
Well, I thought that you didn't want the product code to change.
If you want the product code of the link to change to the product code of the currently selected variant, then you need to have your code inside of a div with a _main id, and similar code in the product / show.php view file in the corresponding div with the _variant_xxx id. There is no alternative to that.
Please Log in or Create an account to join the conversation.
5 years 1 week ago #336156
by netica
Replied by netica on topic Custom link on product page (with variants)
Could you write some example of code in show.php file, please? I don't understand where to put it and how.
As I wrote on my first post maybe it's better to use custom field in my task - what you think about it?
As I wrote on my first post maybe it's better to use custom field in my task - what you think about it?
Please Log in or Create an account to join the conversation.
5 years 6 days ago #336160
by nicolas
Replied by nicolas on topic Custom link on product page (with variants)
Hi,
In show_default, you have this code by default:
So I suppose you want to replace it with:
In the product / show.php view file you can see this code:
So I suppose you want to replace it with:
In show_default, you have this code by default:
Code:
<span id="hikashop_product_code_main" class="hikashop_product_code_main"><?php
echo $this->element->product_code;
?></span>
Code:
<span id="hikashop_product_code_main" class="hikashop_product_code_main">
<div class="button_cont" align="center">
<a class="butdemo" href=" mywebiste.com/ <?php echo $this->element->product_code; ?>" target="_blank" rel="nofollow"><span>See demo on-line</span></a>
</div>
</span>
Code:
<div id="hikashop_product_code_<?php echo $variant_name; ?>" style="display:none;"><?php
echo $variant->product_code;
?></div>
Code:
<div id="hikashop_product_code_<?php echo $variant_name; ?>" style="display:none;">
<div class="button_cont" align="center">
<a class="butdemo" href=" mywebiste.com/ <?php echo $variant->product_code; ?>" target="_blank" rel="nofollow"><span>See demo on-line</span></a>
</div></div>
Please Log in or Create an account to join the conversation.
4 years 11 months ago #336359
by netica
Replied by netica on topic Custom link on product page (with variants)
Hi, Nicolas, thak you very much. Code solved the problem.
Please Log in or Create an account to join the conversation.
Time to create page: 0.181 seconds