Topic-icon Virtuemart: Creating all JFBCComments in parent product

Active Subscriptions:

None
I'm using a custom VM template which has the JFBCComments tag in it. I'm going to be selling photographic prints, and I want to set up one non-orderable parent product with a number of different child items for each different size of print.

Currently, when I choose a child item from the Generic Child Variant dropdown box, it goes to the child page which has its own set of comments and likes. How difficult would it be to have the parent and all child products share the same set of comments/likes? Is there a way to get the URL of the parent item so I can pass that as an href to JFBCComments?
The topic has been locked.
Support Specialist
If you already know what the parent URL is, you can just add that to the tag, like {JFBCComments href=http://site.com/parent-url}

That will make it so that any sub-product that that tag displays on will share the same comment URL as the parent and they will all display the same comments by users.

I hope that helps, but if you were looking for something different, just let me know.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
10 years 5 months ago #39141 by rammed
Well, that is the problem. I'm not sure how to programatically get the URL of the parent item. I'm sure there is some php function call in VM to return it, but I don't know how to find it.
The topic has been locked.
Support Specialist
Ahh.. Thanks for the explanation.

Can you post (or Private Message) me a link to a parent category and a few of it's children? From that, we can look at the URLs and may be be able to help you come up with something.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
10 years 5 months ago #39269 by rammed
I managed to figure it out. I don't really know php, but I managed to write a function that returns the long (non-sef) URL with the product ID as the parent, if one exists. I don't plan to have more levels of children than that, so it should work out okay.

Thanks for responding so quickly, though. Some of the other extension vendors are really bad at support.
The topic has been locked.
Support Specialist
Ramon,
Wow! Great job on getting that going! I'm glad to hear you dug in and figured it out. If you do run into any issues with the Virtuemart parent determination, feel free to post the code you came up with and we'll gladly let you know if we see any issues or have any improvements that may make things run a little smoother.

As always though, should you need anything else, or have any general questions, just let us know. It's what we're here for, and we take support very seriously.

Finally, if you haven't already, please consider leaving a rating and review for JFBConnect, or our support, on the Joomla Extension Directory. It certainly isn't required, but is very appreciated:
extensions.joomla.org/extensions/social-...ook-integration/7215

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
10 years 5 months ago - 10 years 5 months ago #39360 by rammed
So, I was wrong. I did end up wanting to do more than one level of children. So, I had to change my solution. Now I'm using database queries. Here is my code, in case anyone wants to do the same thing I'm doing.

Just put this code within a php tag near the top of the template override page you are editing:
global $CurrentItemID;
$CurrentItemID = $this->product->virtuemart_product_id;

function GetParentID($productId)
{
	$database = JFactory::getDBO();
	
	$query = "SELECT `p`.`product_parent_id`";
	$query .= " FROM `#__virtuemart_products` AS `p`";
	$query .= " WHERE `p`.`virtuemart_product_id` = '{$productId}'";
	
	$database->setQuery($query);
	$row = $database->loadObject();

	if (!$row) {
		return 0;
	}
	else {
		return $row->product_parent_id;
	}
}

function parentProductURL() {
	global $CurrentItemID;
	$ParentID = 0;
	$FirstPart = 'https://'.$_SERVER['SERVER_NAME'].'/index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=';
	$LastPart = "";

	$loop_ParentID = GetParentID($CurrentItemID);
	do {
		$ParentID = $loop_ParentID;
		$loop_ParentID = GetParentID($ParentID);
	} while ($loop_ParentID != 0);
	
	
	if ($ParentID == 0) {
		$LastPart = $CurrentItemID;
	} else {
		$LastPart = $ParentID;
	}
	return $FirstPart . $LastPart;
}

Then, wherever you want the JFBConnect modules to load, just use an href like this:
<?php echo '{JFBCComments href=' . parentProductURL() . '}'; ?>

It has to be inside php tags so it can run the function we defined earlier, so I'm guessing it wouldn't work if you added it as content to part of the page, but I haven't tried. I added it directly to the .php file of the productdetails template override of the Virtuemart template I'm using.

Also note, that I have it using https. If you're not using it, just change the $FirstPart = 'https://' to 'http://'
Last edit: 10 years 5 months ago by rammed.
The topic has been locked.
Support Specialist
Awesome! Thanks for the feedback on what's worked for you. The code looks reasonable and pretty clean. The one thing I'd highly suggest is cleaning, or at least using the built-in quoting call, the productId in the SQL query above. I'm assuming the cleaning has been done by Virtuemart somewhere along the way, but it never hurts to do it again.

* Cleaning makes sure that only an integer is really being passed to the SQL call.
* Using the db quote call ensures that someone doesn't use a URL with a ' in the product ID to corrupt the input to the database and run whatever they want.

Proper quoting:
$query .= " WHERE `p`.`virtuemart_product_id` = " . $database->q($productId);
I hope that helps, and best of luck to you!

Thanks,
Alex
The topic has been locked.