Last active
May 6, 2020 11:06
-
-
Save CrazyBoy49z/c381e0477b953b55ecbb90d246f836ff to your computer and use it in GitHub Desktop.
catalog prom.ua generate laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Generate prom.ua catalog | |
* | |
* @url https://support.prom.ua/hc/ru/articles/360004960817 | |
* @create CrazyBoy49z | |
* @date 06.05.2020 | |
*/ | |
$func = function ($value) { | |
return '"{$value}"'; | |
}; | |
$db = DB::table('rows')->get(); | |
$data = '"Код_товара"; "Название_позиции"; "Производитель"; "HTML_ключевые_слова"; "Описание"; "Тип_товара"; "Цена"; '. | |
'"Валюта"; "Единица_измерения"; "Минимальный_объем_заказа"; "Оптовая_цена"; "Минимальный_заказ_опт"; '. | |
'"Ссылка_изображения"; "Наличие"; "Скидка"'.PHP_EOL; | |
foreach ($db as $row) { | |
$row = (object)$row; | |
$new = [ | |
$row->cat_num, | |
$row->name, | |
$row->dev, | |
$row->orig_num, | |
'', | |
'u', | |
preg_replace("/[^\.\d]+/", '', $row->price), | |
'UAH', | |
'шт', | |
'1', | |
'', | |
'1', | |
'', | |
'+', | |
'', | |
]; | |
$new = array_map($func, (array)$new); | |
$line = implode(';', array_values($new)); | |
$data .= $line.PHP_EOL; | |
} | |
file_put_contents('catalog.csv', $data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment