Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
product.php
1<?php
11namespace Bitrix\Sale\Internals;
12
13use Bitrix\Main;
15
16Loc::loadMessages(__FILE__);
17
18if (!Main\Loader::includeModule('iblock'))
19{
20 return;
21}
22
39class ProductTable extends Main\Entity\DataManager
40{
41 public static function getTableName()
42 {
43 return 'b_catalog_product';
44 }
45
46 public static function getMap()
47 {
48 // Get weight factor
49 $siteId = '';
50 $weight_koef = 0;
51 $site_currency = '';
52 if (class_exists('\CBaseSaleReportHelper'))
53 {
54 if (\CBaseSaleReportHelper::isInitialized())
55 {
56 $siteId = \CBaseSaleReportHelper::getDefaultSiteId();
57 if ($siteId !== null)
58 {
59 $weight_koef = intval(\CBaseSaleReportHelper::getDefaultSiteWeightDivider());
60 }
61
62 // Get site currency
63 $site_currency = \CBaseSaleReportHelper::getSiteCurrencyId();
64 }
65 }
66 if ($weight_koef <= 0) $weight_koef = 1;
67
68 global $DB;
69
70 if (function_exists('___dbCastIntToChar') !== true)
71 {
72 eval(
73 'function ___dbCastIntToChar($dbtype, $param)'.
74 '{'.
75 ' $result = $param;'.
76 ' if (ToLower($dbtype) === "mssql")'.
77 ' {'.
78 ' $result = "CAST(".$param." AS VARCHAR)";'.
79 ' }'.
80 ' return $result;'.
81 '}'
82 );
83 }
84
85 $fieldsMap = array(
86 'ID' => array(
87 'data_type' => 'integer',
88 'primary' => true
89 ),
90 /*'IBLOCK_ID' => array(
91 'data_type' => 'integer'
92 ),*/
93 'TIMESTAMP_X' => array(
94 'data_type' => 'integer'
95 ),
96 'DATE_UPDATED' => array(
97 'data_type' => 'datetime',
98 'expression' => array(
99 $DB->datetimeToDateFunction('%s'), 'TIMESTAMP_X',
100 )
101 ),
102 'QUANTITY' => array(
103 'data_type' => 'float'
104 ),
105 'MEASURE' => array(
106 'data_type' => 'integer'
107 ),
108 'PURCHASING_PRICE' => array(
109 'data_type' => 'float'
110 ),
111 'PURCHASING_CURRENCY' => array(
112 'data_type' => 'string'
113 ),
114 'IBLOCK' => array(
115 'data_type' => 'Bitrix\Iblock\Element',
116 'reference' => array('=this.ID' => 'ref.ID')
117 ),
118 'NAME' => array(
119 'data_type' => 'string',
120 'expression' => array(
121 '%s', 'IBLOCK.NAME'
122 )
123 ),
124 'NAME_WITH_IDENT' => array(
125 'data_type' => 'string',
126 'expression' => array(
127 $DB->concat('%s', '\' [\'', ___dbCastIntToChar('mysql', '%s'), '\']\''), 'NAME', 'ID'
128 )
129 ),
130 'ACTIVE' => array(
131 'data_type' => 'boolean',
132 'expression' => array(
133 '%s', 'IBLOCK.ACTIVE'
134 ),
135 'values' => array('N','Y')
136 ),
137 'WEIGHT' => array(
138 'data_type' => 'float'
139 ),
140 'WEIGHT_IN_SITE_UNITS' => array(
141 'data_type' => 'float',
142 'expression' => array(
143 '%s / '.$DB->forSql($weight_koef), 'WEIGHT'
144 )
145 ),
146 'PRICE' => array(
147 'data_type' => 'float',
148 'expression' => array(
149 '(SELECT b_catalog_price.PRICE FROM b_catalog_price
150 LEFT JOIN b_catalog_group ON b_catalog_group.ID = b_catalog_price.CATALOG_GROUP_ID
151 WHERE
152 b_catalog_price.PRODUCT_ID = %s
153 AND
154 b_catalog_group.base = \'Y\'
155 AND
156 ( b_catalog_price.quantity_from <= 1 OR b_catalog_price.quantity_from IS NULL )
157 AND
158 ( b_catalog_price.quantity_to >= 1 OR b_catalog_price.quantity_to IS NULL)
159 LIMIT 1)', 'ID'
160 )
161 ),
162 'CURRENCY' => array(
163 'data_type' => 'string',
164 'expression' => array(
165 '(SELECT b_catalog_price.CURRENCY FROM b_catalog_price
166 LEFT JOIN b_catalog_group ON b_catalog_group.ID = b_catalog_price.CATALOG_GROUP_ID
167 WHERE
168 b_catalog_price.PRODUCT_ID = %s
169 AND
170 b_catalog_group.base = \'Y\'
171 AND
172 ( b_catalog_price.quantity_from <= 1 OR b_catalog_price.quantity_from IS NULL )
173 AND
174 ( b_catalog_price.quantity_to >= 1 OR b_catalog_price.quantity_to IS NULL)
175 LIMIT 1)', 'ID'
176 )
177 ),
178 'SUMMARY_PRICE' => array(
179 'data_type' => 'float',
180 'expression' => array(
181 '%s * %s', 'QUANTITY', 'PRICE'
182 ),
183 ),
184
185
186
187 'CURRENT_CURRENCY_RATE' => array(
188 'data_type' => 'float',
189 'expression' => array(
190 '('.$DB->topSql('SELECT (CASE WHEN b_catalog_currency_rate.RATE IS NOT NULL THEN b_catalog_currency_rate.RATE ELSE b_catalog_currency.AMOUNT END)
191 FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1
192 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= '.$DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X').')
193 WHERE b_catalog_product.ID = %s AND b_catalog_currency.CURRENCY = %s
194 ORDER BY DATE_RATE DESC', 1).')', 'ID', 'CURRENCY'
195 )
196 ),
197 'CURRENT_CURRENCY_RATE_CNT' => array(
198 'data_type' => 'float',
199 'expression' => array(
200 '('.$DB->topSql('SELECT (CASE WHEN b_catalog_currency_rate.RATE_CNT IS NOT NULL THEN b_catalog_currency_rate.RATE_CNT ELSE b_catalog_currency.AMOUNT_CNT END)
201 FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1
202 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= '.$DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X').')
203 WHERE b_catalog_product.ID = %s AND b_catalog_currency.CURRENCY = %s
204 ORDER BY DATE_RATE DESC', 1).')', 'ID', 'CURRENCY'
205 )
206 ),
207
208 'CURRENT_SITE_CURRENCY_RATE' => array(
209 'data_type' => 'float',
210 'expression' => array(
211 '('.$DB->topSql('SELECT (CASE WHEN b_catalog_currency_rate.RATE IS NOT NULL THEN b_catalog_currency_rate.RATE ELSE b_catalog_currency.AMOUNT END)
212 FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1
213 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= '.$DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X').')
214 WHERE b_catalog_product.ID = %s AND b_catalog_currency.CURRENCY = \''.$DB->forSql($site_currency).'\'
215 ORDER BY DATE_RATE DESC', 1).')', 'ID'
216 )
217 ),
218
219 'CURRENT_SITE_CURRENCY_RATE_CNT' => array(
220 'data_type' => 'float',
221 'expression' => array(
222 '('.$DB->topSql('SELECT (CASE WHEN b_catalog_currency_rate.RATE_CNT IS NOT NULL THEN b_catalog_currency_rate.RATE_CNT ELSE b_catalog_currency.AMOUNT_CNT END)
223 FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1
224 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= '.$DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X').')
225 WHERE b_catalog_product.ID = %s AND b_catalog_currency.CURRENCY = \''.$DB->forSql($site_currency).'\'
226 ORDER BY DATE_RATE DESC', 1).')', 'ID'
227 )
228 ),
229
230
231
232 'PURCHASING_CURRENCY_RATE' => array(
233 'data_type' => 'float',
234 'expression' => array(
235 '('.$DB->topSql('SELECT (CASE WHEN b_catalog_currency_rate.RATE IS NOT NULL THEN b_catalog_currency_rate.RATE ELSE b_catalog_currency.AMOUNT END)
236 FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1
237 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= '.$DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X').')
238 WHERE b_catalog_product.ID = %s AND b_catalog_currency.CURRENCY = %s
239 ORDER BY DATE_RATE DESC', 1).')', 'ID', 'PURCHASING_CURRENCY'
240 )
241 ),
242 'PURCHASING_CURRENCY_RATE_CNT' => array(
243 'data_type' => 'float',
244 'expression' => array(
245 '('.$DB->topSql('SELECT (CASE WHEN b_catalog_currency_rate.RATE_CNT IS NOT NULL THEN b_catalog_currency_rate.RATE_CNT ELSE b_catalog_currency.AMOUNT_CNT END)
246 FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1
247 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= '.$DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X').')
248 WHERE b_catalog_product.ID = %s AND b_catalog_currency.CURRENCY = %s
249 ORDER BY DATE_RATE DESC', 1).')', 'ID', 'PURCHASING_CURRENCY'
250 )
251 ),
252
253
254
255 'PRICE_IN_SITE_CURRENCY' => array(
256 'data_type' => 'float',
257 'expression' => array(
258 '%s * (%s * %s / %s / %s)',
259 'PRICE', 'CURRENT_CURRENCY_RATE', 'CURRENT_SITE_CURRENCY_RATE_CNT', 'CURRENT_SITE_CURRENCY_RATE', 'CURRENT_CURRENCY_RATE_CNT'
260 )
261 ),
262
263 'PURCHASING_PRICE_IN_SITE_CURRENCY' => array(
264 'data_type' => 'float',
265 'expression' => array(
266 '%s * (%s * %s / %s / %s)',
267 'PURCHASING_PRICE', 'PURCHASING_CURRENCY_RATE', 'CURRENT_SITE_CURRENCY_RATE_CNT', 'CURRENT_SITE_CURRENCY_RATE', 'PURCHASING_CURRENCY_RATE_CNT'
268 )
269 ),
270
271 'SUMMARY_PRICE_IN_SITE_CURRENCY' => array(
272 'data_type' => 'float',
273 'expression' => array(
274 '%s * (%s * %s / %s / %s)',
275 'SUMMARY_PRICE', 'CURRENT_CURRENCY_RATE', 'CURRENT_SITE_CURRENCY_RATE_CNT', 'CURRENT_SITE_CURRENCY_RATE', 'CURRENT_CURRENCY_RATE_CNT'
276 )
277 )
278 );
279
280 return $fieldsMap;
281 }
282}
static loadMessages($file)
Definition loc.php:64