How to embed microdata attributes on product page
- ydingilski
-
Topic Author
- Offline
-- HikaShop version -- : 2.6.0
-- Joomla version -- : 3.4.3
-- PHP version -- : 5.3.15
Hi,
I have more microdata attributes from schema.org->productwhich I would like to include in the product page.
I know how to add them in the producttag plugin.
1. How do I embed these in the product page without showing them on the front end? Let's say that I have custom field with the mpn number of the product.
Is the following code correct:
<span hidden id="hikashop_product_mpn_main" class="hikashop_product_mpn_main">
<?php
echo $this->element->product_mpn;
?>
</span>
Do I need the code class="hikashop_product_mpn_main" if I'm not showing this attribute in the front end?
Is there another better (or correct) way to do it?
2. Let's say I'm using tabular view. How do I embed the manufacturer name which is included in the show_block_dimensions.php file? Do I have to add anothr variable for it in the show_tabular.php file?
Thank you.
Please Log in or Create an account to join the conversation.
To add them on the product page directly, you can indeed edit the view of that product page.
If you are using the tabular view so the view to edit is "product / show_tabular" and there add the desired code.
You can add it anywhere as it is hidden, so no need to add it in show_block_dimensions. Even if it is duplicated, no problem as the schema attributes will be only on the added code.
You don't have to set an id or a class, only what is needed for the meta data and to hide the content.
Please Log in or Create an account to join the conversation.
- ydingilski
-
Topic Author
- Offline
Could you please post the correct code (for example for custom field mpn). I'm a little confused how to do it without id.
Thanks.
Please Log in or Create an account to join the conversation.
For the micro data it is the "itemprop" attribute which is mandatory, not the id or the class.
So the code would be:
Please Log in or Create an account to join the conversation.
- ydingilski
-
Topic Author
- Offline
I've noticed a mistake when checking a product page with the Google Microdata Testing Tool - it doesn't recognize the itemprop="length".
I've checked the schema.org/product properties and there is no length one. I think the correct one is depth and the following code of the producttag plugin should be changed accordingly the bold text:
//Product length
$pattern='/class="hikashop_product_length_main"/';
$replacement='class="hikashop_product_length_main" itemprop="depth";
$product_page_parts[1] = preg_replace($pattern,$replacement,$product_page_parts[1],1);
Please Log in or Create an account to join the conversation.
Thank you for this report, we will fix that for the next release.
Please Log in or Create an account to join the conversation.
- ydingilski
-
Topic Author
- Offline
I have one more question, hopefully the last on this topic:
How can I change the url of the product pointing to the real canonical url:
Now it is:
www.filkab.solar/bg/products/hikashop_pr...00201050125_000_page
And I think it should be:
www.filkab.solar/bg/products/4-sma-sunny-boy-2-5
Please Log in or Create an account to join the conversation.
This seems to be taking the id of the div where the data:
But I am not sure that this has any impact on the used url, it seems to be just the Google testing tool which is not
using the standard of schema.org.
To be sure, you can edit the view "product / show" and remove the id, you can delete it by removing this code:
Please Log in or Create an account to join the conversation.
- ydingilski
-
Topic Author
- Offline
That did the trick.
Please Log in or Create an account to join the conversation.
- ydingilski
-
Topic Author
- Offline
For some of our products we don't have a price, it's only on request. I've modified the product page so it displays the product contact button instead of the FREE_PRICE string. But the microdata for these products has error, because the price is a required attribute in the Offer schema.
How should I modify the hikashopproducttag plugin in order to exclude the whole Offer microdata for the products without price?
P.S. I have decided to post my question here instead of opening new topic. Please let me know if I should open a new topic instead.
Please Log in or Create an account to join the conversation.
The best way would be to add the modification in the product page code directly.
So instead of the "FREE_PRICE" string, you added the product contact button, and you can add that code too:
That way this code will be added only when no price and will add a price for the microdata.
ps: In the future releases of HikaShop the microdata will be added in the views directly and no more use a plugin
Please Log in or Create an account to join the conversation.
- ydingilski
-
Topic Author
- Offline
The code provided in your previous post generates another mistake - the first exclamation mark on the attached screenshot.
If I only leave the rows:
Your solution fixes the error but the price is still not correct.
I was hoping that there is a way to "dismiss" the whole offers [Offer] part when I have no price set (the blue rectangular on the attached screenshot.
Please Log in or Create an account to join the conversation.
So to remove the whole offers part you can remove the HTML code:
[code]
<span id="hikashop_product_price_main" class="hikashop_product_price_main" >
...
</span>
[code]
In the view "product / show_default" when there is no price.
That way the plugin will not add any microdata for the price.
Please Log in or Create an account to join the conversation.
- ydingilski
-
Topic Author
- Offline
Thank you very much for all your help but I need a little more assistance please. I thought I can modify the code by myself but apparently I'm doing something wrong.
This is the code I added and when testing with Google structured data testing tool the error is still present:
Please Log in or Create an account to join the conversation.
This modification seems to be correct. I would have given the same code
Could you give me the link to a page of a free product ?
Please Log in or Create an account to join the conversation.
- ydingilski
-
Topic Author
- Offline
Products without prices:
www.filkab.solar/products/858-sunlight-res-opzv-2v-4245
www.filkab.solar/products/859-sunlight-res-sopzv-2v-150
In this category you can find both products with and without prices:
www.filkab.solar/products/category/33-deep-cycle
Attached you can find our hikashopproducttag.php file just for reference. All the modifications in it are some fields commented out. I don't think they interfere in any way with the price.
Please Log in or Create an account to join the conversation.
I can see that you are using the "product / show_tabular" view, so do you have added the modifications in that view ?
The "hikashop_product_price_main" div is still on the page.
Please Log in or Create an account to join the conversation.
- ydingilski
-
Topic Author
- Offline
I finally made it work :blink: I'll explain more details just for reference of other people on the forum.
1. Like Xavier said you have to use the correct view. I thought the code should be added in the "product / show_default" view but i was totally wrong. Modify the code in the view you use.
2. This is the code to cut off "offers" microdata when the product has no price for "product / show_tabular" view, plus adding contact button for price request in that case:
3. Unfortunately another problem occured. I had additional microdata attributes added in the end of the file, right after the hikashop_product_bottom_part div (read the whole topic):
The problem is that when the product has no price the rest of the additional attributes are also gone. If I move the div with the additional microdata attributes anywhere after the first code, the one for cutting off the "offers"microdata, another problem arises. It would be either for the products with prices or for the products without prices. Or for both of them.
To fix that I had to move the additional microdata attributes div just before the code for cutting off the "offers"microdata:
I don't know what was the problem. I didn't have time to spend on it and even if I had maybe I wouldn't find out. :whistle:
Once again this code is for "product / show_tabular" view. Attached is my working file if someone want to dig into it.
Please Log in or Create an account to join the conversation.