Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

How-To: Use The Product Name As The Page Title Instead Of Categories :: Product Name Rate Topic   * * * * * 1 votes

 
  • Hungryweb
  • Senior Member
  • Authorized Reseller
  • Join Date: 10-Feb 12
  • 1249 posts

Posted 20 July 2018 - 05:57 AM #1

How to use The Product Name As The Page Title

Instead Of Categories :: Product Name

 

 

Please add:
 
#file - if folder structure is missing please create it

app/addons/my_changes/controllers/frontend/products.post.php

#content

<?php

use Tygh\Registry;

if (!defined('BOOTSTRAP')) { die('Access denied'); }

if ($mode == 'view' && !empty($_REQUEST['product_id'])) {
	$product = Tygh::$app['view']->getTemplateVars('product');
	if(empty($product['page_title'])){
		//other data can be added to title dynamic also
		$page_title = $product['product'];
		Tygh::$app['view']->assign('page_title', $page_title);
	}
}

* The modification will create the dynamic page title only for products with empty page_tile 

* Tested on CS-Cart 4.8.1
 
PS: "My Changes" add-on needs to be active

 

Please feel free to ask any questions!

 

Keep on smiling,

---
Valentin
part of hungryweb.net



 
  • b4lly
  • Junior Member
  • Members
  • Join Date: 29-Oct 08
  • 81 posts

Posted 25 July 2018 - 01:16 AM #2

How to use The Product Name As The Page Title

Instead Of Categories :: Product Name

 

 

Please add:
 
#file - if folder structure is missing please create it

app/addons/my_changes/controllers/frontend/products.post.php

#content

<?php

use Tygh\Registry;

if (!defined('BOOTSTRAP')) { die('Access denied'); }

if ($mode == 'view' && !empty($_REQUEST['product_id'])) {
	$product = Tygh::$app['view']->getTemplateVars('product');
	if(empty($product['page_title'])){
		//other data can be added to title dynamic also
		$page_title = $product['product'];
		Tygh::$app['view']->assign('page_title', $page_title);
	}
}

* The modification will create the dynamic page title only for products with empty page_tile 

* Tested on CS-Cart 4.8.1
 
PS: "My Changes" add-on needs to be active

 

Please feel free to ask any questions!

 

Keep on smiling,

---
Valentin
part of hungryweb.net

Hi Valentin

 

I followed your instructions but received an error, the site would not load any product pages. I'm using version 4.2.3. Any ideas?

 

Thanks



 
  • Hungryweb
  • Senior Member
  • Authorized Reseller
  • Join Date: 10-Feb 12
  • 1249 posts

Posted 25 July 2018 - 05:04 AM #3

For 4.0.x / 4.1.x / 4.2.x / 4.3.x please use

#content
<?php

use Tygh\Registry;

if (!defined('BOOTSTRAP')) { die('Access denied'); }

if ($mode == 'view' && !empty($_REQUEST['product_id'])) {
	$product = Registry::get('view')->getTemplateVars('product');
	if(empty($product['page_title'])){
		//other data can be added to title dynamic also
		$page_title = $product['product'];
		Registry::get('view')->assign('page_title', $page_title);
	}
}


 
  • b4lly
  • Junior Member
  • Members
  • Join Date: 29-Oct 08
  • 81 posts

Posted 25 July 2018 - 05:11 AM #4

For 4.0.x / 4.1.x / 4.2.x / 4.3.x please use

#content

<?php

use Tygh\Registry;

if (!defined('BOOTSTRAP')) { die('Access denied'); }

if ($mode == 'view' && !empty($_REQUEST['product_id'])) {
	$product = Registry::get('view')->getTemplateVars('product');
	if(empty($product['page_title'])){
		//other data can be added to title dynamic also
		$page_title = $product['product'];
		Registry::get('view')->assign('page_title', $page_title);
	}
}

Great, thanks so much Valentin. This works perfectly! : )



 
  • b4lly
  • Junior Member
  • Members
  • Join Date: 29-Oct 08
  • 81 posts

Posted 17 September 2018 - 06:16 AM #5

 

For 4.0.x / 4.1.x / 4.2.x / 4.3.x please use

#content

<?php

use Tygh\Registry;

if (!defined('BOOTSTRAP')) { die('Access denied'); }

if ($mode == 'view' && !empty($_REQUEST['product_id'])) {
	$product = Registry::get('view')->getTemplateVars('product');
	if(empty($product['page_title'])){
		//other data can be added to title dynamic also
		$page_title = $product['product'];
		Registry::get('view')->assign('page_title', $page_title);
	}
}

Great, thanks so much Valentin. This works perfectly! : )

 

Hi again Valentin

 

I'd also like to automatically capitalize all my product titles eg. masport motor mower = Masport Motor Mower. I believe I would use UCWORDS() for this, but I'm not sure how to correctly incorporate this into the solution you have already provided above. If it's not too much trouble, are you able to show me how this is done?

 

Thanks in advance

: )



 
  • Hungryweb
  • Senior Member
  • Authorized Reseller
  • Join Date: 10-Feb 12
  • 1249 posts

Posted 17 September 2018 - 08:29 AM #6

 

..

I'd also like to automatically capitalize all my product titles eg. masport motor mower = Masport Motor Mower. I believe I would use UCWORDS() for this, but I'm not sure how to correctly incorporate this into the solution you have already provided above. If it's not too much trouble, are you able to show me how this is done?..

 

Please use:

<?php

use Tygh\Registry;

if (!defined('BOOTSTRAP')) { die('Access denied'); }

if ($mode == 'view' && !empty($_REQUEST['product_id'])) {
	$product = Tygh::$app['view']->getTemplateVars('product');
	if(empty($product['page_title'])){
		//other data can be added to title dynamic also
		$page_title = ucwords(strtolower($product['product']));
		Tygh::$app['view']->assign('page_title', $page_title);
	}
}

the only difference is:

$page_title = ucwords(strtolower($product['product']));

Hope this helps!



 
  • b4lly
  • Junior Member
  • Members
  • Join Date: 29-Oct 08
  • 81 posts

Posted 17 September 2018 - 11:43 PM #7

 

 

For 4.0.x / 4.1.x / 4.2.x / 4.3.x please use

#content

<?php

use Tygh\Registry;

if (!defined('BOOTSTRAP')) { die('Access denied'); }

if ($mode == 'view' && !empty($_REQUEST['product_id'])) {
	$product = Registry::get('view')->getTemplateVars('product');
	if(empty($product['page_title'])){
		//other data can be added to title dynamic also
		$page_title = $product['product'];
		Registry::get('view')->assign('page_title', $page_title);
	}
}

Great, thanks so much Valentin. This works perfectly! : )

 

Hi again Valentin

 

I'd also like to automatically capitalize all my product titles eg. masport motor mower = Masport Motor Mower. I believe I would use UCWORDS() for this, but I'm not sure how to correctly incorporate this into the solution you have already provided above. If it's not too much trouble, are you able to show me how this is done?

 

Thanks in advance

: )

 

Thank you so much Valentin, that's great. Working well. : )



 
  • Antars
  • Member
  • Members
  • Join Date: 18-Sep 11
  • 44 posts

Posted 01 November 2019 - 08:47 AM #8

that's great, thanks.

Is there a way to add also company name to the title?

like
product name | company name?



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 19847 posts

Posted 01 November 2019 - 01:35 PM #9

Try 

$page_title = $product['product'] . ' ' .  Registry::get('settings.Company.company_name');

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.