News:

Looking for documentation? Take a look on our wiki

Main Menu

Query to show category name of a product

Started by inkomico, June 08, 2014, 16:43:48 PM

Previous topic - Next topic

inkomico

Hi everyone!

I need to show the category name of a product in a query like this that show SKU:

$qGetSKU = 'select product_sku from #__virtuemart_products where virtuemart_product_id = '.$row['product_id'];
$dbj->setQuery($qGetSKU);
$SKUsrcstring = $dbj->loadResult();
echo $SKUsrcstring;


This is a very a simple query, but to show the category name I need to do some joins that I canĀ“t figure out.

I just know that joining the tables  #__virtuemart_products #__virtuemart_product_categories #__virtuemart_categories_pt_br I got my result.

Could you help me with this code?

GJC Web Design

$query = $db->getQuery(true);
$query->select($db->quoteName(array('a.virtuemart_category_id', 'b.category_name')));
$query->from($db->quoteName('#__virtuemart_product_categories',a));
$query->where($db->quoteName('a.virtuemart_product_id')." = ".$row['product_id']);
$query->join('INNER', $db->quoteName('#__virtuemart_categories_'.VMLANG, 'b') . ' ON (' . $db->quoteName('a.virtuemart_category_id') . ' = ' . $db->quoteName('b.virtuemart_category_id') . ')');
$db->setQuery($query);
$cats = $db->loadObject();
print 'Debug Line '.__LINE__.' $cats <pre>'; print_r ($cats); print "</pre><br />\n";


e.g.

Debug Line 182 $cats
stdClass Object
(
    [virtuemart_category_id] => 2
    [category_name] => Letter Weight Products
)
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

inkomico


PRO

where are you doing this at? product page?


inkomico