How to embed microdata attributes on product page

  • Posts: 52
  • Thank you received: 0
9 years 3 months ago #226115

-- url of the page with the problem -- : www.filkab.solar
-- 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.

  • Posts: 13201
  • Thank you received: 2322
9 years 3 months ago #226169

Hi,

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.

  • Posts: 52
  • Thank you received: 0
9 years 3 months ago #226179

Thank you Xavier,
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.

  • Posts: 13201
  • Thank you received: 2322
9 years 3 months ago #226181

Hi,

For the micro data it is the "itemprop" attribute which is mandatory, not the id or the class.
So the code would be:

<span hidden itemprop="mpn"><?php echo $this->element->product_mpn; ?></span>

The following user(s) said Thank You: ydingilski

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

  • Posts: 52
  • Thank you received: 0
9 years 3 months ago #226368

Thank you Xavier,
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.

  • Posts: 13201
  • Thank you received: 2322
9 years 3 months ago #226408

Hi,

Thank you for this report, we will fix that for the next release.

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

  • Posts: 52
  • Thank you received: 0
9 years 3 months ago #226442

Hi,
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.

  • Posts: 13201
  • Thank you received: 2322
9 years 3 months ago #226454

Hi,

This seems to be taking the id of the div where the data:

itemscope itemtype="http://schema.org/Product"
is added.

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:
id="hikashop_product_<?php echo preg_replace('#[^a-z0-9]#i','_',@$this->element->product_code); ?>_page"

The following user(s) said Thank You: ydingilski

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

  • Posts: 52
  • Thank you received: 0
9 years 3 months ago #226500

Thank you Xavier,
That did the trick.

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

  • Posts: 52
  • Thank you received: 0
9 years 1 month ago #233623

Hi,
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.

  • Posts: 13201
  • Thank you received: 2322
9 years 1 month ago #233765

Hi,

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:

<div itemprop="offers" itemscope itemtype="http://schema.org/Offer" style="display:none;">
  <span itemprop="price" style="display: none;">
    0.00
  </span>
</div>

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.

  • Posts: 52
  • Thank you received: 0
9 years 1 month ago #233835

Dear Xavier,
The code provided in your previous post generates another mistake - the first exclamation mark on the attached screenshot.
If I only leave the rows:

<span itemprop="price" style="display: none;">
    0.00
  </span>
then there is no mistake and the price is set to zero.
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.

Attachments:

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

  • Posts: 13201
  • Thank you received: 2322
9 years 1 month ago #233896

Hi,

So to remove the whole offers part you can remove the HTML 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.[code]
<span id="hikashop_product_price_main" class="hikashop_product_price_main" >
...
</span>
In the view "product / show_default" when there is no price. That way the plugin will not add any microdata for the price.[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.

  • Posts: 52
  • Thank you received: 0
9 years 1 month ago #233974

Hi Xavier,
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:

<?php		
	if (!empty($this->element->prices)) {
	?>
	
	<span id="hikashop_product_price_main" class="hikashop_product_price_main">
		<?php
		if ($this->params->get('show_price')) {
			$this->row = & $this->element;
			$this->setLayout('listing_price');
			echo $this->loadTemplate();
		}
		?>
	</span>
	
	<?php } ?>

Last edit: 9 years 1 month ago by ydingilski.

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

  • Posts: 13201
  • Thank you received: 2322
9 years 1 month ago #234020

Hi,

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.

  • Posts: 52
  • Thank you received: 0
9 years 1 month ago #234047

Hi,
Products without prices:
http://www.filkab.solar/products/858-sunlight-res-opzv-2v-4245
http://www.filkab.solar/products/859-sunlight-res-sopzv-2v-150

In this category you can find both products with and without prices:
http://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.

Attachments:
Last edit: 9 years 1 month ago by ydingilski.

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

  • Posts: 13201
  • Thank you received: 2322
9 years 1 month ago #234057

Hi,

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.

The following user(s) said Thank You: ydingilski

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

  • Posts: 52
  • Thank you received: 0
9 years 1 month ago #234118

Hi Xavier,
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:

<?php		
	if (!empty($this->element->prices)) {
?>
	
	<span id="hikashop_product_price_main" class="hikashop_product_price_main">
		<?php
		if ($this->params->get('show_price')) {
			$this->row = & $this->element;
			$this->setLayout('listing_price');
			echo $this->loadTemplate();
		}
		?>
	</span>
	
	<?php } else {
	echo $this->cart->displayButton(JText :: _('CONTACT_US_FOR_INFO'), 'contact_us', $params, hikashop_completeLink('product&task=contact&cid=' . $this->element->product_id.$url_itemid), 'window.location=\'' . hikashop_completeLink('product&task=contact&cid=' . $this->element->product_id.$url_itemid) . '\';return false;');
	} ?>
	<br />

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):
<div id="hikashop_product_bottom_part" class="hikashop_product_bottom_part show_tabular">
	.......
</div>

<div>
	<span hidden itemprop="name"><?php echo $this->element->product_page_title; ?></span>
	<span hidden itemprop="model"><?php echo $this->element->product_model; ?></span>
	<span hidden itemprop="mpn"><?php echo $this->element->product_mpn; ?></span>
	<span hidden itemprop="manufacturer"><?php echo $this->element->product_microdata_manufacturer; ?></span>
</div>

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:
<div>
	<span hidden itemprop="name"><?php echo $this->element->product_page_title; ?></span>
	<span hidden itemprop="model"><?php echo $this->element->product_model; ?></span>
	<span hidden itemprop="mpn"><?php echo $this->element->product_mpn; ?></span>
	<span hidden itemprop="manufacturer"><?php echo $this->element->product_microdata_manufacturer; ?></span>
	</div>
	
	<?php	
	if (!empty($this->element->prices)) {
	?>
	
	<span id="hikashop_product_price_main" class="hikashop_product_price_main">
		<?php
		if ($this->params->get('show_price')) {
			$this->row = & $this->element;
			$this->setLayout('listing_price');
			echo $this->loadTemplate();
		}
		?>
	</span>
	
	<?php } else {
	echo $this->cart->displayButton(JText :: _('CONTACT_US_FOR_INFO'), 'contact_us', $params, hikashop_completeLink('product&task=contact&cid=' . $this->element->product_id.$url_itemid), 'window.location=\'' . hikashop_completeLink('product&task=contact&cid=' . $this->element->product_id.$url_itemid) . '\';return false;');
	} ?>
	<br />

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.

Attachments:

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

Time to create page: 0.098 seconds
Powered by Kunena Forum