154 lines
5.4 KiB
PHP
154 lines
5.4 KiB
PHP
<?php
|
|
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
|
|
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
|
$_SERVER['SERVER_PORT'] = 80;
|
|
|
|
include(dirname(__FILE__) . '/../../../config/config.inc.php');
|
|
include( dirname(__FILE__) . '/../philea_magistor.php');
|
|
|
|
$id_sale = (int) $argv[1];
|
|
if($id_sale == 0) {
|
|
exit;
|
|
}
|
|
|
|
function getName($id_product, $id_lang, $id_product_attribute = FALSE) {
|
|
$name = DB::getInstance()->getValue('
|
|
SELECT `name`
|
|
FROM `'._DB_PREFIX_.'product_lang`
|
|
WHERE `id_product` = '.$id_product.'
|
|
AND `id_lang` = '.$id_lang.'
|
|
');
|
|
|
|
if($id_product_attribute) {
|
|
foreach(Db::getInstance()->ExecuteQ('
|
|
SELECT agl.`name` AS group_name, al.`name` AS attribute_name
|
|
FROM `'._DB_PREFIX_.'product_attribute_combination` pac
|
|
LEFT JOIN `'._DB_PREFIX_.'attribute` a
|
|
ON a.`id_attribute` = pac.`id_attribute`
|
|
LEFT JOIN `'._DB_PREFIX_.'attribute_group` ag
|
|
ON ag.`id_attribute_group` = a.`id_attribute_group`
|
|
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al
|
|
ON a.`id_attribute` = al.`id_attribute`
|
|
AND al.`id_lang` = '.(int) $id_lang.'
|
|
LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl
|
|
ON ag.`id_attribute_group` = agl.`id_attribute_group`
|
|
AND agl.`id_lang` = '.(int) $id_lang.'
|
|
WHERE pac.`id_product_attribute` = '.(int) $id_product_attribute.'
|
|
ORDER BY pac.`id_product_attribute`
|
|
') as $name_attribute) {
|
|
$name .= ' - '.$name_attribute['group_name'].' : '.$name_attribute['attribute_name'];
|
|
}
|
|
}
|
|
return $name;
|
|
}
|
|
|
|
|
|
$magistorModule = new philea_magistor();
|
|
@ini_set('display_errors', 'on');
|
|
|
|
if($magistorModule->active) {
|
|
global $regex_file_out;
|
|
$regex_file_out = '@^ART01(.*)\.(BAL|DAT)@';
|
|
@set_time_limit(0);
|
|
|
|
$fileName = dirname(__FILE__) . '/OUT/ART01' . date('ymdHis');
|
|
|
|
$repo_archive = dirname(__FILE__) . '/archives/OUT/ARTICLES/';
|
|
$repo_paths = array(date('Y'), date('m'));
|
|
foreach ($repo_paths as $repo_path) {
|
|
$repo_archive .= $repo_path . '/';
|
|
if (!file_exists($repo_archive))
|
|
mkdir($repo_archive);
|
|
}
|
|
|
|
$fileArchive = $repo_archive . 'ART01' . date('ymdHis');
|
|
|
|
$code_societe = (int)(Configuration::get('PHILEA_MAGISTOR_CODE_STE'));
|
|
$db = Db::getInstance();
|
|
$products = $db->ExecuteS('
|
|
SELECT * FROM `'._DB_PREFIX_.'product` p
|
|
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
|
|
ON (
|
|
p.`id_product` = pl.`id_product`
|
|
AND pl.`id_lang` = '.(int)(Configuration::get('PS_LANG_DEFAULT')).'
|
|
)
|
|
LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` c
|
|
ON c.`id_product` = p.`id_product`
|
|
WHERE c.`id_sale` = '.(int) $id_sale.'
|
|
ORDER BY p.`id_product` ASC
|
|
');
|
|
if (!$products) {
|
|
$products = array();
|
|
}
|
|
|
|
$data = '';
|
|
|
|
foreach($products as $product) {
|
|
|
|
$link = new Link();
|
|
$cover = Db::getInstance()->getValue('
|
|
SELECT `id_image`
|
|
FROM `'._DB_PREFIX_.'image`
|
|
WHERE id_product = ' . (int) $product['id_product'] . '
|
|
AND `cover` = 1');
|
|
$ids = (int) $product['id_product'] . '-' . (int) $cover;
|
|
$img_link = 'http://'.$link->getImageLink($product['link_rewrite'], $ids, 'thickbox');
|
|
|
|
$attributes = $db->ExecuteQ('
|
|
SELECT *
|
|
FROM `'._DB_PREFIX_.'product_attribute`
|
|
WHERE `id_product` = '.$product['id_product'].'
|
|
');
|
|
if(count($attributes) > 0) {
|
|
foreach($attributes as $attribute) {
|
|
if(isset($attribute['ean13']) && !empty($attribute['ean13'])) {
|
|
$ean = $attribute['ean13'];
|
|
} else {
|
|
$ean = $attribute['supplier_reference'];
|
|
}
|
|
|
|
$data .= str_pad('ART01', 10, ' ', STR_PAD_RIGHT);
|
|
$data .= str_pad($code_societe, 20, ' ', STR_PAD_RIGHT);
|
|
$data .= str_pad(substr(utf8_decode(str_replace(array("\r", "\n"), '', $ean)), 0, 50), 50, ' ', STR_PAD_RIGHT);
|
|
$data .= str_pad(substr(utf8_decode(str_replace(array("\r", "\n"), '', getName($product['id_product'], Configuration::get('PS_LANG_DEFAULT'), $attribute['id_product_attribute']))), 0,80), 80, ' ', STR_PAD_RIGHT);
|
|
$data .= str_pad(1, 10, '0', STR_PAD_LEFT);
|
|
$data .= str_pad(str_replace(array("\r", "\n"), '', $attribute['ean13']), 14, ' ', STR_PAD_LEFT);
|
|
$data .= str_pad(str_replace('.', ',', $product['weight'] + $attribute['weight']), 10, '0', STR_PAD_LEFT);
|
|
$data .= str_pad($product['width'] * $product['height'] * $product['depth'], 10, '0', STR_PAD_LEFT);
|
|
$data .= str_pad(substr($img_link, 0, 150), 150, ' ', STR_PAD_RIGHT);
|
|
$data .= PHP_EOL;
|
|
}
|
|
} else {
|
|
if(isset($product['ean13']) && !empty($product['ean13'])) {
|
|
$ean = $product['ean13'];
|
|
} else {
|
|
$ean = $product['supplier_reference'];
|
|
}
|
|
|
|
$data .= str_pad('ART01', 10, ' ', STR_PAD_RIGHT);
|
|
$data .= str_pad($code_societe, 20, ' ', STR_PAD_RIGHT);
|
|
$data .= str_pad(str_replace(array("\r", "\n"), '', $ean), 50, ' ', STR_PAD_RIGHT);
|
|
$data .= str_pad(substr(utf8_decode(str_replace(array("\r", "\n"), '', $product['name'])), 0, 80), 80, ' ', STR_PAD_RIGHT);
|
|
$data .= str_pad(1, 10, '0', STR_PAD_LEFT);
|
|
$data .= str_pad(str_replace(array("\r", "\n"), '', $product['ean13']), 14, ' ', STR_PAD_LEFT);
|
|
$data .= str_pad(str_replace('.', ',', $product['weight']), 10, '0', STR_PAD_LEFT);
|
|
$data .= str_pad($product['width'] * $product['height'] * $product['depth'], 10, '0', STR_PAD_LEFT);
|
|
$data .= str_pad(substr($img_link, 0, 150), 150, ' ', STR_PAD_RIGHT);
|
|
$data .= PHP_EOL;
|
|
}
|
|
}
|
|
|
|
if($data != '') {
|
|
file_put_contents($fileName.'.DAT', "\xEF\xBB\xBF".utf8_encode($data));
|
|
file_put_contents($fileArchive.'.DAT', "\xEF\xBB\xBF".utf8_encode($data));
|
|
unset($data);
|
|
|
|
chmod($fileName.'.DAT', 0755);
|
|
file_put_contents($fileName.'.BAL', '');
|
|
chmod($fileName.'.BAL', 0755);
|
|
require_once('connection_ftp.php');
|
|
echo 'fin';
|
|
}
|
|
}
|
|
|