Srv Bebeboutik 6c0978166c add modules
2016-01-04 12:49:26 +01:00

73 lines
2.3 KiB
PHP
Executable File

<?php
require_once(dirname(__FILE__).'/../../config/config.inc.php');
require_once(dirname(__FILE__) . '/../../modules/amazon/amazon.php');
require_once(dirname(__FILE__) . '/../../modules/amazon/classes/amazon.product.class.php');
@ini_set('display_errors', 'on');
@ini_set('max_execution_time', 0);
if (!defined('_PS_BASE_URL_'))
define('_PS_BASE_URL_', Tools::getShopDomain(true));
$path = _PS_ROOT_DIR_.'/modules/importproduit/';
$fichier = "amazon.csv";
$handle = fopen($path.$fichier, "r");
if($handle){
$row = 0;
while (($data01 = fgetcsv($handle, 100000, ";")) !== FALSE) {
$num = count($data01);
$data = utf8EncodeArray($data01);
if($row > 0){
$reference = $data[0]; // A
$asin = $data[1]; // A
$id_product = existsRefInDatabase($reference);
if($id_product){
$options = array(
'force' => 0,
'nopexport' => 0,
'noqexport' => 0,
'fba' => 0,
'fba_value' => 0,
'latency' => 0,
'disable' => 0,
'price' => 0,
'asin1' => $asin,
'asin2' => "",
'asin3' => "",
'text' => "",
'bullet_point1' =>"",
'bullet_point2' => "",
'bullet_point3' => "",
'bullet_point4' => "",
'bullet_point5' => "",
'shipping' => null,
'shipping_type' => 1
);
Amazon_Product::setProductOptions($id_product, 1, $options);
}
}
$row++;
echo $row."<br/>";
ob_end_flush();
flush();
ob_start();
}
fclose($handle);
echo "Import terminé";
}else{
echo "prob ouverture";
}
function utf8EncodeArray($array){
return (is_array($array) ? array_map('utf8_encode', $array) : utf8_encode($array));
}
function existsRefInDatabase($reference){
$row = Db::getInstance()->getRow('
SELECT `id_product`
FROM `'._DB_PREFIX_.'product` p
WHERE p.reference = "'.$reference.'"');
return $row['id_product'];
}