166 lines
6.1 KiB
PHP
166 lines
6.1 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];
|
|
|
|
//$_id_shipping = 4; // philea
|
|
|
|
if($id_sale == 0) {
|
|
exit;
|
|
}
|
|
|
|
$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);
|
|
|
|
$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();
|
|
|
|
if((int) Db::getInstance()->getValue('
|
|
SELECT `featured`
|
|
FROM `'._DB_PREFIX_.'privatesale`
|
|
WHERE `id_sale` = '.(int) $id_sale.'
|
|
')) {
|
|
$code_societe = 101; // 78
|
|
} else {
|
|
$code_societe = (int)(Configuration::get('PHILEA_MAGISTOR_CODE_STE'));
|
|
}
|
|
|
|
$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');
|
|
|
|
$data = '';
|
|
|
|
foreach( $products as $product ) {
|
|
/*if($product['send_philea'])*/
|
|
// ANTADIS
|
|
// continue;
|
|
|
|
/**
|
|
* @Override
|
|
* Get image link
|
|
*/
|
|
$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->ExecuteS('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 = '';
|
|
$ean = substr(!empty($attribute['supplier_reference'])? $attribute['supplier_reference']: $product['supplier_reference'], 0, 13);
|
|
|
|
if($code_societe == 78) {
|
|
$ref = !empty($attribute['ean13'])? $attribute['ean13']: $attribute['supplier_reference'];
|
|
} else {
|
|
$ref = $product['id_product'].'_'.$attribute['id_product_attribute'];
|
|
}
|
|
|
|
$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"), "", $ref)),0,50), 50, ' ', STR_PAD_RIGHT );
|
|
$data .= str_pad( substr(utf8_decode(str_replace(array("\r", "\n"), "", $magistorModule->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"), "", $ean), 14, ' ', STR_PAD_LEFT );
|
|
$data .= str_pad( str_replace('.',',',($product['weight']+$attribute['weight'])/**1000*/), 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 .= str_pad( '', 14, '0', STR_PAD_LEFT );
|
|
// $data .= str_pad( '', 10, '0', STR_PAD_LEFT );
|
|
// $data .= str_pad( '', 10, '0', STR_PAD_LEFT );
|
|
// $data .= str_pad( '', 10, '0', STR_PAD_LEFT );
|
|
// $data .= str_pad( '', 14, '0', STR_PAD_LEFT );
|
|
// $data .= str_pad( '', 10, '0', STR_PAD_LEFT );
|
|
// $data .= str_pad( '', 10, '0', STR_PAD_LEFT );
|
|
// $data .= str_pad( '', 10, '0', STR_PAD_LEFT );
|
|
$data .= PHP_EOL;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(isset($product['ean13']) && !empty($product['ean13']))
|
|
$ean = $product['ean13'];
|
|
else
|
|
//$ean = '';
|
|
$ean = substr($product['supplier_reference'], 0, 13);
|
|
|
|
if($code_societe == 78) {
|
|
$ref = !empty($product['ean13'])? $product['ean13']: $product['supplier_reference'];
|
|
} else {
|
|
$ref = $product['id_product'];
|
|
}
|
|
|
|
$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"), "", $ref), 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"), "", $ean), 14, ' ', STR_PAD_LEFT );
|
|
$data .= str_pad( str_replace('.',',',$product['weight']/**1000*/), 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 .= str_pad( '', 14, '0', STR_PAD_LEFT );
|
|
// $data .= str_pad( '', 10, '0', STR_PAD_LEFT );
|
|
// $data .= str_pad( '', 10, '0', STR_PAD_LEFT );
|
|
// $data .= str_pad( '', 10, '0', STR_PAD_LEFT );
|
|
// $data .= str_pad( '', 14, '0', STR_PAD_LEFT );
|
|
// $data .= str_pad( '', 10, '0', STR_PAD_LEFT );
|
|
// $data .= str_pad( '', 10, '0', STR_PAD_LEFT );
|
|
// $data .= str_pad( '', 10, '0', STR_PAD_LEFT );
|
|
$data .= PHP_EOL;
|
|
}
|
|
} //End if send_philea
|
|
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';
|
|
}
|