38 $request = Main\Context::getCurrent()->getRequest();
40 isset($request[static::URL_PARAM_CAMPAIGN])
41 && isset($request[static::URL_PARAM_BANNER])
44 $session = self::getSessionStorage();
48 'ENGINE' => YandexDirect::ENGINE_ID,
49 'CAMPAIGN_ID' => $request[static::URL_PARAM_CAMPAIGN],
50 'BANNER_ID' => $request[static::URL_PARAM_BANNER],
133 if (in_array($orderId, static::$orderHandlerCalled))
138 Main\Loader::includeModule(
'sale')
139 && Main\Loader::includeModule(
'catalog')
151 $bannerId = (string)($data[
'BANNER_ID'] ??
'');
152 if ($bannerId !==
'')
154 static::$orderHandlerCalled[] = $orderId;
156 $engine = (string)($data[
'ENGINE'] ??
'');
160 case YandexDirect::ENGINE_ID:
161 $dbRes = YandexBannerTable::getList(array(
163 '=XML_ID' => $bannerId,
164 '=ENGINE.CODE' => YandexDirect::ENGINE_ID,
167 'ID',
'CAMPAIGN_ID',
'ENGINE_ID',
170 $banner = $dbRes->fetch();
176 $linkedProductsList = static::getBannerLinkedProducts($banner[
'ID']);
178 if (count($linkedProductsList) > 0)
180 $basket = BasketTable::getList(array(
182 '=ORDER_ID' => $orderId,
184 'select' => array(
'PRODUCT_ID'),
188 while ($item = $basket->fetch())
190 if (in_array($item[
'PRODUCT_ID'], $linkedProductsList))
197 $productInfo = \CCatalogSKU::GetProductInfo($item[
'PRODUCT_ID']);
199 if (is_array($productInfo) && in_array($productInfo[
'ID'], $linkedProductsList))
210 'ENGINE_ID' => $banner[
'ENGINE_ID'],
211 'CAMPAIGN_ID' => $banner[
'CAMPAIGN_ID'],
212 'BANNER_ID' => $banner[
'ID'],
213 'ORDER_ID' => $orderId,
218 OrderTable::add($entryData);
228 Main\Loader::includeModule(
'sale')
229 && Main\Loader::includeModule(
'catalog')
230 && Main\Loader::includeModule(
'currency')
233 $orderLinks = OrderTable::getList(array(
235 '=ORDER_ID' => $orderId,
238 'select' => array(
'ID',
'BANNER_ID')
240 $orderLink = $orderLinks->fetch();
243 $linkedProductsList = static::getBannerLinkedProducts($orderLink[
'BANNER_ID']);
244 if(count($linkedProductsList) > 0)
246 $basket = BasketTable::getList(array(
248 '=ORDER_ID' => $orderId,
250 'select' => array(
'PRODUCT_ID',
'GROSS_PROFIT',
'SUMMARY_PRICE',
'SUMMARY_PURCHASING_PRICE',
'QUANTITY'),
254 while($item = $basket->fetch())
256 if(in_array($item[
'PRODUCT_ID'], $linkedProductsList))
258 $sum += static::getProductProfit($item);
262 $productInfo = \CCatalogSKU::GetProductInfo($item[
'PRODUCT_ID']);
264 if(is_array($productInfo) && in_array($productInfo[
'ID'], $linkedProductsList))
266 $sum += static::getProductProfit($item);
271 OrderTable::update($orderLink[
'ID'], array(
306 if($productInfo[
'GROSS_PROFIT'] <>
'')
308 $profit = doubleval($productInfo[
'GROSS_PROFIT']);
313 if($productInfo[
'SUMMARY_PURCHASING_PRICE'] <>
'')
315 $purchasingCost = doubleval($productInfo[
'SUMMARY_PURCHASING_PRICE']);
319 $dbRes = ProductTable::getList(array(
321 '=ID' => $productInfo[
'PRODUCT_ID'],
324 'ID',
'PURCHASING_PRICE',
'PURCHASING_CURRENCY'
327 $productInfoBase = $dbRes->fetch();
330 $purchasingCost = $productInfoBase[
'PURCHASING_PRICE'] * $productInfo[
'QUANTITY'];
332 $baseCurrency = CurrencyManager::getBaseCurrency();
333 if($baseCurrency != $productInfoBase[
'PURCHASING_CURRENCY'])
335 $purchasingCost = \CCurrencyRates::convertCurrency(
337 $productInfoBase[
'PURCHASING_CURRENCY'],
344 $profit = doubleval($productInfo[
'SUMMARY_PRICE'])-$purchasingCost;