Page Title As "Manufacturer Name" Instead Of "Items"

Phoca Cart - complex e-commerce extension
SpruceGuy
Phoca Member
Phoca Member
Posts: 14
Joined: 18 Aug 2023, 22:35

Page Title As "Manufacturer Name" Instead Of "Items"

Post by SpruceGuy »

Hi Jan,
I have PhocaCart 4.0.12 on Joomla 4.4.14. I use the manufacturers pages where it lists all "items" from each manufacturer. how do I make it display the page title as each of the manufacturers names instead of the word "items".
I have already adjusted the language file to change "items" to "Search Results" which works for most pages that are derived from a search on the site but would like to make the title display the specific manufacturer title/name instead of the generic title "items" (which is now "Search Results" in my case on my site) its in the H1 tags on the web page. I take it I will need to make an overide to do this? Is it possible?

Example page is https://www.actionlawn.co.uk/products/i ... 11-weibang

Kind regards
Graham
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 49199
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Page Title As "Manufacturer Name" Instead Of "Items"

Post by Jan »

Hi, yes, I think, you need to make override and there to get info about the url params and if there will be manufacturer, then gets the alias and find in database the name. Such will be then used instead of title:
components/com_phocacart/views/items/tmpl/default_header.php

Jan
If you find Phoca extensions useful, please support the project
SpruceGuy
Phoca Member
Phoca Member
Posts: 14
Joined: 18 Aug 2023, 22:35

Re: Page Title As "Manufacturer Name" Instead Of "Items"

Post by SpruceGuy »

Hi Jan,
Thank you I had a look at:
components/com_phocacart/views/items/tmpl/default_header.php
I will make an override of that file and make some adjustments and see what i can acheive.
If I get stuck I will get back to you.

Kind regards
Graham
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 49199
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Page Title As "Manufacturer Name" Instead Of "Items"

Post by Jan »

OK
If you find Phoca extensions useful, please support the project
SpruceGuy
Phoca Member
Phoca Member
Posts: 14
Joined: 18 Aug 2023, 22:35

Re: Page Title As "Manufacturer Name" Instead Of "Items"

Post by SpruceGuy »

Hi Jan,

I got the desired result from creating an override of "components/com_phocacart/views/items/tmpl/default_header.php"
Placing the file in "templates/[template name]/html/com_phocacart/items/default_header.php"
And using the following code within the newly created "default_header.php" file.

Code: Select all

<?php
/* @package Joomla
 * @copyright Copyright (C) Open Source Matters. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 * @extension Phoca Extension
 * @copyright Copyright (C) Jan Pavelka www.phoca.cz
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
 */
defined('_JEXEC') or die();
use Joomla\CMS\Router\Route;
use Joomla\CMS\Language\Text;
use Joomla\CMS\HTML\HTMLHelper;





if (isset($this->category[0]->parentid) && ($this->t['display_back'] == 1 || $this->t['display_back'] == 3)) {
	if ($this->category[0]->parentid == 0) {
		$linkUp = Route::_(PhocacartRoute::getCategoriesRoute());
		$linkUpText = Text::_('COM_PHOCACART_CATEGORIES');
	} else if ($this->category[0]->parentid > 0) {
		$linkUp = Route::_(PhocacartRoute::getCategoryRoute($this->category[0]->parentid, $this->category[0]->parentalias));
		$linkUpText = $this->category[0]->parenttitle;
	} else {
		$linkUp 	= false;
		$linkUpText = false;
	}

	if ($linkUp && $linkUpText) {
		echo '<div class="ph-top">'
		.'<a class="'.$this->s['c']['btn.btn-secondary'].'" title="'.$linkUpText.'" href="'. $linkUp.'" >'
        //.'<span class="'.$this->s['i']['back-category'].'"></span> '
		. PhocacartRenderIcon::icon($this->s['i']['back-category'], '', ' ')
		.Text::_($linkUpText).'</a>'
        .'</div>';
	}
}

echo $this->t['event']->onItemsBeforeHeader;

$title = '';
if (isset($this->category[0]->title) && $this->category[0]->title != '') {
	$title = $this->category[0]->title;
}
if(isset($_GET['manufacturer'])){
// Check if url has "manufacturer" in it 
$manufacturer = htmlspecialchars($_GET["manufacturer"]); 
// Using preg_replace to extract manufacturer ID
$manufacturerID = preg_replace('/[^0-9]/', '', $manufacturer);
// Connect to Database
$host = "********";
$user = "********";
$password = "********";
$db = "********";
$conn = new mysqli($host, $user, $password, $db);
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}
// Query database table
$sql = "SELECT title FROM ****_phocacart_manufacturers WHERE id = ($manufacturerID)";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
  while($row = $result->fetch_assoc()) {
// Display manufacturer title as page title
    echo PhocacartRenderFront::renderHeader(array($title,"All " .$row["title"]. " Products"), '', $this->t['image_items_view']);
  }
} else {
  echo "0 results";
}
$conn->close();
}
// Else display items title as page title
else {
	echo PhocacartRenderFront::renderHeader(array($title, Text::_('COM_PHOCACART_ITEMS')), '', $this->t['image_items_view']);
}

if ( isset($this->category[0]->description) && $this->category[0]->description != '') {
	echo '<div class="ph-desc">'. HTMLHelper::_('content.prepare', $this->category[0]->description). '</div>';
}
?>
It works but is there any way to clean up code regarding db connection as could not seem to get native Joomla! code to work other than making a new connection to the database, also would there be any thing else you would recommend changing in my above code?

Kind regards
Graham
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 49199
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Page Title As "Manufacturer Name" Instead Of "Items"

Post by Jan »

Hi, recommended is to debug all variables if there is no information about the manufacturer, I don't think, there will be no such variables. When there is no such information you need to ask database (when you call the database per joomla methods, the connection is ready yet, you only ask one new SQL query - mostly this is not something which significantly burdens the database because you are asking one simple information with exact rules)

Just ask the query with Joomla methods:

Code: Select all

// head of php file:
use Joomla\CMS\Factory;

// code
$db = Factory::getDBO();
$query = 'SELECT ...';
$db->setQuery( $query );
$item = $db->loadRow();
If you find Phoca extensions useful, please support the project
Post Reply