Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require_once($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/classes/general/csv_data.php");
- CModule::IncludeModule("sale");
- CModule::IncludeModule("catalog");
- $filePath = $_SERVER['DOCUMENT_ROOT'] . '/upload/coupons.csv';
- $fp = fopen($filePath, 'w+');
- @fclose($fp);
- $fields_type = 'R'; //дописываем строки в файл
- $delimiter = ";"; //разделитель для csv-файла
- $csvFile = new \CCSVData($fields_type, false);
- $csvFile->SetFieldsType($fields_type);
- $csvFile->SetDelimiter($delimiter);
- $csvFile->SetFirstHeader(true);
- $csvFile->SaveFile($filePath, array("ID", "COUPON"));
- $rsCoupons = CCatalogDiscountCoupon::GetList([],['DISCOUNT_ID' => 20, "<ID" => 3000, ">ID" => 1000]);
- $arCoupons = [];
- while($arCoupon = $rsCoupons->Fetch()) {
- $arCoupons[] = [$arCoupon['ID'], $arCoupon['COUPON']];
- }
- foreach($arCoupons as $line)
- {
- $csvFile->SaveFile($filePath, $line);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement