для Joomla 4 есть? 500 ошибка при вызове скрипта.
<?php
/**
* version 4
* author Sergey Bordyzhan (bordyzhan@gmail.com)
*
* Donate:
* Z272730060230 вебмани
* 410011118020069 Юmoney
*/
define('NAME', 'Название организации'); // название организации (не должно превышать 20 символов)
define('DESC', 'Описание организации'); // описание организации
define('CURRENCY', 'USD'); // валюта магазина (RUB, USD, EUR, UAH, KZT)
define('DELIVERY', 'false'); // наличие доставки в магазине (true - есть, false - нет)
define('EXCLUDE_CAT', '0'); // id категорий которые нужно исключить из выгрузки, перечислить через запятую, например define('EXCLUDE_CAT', '2,8,54,5')
define('EXCLUDE_PROD', '0'); // id товаров которые нужно исключить из выгрузки, перечислить через запятую, например define('EXCLUDE_PROD', '2,8,54,5')
define('FILE', 0); // 1 если нужно cоздать файл vm4_market.xml, 0 - выввод xml в браузер
define('_JEXEC', 1);
if (!defined('_JDEFINES'))
{
define('JPATH_BASE', dirname(__FILE__));
require_once JPATH_BASE . '/includes/defines.php';
}
require_once JPATH_BASE . '/includes/framework.php';
use \Joomla\CMS\Factory;
// Boot the DI container
$container = \Joomla\CMS\Factory::getContainer();
$container->alias('session.web', 'session.web.site')
->alias('session', 'session.web.site')
->alias('JSession', 'session.web.site')
->alias(\Joomla\CMS\Session\Session::class, 'session.web.site')
->alias(\Joomla\Session\Session::class, 'session.web.site')
->alias(\Joomla\Session\SessionInterface::class, 'session.web.site');
// Instantiate the application.
$app = $container->get(\Joomla\CMS\Application\SiteApplication::class);
// $session = $container->get(\Joomla\CMS\Session\Session::class);
// Set the application as global app
\Joomla\CMS\Factory::$application = $app;
$app->createExtensionNamespaceMap();
// $app->initialise();
require_once(JPATH_ADMINISTRATOR.'/components/com_virtuemart/helpers/config.php');
require_once(JPATH_ADMINISTRATOR.'/components/com_virtuemart/helpers/calculationh.php');
VmConfig::loadConfig();
require_once(JPATH_ADMINISTRATOR.'/components/com_virtuemart/models/product.php');
$model = new VirtueMartModelProduct();
$lang = VmConfig::$defaultLang;
$db = Factory::getContainer()->get('DatabaseDriver');
$live_site = trim(Joomla\CMS\Uri\Uri::root(), '/');
$calculator = calculationHelper::getInstance();
function getImages($id) {
global $db, $live_site;
$query = 'SELECT a.file_url FROM #__virtuemart_medias a JOIN #__virtuemart_product_medias b ON b.virtuemart_media_id = a.virtuemart_media_id WHERE a.published = 1 AND b.virtuemart_product_id = '.$id.' ORDER BY b.ordering, b.id LIMIT 10';
$db->setQuery($query);
$rows = $db->loadObjectList();
$media = '';
if ($rows) {
foreach ($rows as $row) {
$media .= '<picture>'.$live_site.'/'.htmlspecialchars(str_replace(' ', '%20', $row->file_url)).'</picture>'."\n";
}
}
return $media;
}
if (!FILE) {
ob_start('ob_gzhandler', 9);
header('Content-Type: application/xml; charset=utf-8');
} else {
header('Content-Type: text/html; charset=UTF-8');
}
$xml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
$xml .= '<yml_catalog date="'.date('Y-m-d H:i').'">'."\n";
$xml .= '<shop>'."\n";
$xml .= '<name>'.htmlspecialchars(NAME, 0, 20, 'UTF-8').'</name>'."\n";
$xml .= '<company>'.htmlspecialchars(DESC).'</company>'."\n";
$xml .= '<url>'.$live_site.'</url>'."\n";
$xml .= '<currencies>'."\n";
$xml .= '<currency id="'.CURRENCY.'" rate="1"/>'."\n";
$xml .= '</currencies>'."\n";
$xml .= '<categories>'."\n";
$query = 'SELECT a.category_parent_id, a.category_child_id, b.category_name FROM #__virtuemart_category_categories a RIGHT JOIN #__virtuemart_categories_'.$lang.' b ON b.virtuemart_category_id = a.category_child_id WHERE a.category_child_id NOT IN ('.EXCLUDE_CAT.') ORDER BY a.category_child_id';
$db->setQuery($query);
$rows = $db->loadObjectList();
$exclude_cat_arr = explode(',', EXCLUDE_CAT);
foreach ($rows as $row) {
$cat_parent_id = $row->category_parent_id;
$cat_child_id = $row->category_child_id;
$cat_name = htmlspecialchars(trim(strip_tags($row->category_name)));
if ($cat_parent_id == 0 || in_array($cat_parent_id, $exclude_cat_arr)) {
$xml .= '<category id="'.$cat_child_id.'">'.$cat_name.'</category>'."\n";
} else {
$xml .= '<category id="'.$cat_child_id.'" parentId="'.$cat_parent_id.'">'.$cat_name.'</category>'."\n";
}
}
$xml .= '</categories>'."\n";
$xml .= '<offers>'."\n";
$query = 'SELECT DISTINCT a.virtuemart_product_id, a.product_parent_id, a.product_sku, a.virtuemart_vendor_id, a.product_in_stock, b.product_name, b.product_desc, d.product_tax_id, d.product_discount_id, d.product_price, d.product_override_price, d.override, d.product_currency, e.mf_name, e.virtuemart_manufacturer_id, g.virtuemart_category_id FROM (#__virtuemart_product_categories g LEFT JOIN (#__virtuemart_product_prices d RIGHT JOIN ((#__virtuemart_product_manufacturers f RIGHT JOIN #__virtuemart_products a ON f.virtuemart_product_id = a.virtuemart_product_id) LEFT JOIN #__virtuemart_manufacturers_'.$lang.' e ON f.virtuemart_manufacturer_id = e.virtuemart_manufacturer_id LEFT JOIN #__virtuemart_products_'.$lang.' b ON b.virtuemart_product_id = a.virtuemart_product_id) ON d.virtuemart_product_id = a.virtuemart_product_id) ON g.virtuemart_product_id = a.virtuemart_product_id) WHERE a.published = 1 AND d.product_price > 0 AND b.product_name <> \'\' AND g.virtuemart_category_id NOT IN ('.EXCLUDE_CAT.') AND a.virtuemart_product_id NOT IN ('.EXCLUDE_PROD.') GROUP BY a.virtuemart_product_id';
$db->setQuery($query);
$rows = $db->loadObjectList();
foreach ($rows as $row) {
$product_name = htmlspecialchars(trim(strip_tags($row->product_name)));
$product_id = $row->virtuemart_product_id;
$product_cat_id = $row->virtuemart_category_id;
$row->categories = array($product_cat_id);
$model->getRawProductPrices($row, 0, array(1), 1);
$prices = $calculator->getProductPrices($row);
$type = $row->mf_name ? ' type="vendor.model"' : '';
$url = $live_site.JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id='.$product_id.'&virtuemart_category_id='.$product_cat_id);
//$available = $row->product_in_stock > 0 ? 'true' : 'false';
//$xml .= '<offer'.$type.' id="'.$product_id.'" available="'.$available.'">'."\n";
$xml .= '<offer'.$type.' id="'.$product_id.'" available="true">'."\n";
$xml .= '<url>'.$url.'</url>'."\n";
$xml .= '<price>'.$prices['salesPrice'].'</price>'."\n";
$xml .= '<currencyId>'.CURRENCY.'</currencyId>'."\n";
$xml .= '<categoryId>'.$product_cat_id.'</categoryId>'."\n";
$xml .= getImages($product_id);
$xml .= '<delivery>'.DELIVERY.'</delivery>'."\n";
if ($row->mf_name) {
$xml .= '<vendor>'.htmlspecialchars($row->mf_name).'</vendor>'."\n";
$xml .= '<model>'.$product_name.'</model>'."\n";
} else {
$xml .= '<name>'.$product_name.'</name>'."\n";
}
//$xml .= '<vendorCode>'.htmlspecialchars($row->product_sku).'</vendorCode>';
if ($row->product_desc) {
$xml .= '<description><![CDATA['.$row->product_desc.']]></description>'."\n";
}
$xml .= '</offer>'."\n";
}
$xml .= '</offers>'."\n";
$xml .= '</shop>'."\n";
$xml .= '</yml_catalog>';
if (FILE) {
$xml_file = fopen('vm4_market.xml', 'w+');
if (!$xml_file) {
echo 'Ошибка открытия файла';
} else {
ftruncate($xml_file, 0);
fputs($xml_file, $xml);
echo 'Файл создан, url - <a href="'.$live_site.'/vm4_market.xml">'.$live_site.'/vm4_market.xml</a>';
}
fclose($xml_file);
} else {
echo $xml;
}