Bitrix-D7  20.5.0
orderprocessing.php
См. документацию.
1 <?php
2 namespace Bitrix\Sale\Internals;
3 use \Bitrix\Main\Entity\DataManager as DataManager;
4 use \Bitrix\Main\Type\DateTime as DateTime;
5 use \Bitrix\Main\Application as Application;
7 
8 Loc::loadMessages(__FILE__);
9 
10 
12 {
13  protected $orderProcessedCache = array();
14 
15  public static function getTableName()
16  {
17  return "b_sale_order_processing";
18  }
19 
20  public static function getMap()
21  {
22  return array(
23  'ORDER_ID' => array(
24  'primary' => true,
25  'data_type' => 'integer',
26  ),
27  'PRODUCTS_ADDED' => array(
28  'data_type' => 'boolean',
29  'values' => array('N','Y')
30  ),
31  'PRODUCTS_REMOVED' =>array (
32  'data_type' => 'boolean',
33  'values' => array('N','Y')
34  ),
35  'ORDER' => array(
36  'data_type' => "Bitrix\\Sale\\OrderTable",
37  'reference' => array('=this.ORDER_ID' => 'ref.ID')
38  )
39  );
40  }
41 
42  /**
43  * Wether order was processed
44  *
45  * @param int $orderId
46  *
47  * @return bool
48  */
49  public static function hasAddedProducts($orderId = 0)
50  {
51  $orderId = (int)$orderId;
52  $iterator = static::getList(array(
53  "filter" => array("ORDER_ID" => $orderId)
54  ));
55 
56  $row = $iterator->fetch();
57  return $row && $row['PRODUCTS_ADDED'] == "Y";
58  }
59 
60  /**
61  * Wether order was processed
62  *
63  * @param int $orderId
64  *
65  * @return bool|null
66  */
67  public static function hasRemovedProducts($orderId = 0)
68  {
69  $orderId = (int)$orderId;
70  $iterator = static::getList(array(
71  "filter" => array("ORDER_ID" => $orderId)
72  ));
73 
74  $row = $iterator->fetch();
75  return $row && $row['PRODUCTS_REMOVED'] == "Y";
76  }
77 
78  /**
79  * Mark order as processed
80  *
81  * @param int $orderId
82  */
83  public static function markProductsAdded($orderId = 0)
84  {
85  $orderId = (int)$orderId;
86  $iterator = static::getList(array(
87  "filter" => array("ORDER_ID" => $orderId)
88  ));
89  if($row = $iterator->fetch())
90  {
91  static::update($orderId, array("PRODUCTS_ADDED" => 'Y'));
92  }
93  else
94  {
95  static::add(array("ORDER_ID" => $orderId, "PRODUCTS_ADDED" => 'Y'));
96  }
97  }
98 
99  /**
100  * Mark orders as processed
101  *
102  * @param array $orderIds
103  */
104  public static function markProductsAddedByList(array $orderIds)
105  {
106  $preparedIds = array();
107  foreach( $orderIds as $orderId)
108  {
109  if ((int)$orderId > 0)
110  $preparedIds[] = (int)$orderId;
111  }
112 
114  $type = $connection->getType();
115  if ($type == "mysql" && !empty($preparedIds))
116  {
117  $sqlUpdate = "UPDATE ". static::getTableName() ." SET PRODUCTS_ADDED = 'Y' WHERE ORDER_ID IN (".implode(',', $preparedIds).")";
118  $connection->query($sqlUpdate);
119  }
120  }
121 
122  /**
123  * Mark order as processed
124  *
125  * @param int $orderId
126  */
127  public static function markProductsRemoved($orderId = 0)
128  {
129  $orderId = (int)$orderId;
130  $iterator = static::getList(array(
131  "filter" => array("ORDER_ID" => $orderId)
132  ));
133  if($row = $iterator->fetch())
134  {
135  static::update($orderId, array("PRODUCTS_REMOVED" => 'Y'));
136  }
137  else
138  {
139  static::add(array("ORDER_ID" => $orderId, "PRODUCTS_REMOVED" => 'Y'));
140  }
141  }
142 
143  /**
144  * @param $orderId
145  *
146  * @return bool
147  */
148  public static function deleteByOrderId($orderId)
149  {
150  if((int)($orderId) <= 0)
151  return false;
152 
154  $con->queryExecute("DELETE FROM ". static::getTableName() ." WHERE ORDER_ID=".(int)($orderId));
155  return true;
156  }
157 
158  /**
159  * Clear table
160  *
161  */
162  public static function clear()
163  {
164  $connection = Application::getConnection();
165  $sql = "DELETE FROM " . static::getTableName() . "
166  WHERE ORDER_ID NOT IN (SELECT ID FROM b_sale_order)";
167  $connection->query($sql);
168  }
169 }
170 
171 ?>
static getConnection($name="")
Static method returns database connection for the specified name.
static loadMessages($file)
Loads language messages for specified file in a lazy way.
Definition: loc.php:67
static markProductsAddedByList(array $orderIds)
Mark orders as processed.
static hasRemovedProducts($orderId=0)
Wether order was processed.
static hasAddedProducts($orderId=0)
Wether order was processed.
static markProductsAdded($orderId=0)
Mark order as processed.
static markProductsRemoved($orderId=0)
Mark order as processed.