4use Bitrix\Currency\CurrencyManager;
6use Bitrix\Main\Application;
7use Bitrix\Main\Localization\Loc;
8use Bitrix\Main\Session\Session;
9use Bitrix\Sale\Internals\BasketTable;
10use Bitrix\Catalog\ProductTable;
11use Bitrix\Seo\Adv\LinkTable;
12use Bitrix\Seo\Adv\OrderTable;
13use Bitrix\Seo\Adv\YandexBannerTable;
14use Bitrix\Seo\Engine\YandexDirect;
16Loc::loadMessages(__FILE__);
32 private const DATA_INDEX =
'SEO_ADV';
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],
58 $session = self::getSessionStorage();
59 if ($session ===
null)
63 $data = $session->get(self::DATA_INDEX);
71 $session = self::getSessionStorage();
72 if ($session ===
null)
76 $data = $session->get(self::DATA_INDEX);
104 static::countSessionOrder(
$orderId);
112 static::countSessionOrder(
$orderId);
119 static::countSessionOrder(
$orderId);
127 static::countSessionOrder(
$orderId);
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;
160 case YandexDirect::ENGINE_ID:
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(
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'],
218 OrderTable::add($entryData);
228 Main\Loader::includeModule(
'sale')
229 &&
Main\Loader::includeModule(
'catalog')
230 &&
Main\Loader::includeModule(
'currency')
233 $orderLinks = OrderTable::getList(
array(
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(
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(
282 $linkedProductsList =
array();
283 $linkedProducts = LinkTable::getList(
287 '=BANNER_ID' => $bannerId,
295 while($link = $linkedProducts->fetch())
297 $linkedProductsList[] = $link[
'LINK_ID'];
300 return $linkedProductsList;
306 if($productInfo[
'GROSS_PROFIT'] <>
'')
308 $profit = doubleval($productInfo[
'GROSS_PROFIT']);
313 if($productInfo[
'SUMMARY_PURCHASING_PRICE'] <>
'')
315 $purchasingCost = doubleval($productInfo[
'SUMMARY_PURCHASING_PRICE']);
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;
356 private static function getSessionStorage(): ?
Session
359 $session = Application::getInstance()->getSession();
360 if (!$session->isAccessible())
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
const TYPE_IBLOCK_ELEMENT
static getBannerLinkedProducts($bannerId)
static onSaleStatusOrder($orderId, $status)
static onBasketOrder($orderId)
static $orderHandlerCalled
static countSessionOrder($orderId)
static onOrderSave($orderId, $orderFields, $orderData, $isNew)
static checkSessionOrder($orderId)
const URL_PARAM_CAMPAIGN_VALUE
const URL_PARAM_BANNER_VALUE
static onSaleDeductOrder($orderId, $val)
static onSalePayOrder($orderId, $val)
static onSaleDeliveryOrder($orderId, $val)
static getProductProfit($productInfo)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"