Advertisement
AD_min

Untitled

Oct 24th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.91 KB | None | 0 0
  1. require_once($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/classes/general/csv_data.php");
  2. CModule::IncludeModule("sale");
  3. CModule::IncludeModule("catalog");
  4. $filePath = $_SERVER['DOCUMENT_ROOT'] . '/upload/coupons.csv';
  5. $fp = fopen($filePath, 'w+');
  6. @fclose($fp);
  7.  
  8. $fields_type = 'R'; //дописываем строки в файл
  9. $delimiter = ";";   //разделитель для csv-файла
  10. $csvFile = new \CCSVData($fields_type, false);
  11. $csvFile->SetFieldsType($fields_type);
  12. $csvFile->SetDelimiter($delimiter);
  13. $csvFile->SetFirstHeader(true);
  14. $csvFile->SaveFile($filePath, array("ID", "COUPON"));
  15.  
  16. $rsCoupons = CCatalogDiscountCoupon::GetList([],['DISCOUNT_ID' => 20, "<ID" => 3000, ">ID" => 1000]);
  17. $arCoupons = [];
  18. while($arCoupon = $rsCoupons->Fetch()) {
  19.     $arCoupons[] = [$arCoupon['ID'], $arCoupon['COUPON']];
  20. }
  21.  
  22. foreach($arCoupons as $line)
  23. {
  24.     $csvFile->SaveFile($filePath, $line);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement