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/modules/catalog/lib/controller/product/ |
Upload File : |
<?php namespace Bitrix\Catalog\Controller\Product; use Bitrix\Catalog\Controller\Product; use Bitrix\Main\Engine; use Bitrix\Main\Engine\Action; use Bitrix\Main\Engine\Response\DataType\Page; use Bitrix\Main\Error; use Bitrix\Main\Result; use Bitrix\Main\UI\PageNavigation; abstract class Base extends Product { protected const TYPE = ''; abstract protected function getAllowedProductTypes(); protected function processBeforeAction(Action $action) { $arguments = $action->getArguments(); $name = $action->getName(); if ($name === 'add' || $name === 'update') { $fields = $arguments['fields'] ?? []; if (!is_array($fields)) { $this->addError(new Error('Incorrect fields format')); return null; } $fields['type'] = static::TYPE; $arguments['fields'] = $fields; $action->setArguments($arguments); } return parent::processBeforeAction($action); } private function isAllowedProductTypeByIBlockId(Engine\Action $action): Result { $arguments = $action->getArguments(); $fields = $arguments['fields']; /** @var \Bitrix\Catalog\RestView\Product $view */ $view = $this->getViewManager()->getView($this); return $view->isAllowedProductTypeByIBlockId(static::TYPE, $fields['iblockId']); } protected function processBeforeAdd(Engine\Action $action): Result { $r = parent::processBeforeAdd($action); if ($r->isSuccess()) { $r = $this->isAllowedProductTypeByIBlockId($action); } return $r; } protected function processBeforeUpdate(Action $action): Result { $r = parent::processBeforeUpdate($action); if ($r->isSuccess()) { $r = $this->isAllowedProductTypeByIBlockId($action); } return $r; } protected function fillKeyResponse($result): ?array { return is_null($result) ? $result : [$this->getServiceItemName() => current($result)]; } public function addAction($fields): ?array { $result = parent::addAction($fields); return $this->fillKeyResponse($result); } public function updateAction($id, array $fields): ?array { $result = parent::updateAction($id, $fields); return $this->fillKeyResponse($result); } /** * @param PageNavigation $pageNavigation * @param array $select * @param array $filter * @param array $order * @param bool $__calculateTotalCount * @return Page|null */ public function listAction( PageNavigation $pageNavigation, array $select = [], array $filter = [], array $order = [], bool $__calculateTotalCount = true ): ?Page { /** @var \Bitrix\Catalog\RestView\Product $view */ $view = $this->getViewManager()->getView($this); $r = $view->isAllowedProductTypeByIBlockId(static::TYPE, $filter['IBLOCK_ID']); if (!$r->isSuccess()) { $this->addErrors($r->getErrors()); return null; } $list = $this->getAllowedProductTypes(); if (isset($filter['TYPE'])) { $filter['TYPE'] = in_array($filter['TYPE'], $list, true) ? $filter['TYPE'] : $list; } else { $filter['TYPE'] = $list; } return parent::listAction($pageNavigation, $select, $filter, $order, $__calculateTotalCount); } protected function get($id) { $result = parent::get($id); if (empty($result) === false) { if (in_array($result['TYPE'], $this->getAllowedProductTypes())) { return $result; } } return false; } }