Hi again,
I finally reduced the function to get an array of all wanted product fields entered in the SQL-Query. To complete the "How-To" I will post the steps I did to reach my goal:
Im using VM 1.1.6 and ChronoForms 3.2
First of all I wanted to have the the modified "ask question" link also in my browse pages. For this Ive needed to get the product_id there.
Open your shop.browse.php located in administrator/components/com_virtuemart/html/
Almost at the end go and find
$products[$i]['product_flypage'] = $url;
$products[$i]['contact_product_id'] = $contact_product_id;
$products[$i]['product_thumb_image'] = $product_thumb_image;
and insert
// Get Product-ID in browsing pages
$contact_product_id = $db_browse->f("product_id");
$products[$i]['product_flypage'] = $url;
$products[$i]['contact_product_id'] = $contact_product_id;
$products[$i]['product_thumb_image'] = $product_thumb_image;
After done this you can use
<?php echo $contact_product_id ?>
In your detail pages you can use
<?php echo $product_id ?>
Now create a link to you form and put the product ID at the end of the url:
index.php?option=com_chronocontact&chronoformname=yourform&product_id=<?php echo $contact_product_id ?>
Example with SEF-Urls:
http://www.domain.com/link/to/your/form?product_id=<?php echo $contact_product_id ?>
To get the necessary informations you need from your product we need to connect the VM tables:
Go to your form in Backend and put these lines on top of your form code:
<?php
function getProduct($id) {
$db = & JFactory::getDBO();
$query = 'SELECT product_name,product_s_desc,product_thumb_image FROM #__vm_product ' . ' WHERE product_id = ' . $id;
$db->setQuery($query);
$product_details = $db->loadRowList();
return $product_details;
}
if(isset($_GET["product_id"])){
$product = getProduct($_GET["product_id"]);
$product_name = $product['0']['0'];
$product_s_desc = $product['0']['1'];
$product_thumb_image = $product['0']['2'];
}
?>
If you have HTML-Tags within your product_s_desc or product_desc and dont need them in your E-Mail template you must strip them before the output or you will get problems in your input values:
echo strip_tags($product_s_desc);
Then fill the inputs with your vars:
<input type="hidden" name="productTitle" value="<? echo $product_name; ?>" />
<input type="hidden" name="productDesc" value="<? echo $product_s_desc; ?>" />
<input type="hidden" name="productThumb" value="<? echo $product_thumb_image; ?>" />
If you need a dynamic subject just like "I have a question to ..." just create a new hidden field
<input type="hidden" name="subject" value="I have a question to <? echo $product_name; ?>" />
and use the name of the field in your dynamic subject field.
Have fun🙂
Maybe one Admin can move this post to the "How-To-Section"?