B
B
BonBon Slick2016-09-04 19:48:53
PHP
BonBon Slick, 2016-09-04 19:48:53

How to properly save a row in a CSV file to import a WooCommerce product?

I have a parser, everything works well, except for the record, it somehow writes crookedly. Here is my code:
Here I process the date, turning it into a string to write ( 1 string == 1 product ):

// сделал переменную всей строки.
  $parsed_string = $parse_cat . ',' .  $parse_sub_cat . ';' . $product_title . ';' . $product_desc . ';';
  // убрал переносы
        $sanitize_strings = array("\r", "\n", "&nbsp");
  $encode_strings = str_replace($sanitize_strings, "", $parsed_string);
//убрал хтмл теги и привел к необходимой кодировке.
  $win_encode_string = array(htmlspecialchars_decode (iconv( "UTF-8" , "WINDOWS-1251", $encode_strings)));
//открыл файл
$fileopen = fopen('parsed_data.csv', 'a');
//положил нашу строку, все данные которые вытянули и обработал
  fputcsv($fileopen, $win_encode_string);
//закрыл файл.
  fclose($fileopen);

As a result, if goods already exist, it appends everything to the last one.
If there are no products, records, it writes new lines, imports, only all in one column.
Here is the header of the table:
Категория;"Метки товара";"Артикул";"Наименование";"Подробное описание";"Краткое описание";"Цена";"Цена со скидкой";"Кол-во на складе";"Цвет";"Перекрестные товары";"Картинка";"ATTACHMENT";"ATTACHMENT";"Статус товара";virtual;downloadable;file_paths

Here's what the entry looks like after it's been added:
Категория_1, категория_2;название товара;описание товара;

Here, what could be the problem?
P.S. (Unfortunately, my excel is g *, 2007, pirated, yo-ho-ho, maybe this is a repack, I can’t edit it manually, the encodings are merged. )

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question