Exemple #1
0
 function import()
 {
     global $toC_Json, $osC_Language;
     $max_execution_time = ini_get('max_execution_time');
     ini_set('max_execution_time', 600);
     $type = strpos($_REQUEST['type'], 'customers') !== false ? 'customers' : 'products';
     $param = array('type' => $type, 'filename' => $_FILES['files'], 'image_file' => $_FILES['image_zip'], 'csv_field_seperator' => $_REQUEST['seperator'], 'csv_field_enclosed' => $_REQUEST['enclosed'], 'file_type' => $_REQUEST['file_type'], 'compression_type' => $_REQUEST['compression']);
     $importer = toC_Importer::getImporter($param);
     if ($importer->parse()) {
         $response = array('success' => true, 'feedback' => $osC_Language->get('ms_success_action_performed'));
     } else {
         $response = array('success' => false, 'feedback' => $osC_Language->get('ms_error_action_not_performed'));
     }
     ini_set('max_execution_time', $max_execution_time);
     header('Content-Type: text/html');
     echo $toC_Json->encode($response);
 }
 function insertProduct($product, $descriptions, $categories_id, $images)
 {
     global $osC_Database;
     $insert = true;
     $products_id = (int) $product['products_id'];
     unset($product['products_id']);
     if ($products_id > 0 && osC_Products_Importer::isProductExist($products_id)) {
         $insert = false;
     }
     if ($insert == true) {
         $products_id = toC_Importer::insertData(TABLE_PRODUCTS, $product);
         //categories
         if (is_array($categories_id) && !empty($categories_id)) {
             foreach ($categories_id as $category) {
                 $data = array('categories_id' => $category, 'products_id' => $products_id);
                 toC_Importer::insertData(TABLE_PRODUCTS_TO_CATEGORIES, $data);
             }
         }
         //description
         foreach ($descriptions as $description) {
             $description['products_id'] = $products_id;
             toC_Importer::insertData(TABLE_PRODUCTS_DESCRIPTION, $description);
         }
         $sort_id = 1;
         foreach ($images as $image) {
             $image['products_id'] = $products_id;
             $image['default_flag'] = $sort_id == 1 ? 1 : 0;
             $image['sort_order'] = $sort_id++;
             if (file_exists(DIR_FS_CATALOG . DIR_WS_IMAGES . 'products/_upload/' . $image['image'])) {
                 $image_id = toC_Importer::insertData(TABLE_PRODUCTS_IMAGES, $image);
                 copy('../images/products/_upload/' . $image['image'], '../images/products/originals/' . $image['image']);
                 $new_image_name = $products_id . '_' . $image_id . '_' . $image['image'];
                 @rename('../images/products/originals/' . $image['image'], '../images/products/originals/' . $new_image_name);
                 $Qupdate = $osC_Database->query('update :table_products_images set image = :image where id = :id');
                 $Qupdate->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
                 $Qupdate->bindValue(':image', $new_image_name);
                 $Qupdate->bindInt(':id', $image_id);
                 $Qupdate->execute();
                 $osC_Image = new osC_Image_Admin();
                 foreach ($osC_Image->getGroups() as $group) {
                     if ($group['id'] != '1') {
                         $osC_Image->resize($new_image_name, $group['id'], 'products');
                     }
                 }
             }
         }
     }
 }
Exemple #3
0
 function insertProduct($product, $descriptions, $categories_id, $images)
 {
     global $osC_Database;
     $products_id = toC_Importer::insertData(TABLE_PRODUCTS, $product);
     if (isset($products_id) && $products_id != '') {
         foreach ($descriptions as $description) {
             $description['products_id'] = $products_id;
             toC_Importer::insertData(TABLE_PRODUCTS_DESCRIPTION, $description);
         }
         $category['categories_id'] = $categories_id;
         $category['products_id'] = $products_id;
         toC_Importer::insertData(TABLE_PRODUCTS_TO_CATEGORIES, $category);
         $sort_id = 1;
         foreach ($images as $image) {
             $image['products_id'] = $products_id;
             $image['default_flag'] = $sort_id == 1 ? 1 : 0;
             $image['sort_order'] = $sort_id++;
             if (file_exists(DIR_FS_CATALOG . DIR_WS_IMAGES . 'products/_upload/' . $image['image'])) {
                 copy('../images/products/_upload/' . $image['image'], '../images/products/originals/' . $image['image']);
                 $osC_Image = new osC_Image_Admin();
                 foreach ($osC_Image->getGroups() as $group) {
                     if ($group['id'] != '1') {
                         $osC_Image->resize($image['image'], $group['id'], 'products');
                     }
                 }
                 toC_Importer::insertData(TABLE_PRODUCTS_IMAGES, $image);
             }
         }
     }
 }