Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
orderprocessing.php
1<?php
3use \Bitrix\Main\Entity\DataManager as DataManager;
4use \Bitrix\Main\Type\DateTime as DateTime;
5use \Bitrix\Main\Application as Application;
7
8Loc::loadMessages(__FILE__);
9
10
28{
29 protected $orderProcessedCache = array();
30
31 public static function getTableName()
32 {
33 return "b_sale_order_processing";
34 }
35
36 public static function getMap()
37 {
38 return array(
39 'ORDER_ID' => array(
40 'primary' => true,
41 'data_type' => 'integer',
42 ),
43 'PRODUCTS_ADDED' => array(
44 'data_type' => 'boolean',
45 'values' => array('N','Y')
46 ),
47 'PRODUCTS_REMOVED' =>array (
48 'data_type' => 'boolean',
49 'values' => array('N','Y')
50 ),
51 'ORDER' => array(
52 'data_type' => "Bitrix\\Sale\\OrderTable",
53 'reference' => array('=this.ORDER_ID' => 'ref.ID')
54 )
55 );
56 }
57
65 public static function hasAddedProducts($orderId = 0)
66 {
67 $orderId = (int)$orderId;
68 $iterator = static::getList(array(
69 "filter" => array("ORDER_ID" => $orderId)
70 ));
71
72 $row = $iterator->fetch();
73 return $row && $row['PRODUCTS_ADDED'] == "Y";
74 }
75
83 public static function hasRemovedProducts($orderId = 0)
84 {
85 $orderId = (int)$orderId;
86 $iterator = static::getList(array(
87 "filter" => array("ORDER_ID" => $orderId)
88 ));
89
90 $row = $iterator->fetch();
91 return $row && $row['PRODUCTS_REMOVED'] == "Y";
92 }
93
99 public static function markProductsAdded($orderId = 0)
100 {
101 $orderId = (int)$orderId;
102 $iterator = static::getList(array(
103 "filter" => array("ORDER_ID" => $orderId)
104 ));
105 if($row = $iterator->fetch())
106 {
107 static::update($orderId, array("PRODUCTS_ADDED" => 'Y'));
108 }
109 else
110 {
111 static::add(array("ORDER_ID" => $orderId, "PRODUCTS_ADDED" => 'Y'));
112 }
113 }
114
120 public static function markProductsAddedByList(array $orderIds)
121 {
122 $preparedIds = array();
123 foreach( $orderIds as $orderId)
124 {
125 if ((int)$orderId > 0)
126 $preparedIds[] = (int)$orderId;
127 }
128
129 $connection = \Bitrix\Main\Application::getConnection();
130 $type = $connection->getType();
131 if ($type == "mysql" && !empty($preparedIds))
132 {
133 $sqlUpdate = "UPDATE ". static::getTableName() ." SET PRODUCTS_ADDED = 'Y' WHERE ORDER_ID IN (".implode(',', $preparedIds).")";
134 $connection->query($sqlUpdate);
135 }
136 }
137
143 public static function markProductsRemoved($orderId = 0)
144 {
145 $orderId = (int)$orderId;
146 $iterator = static::getList(array(
147 "filter" => array("ORDER_ID" => $orderId)
148 ));
149 if($row = $iterator->fetch())
150 {
151 static::update($orderId, array("PRODUCTS_REMOVED" => 'Y'));
152 }
153 else
154 {
155 static::add(array("ORDER_ID" => $orderId, "PRODUCTS_REMOVED" => 'Y'));
156 }
157 }
158
164 public static function deleteByOrderId($orderId)
165 {
166 if((int)($orderId) <= 0)
167 return false;
168
169 $con = \Bitrix\Main\Application::getConnection();
170 $con->queryExecute("DELETE FROM ". static::getTableName() ." WHERE ORDER_ID=".(int)($orderId));
171 return true;
172 }
173
178 public static function clear()
179 {
180 $connection = Application::getConnection();
181 $sql = "DELETE FROM " . static::getTableName() . "
182 WHERE ORDER_ID NOT IN (SELECT ID FROM b_sale_order)";
183 $connection->query($sql);
184 }
185}
186
187?>
static getConnection($name="")
static loadMessages($file)
Definition loc.php:64