VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: OliviaH on April 21, 2016, 16:58:06 PM

Title: Getting child products ID's
Post by: OliviaH on April 21, 2016, 16:58:06 PM
How would I go about retrieving the product Id's of a parent products child products.
Is there already a variable that contains this data, or would it have to be retrieved from the database?

Joomla 3.0.12
Virtuemart 3.4.8
PHP 5.6.20
Title: Re: Getting child products ID's
Post by: GJC Web Design on April 21, 2016, 17:12:14 PM
in  administrator\components\com_virtuemart\models\product.php

function getProductChildIds ($product_id) {

      if (empty($product_id)) {
         return array();
      }
      $db = JFactory::getDBO ();
      $db->setQuery (' SELECT virtuemart_product_id FROM `#__virtuemart_products` WHERE `product_parent_id` =' . (int)$product_id.' ORDER BY pordering, created_on ASC');

      return $db->loadColumn ();

   }

so something like


$productModel = VmModel::getModel('Product');

$products = $productModel->getProductChildIds( $product_id);