/** * Add an sql join in query between a table and its associated table in multi-shop * * @param string $table Table name (E.g. product, module, etc) * @param bool $inner_join * @param null $on * @param null $force_not_default * @internal param $alias * @return string */ public static function addSqlAssociation($table, $inner_join = true, $on = null, $force_not_default = null) { $db = JFactory::getDBO(); $table_alias = $table . '_shop'; if (strpos($table, '.') !== false) { list($table_alias, $table) = explode('.', $table); } if ($table == 'group') { $output_alias = 'grp'; } else { $output_alias = $table; } $associated_table = JeproshopShopModelShop::getAssociatedTable($table); if ($associated_table === false || $associated_table['type'] != 'shop') { return; } $query = ($inner_join ? " INNER " : " LEFT ") . "JOIN " . $db->quoteName('#__jeproshop_' . $table . '_shop') . " AS "; $query .= $table_alias . " ON( " . $table_alias . "." . $table . "_id = " . $output_alias . "." . $table . "_id"; if ((int) self::$context_shop_id) { $query .= " AND " . $table_alias . ".shop_id = " . (int) self::$context_shop_id; } elseif (JeproshopShopModelShop::checkDefaultShopId($table) && !$force_not_default) { $query .= " AND " . $table_alias . ".shop_id = " . $output_alias . ".default_shop_id"; } else { $query .= " AND " . $table_alias . ".shop_id IN (" . implode(', ', JeproshopShopModelShop::getContextListShopId()) . ")"; } $query .= ($on ? " AND " . $on : "") . ")"; return $query; }