/** * return the total quantity and Product name of product on the basis of the attribute * * @param $id * @param $attribute CSV of attribute properties, in numeric order * @return an array with the name and the quantity of Product; */ function getAvailableQuantity($id, $attribute) { Tienda::load('TiendaQuery', 'library.query'); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $tableQuantity = JTable::getInstance('ProductQuantities', 'TiendaTable'); $tableProduct = JTable::getInstance('Products', 'TiendaTable'); $tableProduct->load($id, true, false); if (empty($tableProduct->product_check_inventory)) { $tableProduct->quantity = '9999'; return $tableProduct; } $query = new TiendaQuery(); $select[] = "product.product_name"; $select[] = "quantities.quantity"; $select[] = "product.product_check_inventory"; $query->select($select); $query->from($tableProduct->getTableName() . " AS product"); $leftJoinCondition = $tableQuantity->getTableName() . " as quantities ON product.product_id = quantities.product_id "; $query->leftJoin($leftJoinCondition); $whereClause[] = "quantities.product_id = " . (int) $id; $whereClause[] = "quantities.product_attributes='" . $attribute . "'"; $whereClause[] = "product.product_check_inventory =1 "; $query->where($whereClause, "AND"); $db = JFactory::getDBO(); $db->setQuery((string) $query); $item = $db->loadObject(); if (empty($item)) { $return = new JObject(); $return->product_id = $id; $return->product_name = $tableProduct->product_name; $return->quantity = 0; $return->product_check_inventory = $tableProduct->product_check_inventory; return $return; } return $item; }