This commit is contained in:
2025-04-01 00:38:54 +02:00
parent d4d4c0c09d
commit 87da06293a
22351 changed files with 5168854 additions and 7538 deletions

View File

@@ -0,0 +1,81 @@
<?php
/**
* 2010-2023 Bl Modules.
*
* If you wish to customize this module for your needs,
* please contact the authors first for more information.
*
* It's not allowed selling, reselling or other ways to share
* this file or any other module files without author permission.
*
* @author Bl Modules
* @copyright 2010-2023 Bl Modules
* @license
*/
class BrandXmlApi
{
protected $settings = array();
protected $feedLangId = 1;
protected $protocol = '';
public function getFeed($settings, $protocol)
{
$this->settings = $settings;
$this->feedLangId = (int)Configuration::get('PS_LANG_DEFAULT');
$this->protocol = $protocol;
return $this->generateXml($this->getBrands());
}
protected function generateXml($brands)
{
$xml = '<items>';
if (empty($brands)) {
return '</items>';
}
$link = new Link();
$addImage = method_exists($link, 'getManufacturerImageLink');
foreach ($brands as $b) {
if ($addImage) {
$logoUrl = $link->getManufacturerImageLink($b['id_manufacturer']);
if (!empty($logoUrl) && Tools::substr($logoUrl, 0, 4) != 'http') {
$logoUrl = $this->protocol . $logoUrl;
}
}
$xml .= '<item>';
$xml .= '<id><![CDATA['.$b['id_manufacturer'].']]></id>';
$xml .= '<name><![CDATA['.$b['name'].']]></name>';
$xml .= '<url><![CDATA[' . $link->getManufacturerLink($b['id_manufacturer'], null, (int)$this->feedLangId) . ']]></url>';
$xml .= '<date_add><![CDATA['.$b['date_add'].']]></date_add>';
$xml .= '<date_upd><![CDATA['.$b['date_upd'].']]></date_upd>';
$xml .= '<description><![CDATA['.strip_tags($b['description']).']]></description>';
$xml .= '<short_description><![CDATA['.strip_tags($b['short_description']).']]></short_description>';
$xml .= !empty($logoUrl) ? '<logo><![CDATA['.$logoUrl.']]></logo>' : '';
$xml .= '<active><![CDATA['.$b['active'].']]></active>';
$xml .= '</item>';
}
$xml .= '</items>';
return $xml;
}
protected function getBrands()
{
return Db::getInstance()->ExecuteS('
SELECT m.*, l.description, l.short_description
FROM '._DB_PREFIX_.'manufacturer m
LEFT JOIN '._DB_PREFIX_.'manufacturer_lang l ON
(l.id_manufacturer = m.id_manufacturer AND l.id_lang = "'.(int)$this->feedLangId.'")
WHERE m.`active` = 1
ORDER BY m.name ASC
');
}
}

View File

@@ -0,0 +1,237 @@
<?php
/**
* 2010-2023 Bl Modules.
*
* If you wish to customize this module for your needs,
* please contact the authors first for more information.
*
* It's not allowed selling, reselling or other ways to share
* this file or any other module files without author permission.
*
* @author Bl Modules
* @copyright 2010-2023 Bl Modules
* @license
*/
class CategoryXmlApi
{
public function getFeed($id = 0,
$pref_s = '',
$pref_e = '',
$html_tags_status = false,
$extra_feed_row = false,
$one_branch = false,
$only_enabled = false,
$multistoreString = false,
$settings = []
) {
$block_name = array();
$xml_name = array();
$xml_name_l = array();
$all_l_iso = array();
$id_lang = Configuration::get('PS_LANG_DEFAULT');
$categoryTreeSeparator = !empty($settings['category_tree_separator']) ? $settings['category_tree_separator'] : ' > ';
$toolsR = new ReflectionMethod('Tools', 'getPath');
$totalGetPathMethods = $toolsR->getNumberOfRequiredParameters();
$block_n = Db::getInstance()->ExecuteS('SELECT `name`, `value`
FROM '._DB_PREFIX_.'blmod_xml_block
WHERE category = "'.(int)$id.'"');
foreach ($block_n as $bn) {
$block_name[$bn['name']] = $bn['value'];
}
$r = Db::getInstance()->ExecuteS('SELECT `name`, `status`, `title_xml`, `table`
FROM '._DB_PREFIX_.'blmod_xml_fields
WHERE category = "'.(int)$id.'" AND `table` != "lang" AND `table` != "category_lang" AND status = 1
AND `table` != "bl_extra"
ORDER BY `table` ASC');
$extra_field = Db::getInstance()->ExecuteS('SELECT `name`, `title_xml`, CONCAT(`table`, "_", `name`) AS field_key
FROM '._DB_PREFIX_.'blmod_xml_fields
WHERE category = "'.(int)$id.'" AND `table` = "bl_extra" AND status = 1');
$field = '';
if (!empty($r)) {
foreach ($r as $f) {
$field .= ' `'._DB_PREFIX_.$f['table'].'`.`'.$f['name'].'` AS '.$f['table'].'_'.$f['name'].' ,';
$xml_name[$f['table'].'_'.$f['name']] = $f['title_xml'];
}
if (empty($field)) {
exit;
}
$field = ','.trim($field, ',');
}
$where_only_actyve = '';
if (!empty($only_enabled)) {
$where_only_actyve = 'WHERE '._DB_PREFIX_.'category.active = "1"';
}
if (!empty($multistoreString)) {
if (empty($where_only_actyve)) {
$where_only_actyve = 'WHERE '._DB_PREFIX_.'category.id_shop_default IN ('.(int)$multistoreString.')';
} else {
$where_only_actyve .= ' AND '._DB_PREFIX_.'category.id_shop_default IN ('.(int)$multistoreString.')';
}
}
$sql = 'SELECT DISTINCT('._DB_PREFIX_.'category.id_category) AS cat_id '.pSQL($field).'
FROM '._DB_PREFIX_.'category
LEFT JOIN '._DB_PREFIX_.'category_group ON
'._DB_PREFIX_.'category_group.id_category = '._DB_PREFIX_.'category.id_category '.
$where_only_actyve;
$xml_d = Db::getInstance()->ExecuteS($sql);
//Language
$l = Db::getInstance()->ExecuteS('SELECT `name`
FROM '._DB_PREFIX_.'blmod_xml_fields
WHERE category = "'.(int)$id.'" AND `table` = "lang"');
$xml_lf = array();
$link_class = new Link();
if (!empty($l)) {
$l_where = '';
$count_lang = count($l);
foreach ($l as $ll) {
$l_where .= 'OR '._DB_PREFIX_.'category_lang.id_lang='.(int)$ll['name'].' ';
}
$l_where = trim($l_where, 'OR');
$rl = Db::getInstance()->ExecuteS('SELECT `name`, `status`, `title_xml`
FROM '._DB_PREFIX_.'blmod_xml_fields
WHERE category = "'.(int)$id.'" AND `table` = "category_lang" AND `status` = 1');
$field = '';
if (!empty($rl)) {
foreach ($rl as $fl) {
$field .= ' `'._DB_PREFIX_.'category_lang`.`'.$fl['name'].'`,';
$xml_name_l[$fl['name']] = $fl['title_xml'];
}
$field = ','.trim($field, ',');
}
$xml_l = Db::getInstance()->ExecuteS('SELECT '._DB_PREFIX_.'category_lang.id_category, '._DB_PREFIX_.'lang.iso_code as blmodxml_l '.pSQL($field).'
FROM '._DB_PREFIX_.'category_lang
LEFT JOIN '._DB_PREFIX_.'lang ON
'._DB_PREFIX_.'lang.id_lang = '._DB_PREFIX_.'category_lang.id_lang
WHERE '.$l_where.'
ORDER BY '._DB_PREFIX_.'category_lang.id_category ASC');
foreach ($xml_l as $xll) {
$id_cat = $xll['id_category'];
$l_iso = $xll['blmodxml_l'];
$all_l_iso[] = $l_iso;
$lang_prefix = '-'.$l_iso;
if ($count_lang < 2) {
$id_lang = $l[0]['name'];
$lang_prefix = '';
}
if (empty($one_branch)) {
$xml_lf[$id_cat.$l_iso] = '<'.$block_name['desc-block-name'].$lang_prefix.'>';
} else {
$xml_lf[$id_cat.$l_iso] = '';
}
foreach ($xll as $idl => $vall) {
if ($idl == 'id_category' || $idl == 'blmodxml_l') {
continue;
}
$vall = isset($vall) ? $vall : false;
if ($html_tags_status) {
$vall = strip_tags($vall);
}
$xml_lf[$id_cat.$l_iso] .= '<'.$xml_name_l[$idl].$lang_prefix.'>'.$pref_s.htmlspecialchars($vall).$pref_e.'</'.$xml_name_l[$idl].$lang_prefix.'>';
}
if (empty($one_branch)) {
$xml_lf[$id_cat.$l_iso] .= '</'.$block_name['desc-block-name'].$lang_prefix.'>';
}
}
$all_l_iso = array_unique($all_l_iso);
}
$xml = '<'.$block_name['file-name'].'>';
$xml .= $extra_feed_row;
foreach ($xml_d as $xdd) {
$xml .= '<'.$block_name['cat-block-name'].'>';
foreach ($xdd as $id => $val) {
if ($id == 'cat_id') {
continue;
}
$val = isset($val) ? $val : false;
$xml .= '<'.$xml_name[$id].'>'.$pref_s.$val.$pref_e.'</'.$xml_name[$id].'>';
}
$id_cat = $xdd['cat_id'];
if (!empty($all_l_iso)) {
foreach ($all_l_iso as $iso) {
$xml_lf[$id_cat.$iso] = isset($xml_lf[$id_cat.$iso]) ? $xml_lf[$id_cat.$iso] : false;
$xml .= $xml_lf[$id_cat.$iso];
}
}
if (!empty($extra_field)) {
foreach ($extra_field as $b_e) {
if ($b_e['name'] == 'category_url_blmod') {
$xml .= '<'.$b_e['title_xml'].'>'.$pref_s.$link_class->getCategoryLink($id_cat, null, $id_lang).$pref_e.'</'.$b_e['title_xml'].'>';
}
if ($b_e['name'] == 'product_categories_tree') {
$xml .= '<'.$b_e['title_xml'].'>'.$pref_s.$this->getTree($totalGetPathMethods, $id_cat, $categoryTreeSeparator, $id_lang).$pref_e.'</'.$b_e['title_xml'].'>';
}
}
}
$xml .= '</'.$block_name['cat-block-name'].'>';
}
$xml .= '</'.$block_name['file-name'].'>';
return $xml;
}
public function getTree($totalGetPathMethods, $categoryId, $separator, $langId)
{
$path = '';
if ($totalGetPathMethods == 2) {
$path = Tools::getPath('', $categoryId);
} elseif ($totalGetPathMethods == 1) {
$path = Tools::getPath($categoryId);
}
$path = htmlspecialchars_decode(strip_tags($path), ENT_QUOTES);
$fullPath = str_replace('>', $separator, $path);
if (!empty($fullPath)) {
return $fullPath;
}
$category = new Category($categoryId, $langId);
return $category->name;
}
}

View File

@@ -0,0 +1,72 @@
<?php
/**
* 2010-2023 Bl Modules.
*
* If you wish to customize this module for your needs,
* please contact the authors first for more information.
*
* It's not allowed selling, reselling or other ways to share
* this file or any other module files without author permission.
*
* @author Bl Modules
* @copyright 2010-2023 Bl Modules
* @license
*/
class CustomerXmlApi
{
protected $settings = array();
protected $feedLangId = 1;
public function getFeed($settings)
{
$this->settings = $settings;
$this->feedLangId = (int)Configuration::get('PS_LANG_DEFAULT');
return $this->generateXml($this->getCustomers());
}
protected function generateXml($customers)
{
$xml = '<items>';
if (empty($customers)) {
return '</items>';
}
foreach ($customers as $b) {
$xml .= '<item>';
$xml .= '<id><![CDATA['.$b['id_customer'].']]></id>';
$xml .= '<id_gender><![CDATA['.$b['id_gender'].']]></id_gender>';
$xml .= '<social_title><![CDATA['.$b['social_title'].']]></social_title>';
$xml .= '<firstname><![CDATA['.$b['firstname'].']]></firstname>';
$xml .= '<lastname><![CDATA['.$b['lastname'].']]></lastname>';
$xml .= '<email><![CDATA['.$b['email'].']]></email>';
$xml .= '<birthday><![CDATA['.$b['birthday'].']]></birthday>';
$xml .= '<newsletter><![CDATA['.$b['newsletter'].']]></newsletter>';
$xml .= '<newsletter_date_add><![CDATA['.$b['newsletter_date_add'].']]></newsletter_date_add>';
$xml .= '<website><![CDATA['.$b['website'].']]></website>';
$xml .= '<is_guest><![CDATA['.$b['is_guest'].']]></is_guest>';
$xml .= '<date_add><![CDATA['.$b['date_add'].']]></date_add>';
$xml .= '<date_upd><![CDATA['.$b['date_upd'].']]></date_upd>';
$xml .= '<active><![CDATA['.$b['active'].']]></active>';
$xml .= '</item>';
}
$xml .= '</items>';
return $xml;
}
protected function getCustomers()
{
return Db::getInstance()->ExecuteS('
SELECT c.*, gl.name AS social_title
FROM '._DB_PREFIX_.'customer c
LEFT JOIN '._DB_PREFIX_.'gender_lang gl ON
(c.id_gender = gl.id_gender AND gl.id_lang = "'.(int)$this->feedLangId.'")
WHERE c.`deleted` = 0
ORDER BY c.date_add DESC
');
}
}

View File

@@ -0,0 +1,524 @@
<?php
/**
* 2010-2023 Bl Modules.
*
* If you wish to customize this module for your needs,
* please contact the authors first for more information.
*
* It's not allowed selling, reselling or other ways to share
* this file or any other module files without author permission.
*
* @author Bl Modules
* @copyright 2010-2023 Bl Modules
* @license
*/
class OrderXmlApi
{
protected $feedId = 0;
protected $settings = array();
protected $fieldsName = array();
protected $fieldsNameAdditionTable = array();
protected $feedLangId = 1;
protected $countryList = array();
protected $stateList = array();
protected $branchNames = array();
protected $prefixStart = '';
protected $prefixEnd = '';
protected $currency = false;
protected $totalProducts = 0;
public function getFeed($settings)
{
$this->settings = $settings;
$this->feedLangId = (int)Configuration::get('PS_LANG_DEFAULT');
$this->feedId = (int)$settings['id'];
$this->currency = Currency::getCurrency(!empty($settings['currency_id']) ? $settings['currency_id'] : Configuration::get('PS_CURRENCY_DEFAULT'));
$this->branchNames = $this->getBranchNames();
$this->loadAddressData();
$orders = $this->getOrders();
return $this->generateXml($orders);
}
protected function generateXml($orders)
{
$xml = $this->getDeepTagName($this->branchNames['orders-branch-name']);
if (!empty($this->settings['extra_feed_row'])) {
$xml .= $this->settings['extra_feed_row'];
}
if (!empty($this->settings['cdata_status'])) {
$this->prefixStart = '<![CDATA[';
$this->prefixEnd = ']]>';
}
foreach ($orders as $order) {
$xmlOrder = $this->getDeepTagName($this->branchNames['order-branch-name']);
$productsBranch = $this->generateXmlAddProducts($order['order_id']);
foreach ($order as $id => $val) {
if (empty($this->fieldsName[$id])) {
continue;
}
if ($this->isPriceField($id)) {
$val = $this->getPriceFormat($val);
}
$xmlOrder .= $this->getDeepTagName($this->fieldsName[$id]).$this->prefixStart.$val.$this->prefixEnd.$this->getDeepTagName($this->fieldsName[$id], true);
}
foreach ($this->fieldsName as $fieldId => $fieldName) {
if (strpos($fieldId, 'bl_extra_') !== 0) {
continue;
}
$method = 'extraField'.str_replace(' ', '', ucwords(str_replace(array('bl_extra_', '_'), array('', ' '), $fieldId)));
$xmlOrder .= $this->getDeepTagName($fieldName).$this->$method($order).$this->getDeepTagName($fieldName, true);
}
$xml .= $this->replaceXmlTree($xmlOrder);
$xml .= $productsBranch;
$xml .= $this->getDeepTagName($this->branchNames['order-branch-name'], true);
}
$xml .= $this->getDeepTagName($this->branchNames['orders-branch-name'], true);
return $xml;
}
protected function generateXmlAddProducts($orderId)
{
$xml = '';
$this->totalProducts = 0;
if (empty($this->fieldsNameAdditionTable['od'])) {
return $xml;
}
$products = $this->getProducts($orderId);
if (!empty($products)) {
$this->totalProducts = count($products);
$xml = $this->getDeepTagName($this->branchNames['products-branch-name']);
foreach ($products as $product) {
$xml .= $this->getDeepTagName($this->branchNames['product-branch-name']);
$xmlOrder = '';
foreach ($product as $id => $val) {
if ($this->isPriceField($id)) {
$val = $this->getPriceFormat($val);
}
if ($this->isNumberField($id)) {
$val = $this->getNumberFormat($val);
}
$xmlOrder .= $this->getDeepTagName($this->fieldsName[$id]).$this->prefixStart.$val.$this->prefixEnd.$this->getDeepTagName($this->fieldsName[$id], true);
}
$xml .= $this->replaceXmlTree($xmlOrder);
$xml .= $this->getDeepTagName($this->branchNames['product-branch-name'], true);
}
$xml .= $this->getDeepTagName($this->branchNames['products-branch-name'], true);
}
return $xml;
}
protected function getOrders()
{
$field = $this->getFields();
return Db::getInstance()->ExecuteS('SELECT DISTINCT(o.id_order) AS order_id, ad.address1, ad.address2, ad.postcode, ad.city, ad.id_country, ad.id_state,
ad.company, ad.phone, ad.phone_mobile, ad.vat_number, ad.firstname AS firstname_d, ad.lastname AS lastname_d,
ai.address1 AS address1_i, ai.address2 AS address2_i, ai.postcode AS postcode_i, ai.city AS city_i,
ai.id_country AS id_country_i, ai.id_state AS id_state_i,
ai.company AS company_i, ai.phone AS phone_i, ai.phone_mobile AS phone_mobile_i, ai.vat_number AS vat_number_i,
ai.firstname AS firstname_i, ai.lastname AS lastname_i, o.total_paid_tax_excl AS total_paid_t_e,
o.total_paid_tax_incl AS total_paid_t_i'.pSQL($field).'
FROM '._DB_PREFIX_.'orders o
LEFT JOIN '._DB_PREFIX_.'order_state_lang sl ON
(sl.id_order_state = o.current_state AND sl.id_lang = "'.(int)$this->feedLangId.'")
LEFT JOIN '._DB_PREFIX_.'customer c ON
c.`id_customer` = o.`id_customer`
LEFT JOIN '._DB_PREFIX_.'address ad ON
ad.id_address = o.id_address_delivery
LEFT JOIN '._DB_PREFIX_.'address ai ON
ai.id_address = o.id_address_invoice
LEFT JOIN '._DB_PREFIX_.'carrier cr ON
cr.id_carrier = o.id_carrier'.$this->getOrdersFilter());
}
protected function getOrdersFilter()
{
$where = array();
if (!empty($this->settings['order_state_status']) && !empty($this->settings['order_state'])) {
$where[] = 'sl.id_order_state IN ('.pSQL($this->settings['order_state']).')';
}
if (!empty($this->settings['order_payments_status']) && !empty($this->settings['order_payment'])) {
$where[] = 'o.module IN ("'.str_replace(',', '","', pSQL($this->settings['order_payment'])).'")';
}
if (!empty($this->settings['filter_date_type'])) {
$dateToday = pSQL(date('Y-m-d').' 00:00:00');
$filterByDate = array(
OrderSettings::FILTER_DATE_NONE => '',
OrderSettings::FILTER_DATE_TODAY => 'o.date_add >= "'.pSQL($dateToday).'"',
OrderSettings::FILTER_DATE_YESTERDAY => 'o.date_add >= "'.pSQL(date('Y-m-d', strtotime('-1 day', strtotime($dateToday)))).' 00:00:00" AND o.date_add < "'.pSQL($dateToday).'"',
OrderSettings::FILTER_DATE_THIS_WEEK => 'o.date_add >= "'.pSQL(date('Y-m-d', strtotime('this week', time()))).' 00:00:00"',
OrderSettings::FILTER_DATE_THIS_MONTH => 'o.date_add >= "'.pSQL(date('Y-m-01')).' 00:00:00"',
OrderSettings::FILTER_DATE_THIS_YEAR => 'o.date_add >= "'.pSQL(date('Y-01-01')).' 00:00:00"',
OrderSettings::FILTER_DATE_CUSTOM_DAYS => 'o.date_add >= "'.pSQL(date('Y-m-d', strtotime('-'.(int)$this->settings['filter_custom_days'].' day', strtotime($dateToday)))).' 00:00:00"',
OrderSettings::FILTER_DATE_DATE_RANGE => 'o.date_add >= "'.pSQL($this->settings['filter_date_from']).' 00:00:00" AND o.date_add <= "'.pSQL($this->settings['filter_date_to']).' 23:59:59" ',
);
$where[] = $filterByDate[$this->settings['filter_date_type']];
}
return !empty($where) ? ' WHERE '.implode(' AND ', $where) : '';
}
protected function getProducts($orderId)
{
return Db::getInstance()->ExecuteS('
SELECT '.pSQL(trim($this->fieldsNameAdditionTable['od'], ',')).'
FROM '._DB_PREFIX_.'order_detail od
LEFT JOIN '._DB_PREFIX_.'product p ON
p.`id_product` = od.`product_id`
LEFT JOIN '._DB_PREFIX_.'order_detail_tax dt ON
dt.id_order_detail = od.id_order_detail
LEFT JOIN '._DB_PREFIX_.'tax t ON
t.id_tax = dt.id_tax
WHERE od.id_order = "'.(int)$orderId.'"
ORDER BY od.id_order_detail ASC');
}
protected function getFields()
{
$fields = Db::getInstance()->ExecuteS('SELECT `name`, `status`, `title_xml`, `table`
FROM '._DB_PREFIX_.'blmod_xml_fields
WHERE category = "'.(int)$this->feedId.'" AND status = "1"
ORDER BY `table` ASC');
$field = '';
$tableMap = array(
'orders' => 'o',
'order_state_lang' => 'sl',
'customer' => 'c',
'order_detail' => 'od',
'address' => 'ad',
'product' => 'p',
'tax' => 't',
'carrier' => 'cr',
);
if (!empty($fields)) {
foreach ($fields as $f) {
$this->fieldsName[$f['table'].'_'.$f['name']] = $f['title_xml'];
if ($f['table'] == 'bl_extra') {
continue;
}
$table = $tableMap[$f['table']];
if ($f['table'] == 'order_detail' || $f['table'] == 'product' || $f['table'] == 'tax') {
if (empty($this->fieldsNameAdditionTable['od'])) {
$this->fieldsNameAdditionTable['od'] = '';
}
$this->fieldsNameAdditionTable['od'] .= $table.'.`'.$f['name'].'` AS '.$f['table'].'_'.$f['name'].',';
continue;
}
$field .= $table.'.`'.$f['name'].'` AS '.$f['table'].'_'.$f['name'].',';
}
if (empty($field)) {
return '';
}
$field = ','.trim($field, ',');
}
return $field;
}
protected function extraFieldAddress($order, $prefix = '')
{
$final = array();
$final[] = $order['address1'.$prefix];
$final[] = $order['address2'.$prefix];
$final[] = $order['postcode'.$prefix];
$final[] = $order['city'.$prefix];
$final[] = !empty($this->stateList[$order['id_country'.$prefix]][$order['id_state'.$prefix]]) ? $this->stateList[$order['id_country'.$prefix]][$order['id_state'.$prefix]] : '';
$final[] = $order['postcode'.$prefix];
return implode(' ', array_filter($final)).(!empty($this->countryList[$order['id_country'.$prefix]]) ? ', '.$this->countryList[$order['id_country'.$prefix]] : '');
}
protected function extraFieldDeliveryAddress($order)
{
$country = !empty($this->countryList[$order['id_country']]) ? $this->countryList[$order['id_country']] : '';
return '<firstname>'.$this->prefixStart.$order['firstname_d'].$this->prefixEnd.'</firstname>
<lastname>'.$this->prefixStart.$order['lastname_d'].$this->prefixEnd.'</lastname>
<company>'.$this->prefixStart.$order['company'].$this->prefixEnd.'</company>
<vat_number>'.$this->prefixStart.$order['vat_number'].$this->prefixEnd.'</vat_number>
<address_line1>'.$this->prefixStart.$order['address1'].$this->prefixEnd.'</address_line1>
<address_line2>'.$this->prefixStart.$order['address2'].$this->prefixEnd.'</address_line2>
<post_code>'.$this->prefixStart.$order['postcode'].$this->prefixEnd.'</post_code>
<city>'.$this->prefixStart.$order['city'].$this->prefixEnd.'</city>
<country>'.$this->prefixStart.$country.$this->prefixEnd.'</country>
<phone>'.$this->prefixStart.$order['phone'].$this->prefixEnd.'</phone>
<phone_mobile>'.$this->prefixStart.$order['phone_mobile'].$this->prefixEnd.'</phone_mobile>';
}
protected function extraFieldInvoiceAddress($order)
{
$country = !empty($this->countryList[$order['id_country_i']]) ? $this->countryList[$order['id_country_i']] : '';
return '<firstname>'.$this->prefixStart.$order['firstname_i'].$this->prefixEnd.'</firstname>
<lastname>'.$this->prefixStart.$order['lastname_i'].$this->prefixEnd.'</lastname>
<company>'.$this->prefixStart.$order['company_i'].$this->prefixEnd.'</company>
<vat_number>'.$this->prefixStart.$order['vat_number_i'].$this->prefixEnd.'</vat_number>
<address_line1>'.$this->prefixStart.$order['address1_i'].$this->prefixEnd.'</address_line1>
<address_line2>'.$this->prefixStart.$order['address2_i'].$this->prefixEnd.'</address_line2>
<post_code>'.$this->prefixStart.$order['postcode_i'].$this->prefixEnd.'</post_code>
<city>'.$this->prefixStart.$order['city_i'].$this->prefixEnd.'</city>
<country>'.$this->prefixStart.$country.$this->prefixEnd.'</country>
<phone>'.$this->prefixStart.$order['phone_i'].$this->prefixEnd.'</phone>
<phone_mobile>'.$this->prefixStart.$order['phone_mobile_i'].$this->prefixEnd.'</phone_mobile>';
}
protected function extraFieldCountry($order)
{
return (!empty($this->countryList[$order['id_country']]) ? $this->countryList[$order['id_country']] : '');
}
protected function extraFieldCity($order)
{
return !empty($order['city']) ? $order['city'] : '';
}
protected function extraFieldPostcode($order)
{
return !empty($order['postcode']) ? $order['postcode'] : '';
}
protected function extraFieldCurrency($order)
{
return !empty($this->currency['iso_code']) ? $this->currency['iso_code'] : '';
}
protected function extraFieldTaxTotalAmount($order)
{
return $this->getPriceFormat($order['total_paid_t_i'] - $order['total_paid_t_e']);
}
protected function extraFieldCustomerMessage($order)
{
return $this->getMessagesBranch($order['order_id']);
}
protected function extraFieldEmployeeMessage($order)
{
return $this->getMessagesBranch($order['order_id'], false);
}
protected function extraFieldVatNumberInvoice($order)
{
return !empty($order['vat_number_i']) ? $order['vat_number_i'] : '';
}
protected function extraFieldTotalProducts($order)
{
if (!empty($this->totalProducts)) {
return $this->totalProducts;
}
return Db::getInstance()->getValue('SELECT COUNt(od.id_order_detail)
FROM '._DB_PREFIX_.'order_detail od
WHERE od.id_order = '.(int)$order['order_id']);
}
protected function loadAddressData()
{
$countries = Db::getInstance()->ExecuteS('SELECT id_country, `name`
FROM `'._DB_PREFIX_.'country_lang`
WHERE `id_lang` = '.(int)$this->feedLangId);
foreach ($countries as $c) {
$this->countryList[$c['id_country']] = $c['name'];
}
$states = Db::getInstance()->ExecuteS('SELECT id_state, id_country, `name`
FROM `'._DB_PREFIX_.'state`');
foreach ($states as $s) {
$this->stateList[$s['id_country']][$s['id_state']] = $s['name'];
}
}
protected function getMessagesBranch($orderId, $isCustomerMessages = true)
{
$xml = '';
$where = $isCustomerMessages ? '=' : '>';
$messages = Db::getInstance()->ExecuteS('SELECT ct.id_customer_thread, cm.`message`, cm.`date_add`, cm.`private`
FROM '._DB_PREFIX_.'customer_thread ct
LEFT JOIN '._DB_PREFIX_.'customer_message cm ON
cm.id_customer_thread = ct.id_customer_thread
WHERE ct.id_order = '.(int)$orderId.' AND cm.`id_employee` '.pSQL($where).' 0
ORDER BY cm.id_customer_message DESC');
if (!empty($messages)) {
foreach ($messages as $m) {
$xml .= '<message>';
$xml .= '<text>'.$this->prefixStart.$m['message'].$this->prefixEnd.'</text>';
$xml .= '<date_add>'.$this->prefixStart.$m['date_add'].$this->prefixEnd.'</date_add>';
$xml .= '<is_private>'.$this->prefixStart.$m['private'].$this->prefixEnd.'</is_private>';
$xml .= '</message>';
}
}
return $xml;
}
protected function getBranchNames()
{
$branchNamesKey = array();
$branchNames = Db::getInstance()->ExecuteS('SELECT `name`, `value`, `category`
FROM '._DB_PREFIX_.'blmod_xml_block
WHERE category = "'.(int)$this->feedId.'"
');
foreach ($branchNames as $bl) {
$branchNamesKey[$bl['name']] = isset($bl['value']) ? $bl['value'] : $bl['name'];
}
return $branchNamesKey;
}
protected function replaceXmlTree($xml)
{
preg_match_all("'<sBLMOD>(.*?)</sBLMOD>'si", $xml, $categories);
$levels = array();
if (empty($categories[1])) {
return $xml;
}
foreach ($categories[1] as $k => $c) {
preg_match("'<nBLMOD>(.*?)</nBLMOD>'si", $c, $name);
$names = explode('_lBLMOD_', $name[1]);
preg_match("'<vBLMOD>(.*?)</vBLMOD>'si", $c, $value);
$levels[$names[0]][] = [
'full' => $categories[0][$k],
'name' => $names[1],
'value' => $value[1],
];
}
foreach ($levels as $branchName => $branch) {
$xmlN = '<'.$branchName.'>';
$firstField = '';
foreach ($branch as $b) {
$xmlN .= '<'.$b['name'].'>';
$xmlN .= $b['value'];
$xmlN .= '</'.$b['name'].'>';
if (empty($firstField)) {
$firstField = $b['full'];
} else {
$xml = str_replace($b['full'], '', $xml);
}
}
$xmlN .= '</'.$branchName.'>';
$xml = str_replace($firstField, $xmlN, $xml);
}
return $xml;
}
protected function getDeepTagName($tag = '', $close = false)
{
if (empty($tag)) {
return '';
}
if (strpos($tag, '/') === false) {
return '<'.($close ? '/' : '').$tag.'>';
}
if ($close) {
return '</vBLMOD></sBLMOD>';
}
return '<sBLMOD><nBLMOD>'.str_replace('/', '_lBLMOD_', $tag).'</nBLMOD><vBLMOD>';
}
protected function getPriceFormat($price = 0)
{
if (!empty($this->settings['currency_id'])) {
$price = Tools::convertPrice($price, $this->settings['currency_id']);
}
$price = PriceFormat::convertByType($price, $this->settings['price_format_id']);
return $price.(!empty($this->settings['price_with_currency']) ? ' '.$this->currency['iso_code'] : '');
}
protected function getNumberFormat($number = 0)
{
return Tools::ps_round($number, 3);
}
protected function isPriceField($field)
{
$priceFields = array(
'orders_total_paid',
'orders_total_paid_tax_incl',
'orders_total_paid_tax_excl',
'orders_total_wrapping',
'orders_total_discounts',
'orders_total_products',
'orders_total_shipping',
'orders_total_shipping_tax_incl',
'orders_total_shipping_tax_excl',
'order_detail_total_price_tax_incl',
'order_detail_total_price_tax_excl',
'order_detail_unit_price_tax_incl',
'order_detail_unit_price_tax_excl',
);
return in_array($field, $priceFields);
}
protected function isNumberField($field)
{
$fields = array(
'tax_rate'
);
return in_array($field, $fields);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,101 @@
<?php
/**
* 2010-2023 Bl Modules.
*
* If you wish to customize this module for your needs,
* please contact the authors first for more information.
*
* It's not allowed selling, reselling or other ways to share
* this file or any other module files without author permission.
*
* @author Bl Modules
* @copyright 2010-2023 Bl Modules
* @license
*/
if (!defined('_PS_VERSION_')) {
require_once(dirname(__FILE__).'/config/config.inc.php');
}
if (!class_exists('SkroutzAnalyticsXml', false)) {
require_once(_PS_MODULE_DIR_.'/xmlfeeds/SkroutzAnalyticsXml.php');
}
$feedSettings = getSkroutzFeedSettings();
if (empty($feedSettings['skroutz_analytics_id'])) {
die('Empty skroutz_analytics_id');
}
$skroutzAnalyticsXml = new SkroutzAnalyticsXml($feedSettings);
$productId = Tools::getValue('product_id');
$combinationId = Tools::getValue('combination_id');
$langId = Tools::getValue('lang_id', (int)Configuration::get('PS_LANG_DEFAULT'));
if (empty($productId)) {
die('Empty URL param product_id');
}
if (empty($combinationId)) {
echo '<div style="margin-bottom: 20px; color: #af0606;">Warning: Empty URL param combination_id</div>';
}
$product = new Product($productId, false);
$combinations = $product->getAttributesResume($langId, ' ', ', ');
$attributesGroups = AttributeGroupCore::getAttributesGroups($langId);
$groupName = '';
foreach ($attributesGroups as $a) {
if ($a['id_attribute_group'] == $feedSettings['merge_attributes_parent']) {
$groupName = $a['name'];
break;
}
}
echo 'Product: '.(!empty($product->name[$langId]) ? $product->name[$langId] : 'empty name').'<br>';
echo 'Product ID: '.$productId.'<br>';
echo 'Combination ID: '.$combinationId.'<br>';
echo 'Skroutz ID: '.$feedSettings['skroutz_analytics_id'].'<br>';
echo 'Merge by group: '.$groupName.'<br>';
foreach ($combinations as $c) {
$skroutzCombinationID = $skroutzAnalyticsXml->getCombinationId($productId, $c['id_product_attribute']);
echo '<div style="'.($combinationId == $c['id_product_attribute'] ? 'color: #f44336;' : '').'">';
echo '<br>Combination ID: '.$c['id_product_attribute'].'<br>';
echo 'Combination name: '.$c['attribute_designation'].'<br>';
echo 'Skroutz combination ID: '.$skroutzCombinationID.'<br>';
echo 'XML item ID: '.$productId.'-'.$skroutzCombinationID.'<br>';
echo '</div>';
}
function getSkroutzFeedSettings()
{
if (!class_exists('FeedMeta', false)) {
require_once(_PS_MODULE_DIR_.'/xmlfeeds/FeedMeta.php');
}
$feeds = Db::getInstance()->executeS('SELECT * FROM '._DB_PREFIX_.'blmod_xml_feeds f
WHERE f.feed_mode = "s"
ORDER BY f.id DESC');
if (empty($feeds)) {
return [];
}
$feedMeta = new FeedMeta();
foreach ($feeds as $f) {
$meta = $feedMeta->getFeedMeta($f['id']);
if (!empty($meta[$f['id']]['skroutz_analytics_id'])) {
return $f+$meta[$f['id']];
}
}
return [];
}
die('');

View File

@@ -0,0 +1,80 @@
<?php
/**
* 2010-2023 Bl Modules.
*
* If you wish to customize this module for your needs,
* please contact the authors first for more information.
*
* It's not allowed selling, reselling or other ways to share
* this file or any other module files without author permission.
*
* @author Bl Modules
* @copyright 2010-2023 Bl Modules
* @license
*/
class SupplierXmlApi
{
protected $settings = array();
protected $feedLangId = 1;
protected $protocol = '';
public function getFeed($settings, $protocol)
{
$this->settings = $settings;
$this->feedLangId = (int)Configuration::get('PS_LANG_DEFAULT');
$this->protocol = $protocol;
return $this->generateXml($this->getSuppliers());
}
protected function generateXml($suppliers)
{
$xml = '<items>';
if (empty($suppliers)) {
return '</items>';
}
$link = new Link();
$addImage = method_exists($link, 'getSupplierImageLink');
foreach ($suppliers as $b) {
if ($addImage) {
$logoUrl = $link->getSupplierImageLink($b['id_supplier']);
if (!empty($logoUrl) && Tools::substr($logoUrl, 0, 4) != 'http') {
$logoUrl = $this->protocol . $logoUrl;
}
}
$xml .= '<item>';
$xml .= '<id><![CDATA['.$b['id_supplier'].']]></id>';
$xml .= '<name><![CDATA['.$b['name'].']]></name>';
$xml .= '<url><![CDATA['.$link->getSupplierLink($b['id_supplier'], null, (int)$this->feedLangId).']]></url>';
$xml .= '<date_add><![CDATA['.$b['date_add'].']]></date_add>';
$xml .= '<date_upd><![CDATA['.$b['date_upd'].']]></date_upd>';
$xml .= '<description><![CDATA['.strip_tags($b['description']).']]></description>';
$xml .= !empty($logoUrl) ? '<logo><![CDATA['.$logoUrl.']]></logo>' : '';
$xml .= '<active><![CDATA['.$b['active'].']]></active>';
$xml .= '</item>';
}
$xml .= '</items>';
return $xml;
}
protected function getSuppliers()
{
return Db::getInstance()->ExecuteS('
SELECT m.*, l.description
FROM '._DB_PREFIX_.'supplier m
LEFT JOIN '._DB_PREFIX_.'supplier_lang l ON
(l.id_supplier = m.id_supplier AND l.id_lang = "'.(int)$this->feedLangId.'")
WHERE m.`active` = 1
ORDER BY m.name ASC
');
}
}

View File

@@ -0,0 +1,24 @@
<?php
/**
* 2010-2023 Bl Modules.
*
* If you wish to customize this module for your needs,
* please contact the authors first for more information.
*
* It's not allowed selling, reselling or other ways to share
* this file or any other module files without author permission.
*
* @author Bl Modules
* @copyright 2010-2023 Bl Modules
* @license
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,641 @@
<?php
/**
* 2010-2023 Bl Modules.
*
* If you wish to customize this module for your needs,
* please contact the authors first for more information.
*
* It's not allowed selling, reselling or other ways to share
* this file or any other module files without author permission.
*
* @author Bl Modules
* @copyright 2010-2023 Bl Modules
* @license
*/
$_SERVER['REQUEST_URI'] = !empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/modules/xmlfeeds/api/xml.php?id=0';
$_SERVER['SCRIPT_NAME'] = !empty($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : '/modules/xmlfeeds/api/xml.php';
$_SERVER['REQUEST_METHOD'] = !empty($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
$_SERVER['REMOTE_ADDR'] = !empty($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '8.8.8.8';
if (!defined('_PS_VERSION_')) {
require_once(dirname(__FILE__).'/../../../config/config.inc.php');
if (empty($argv)) {
$argv = [];
$argv[1] = (int)Tools::getValue('id');
$argv[2] = Tools::getValue('affiliate');
$argv[3] = Tools::getValue('multistore');
$argv[4] = Tools::getValue('type');
}
}
require_once(_PS_MODULE_DIR_.'/xmlfeeds/XmlFeedsTools.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/googlecategory.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/ProductList.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/ProductSettings.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/FeedType.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/PriceFormat.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/AccessLog.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/OrderSettings.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/api/OrderXmlApi.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/MergeAttributesByGroup.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/FilterByAttribute.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/FilterByFeature.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/XmlFeedUrl.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/CategoryMap.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/ProductPropertyMap.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/ProductTitleEditor.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/FeedMeta.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/FeedPrice.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/ProductCombinations.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/api/CustomerXmlApi.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/api/BrandXmlApi.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/api/SupplierXmlApi.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/api/CategoryXmlApi.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/api/ProductXmlApi.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/CategoryTreeGenerator.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/Compressor.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/DatabaseTableConnector.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/vendor/FormulaParser.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/AvailabilityLabel.php');
require_once(_PS_MODULE_DIR_.'/xmlfeeds/FeedShippingPrice.php');
$feedMeta = new FeedMeta();
$protocol = getShopProtocol();
const REPLACE_COMBINATION = 'BLMOD_REPLACE_COMBINATION;';
if (!defined('_PS_VERSION_')) {
die('Not Allowed, api root');
}
$id = htmlspecialchars(Tools::getValue('id'), ENT_QUOTES);
$part = htmlspecialchars(Tools::getValue('part'), ENT_QUOTES);
$affiliateParam = Tools::getValue('affiliate');
$multistore = (int)Tools::getValue('multistore');
$downloadAction = Tools::getValue('download');
$xmlFeedType = Tools::getValue('type');
$isCron = false;
$sessionId = Tools::substr(md5(microtime().rand(1, 9999999)), 0, 16);
$argv = !empty($argv) ? $argv : [];
$affiliate = htmlspecialchars((is_array($affiliateParam) ? implode(',', $affiliateParam) : $affiliateParam), ENT_QUOTES);
if (!empty($argv[1])) {
/**
* Reset currency id, for new PS
*/
if (class_exists('Context', false)) {
$context = Context::getContext();
$context->currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
$context->shop = new Shop(Configuration::get('PS_SHOP_DEFAULT'));
Context::getContext()->cart = new Cart();
}
$id = $argv[1];
$isCron = true;
}
if (empty($context) && class_exists('Context', false)) {
$context = Context::getContext();
}
if (!empty($argv[2])) {
$affiliate = htmlspecialchars($argv[2], ENT_QUOTES);
}
if (!empty($argv[3])) {
$multistore = (int)$argv[3];
}
if (!empty($argv[4])) {
$xmlFeedType = htmlspecialchars($argv[4], ENT_QUOTES);
}
if (!is_numeric($id)) {
die('empty id');
}
if ($affiliate == 'affiliate_name') {
$affiliate = '';
}
if (!empty($multistore)) {
$context->shop = new Shop($multistore);
}
$check_affiliate = Db::getInstance()->getRow('SELECT `affiliate_name` FROM '._DB_PREFIX_.'blmod_xml_affiliate_price WHERE `affiliate_name` = "'.pSQL($affiliate).'"');
$affiliate_cache = '';
$permissions = Db::getInstance()->getRow('SELECT f.*, c.file_name AS file_name_n, c.last_cache_time AS last_cache_time_n
FROM '._DB_PREFIX_.'blmod_xml_feeds f
LEFT JOIN '._DB_PREFIX_.'blmod_xml_feeds_cache c ON
(f.id = c.feed_id AND c.feed_part = "'.(int)$part.'" AND c.affiliate_name = "'.pSQL($affiliate_cache).'")
WHERE f.id = "'.(int)$id.'"');
if (empty($permissions)) {
die('empty settings');
}
AccessLog::save($id, 'start', $sessionId, $isCron, $_GET, $argv);
AccessLog::deleteOld();
$feed_name = 'archive_'.$id;
$permissions['use_cache'] = isset($permissions['use_cache']) ? $permissions['use_cache'] : false;
$permissions['cache_time'] = isset($permissions['cache_time']) ? $permissions['cache_time'] : false;
$permissions['last_cache_time'] = isset($permissions['last_cache_time_n']) ? $permissions['last_cache_time_n'] : '0000-00-00 00:00:00';
$permissions['use_password'] = isset($permissions['use_password']) ? $permissions['use_password'] : false;
$permissions['password'] = isset($permissions['password']) ? $permissions['password'] : false;
$permissions['status'] = isset($permissions['status']) ? $permissions['status'] : false;
$permissions['file_name'] = isset($permissions['file_name_n']) ? $permissions['file_name_n'] : false;
$permissions['html_tags_status'] = isset($permissions['html_tags_status']) ? $permissions['html_tags_status'] : false;
$permissions['one_branch'] = isset($permissions['one_branch']) ? $permissions['one_branch'] : false;
$permissions['header_information'] = isset($permissions['header_information']) ? htmlspecialchars_decode($permissions['header_information'], ENT_QUOTES) : false;
$permissions['footer_information'] = isset($permissions['footer_information']) ? htmlspecialchars_decode($permissions['footer_information'], ENT_QUOTES) : false;
$permissions['extra_feed_row'] = isset($permissions['extra_feed_row']) ? htmlspecialchars_decode($permissions['extra_feed_row'], ENT_QUOTES) : false;
$permissions['only_enabled'] = isset($permissions['only_enabled']) ? $permissions['only_enabled'] : false;
$permissions['split_feed'] = isset($permissions['split_feed']) ? $permissions['split_feed'] : false;
$permissions['split_feed_limit'] = isset($permissions['split_feed_limit']) ? $permissions['split_feed_limit'] : false;
$permissions['cat_list'] = isset($permissions['cat_list']) ? $permissions['cat_list'] : false;
$permissions['categories'] = isset($permissions['categories']) ? $permissions['categories'] : false;
$permissions['price_with_currency'] = isset($permissions['price_with_currency']) ? $permissions['price_with_currency'] : false;
$permissions['manufacturer_list'] = isset($permissions['manufacturer_list']) ? $permissions['manufacturer_list'] : false;
$permissions['manufacturer'] = isset($permissions['manufacturer']) ? $permissions['manufacturer'] : false;
$permissions['supplier_list'] = isset($permissions['supplier_list']) ? $permissions['supplier_list'] : false;
$permissions['supplier'] = isset($permissions['supplier']) ? $permissions['supplier'] : false;
$permissions['currency_id'] = isset($permissions['currency_id']) ? $permissions['currency_id'] : false;
$permissions['feed_generation_time'] = isset($permissions['feed_generation_time']) ? $permissions['feed_generation_time'] : false;
$permissions['feed_generation_time_name'] = isset($permissions['feed_generation_time_name']) ? $permissions['feed_generation_time_name'] : false;
$permissions['split_by_combination'] = isset($permissions['split_by_combination']) ? $permissions['split_by_combination'] : false;
$useCron = !empty($permissions['use_cron']) ? $permissions['use_cron'] : false;
$feed_type = isset($permissions['feed_type']) ? $permissions['feed_type'] : false;
$onlyInStock = !empty($permissions['only_in_stock']) ? $permissions['only_in_stock'] : false;
$priceRange = !empty($permissions['price_range']) ? $permissions['price_range'] : false;
$mode = !empty($permissions['feed_mode']) ? $permissions['feed_mode'] : false;
$allImages = !empty($permissions['all_images']) ? $permissions['all_images'] : false;
$productList = !empty($permissions['product_list']) ? explode(',', $permissions['product_list']) : array();
$productListStatus = !empty($permissions['product_list_status']) ? $permissions['product_list_status'] : false;
$shippingCountry = !empty($permissions['shipping_country']) ? $permissions['shipping_country'] : false;
$filterDiscount = !empty($permissions['filter_discount']) ? $permissions['filter_discount'] : 0;
$filterCategoryType = !empty($permissions['filter_category_type']) ? $permissions['filter_category_type'] : 0;
$productSettingsPackageId = !empty($permissions['product_settings_package_id']) ? $permissions['product_settings_package_id'] : 0;
$permissions['filter_qty_status'] = !empty($permissions['filter_qty_status']) ? $permissions['filter_qty_status'] : 0;
$permissions['filter_qty_type'] = !empty($permissions['filter_qty_type']) ? $permissions['filter_qty_type'] : 0;
$permissions['filter_qty_value'] = !empty($permissions['filter_qty_value']) ? $permissions['filter_qty_value'] : 0;
$permissions['price_format_id'] = !empty($permissions['price_format_id']) ? $permissions['price_format_id'] : 0;
$permissions['in_stock_text'] = isset($permissions['in_stock_text']) ? $permissions['in_stock_text'] : '';
$permissions['out_of_stock_text'] = isset($permissions['out_of_stock_text']) ? $permissions['out_of_stock_text'] : '';
$permissions['merge_attributes_by_group'] = !empty($permissions['merge_attributes_by_group']) ? $permissions['merge_attributes_by_group'] : 0;
$permissions['merge_attributes_parent'] = !empty($permissions['merge_attributes_parent']) ? $permissions['merge_attributes_parent'] : 0;
$permissions['merge_attributes_child'] = !empty($permissions['merge_attributes_child']) ? $permissions['merge_attributes_child'] : 0;
$permissions['only_with_attributes_status'] = !empty($permissions['only_with_attributes_status']) ? $permissions['only_with_attributes_status'] : 0;
$permissions['only_with_attributes'] = !empty($permissions['only_with_attributes']) ? explode(',', $permissions['only_with_attributes']) : array();
$permissions['only_without_attributes_status'] = !empty($permissions['only_without_attributes_status']) ? $permissions['only_without_attributes_status'] : 0;
$permissions['only_without_attributes'] = !empty($permissions['only_without_attributes']) ? explode(',', $permissions['only_without_attributes']) : array();
$permissions['product_list_exclude'] = !empty($permissions['product_list_exclude']) ? explode(',', $permissions['product_list_exclude']) : array();
$permissions['category_map_id'] = !empty($permissions['category_map_id']) ? $permissions['category_map_id'] : 0;
$permissions['encoding_text'] = !empty($permissions['encoding_text']) ? $permissions['encoding_text'] : 'UTF-8';
$permissions['only_on_sale'] = !empty($permissions['only_on_sale']) ? $permissions['only_on_sale'] : 0;
$permissions['filter_exclude_empty_params'] = !empty($permissions['filter_exclude_empty_params']) ? explode(',', $permissions['filter_exclude_empty_params']) : '';
$permissions['product_list_xml_tag_array'] = !empty($permissions['product_list_xml_tag']) ? explode(',', $permissions['product_list_xml_tag']) : [];
$permissions['xml_type'] = $xmlFeedType;
$feedMetaValues = $feedMeta->getFeedMeta($id);
$feedMetaValues[$id]['empty_description'] = !empty($feedMetaValues[$id]['empty_description']) ? $feedMetaValues[$id]['empty_description'] : 0;
$feedMetaValues[$id]['title_length'] = !empty($feedMetaValues[$id]['title_length']) ? (int)$feedMetaValues[$id]['title_length'] : 0;
$permissions = array_merge($permissions, $feedMetaValues[$id]);
$permissions['url_protocol_without_slash'] = XmlFeedsTools::getUrlProtocolWithoutSlash();
$taxRateList = [];
if (!empty($permissions['currency_id'])) {
$context->currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
}
$compressor = new Compressor();
$compressor->setSettings($permissions);
if (!empty($permissions['last_modified_header'])) {
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
}
if (!empty($permissions['affiliate'])) {
$affiliateList = Db::getInstance()->ExecuteS('SELECT a.affiliate_name
FROM '._DB_PREFIX_.'blmod_xml_affiliate_price a
WHERE a.affiliate_id IN ('.pSQL(implode($permissions['affiliate'], ',')).')');
unset($affiliate);
foreach ($affiliateList as $a) {
$affiliate[] = $a['affiliate_name'];
}
} else if (!empty($affiliate)) {
$affiliate2 = $affiliate;
unset($affiliate);
$affiliate[] = $affiliate2;
}
if (empty($affiliate)) {
$affiliate = '';
}
$affiliateNameString = (!empty($affiliate) && is_array($affiliate)) ? implode(',', $affiliate) : '';
if (!empty($shippingCountry)) {
$context->country->id = $shippingCountry;
}
if ($useCron) {
$permissions['split_feed'] = false;
}
$settings = $permissions;
if ($permissions['status'] != 1) {
die('disabled');
}
if ($permissions['use_password'] == 1 && !empty($permissions['password']) && !$useCron) {
$pass = Tools::getValue('password');
if ($permissions['password'] != $pass) {
die('permissions, password');
}
}
if (!empty($permissions['protect_by_ip']) && !$useCron) {
$ipList = explode(',', str_replace(' ', '', trim($permissions['protect_by_ip'])));
if (!empty($ipList) && !in_array(get_ip(), $ipList)) {
die('permissions, IP address');
}
}
if (!$useCron) {
insert_statistics($id, $affiliateNameString);
}
$now = date('Y-m-d h:i:s');
$cache_period = date('Y-m-d h:i:s', strtotime($permissions['last_cache_time'].'+ '.$permissions['cache_time'].' minutes'));
if ($permissions['use_cache'] && !$useCron) {
$file_url = _PS_ROOT_DIR_.'/modules/xmlfeeds/xml_files/'.$permissions['file_name'].'.xml';
if ($now < $cache_period) {
if (!empty($permissions['file_name'])) {
$xml = Tools::file_get_contents($file_url);
}
if (!empty($xml)) {
header('Content-type: text/xml;charset:'.$permissions['encoding_text']);
$download = Tools::getValue('download');
if (!empty($download)) {
header('Content-Disposition:attachment;filename='.$feed_name.'_feed.xml');
}
AccessLog::save($id, 'end_cache', $sessionId);
echo '<?xml version="1.0" encoding="'.$permissions['encoding_text'].'"?>';
echo $xml;
die;
}
} else {
Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'blmod_xml_feeds_cache WHERE `feed_id` = "'.(int)$id.'" AND `affiliate_name` = "'.pSQL($affiliate_cache).'"');
@unlink($file_url);
}
}
if (!empty($permissions['cdata_status'])) {
$pref_s = '<![CDATA[';
$pref_e = ']]>';
} else {
$pref_s = '';
$pref_e = '';
}
$multistoreArray = array();
$multistoreString = false;
if (!empty($multistore)) {
if ($multistore == 'auto') {
$multistoreString = Context::getContext()->shop->id;
} else {
$multistoreArrayCheck = explode(',', $multistore);
foreach ($multistoreArrayCheck as $m) {
$mId = (int) $m;
if (empty($mId)) {
continue;
}
$multistoreArray[] = $mId;
}
$multistoreString = implode(',', $multistoreArray);
}
}
function create_split_xml_product(
$only_enabled = false,
$limit = 5000,
$page = 1,
$use_password = false,
$password = false,
$affiliate = false,
$multistoreString = 0,
$categories = false,
$cat_list = '',
$filterCategoryType = false,
$permissions = array(),
$settings = array(),
$productList = array(),
$productListStatus = false
) {
$xmlFeedUrl = new XmlFeedUrl();
$productListClass = new ProductList($settings['product_list_exclude']);
$where_only_active = '';
if (!empty($only_enabled)) {
$where_only_active = 'WHERE '._DB_PREFIX_.'product.active = "1"';
}
$category_table = false;
if (!empty($categories) && !empty($cat_list)) {
if (empty($filterCategoryType)) {
$category_table = '
LEFT JOIN ' . _DB_PREFIX_ . 'category_product ON
' . _DB_PREFIX_ . 'category_product.id_product = ' . _DB_PREFIX_ . 'product.id_product ';
$where_only_active .= whereType($where_only_active) . _DB_PREFIX_ . 'category_product.id_category IN ('.pSQL($cat_list).')';
} else {
$category_table = 'INNER JOIN '._DB_PREFIX_.'category_product ON
('._DB_PREFIX_.'category_product.id_product = '._DB_PREFIX_.'product.id_product AND '._DB_PREFIX_.'category_product.id_category IN ('.pSQL($cat_list).'))';
}
}
$multistoreJoin = '';
if (!empty($multistoreString)) {
$multistoreJoin = ' INNER JOIN '._DB_PREFIX_.'product_shop ps ON
(ps.id_product = '._DB_PREFIX_.'product.id_product AND ps.id_shop IN ('.(int)$multistoreString.')) AND ps.`active` = "1" ';
}
if (!empty($permissions['manufacturer']) && !empty($permissions['manufacturer_list'])) {
$where_only_active .= whereType($where_only_active)._DB_PREFIX_.'product.id_manufacturer IN ('.pSQL($permissions['manufacturer_list']).')';
}
if (!empty($permissions['supplier']) && !empty($permissions['supplier_list'])) {
$where_only_active .= whereType($where_only_active)._DB_PREFIX_.'product.id_supplier IN ('.pSQL($permissions['supplier_list']).')';
}
if ((!empty($settings['product_list_exclude']) || !empty($productList)) && !empty($productListStatus)) {
$productListExcludeActive = $productListClass->getExcludeProductsByProductList();
$productListActive = $productListClass->getProductsByProductList($productList, $productListExcludeActive);
$productListActive = !empty($productListActive) ? $productListActive : array('"none_id"');
$productListExcludeActive = $productListClass->getExcludeProductsByProductList();
if (!empty($productList)) {
$where_only_active .= whereType($where_only_active) . _DB_PREFIX_ . 'product.id_product IN (' . pSQL(implode(',', $productListActive)) . ')';
}
if (!empty($productListExcludeActive)) {
$where_only_active .= whereType($where_only_active)._DB_PREFIX_.'product.id_product NOT IN ('.pSQL(implode(',', $productListExcludeActive)).')';
}
}
$sql = 'SELECT COUNT(DISTINCT('._DB_PREFIX_.'product.id_product)) AS c
FROM '._DB_PREFIX_.'product
LEFT JOIN '._DB_PREFIX_.'manufacturer ON
'._DB_PREFIX_.'manufacturer.id_manufacturer = '._DB_PREFIX_.'product.id_manufacturer
'.$multistoreJoin.$category_table.$where_only_active;
$product_total = Db::getInstance()->getRow($sql);
if (empty($product_total['c'])) {
return '<feeds><total>0</total></feeds>';
}
$parts = 1;
if ($product_total['c'] > $limit) {
$parts = ceil($product_total['c'] / $limit);
}
$pass_in_link = (!empty($use_password) && !empty($password)) ? '&password='.$password : '';
$multistoreUrl = !empty($multistoreString) ? '&multistore='.$multistoreString : '';
$link = $xmlFeedUrl->get('id='.$page.$pass_in_link.$multistoreUrl.'&part=');
$xml = '<feeds>';
$xml .= '<total>'.$parts.'</total>';
for ($i = 1; $i <= $parts; ++$i) {
$xml .= '<feed_'.$i.'><![CDATA['.$link.$i.']]></feed_'.$i.'>';
}
$xml .= '</feeds>';
return $xml;
}
$xml = '';
if ($feed_type == 1) {
if (empty($part) && !empty($permissions['split_feed']) && !empty($permissions['split_feed_limit'])) {
$xml = create_split_xml_product(
$permissions['only_enabled'],
$permissions['split_feed_limit'],
$id,
$permissions['use_password'],
$permissions['password'],
$affiliate,
$multistoreString,
$permissions['categories'],
$permissions['cat_list'],
$filterCategoryType,
$permissions,
$settings,
$productList,
$productListStatus
);
} else {
$productXmlApi = new ProductXmlApi();
$xml = $productXmlApi->getFeed(
$permissions,
$id,
$pref_s,
$pref_e,
$permissions['html_tags_status'],
$permissions['extra_feed_row'],
$permissions['one_branch'],
$permissions['only_enabled'],
$permissions['split_feed_limit'],
$part,
$permissions['categories'],
$permissions['cat_list'],
$multistoreString,
$onlyInStock,
$priceRange,
$permissions['price_with_currency'],
$mode,
$allImages,
$affiliate,
$permissions['currency_id'],
$permissions['feed_generation_time'],
$permissions['feed_generation_time_name'],
$permissions['split_by_combination'],
$productList,
$productListStatus,
$shippingCountry,
$filterDiscount,
$filterCategoryType,
$productSettingsPackageId,
$settings,
$permissions,
$context
);
}
} elseif ($feed_type == 2) {
$categoryXmlApi = new CategoryXmlApi();
$xml = $categoryXmlApi->getFeed(
$id,
$pref_s,
$pref_e,
$permissions['html_tags_status'],
$permissions['extra_feed_row'],
$permissions['one_branch'],
$permissions['only_enabled'],
$multistoreString,
$permissions
);
} elseif ($feed_type == 3) {
$orderXmlApi = new OrderXmlApi();
$xml = $orderXmlApi->getFeed($permissions);
} elseif ($feed_type == 4) {
$customerXmlApi = new CustomerXmlApi();
$xml = $customerXmlApi->getFeed($permissions);
} elseif ($feed_type == 5) {
$brandXmlApi = new BrandXmlApi();
$xml = $brandXmlApi->getFeed($permissions, $protocol);
} elseif ($feed_type == 6) {
$supplierXmlApi = new SupplierXmlApi();
$xml = $supplierXmlApi->getFeed($permissions, $protocol);
}
if ($mode == 'tot') {
$permissions['header_information'] .= '<created>'.date('Y-m-d').'</created>';
}
if ($mode == 'ep' || $mode == 'ro') {
$permissions['header_information'] = '<yml_catalog date="'.date('Y-m-d H:i').'">'.$permissions['header_information'];
$permissions['footer_information'] .= '</yml_catalog>';
}
$xml = $permissions['header_information'].$xml.$permissions['footer_information'];
if ($permissions['use_cache']) {
if ($now > $cache_period) {
if (empty($check_affiliate['affiliate_name'])) {
$affiliate = false;
}
$create_name = '';
if (empty($permissions['file_name'])) {
$permissions['file_name'] = md5(md5(rand(99999, 99999999).'aKf5ad@d50gaq0sd'.date('Y-m-d H:i:s')));
$create_name = 'file_name="'.$permissions['file_name'].'", ';
}
$file_url = _PS_ROOT_DIR_.'/modules/xmlfeeds/xml_files/'.$permissions['file_name'].'.xml';
file_put_contents($file_url, $xml);
if (file_exists($file_url)) {
Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'blmod_xml_feeds_cache
(`feed_id`, `feed_part`, `file_name`, `last_cache_time`, `affiliate_name`)
VALUES
("'.(int)$id.'", "'.(int)$part.'", "'.pSQL($permissions['file_name']).'", "'.pSQL($now).'", "")');
}
}
}
if ($useCron) {
$file_url = _PS_ROOT_DIR_.'/modules/xmlfeeds/xml_files/feed_'.$id.'.xml';
file_put_contents($file_url, '<?xml version="1.0" encoding="'.$permissions['encoding_text'].'"?>'.$xml);
Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'blmod_xml_feeds SET `last_cron_date` = "'.pSQL(date('Y-m-d H:i:s')).'" WHERE id = "'.(int)$id.'"');
$compressor->compress('feed_'.$id.'.xml');
AccessLog::save($id, 'end_cron', $sessionId);
die('done');
}
function insert_statistics($feed_id = false, $affiliate = '')
{
Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'blmod_xml_statistics WHERE `date` < "'.XmlFeedsTools::dateMinusDays(180).'"');
Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'blmod_xml_statistics
(`feed_id`, `affiliate_name`, `date`, `ip_address`)
VALUES
("'.(int)$feed_id.'", "'.pSQL(is_array($affiliate) ? implode(', ', $affiliate) : '').'", "'.pSQL(date('Y-m-d H:i:s')).'", "'.pSQL(get_ip()).'")');
Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'blmod_xml_feeds SET total_views = total_views + 1 WHERE id = "'.(int)$feed_id.'"');
}
function get_ip()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
function getShopProtocol()
{
if (method_exists('Tools', 'getShopProtocol')) {
return Tools::getShopProtocol();
}
return (Configuration::get('PS_SSL_ENABLED') || (!empty($_SERVER['HTTPS'])
&& Tools::strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://';
}
function whereType($type)
{
if (!empty($type)) {
return ' AND ';
}
return ' WHERE ';
}
header('Content-type: text/xml;charset:'.$permissions['encoding_text']);
if (!empty($downloadAction)) {
header('Content-Disposition:attachment;filename='.$feed_name.'_feed.xml');
}
AccessLog::save($id, 'end', $sessionId);
$xmlWithHeader = '<?xml version="1.0" encoding="'.$permissions['encoding_text'].'"?>'.$xml;
$compressor->compress('', $xmlWithHeader);
echo $xmlWithHeader;
die;