Display Variant Name instead of Main Product Name

  • Posts: 32
  • Thank you received: 5
1 year 8 months ago #352350

-- url of the page with the problem -- : www.ms-verlag.de/buecher/kinderbuch/entd...4-entdecke-die-biber
-- HikaShop version -- : 4.7.3
-- Joomla version -- : 4.3.2
-- PHP version -- : 7.4.33
-- Browser(s) name and version -- : Firefox 113.0.2 (64-bit)

Hi,

I am trying to display the product's variant name instead of the main product name for products with variants.

I have tried changing product/show_default.php:

<span id="hikashop_product_name_main" class="hikashop_product_name_main">
<?php
if (hikashop_getCID('product_id')!=$this->element->product_id && isset ($this->element->main->product_name))
//echo $this->element->main->product_name;
echo $variant->product_name;
else
echo $this->element->product_name;
?>
</span>

But this only appends the last variant's name in the list to the title when the page is first loaded.

I also tried adding && !isset($this->element->variants) to the if clause to only set the main product name if there are no variants, but then I have a blank title until I select a variant at which point the main product name appears again as well.

EDIT: Also tried to use CSS for this. But there is no way to know if a product has variants or not since :has(.hikashop_product_variant_subname) isn't really supported and :empty() doesn't apply because the title has text.

[MODERATOR :] Please don't edit your message so long after posting it, it may bug our ticket service and increase response times for everyone, including you.
Thank you for your attention[/MODERATOR]
.

Last edit: 1 year 8 months ago by Philip.

Please Log in or Create an account to join the conversation.

  • Posts: 83326
  • Thank you received: 13473
  • MODERATOR
1 year 8 months ago #352352

Hi,

In the if, you want to have :

echo $this->element->characteristics_text;
That way, for products without variants, it will display the name of the product, and for products with variants it will display the name of the default variant when the page is loaded.
Then, for the display of the name when the variant selection is changed, you want to edit product / show
There, you can change:
echo $variant->product_name;
to:
echo $variant->characteristics_text;

The following user(s) said Thank You: NTV

Please Log in or Create an account to join the conversation.

  • Posts: 32
  • Thank you received: 5
1 year 8 months ago #352491

Thanks nicolas - it's working great!

I also adjusted checkout/show_block_cart.php, cart/show.php and product/cart.php to make it look the same way:

echo $product->product_name;
to
if(empty($product->characteristics_text)) {
echo $product->product_name;
}
else {
echo $product->characteristics_text;
}

However, I can't figure out how to do the same thing for already ordered products (visible in the control panel), presumably because the $product there is of the type order_product and doesn't have characteristics_text set.

Also, links from linked product names and from the Joomla search still display both product name and variant name until another variant is selected.

Any suggestions for these issues?

Please Log in or Create an account to join the conversation.

  • Posts: 83326
  • Thank you received: 13473
  • MODERATOR
1 year 8 months ago #352496

Hi,

The characteristics_text attribute is calculated dynamically based on the variant and product data.
When the cart is loaded, this variable is set but when the order data is generated from the cart data, it uses the standard variable to get the product name.
This is done with the line:

$orderProduct->order_product_name = $product->product_name;
in the file administrator/components/com_hikashop/classes/order.php
You could change the line directly, but that mean you'll end up having to do the change after each release of HikaShop.
A cleaner solution would be to implement the onBeforeOrderCreate(&$order, &$do) event of HikaShop in a plugin of the group "hikashop" to override the order_product_name of each product in $order->products based on the data in $order->cart->products where you should find the characteristics_text attribute. But this requires some coding skills.
www.hikashop.com/support/documentation/6...#onBeforeOrderCreate

For "links from linked product names" I don't understand what you're talking about.

For the Joomla search, which search are you using ? The old Joomla search system ? The new smart search system ? Or HikaShop filters ? Each mode would require a different solution.

The following user(s) said Thank You: NTV

Please Log in or Create an account to join the conversation.

  • Posts: 32
  • Thank you received: 5
1 year 8 months ago #352516

Hello,

since constant maintenance or making a plugin just for this aren't options, I used CSS to hide the variant name in these two cases. Not great, but it will do.

Concerning links: I was talking about the URL that is generated and stuck to product titles (for example in the cart/during checkout) or to search results. I am using the Joomla SmartSearch Extension.

I fixed these for the links generated by Hika by removing the product code from the Canonical URL. SmartSearch results still have this issue though.

Hika generated link (this always links to the main product, even from a variant in the cart):
https://www.ms-verlag.de/pluesch-co/saeugetiere/product/plueschtier-fledermaus

SmartSearch generated link (links to the variant, which is probably where the issue arises):
https://www.ms-verlag.de/magazine/product/plueschtier-fledermaus-hellbraun/highlight-WyJmbGVkZXJtYXVzIiwiZmxlZGVybVx1MDBlNHVzZSIsImZsZWRlcm1cdTAwZTR1c2VuIl0=

Please Log in or Create an account to join the conversation.

  • Posts: 83326
  • Thank you received: 13473
  • MODERATOR
1 year 8 months ago #352517

Hi,

I think that the problem with the smart search is that the non SEF link is generated by HikaShop during the indexing. And then Joomla's smart search asked HikaShop to transform the non SEF link to a SEF link when displaying the results. However, when it's HikaShop displaying a link to the product, on top of the non SEF link, it also provides the transformation mechanism with the canonical URL to be used. Here, the smart search system doesn't and that's why the canonical URL is ignored.
Now, it shouldn't matter too much as these are links which won't be indexed anyways as search engines won't be querying the smart search when indexing the website.

The following user(s) said Thank You: NTV

Please Log in or Create an account to join the conversation.

Time to create page: 0.063 seconds
Powered by Kunena Forum