Custom Metadata

  • Posts: 1
  • Thank you received: 0
10 years 1 month ago #147426

Hi there, i'm wondering what file that i have to edit to change the meta desc and meta keyword on a product page.

The meta desc and keywords on product page normally will use the product's metadata.
But if the product's metada empty, it will use the site's default meta keyword and description, am i right?

I wanted to change it's behaviour, so if the metadata of the product is empty, it will use my custom words instead of using site's default metadata.

If it's empty, i want to make something like: Get this $productname now for only $price ! Or find other similar product in $category.

I tried to check and change in view.html.php but i don't know which line to edit (or wrong file to edit?).
Please help me to locate which file to edit and what line / part of the file. Thanks a lot for the nice components that support J3!
:)

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

  • Posts: 81504
  • Thank you received: 13064
  • MODERATOR
10 years 1 month ago #147436

Hi,

It's indeed the components/com_hikashop/views/product/view.html.php file that you need to edit. It's those lines:

$doc = JFactory::getDocument();
		$product_name = $this->element->product_name;
		$product_page_title = $this->element->product_page_title;
		$product_description = $element->product_meta_description;
		$product_keywords = $element->product_keywords;

		if(!empty($this->element->main)){
			$product_name = $this->element->main->product_name;
			if(!empty($this->element->main->product_page_title)){
				$product_page_title = $this->element->main->product_page_title;
			}
			if(!empty($this->element->main->product_meta_description)){
				$product_description = $this->element->main->product_meta_description;
			}
			if(!empty($this->element->main->product_keywords)){
				$product_keywords = $this->element->main->product_keywords;
			}
		}

		if(!empty($product_keywords)){
			$doc->setMetadata('keywords', $product_keywords);
		}
		if(!empty($product_description)){
			$doc->setMetadata('description', $product_description);
		}

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

  • Posts: 23
  • Thank you received: 0
7 years 7 months ago #248285

Hi Nicolas,

Is this tweak still valid? I'd like to be able to auto create Metadescription with Product Name, Brand, Category & Price if it's left blank?

To test I have set lines 1327-1329 to this:

if(!empty($product_description)){
			$doc->setMetadata('description', $productname only $price);
		}

But it still just seems to set the meta to the text from the product description.

Aran
(2.6.3 Business)

Last edit: 7 years 7 months ago by aran.gibbs.

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

  • Posts: 81504
  • Thank you received: 13064
  • MODERATOR
7 years 7 months ago #248287

Hi,

Sure, you need to add to the end of that code something like that:

else{
$doc->setMetadata('description', 'My custom meta description');
}

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

  • Posts: 23
  • Thank you received: 0
7 years 7 months ago #248333

Hi,

Thanks for coming back to me. I've added that code but still no joy. I've attached a copy of the file.

Are you sure its not pulling it from somewhere else too? I'm editing the file stored in /components/com_hikashop/views/product and even if I delete that file completely it still just put the text from the product description into the meta data.

Aran

Attachments:
Last edit: 7 years 7 months ago by Jerome.

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

  • Posts: 81504
  • Thank you received: 13064
  • MODERATOR
7 years 7 months ago #248338

Hi,

You're not editing the correct file. That's the view.feed.php but you need to edit the view.html.php file.

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

  • Posts: 23
  • Thank you received: 0
7 years 7 months ago #248387

HI,

I am editing the view.html.php file. Must have attached the wrong one.

Attachments:
Last edit: 7 years 7 months ago by Jerome.

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

  • Posts: 26000
  • Thank you received: 4004
  • MODERATOR
7 years 7 months ago #248390

Hi,

The code

if(!empty($product_description)){
	$doc->setMetadata('description', $productname only $price);
}
is unfortunately incorrect, it is not a valid PHP code so I think it generates you fatal errors.
So I recommend you to use some like :
$doc->setMetadata('description', $product_name . ' - ');
If you want to generate a string with variables, you need to "concat" them.
Such kind of modification requires some PHP/Development skills and if you want to add a price in the meta description, it will require a more complexe modification.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

Time to create page: 0.079 seconds
Powered by Kunena Forum