403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/cvetdv.ru/bitrix/components/bitrix/catalog.productcard.variation.grid/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/cvetdv.ru/bitrix/components/bitrix/catalog.productcard.variation.grid/ajax.php
<?php

if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true)
{
	die();
}

use Bitrix\Main\Engine\Response;
use Bitrix\Main\Engine\Response\AjaxJson;
use Bitrix\Main\Error;
use Bitrix\Main\ErrorCollection;
use Bitrix\Main\Grid\Options;
use Bitrix\Main\Loader;

class VariationGridController extends \Bitrix\Main\Engine\Controller
{
	public function getProductGridAction()
	{
		if (!Loader::includeModule('catalog'))
		{
			return $this->sendErrorResponse('Could not load "catalog" module.');
		}

		$params = $this->getUnsignedParameters();

		$iblockId = (int)($params['IBLOCK_ID'] ?? 0);

		if ($iblockId <= 0)
		{
			return $this->sendErrorResponse(sprintf('Wrong iblock id {%s}.', $iblockId));
		}

		return new Response\Component(
			'bitrix:catalog.productcard.variation.grid',
			'',
			[
				'IBLOCK_ID' => $iblockId,
				'PRODUCT_ID' => (int)($params['PRODUCT_ID'] ?? 0),
				'VARIATION_ID_LIST' => $params['VARIATION_ID_LIST'] ?? null,
				'COPY_PRODUCT_ID' => (int)($params['COPY_PRODUCT_ID'] ?? 0),
				'EXTERNAL_FIELDS' => $params['EXTERNAL_FIELDS'] ?? null,
				'PATH_TO' => $params['PATH_TO'] ?? [],
			]
		);
	}

	private function sendErrorResponse(string $message): AjaxJson
	{
		$errorCollection = new ErrorCollection();
		$errorCollection->setError(new Error($message));

		return Response\AjaxJson::createError($errorCollection);
	}

	/**
	 * @param string $gridId
	 * @param string $propertyCode
	 * @param string $anchor
	 * @param array $currentHeaders
	 *
	 * @return Response\AjaxJson
	 */
	public function addPropertyHeaderAction(string $gridId, string $propertyCode, array $currentHeaders, string $anchor = ''): AjaxJson
	{
		$options = new Options($gridId);
		$allUsedColumns = $options->getUsedColumns();

		if (empty($allUsedColumns))
		{
			$allUsedColumns = $currentHeaders;
		}

		if (empty($anchor))
		{
			$anchor = $allUsedColumns[0];
		}

		Loader::includeModule('catalog');

		/** @var \CatalogProductVariationGridComponent $componentClass */
		$componentClass = CBitrixComponent::includeComponentClass('bitrix:catalog.productcard.variation.grid');

		foreach ($allUsedColumns as $key => $header)
		{
			if ($header === $componentClass::formatFieldName($componentClass::HEADER_EMPTY_PROPERTY_COLUMN))
			{
				array_splice($allUsedColumns, $key, 1, $propertyCode);
				break;
			}

			if ($header === $anchor)
			{
				array_splice($allUsedColumns, $key + 1, 0, $propertyCode);
				break;
			}
		}

		$options->setColumns(implode(',', $allUsedColumns));
		$options->save();

		return AjaxJson::createSuccess();
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit