Возвращаем блок "Предложите покупателю" в детальный заказ 1С-Битрикс

, Михаил
Добавляем в /bitrix/php_interface/admin_header.php

<?php 
<? if (stripos($_SERVER['REQUEST_URI'], '/bitrix/admin/sale_order_view.php') !== false) : ?>
    <script type="text/javascript">
        $(function () {
	            $.ajax({  method: "GET", url: "/bitrix/diva/ajaxGetBasket.php", data: {ID: <?= intval($_REQUEST['ID']) ?>}
		}).done(function (msg) {
		                $('.adm-s-result-container').prepend(msg);
		});
	});
    </script>
<?endif;
?>
?>

Создаём обработчик /bitrix/diva/ajaxGetBasket.php

<?php 

define("NO_KEEP_STATISTIC"true);
//define("NOT_CHECK_PERMISSIONS", true);
require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php");
$ID intval($_REQUEST['ID']);
if (!$USER->IsAdmin() || $ID == 0) {
	    die();
	}
require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/sale/general/admin_tool.php");
require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/sale/lang/ru/admin/order_detail.php");
CModule::IncludeModule("iblock");
CModule::IncludeModule("catalog");
CModule::IncludeModule("sale");
$dbOrder CSaleOrder::GetList(
                array("ID" => "DESC"), array("ID" => $ID), falsefalse, array(
            "ID""LID""PERSON_TYPE_ID",
            "PAYED""DATE_PAYED""EMP_PAYED_ID""PAY_VOUCHER_NUM""PAY_VOUCHER_DATE",
            "CANCELED""DATE_CANCELED""EMP_CANCELED_ID""REASON_CANCELED",
            "STATUS_ID""DATE_STATUS""EMP_STATUS_ID""PRICE_DELIVERY",
            "ALLOW_DELIVERY""DATE_ALLOW_DELIVERY""EMP_ALLOW_DELIVERY_ID",
            "DEDUCTED""DATE_DEDUCTED""EMP_DEDUCTED_ID""REASON_UNDO_DEDUCTED",
            "MARKED""DATE_MARKED""EMP_MARKED_ID""REASON_MARKED",
            "PRICE""CURRENCY""DISCOUNT_VALUE""SUM_PAID""USER_ID""PAY_SYSTEM_ID",
            "DELIVERY_ID""DATE_INSERT""DATE_INSERT_FORMAT""DATE_UPDATE""USER_DESCRIPTION",
            "ADDITIONAL_INFO""PS_STATUS""PS_STATUS_CODE""PS_STATUS_DESCRIPTION",
            "PS_STATUS_MESSAGE""PS_SUM""PS_CURRENCY""PS_RESPONSE_DATE""COMMENTS",
            "TAX_VALUE""STAT_GID""RECURRING_ID""AFFILIATE_ID""LOCK_STATUS",
            "USER_LOGIN""USER_NAME""USER_LAST_NAME""USER_EMAIL""DELIVERY_DOC_NUM",
            "DELIVERY_DOC_DATE""STORE_ID""ACCOUNT_NUMBER""TRACKING_NUMBER",
                )
);
if (($arOrder $dbOrder->Fetch())) {
	    ?>
	    <div class="load_product order_summary" style="float: left;
	">
	        <table width="100%" class="itog_header"><tr><td>Предложите покупателю</td></tr></table>
	        <div id="tabs">
	            <?
	            $crmMode false;
	            $displayNone "block";
	            $displayNoneBasket "block";
	            $displayNoneViewed "block";
	            $arFilterRecomendet = array();
	            $arBasketItems = array();
	            $dbBasketTmp CSaleBasket::GetList(array("ID" => "ASC"), array("ORDER_ID" => $arOrder["ID"]), falsefalse, array("ID""PRODUCT_ID"));
	            while ($arBasketTmp $dbBasketTmp->GetNext()) {
		                $arBasketItems[] = $arBasketTmp;
		            }
	            //pr($arBasketItems);
	            foreach ($arBasketItems as $arItem) {
		                if (!CSaleBasketHelper::isSetItem($arItem)) {
			                    $arFilterRecomendet[] = $arItem["PRODUCT_ID"];
			                }
		            }
	            $arRecommendedResult CSaleProduct::GetRecommendetProduct($arOrder["USER_ID"], $arOrder["LID"], $arFilterRecomendet);
	            $recomCnt count($arRecommendedResult);
	            if ($recomCnt 2) {
		                $arTmp = array();
		                $arTmp[] = $arRecommendedResult[0];
		                $arTmp[] = $arRecommendedResult[1];
		                $arRecommendedResult $arTmp;
		            }
	            if ($recomCnt <= 0)
	                $displayNone "none";
	            $arErrors = array();
	            $arFuserItems CSaleUser::GetList(array("USER_ID" => intval($arOrder["USER_ID"])));
	            $arCartWithoutSetItems = array();
	            $arTmpShoppingCart CSaleBasket::DoGetUserShoppingCart($arOrder["LID"], $arOrder["USER_ID"], $arFuserItems["ID"], $arErrors, array());
	            if (is_array($arTmpShoppingCart)) {
		                foreach ($arTmpShoppingCart as $arCartItem) {
			                    if (CSaleBasketHelper::isSetItem($arCartItem))
			                        continue;
			                    $item findPositionsByID($arCartItem["PRODUCT_ID"]);
			                    if ($item['IBLOCK_ID'] != CATALOG_IBLOCK_ID) {
				                        if ($item['PROPS']['CML2_LINK']['VALUE'] != "") {
					                            $item findPositionsByID($item['PROPS']['CML2_LINK']['VALUE']);
					                        }
				                    }
			                    $arCartItem['MASTER'] = $item;
			                    $arCartItem['NAME'] = "[" $item['PROPS']['CML2_ARTICLE']['VALUE'] . "] " $arCartItem['NAME'];
			                    $arCartWithoutSetItems[] = $arCartItem;
			                }
		            }
	            $basketCnt count($arCartWithoutSetItems);
	            if ($basketCnt 2) {
		                $arTmp = array();
		                $arTmp[] = $arCartWithoutSetItems[0];
		                $arTmp[] = $arCartWithoutSetItems[1];
		                $arCartWithoutSetItems $arTmp;
		            }
	            if ($basketCnt <= 0)
	                $displayNoneBasket "none";
	            ///
	            $arViewed = array();
	            $arViewedIds = array();
	            $viewedCount 0;
	            $mapViewed = array();
	            if (CModule::includeModule("catalog")) {
		                $viewedIterator = \Bitrix\Catalog\CatalogViewedProductTable::getList(array(
		                            'order' => array("DATE_VISIT" => "DESC"),
		                            'filter' => array('FUSER_ID' => $arFuserItems["ID"], "SITE_ID" => $arOrder["LID"]),
		                            'select' => array("ID""FUSER_ID""DATE_VISIT""PRODUCT_ID""LID" => "SITE_ID""NAME" => "ELEMENT.NAME""PREVIEW_PICTURE" => "ELEMENT.PREVIEW_PICTURE""DETAIL_PICTURE" => "ELEMENT.DETAIL_PICTURE")
		                ));
		                while ($viewed $viewedIterator->fetch()) {
			                    $viewed['MODULE'] = 'catalog';
			                    $arViewed[$viewedCount] = $viewed;
			                    $arViewedIds[] = $viewed['PRODUCT_ID'];
			                    $mapViewed[$viewed['PRODUCT_ID']] = $viewedCount;
			                    $viewedCount++;
			                }
		                unset($viewedCount);
		                $baseGroup CCatalogGroup::getBaseGroup();
		                if (!empty($arViewedIds)) {
			                    $priceIterator CPrice::getList(
			                                    array(), array("PRODUCT_ID" => $arViewedIds'CATALOG_GROUP_ID' => $baseGroup['ID']), falsefalse, array("PRODUCT_ID""PRICE""CURRENCY"));
			                    while ($productPrice $priceIterator->fetch()) {
				                        if (isset($mapViewed[$productPrice['PRODUCT_ID']])) {
					                            $key $mapViewed[$productPrice['PRODUCT_ID']];
					                            $arViewed[$key]["PRICE"] = $productPrice["PRICE"];
					                            $arViewed[$key]["CURRENCY"] = $productPrice["CURRENCY"];
					                        }
				                    }
			                }
		                $viewedCnt count($arViewed);
		                $arViewed array_slice($arViewed02);
		                if (count($arViewed) <= 0)
		                    $displayNoneViewed "none";
		            }
	            else {
		                $displayNoneViewed "none";
		            }
	            $tabBasket "tabs";
	            $tabViewed "tabs";
	            if ($displayNoneBasket == 'none' && $displayNone == 'none' && $displayNoneViewed == 'block')
	                $tabViewed .= " active";
	            if ($displayNoneBasket == 'block' && $displayNone == 'none')
	                $tabBasket .= " active";
	            ?>
	            <div id="tab_1" style="display:<?= $displayNone ?>"       class="tabs active"     onClick="fTabsSelect('buyer_recmon', this);
	" ><?= GetMessage('SOD_SUBTAB_RECOMENET'?></div>
	            <div id="tab_2" style="display:<?= $displayNoneBasket ?>" class="<?= $tabBasket ?>" onClick="fTabsSelect('buyer_basket', this);
	"><?= GetMessage('SOD_SUBTAB_BASKET'?></div>
	            <div id="tab_3" style="display:<?= $displayNoneViewed ?>" class="<?= $tabViewed ?>" onClick="fTabsSelect('buyer_viewed', this);
	"><?= GetMessage('SOD_SUBTAB_LOOKED'?></div>
	            <?
	            if ($displayNone == 'block') {
		                $displayNoneBasket 'none';
		                $displayNoneViewed 'none';
		            }
	            if ($displayNoneBasket == 'block') {
		                $displayNone 'none';
		                $displayNoneViewed 'none';
		            }
	            if ($displayNoneViewed == 'block') {
		                $displayNone 'none';
		                $displayNoneBasket 'none';
		            }
	            ?>
	            <div id="buyer_recmon" class="tabstext active" style="display:<?= $displayNone ?>">
	                <? echo fGetFormatedProductData($arOrder["USER_ID"], $arOrder["LID"], $arRecommendedResult$recomCnt$arOrder["CURRENCY"], 'recom'$crmMode);
	 ?>
	            </div>
	            <div id="buyer_basket" class="tabstext active" style="display:<?= $displayNoneBasket ?>">
	                if (count($arCartWithoutSetItems) > 0)
	                echo fGetFormatedProductData($arOrder["USER_ID"], $arOrder["LID"], $arCartWithoutSetItems, $basketCnt, $arOrder["CURRENCY"], 'basket', $crmMode);
	                ?>
	            </div>
	            <div id="buyer_viewed" class="tabstext active" style="display:<?= $displayNoneViewed ?>">
	                <?
	                if (count($arViewed) > 0)
	                    echo fGetFormatedProductData($arOrder["USER_ID"], $arOrder["LID"], $arViewed$viewedCnt$arOrder["CURRENCY"], 'viewed'$crmMode);
	                ?>
	            </div>
	        </div>
	        <script type="text/javascript">
	            function fTabsSelect(tabText, el)
	            {
		                BX('tab_1').className = "tabs";
		                BX('tab_2').className = "tabs";
		                BX('tab_3').className = "tabs";
		                BX(el).className = "tabs active";
		                BX(el).className = "tabs active";
		                BX(el).style.display = 'block';
		                BX('buyer_recmon').className = "tabstext";
		                BX('buyer_basket').className = "tabstext";
		                BX('buyer_viewed').className = "tabstext";
		                BX('buyer_recmon').style.display = 'none';
		                BX('buyer_basket').style.display = 'none';
		                BX('buyer_viewed').style.display = 'none';
		                BX(tabText).style.display = 'block';
		                BX(tabText).className = "tabstext active";
		            }
	        </script>
	        <script type="text/javascript">
	            /*
	             * click on recommendet More
	             */
	            function fGetMoreProduct(type)
	            {
		                BX.showWait();
		                productData = <? echo CUtil::PhpToJSObject($arFilterRecomendet);
		 ?>;
		                var userId = '<?= $arOrder["USER_ID"?>';
		                var fUserId = '<?= $arFuserItems["ID"?>';
		                var currency = '<?= $arOrder["CURRENCY"?>';
		                var lid = '<?= $arOrder["LID"?>';
		                BX.ajax.post('/bitrix/admin/sale_order_detail.php', '<?= CUtil::JSEscape(bitrix_sessid_get()) ?>&ORDER_AJAX=Y&type=' + type + '&arProduct=' + productData + '&currency=' + currency + '&LID=' + lid + '&userId=' + userId + '&fUserId=' + fUserId + '&ID=<?= $ID ?>', fGetMoreProductResult);
		            }
	            function fGetMoreProductResult(res)
	            {
		                BX.closeWait();
		                var rs = eval('(' + res + ')');
		                if (rs["ITEMS"].length > 0)
		                {
			                    if (rs["TYPE"] == 'basket')
			                        BX("buyer_basket").innerHTML = rs["ITEMS"];
			                    if (rs["TYPE"] == 'recom')
			                        BX("buyer_recmon").innerHTML = rs["ITEMS"];
			                    if (rs["TYPE"] == 'viewed')
			                        BX("buyer_viewed").innerHTML = rs["ITEMS"];
			                }
		            }
	        </script>    
	    </div>
	    <?
	}
require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/epilog_after.php");

?>