- Модуль: iblock
- Путь к файлу: ~/bitrix/modules/iblock/lib/component/base.php
- Класс: BitrixIblockComponentBase
- Вызов: Base::processLinkAction
protected function processLinkAction()
{
global $APPLICATION;
if ($this->request->get($this->arParams['ACTION_VARIABLE'].self::ACTION_BUY) !== null)
{
$action = self::ACTION_BUY;
}
elseif ($this->request->get($this->arParams['ACTION_VARIABLE'].self::ACTION_ADD_TO_BASKET))
{
$action = self::ACTION_ADD_TO_BASKET;
}
else
{
$action = mb_strtoupper($this->request->get($this->arParams['ACTION_VARIABLE']));
}
$productId = (int)$this->request->get($this->arParams['PRODUCT_ID_VARIABLE']);
if (
($action == self::ACTION_ADD_TO_BASKET || $action == self::ACTION_BUY || $action == self::ACTION_SUBSCRIBE)
&& Loader::includeModule('sale')
&& Loader::includeModule('catalog')
)
{
$addByAjax = $this->request->get('ajax_basket') === 'Y';
if ($addByAjax)
{
$this->request->set(MainTextEncoding::convertEncoding($this->request->toArray(), 'UTF-8', SITE_CHARSET));
}
[$successfulAdd, $errorMsg] = $this->addProductToBasket($productId, $action);
if ($addByAjax)
{
if ($successfulAdd)
{
$addResult = array(
'STATUS' => 'OK',
'MESSAGE' => Loc::getMessage('CATALOG_SUCCESSFUL_ADD_TO_BASKET')
);
}
else
{
$addResult = array(
'STATUS' => 'ERROR',
'MESSAGE' => $errorMsg
);
}
$APPLICATION->RestartBuffer();
header('Content-Type: application/json');
CMain::FinalActions(MainWebJson::encode($addResult));
}
else
{
if ($successfulAdd)
{
$pathRedirect = $action == self::ACTION_BUY
? $this->arParams['BASKET_URL']
: $APPLICATION->GetCurPageParam('', array(
$this->arParams['PRODUCT_ID_VARIABLE'],
$this->arParams['ACTION_VARIABLE'],
$this->arParams['PRODUCT_QUANTITY_VARIABLE'],
$this->arParams['PRODUCT_PROPS_VARIABLE']
));
LocalRedirect($pathRedirect);
}
else
{
$this->errorCollection->setError(new Error($errorMsg, self::ERROR_TEXT));
}
}
}
}