Thank you for your help, Nicolas.
Following your advice I moved MySQL request before foreach of the products and I replaced product_name with value.
Here is the code:
$query = 'SELECT * FROM '.hikashop_table('product').' WHERE product_access=\'all\' AND product_published=1 AND product_type=\'main\'';
if(!empty($plugin->params['fb-in_stock_only'])){
$query .= ' AND product_quantity!=0';
}
$db->setQuery($query);
$products = $db->loadObjectList();
if(empty($products)){
return true;
}
//=========================================
$queryNametr = "SELECT a.*"
. "\n FROM #__falang_content a"
. "\n INNER JOIN amkal_hikashop_product b "
. "\n ON a.reference_id = b.product_id "
. "\n WHERE language_id=".$plugin->params['fb_lang_id']
. "\n AND published=1"
. "\n AND reference_field = 'product_name'"
//. "\n AND reference_field = 'product_description'"
;
$db->setQuery($queryNametr);
$products = $db->loadObjectList();
//================================================== */
$ids = array();
foreach($products as $key => $row){
$ids[] = (int)$row->product_id;
if($plugin->params['fb_lang_id'] == 0){
$products[$key]->alias = JFilterOutput::stringURLSafe($row->product_name);
} else {
$products[$key]->alias = JFilterOutput::stringURLSafe($row->value);
}
}
In this case I receive the following SQL syntax error:
1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') AND a.category_published=1 AND a.category_type='product' AND b.category_id!=2 ' at line 1
If I upload the request before
$query = 'SELECT * FROM '.hikashop_table('product').' WHERE product_access=\'all\' AND product_published=1 AND product_type=\'main\'';
[CDATA[ '.$product->product_name.' ]] - the main language remains.
In order to test MySQL request, I return it back to its previous place and then naturally I receive all the translations names in <item> </item>
Here is the code:
$db->setQuery($queryNametr);
$products = $db->loadObjectList();
$ids = array();
foreach($products as $key => $row){
$ids[] = (int)$row->reference_id;
$products[$key]->alias = JFilterOutput::stringURLSafe($row->value);
$xml .= "\t".'<2g:title><![CDATA[ '.$row->value.' ]]></2g:title>'."\n";
}