-
-
Save JamesBondsky/5b76e7915f07be9522c6514b42125c1e to your computer and use it in GitHub Desktop.
Битрикс удалить все заказы
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
<? | |
if (!isset($_SERVER['DOCUMENT_ROOT']) || !$_SERVER['DOCUMENT_ROOT']) { | |
$_SERVER['DOCUMENT_ROOT'] = dirname(__DIR__); | |
} | |
require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php"); | |
\Bitrix\Main\Loader::includeModule('sale'); | |
use Bitrix\Sale; | |
// Выбираем заказы которые будем удалять | |
$order_list = array(); | |
$log_file = $_SERVER["DOCUMENT_ROOT"]."/orders.log"; | |
if(file_exists($log_file)) | |
unlink($log_file); | |
$db_sales = CSaleOrder::GetList(array("DATE_INSERT" => "ASC"), []); | |
while($ar_sales = $db_sales->Fetch()) | |
{ | |
$order_list[] = $ar_sales["ID"]; | |
} | |
foreach($order_list as $id) | |
{ | |
$order = Sale\Order::load($id); | |
file_put_contents($log_file, "Работаем с заказом " . $id . "\n", FILE_APPEND); | |
//отменяем оплаты если есть | |
$paymentCollection = $order->getPaymentCollection(); | |
if($paymentCollection->isPaid()) | |
{ | |
file_put_contents($log_file, "Оплачен\n", FILE_APPEND); | |
foreach($paymentCollection as $payment) | |
{ | |
$payment->setReturn("Y"); | |
} | |
} | |
//отменяем отгрузки если есть | |
$shipmentCollection = $order->getShipmentCollection(); | |
if($shipmentCollection->isShipped()) | |
{ | |
file_put_contents($log_file, "Отгружен\n", FILE_APPEND); | |
$shipment = $shipmentCollection->getItemById($shipmentCollection[0]->getField("ID")); | |
$res = $shipment->setField("DEDUCTED", "N"); | |
if(!$res->isSuccess()) | |
{ | |
file_put_contents($log_file, print_r($res->getErrors(), true), FILE_APPEND); | |
} | |
} | |
$order->save(); | |
$res_delete = Sale\Order::delete($id); | |
if(!$res_delete->isSuccess()) { | |
file_put_contents($log_file, print_r($res_delete->getErrors(), true), FILE_APPEND); | |
} | |
else | |
{ | |
file_put_contents($log_file, "Заказ " . $id . " удален\n", FILE_APPEND); | |
} | |
file_put_contents($log_file, "------------\n", FILE_APPEND); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment