Massimiliano Gatto
I have resolved with this code:
try{
$jinput = JFactory::getApplication()->input;
$p_id = $jinput->get('virtuemart_product_id');
// The Category ID it should appear on, more on comment
$category_id = 165;
//$category_id2 = 78;
/**check if a product is in a category**/
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
$query->select('*');
$query->from($db->quoteName('#__virtuemart_product_categories'));
$query->where($db->quoteName('virtuemart_product_id') . ' LIKE ' . $db->quote($p_id).' AND '. $db->quoteName('virtuemart_category_id') .' LIKE '.$db->quote($category_id));
//for multiple categories use: $query->where($db->quoteName('virtuemart_product_id') . ' LIKE ' . $db->quote($p_id).' AND '. $db->quoteName('virtuemart_category_id') .' IN ('.$db->quote($category_id).','.$db->quote($category_id2).')');
$db->setQuery($query);
$results = $db->loadRowList();
foreach ($results as $row) {
return true;
}
return false;
}
catch(Exception $e){
return false;}