Bitrix-D7  20.5.0
recurring.php
См. документацию.
1 <?php
2 /**
3  * Bitrix Framework
4  * @package bitrix
5  * @subpackage sale
6  * @copyright 2001-2012 Bitrix
7  */
8 namespace Bitrix\Sale;
9 
10 use Bitrix\Main;
11 
13 
14 /**
15  * Class Basket
16  * @package Bitrix\Sale
17  */
18 class Recurring
19 {
20  /**
21  * @param Order $order
22  * @param array $resultList
23  *
24  * @throws Main\ObjectNotFoundException
25  */
26  public static function repeat(Order $order, array $resultList)
27  {
28  $recurringID = intval($order->getField("RECURRING_ID"));
29 
30  $basket = $order->getBasket();
31  foreach ($resultList as $providerName => $basketList)
32  {
33  foreach ($basketList as $basketCode => $resultData)
34  {
35  if ($order->isPaid())
36  {
37  if (!empty($resultData) && is_array($resultData))
38  {
39  if (empty($resultData['ORDER_ID']) || intval($resultData['ORDER_ID']) < 0)
40  $resultData["ORDER_ID"] = $order->getId();
41 
42  $resultData["REMAINING_ATTEMPTS"] = (defined("SALE_PROC_REC_ATTEMPTS") ? SALE_PROC_REC_ATTEMPTS : 3);
43  $resultData["SUCCESS_PAYMENT"] = "Y";
44 
45  if ($recurringID > 0)
46  \CSaleRecurring::Update($recurringID, $resultData);
47  else
48  \CSaleRecurring::Add($resultData);
49  }
50  elseif ($recurringID > 0)
51  {
52  \CSaleRecurring::Delete($recurringID);
53  }
54  }
55  else
56  {
57  if (!$basketItem = $basket->getItemByBasketCode($basketCode))
58  {
59  throw new Main\ObjectNotFoundException('Entity "BasketItem" not found');
60  }
61 
62  $resRecurring = \CSaleRecurring::GetList(
63  array(),
64  array(
65  "USER_ID" => $order->getUserId(),
66  "PRODUCT_ID" => $basketItem->getProductId(),
67  "MODULE" => $basketItem->getField("MODULE"),
68  "ORDER_ID" => $order->getId(),
69  )
70  );
71  while ($recurringData = $resRecurring->Fetch())
72  {
73  \CSaleRecurring::Delete($recurringData["ID"]);
74  }
75  }
76  }
77  }
78  }
79 }
static loadMessages($file)
Loads language messages for specified file in a lazy way.
Definition: loc.php:67
Exception is thrown when an object is not present.
static repeat(Order $order, array $resultList)
Definition: recurring.php:26