HEX
Server: Apache/2.4.6 (CentOS) mpm-itk/2.4.7-04 mod_fcgid/2.3.9 PHP/5.4.16
System: Linux dvm.vladweb.ru 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: region-gk.ru (1016)
PHP: 7.3.33
Disabled: NONE
Upload Files
File: //home/bk/100/ajax/basket_market.php
<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();


include_once $_SERVER["DOCUMENT_ROOT"].SITE_TEMPLATE_PATH."/lang/".LANGUAGE_ID."/ajax.php";

$arResult = array();

try
{
	$productId = intVal($_GET["id"]);
	$productQty = intVal($_GET["quantity"]);

	if($productId == 0) { throw new Exception(GetMessage('PRODUCT_ID_NOT_FOUND'));}
	if($productQty <= 0) { $productQty = 1;}

	if (!CModule::IncludeModule('iblock')) {
		throw new Exception('Module iblock is not installed', 1);
	}
	if (!CModule::IncludeModule('yenisite.market')) {
		throw new Exception('Module yenisite.market is not installed', 1);
	}
	$res = CIBlockElement::GetByID($productId);
	if($el = $res->GetNextElement())
	{
		$fields = $el->GetFields();
		if(!CMarketCatalog::IsCatalog($fields["IBLOCK_ID"])) {
			throw new Exception(GetMessage('MARKET_IBLOCK_NOT_CATALOG', array("#IBLOCK_ID#" => $fields["IBLOCK_ID"])));
		}
	} else {
		throw new Exception(GetMessage('PRODUCT_ID_NOT_FOUND'), 1);
	}

	$arProduct = CMarketCatalogProduct::GetByID($productId, $fields['IBLOCK_ID']);
	if ($arProduct['QUANTITY_TRACE'] == 'Y' && $arProduct['CAN_BUY_ZERO'] != 'Y') {
		if ($arProduct['QUANTITY'] <= 0) throw new Exception("Product is not available", 1);
		if ($arProduct['QUANTITY'] < $productQty) {
			$productQty = $arProduct['QUANTITY'];
		}
	}

	$cartId = CMarketBasket::Add($productId, (array)$_REQUEST["prop"], $productQty);

	if(!$cartId){
		throw new Exception(GetMessage('ADD_TO_CART_ERROR'));
	}

	$arResult = array('STATUS' => 'OK', 'MESSAGE' => GetMessage('ADD_TO_CART_SUCCESS'));
}
catch (Exception $e) {
	$arResult["STATUS"] = 'ERROR';
	$arResult["CODE"] = $e->getMessage();
}
if (!defined('BX_UTF')) {
	$arResult['MESSAGE'] = iconv('windows-1251', 'utf-8', $arResult['MESSAGE']);
}
echo json_encode($arResult);
?>