Your IP : 18.224.8.221


Current Path : /home/bitrix/ext_www/dev.home-comfort.in.ua/local/tools/
Upload File :
Current File : /home/bitrix/ext_www/dev.home-comfort.in.ua/local/tools/ajax.php

<?php
require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php");

if (!check_bitrix_sessid())
	die();

error_reporting(E_ERROR && ~E_WARNING);
ini_set('display_errors', '1');


class AjaxHandler
{
	public function processRequest($request)
	{
		try{
			$action = $request["action"];
			
			if (empty($action))
				throw new \Exception("Action not set");
			
			if (!method_exists($this, $action))
				throw new \Exception("Unknown action");
			
			$data = &$request["data"];
			
			$data = call_user_func(array($this, $action), $data);
			$success = true;
		}
		catch (\Exception $e)
		{
			$success = false;
			$data = array("message" => $e->getMessage(), "trace" => $e->getTrace());
		}
		
		return array("success" => $success, "data" => $data);
	}
	
	protected function getBasket()
	{
		\Bitrix\Main\Loader::includeModule("sale");
		$dbBasketItems = \CSaleBasket::GetList(
			[],
			[
				"FUSER_ID" => \CSaleBasket::GetBasketUserID(),
				"LID" => SITE_ID,
				"ORDER_ID" => "NULL"
			],
			false,
			false,
			[
				"ID",
				"NAME",
				"PRODUCT_ID"
			]
		);
		
		$arResult = [];
		while ($basket = $dbBasketItems->fetch())
			$arResult[] = $basket;
		
		return $arResult;
	}

	protected function getProducts($data)
	{
		$prodIds = $data["prodIds"];
		
		if (sizeof($prodIds) <= 0)
			return "";
		
		
		\Bitrix\Main\Loader::includeModule("iblock");
		
		$dbElements = \CIBlockElement::getList(
			[],
			[
				"ID" => $prodIds
			],
			false,
			false,
			[
				"ID",
				"IBLOCK_ID",
                "PROPERTY_697",
                "NAME",
                "CATALOG_GROUP_1"
			]
		);
		
		$arResult = [];
		while ($arElement = $dbElements->fetch())
        {
	        $arElement["PHOTO_URL"] = resizeImgInfo($arElement['PROPERTY_697_VALUE'], "CATALOG_ITEM_FULL");
            $arResult[] = $arElement;
            
            
        }
        
//        return [
//	        $prodIds,
//            $arResult
//        ];
		ob_start();
		
		foreach ($arResult as $arItem)
		{
			?>
            <div class="additional-product">
                <div class="image">
                    <picture>
                        <img src="<?=$arItem["PHOTO_URL"]["regularFile"]["src"]?>" alt="">
                    </picture>
                </div>
                <div class="name catalog-plate__name">
                    <span><?=$arItem["NAME"]?></span>
                </div>
                <div class="catalog-plate__current-price js-price price"><?=$arItem["CATALOG_PRICE_1"]?> руб.</div>
                <a data-href-additional-product-id="<?=$arItem["ID"]?>" href="javascript:void(0);"></a>
            </div>
			<?
		}
		
		return ob_get_clean();
	}
}

$handler = new AjaxHandler();
$response = $handler->processRequest($_REQUEST);

$GLOBALS["APPLICATION"]->RestartBuffer();
echo json_encode($response);
die();