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()->ExecuteS(' 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' . $dateNow; $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' . $dateNow; $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 = ''; /** * @Override check pack items */ $product_ids = array_map(function($product){ return $product['id_product']; }, $products); foreach(Db::getInstance()->executeS(' SELECT p.*, pl.*, s.* FROM `'._DB_PREFIX_.'pack` pp LEFT JOIN `'._DB_PREFIX_.'product` p ON (pp.`id_product_item` = p.`id_product`) 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` = pp.`id_product_pack`) LEFT JOIN `'._DB_PREFIX_.'privatesale_shipping_sale` s ON (s.`id_sale` = c.`id_sale`) WHERE s.`id_shipping` = '.(int) $_id_shipping.' AND s.`id_sale` = '.(int) $id_sale.' ORDER BY p.`id_product` ASC ') as $row){ // do not add product item it's in product list if (!in_array($row['id_product'], $product_ids)) $products[] = $row; } foreach($products as $product) { /** * @Override check pack items * Do not add pack item (only content items) */ if (isset($product['cache_is_pack']) && $product['cache_is_pack']) { continue; } $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 = $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"), '', $product['id_product'].'_'.$attribute['id_product_attribute'])), 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"), '', $product['id_product']), 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 = 'ART01'.$dateNow.'.DAT'; Db::getInstance()->Execute(' INSERT INTO `'._DB_PREFIX_.'philea_syncreport` (`id_sale`, `filename`, `date_add`) VALUES ( '.(int)$id_sale.', "'.pSQL($file).'", NOW() ) '); 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'; } }