![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-eav/Model/Attribute/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace Magento\Eav\Model\Attribute; use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface; use Magento\Framework\Exception\InputException; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Exception\StateException; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class GroupRepository implements \Magento\Eav\Api\AttributeGroupRepositoryInterface { /** * @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Group */ protected $groupResource; /** * @var \Magento\Eav\Model\Entity\Attribute\GroupFactory */ protected $groupFactory; /** * @var \Magento\Eav\Api\AttributeSetRepositoryInterface */ protected $setRepository; /** * @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory */ protected $groupListFactory; /** * @var \Magento\Eav\Api\Data\AttributeGroupSearchResultsInterfaceFactory */ protected $searchResultsFactory; /** * @var \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface */ protected $joinProcessor; /** * @var CollectionProcessorInterface */ private $collectionProcessor; /** * @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Group $groupResource * @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory $groupListFactory * @param \Magento\Eav\Model\Entity\Attribute\GroupFactory $groupFactory * @param \Magento\Eav\Api\AttributeSetRepositoryInterface $setRepository * @param \Magento\Eav\Api\Data\AttributeGroupSearchResultsInterfaceFactory $searchResultsFactory * @param \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $joinProcessor * @param CollectionProcessorInterface $collectionProcessor * @codeCoverageIgnore */ public function __construct( \Magento\Eav\Model\ResourceModel\Entity\Attribute\Group $groupResource, \Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory $groupListFactory, \Magento\Eav\Model\Entity\Attribute\GroupFactory $groupFactory, \Magento\Eav\Api\AttributeSetRepositoryInterface $setRepository, \Magento\Eav\Api\Data\AttributeGroupSearchResultsInterfaceFactory $searchResultsFactory, \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $joinProcessor, CollectionProcessorInterface $collectionProcessor = null ) { $this->groupResource = $groupResource; $this->groupListFactory = $groupListFactory; $this->groupFactory = $groupFactory; $this->setRepository = $setRepository; $this->searchResultsFactory = $searchResultsFactory; $this->joinProcessor = $joinProcessor; $this->collectionProcessor = $collectionProcessor ?: $this->getCollectionProcessor(); } /** * {@inheritdoc} */ public function save(\Magento\Eav\Api\Data\AttributeGroupInterface $group) { try { $this->setRepository->get($group->getAttributeSetId()); } catch (NoSuchEntityException $ex) { throw NoSuchEntityException::singleField('attributeSetId', $group->getAttributeSetId()); } if ($group->getAttributeGroupId()) { /** @var \Magento\Eav\Model\Entity\Attribute\Group $existingGroup */ $existingGroup = $this->groupFactory->create(); $this->groupResource->load($existingGroup, $group->getAttributeGroupId()); if (!$existingGroup->getId()) { throw NoSuchEntityException::singleField('attributeGroupId', $existingGroup->getId()); } if ($existingGroup->getAttributeSetId() != $group->getAttributeSetId()) { throw new StateException( __("The attribute group doesn't belong to the provided attribute set.") ); } } try { $this->groupResource->save($group); } catch (\Exception $e) { throw new StateException(__("The attributeGroup can't be saved.")); } return $group; } /** * {@inheritdoc} */ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria) { /** @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\Collection $collection */ $collection = $this->groupListFactory->create(); $this->joinProcessor->process($collection); $this->collectionProcessor->process($searchCriteria, $collection); /** @var \Magento\Eav\Api\Data\AttributeGroupSearchResultsInterface $searchResult */ $searchResult = $this->searchResultsFactory->create(); $searchResult->setSearchCriteria($searchCriteria); $searchResult->setItems($collection->getItems()); $searchResult->setTotalCount($collection->getSize()); return $searchResult; } /** * {@inheritdoc} */ public function get($groupId) { /** @var \Magento\Eav\Model\Entity\Attribute\Group $group */ $group = $this->groupFactory->create(); $this->groupResource->load($group, $groupId); if (!$group->getId()) { throw new NoSuchEntityException( __('The group with the "%1" ID doesn\'t exist. Verify the ID and try again.', $groupId) ); } return $group; } /** * {@inheritdoc} */ public function delete(\Magento\Eav\Api\Data\AttributeGroupInterface $group) { try { $this->groupResource->delete($group); } catch (\Exception $e) { throw new StateException( __( 'The attribute group with id "%1" can\'t be deleted.', $group->getId() ), $e ); } return true; } /** * {@inheritdoc} */ public function deleteById($groupId) { $this->delete( $this->get($groupId) ); return true; } /** * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria * @return null|string * @deprecated 101.0.3 */ protected function retrieveAttributeSetIdFromSearchCriteria( \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria ) { foreach ($searchCriteria->getFilterGroups() as $group) { foreach ($group->getFilters() as $filter) { if ($filter->getField() == 'attribute_set_id') { return $filter->getValue(); } } } return null; } /** * Retrieve collection processor * * @deprecated 101.0.0 * @return CollectionProcessorInterface */ private function getCollectionProcessor() { if (!$this->collectionProcessor) { $this->collectionProcessor = \Magento\Framework\App\ObjectManager::getInstance()->get( 'Magento\Eav\Model\Api\SearchCriteria\AttributeGroupCollectionProcessor' ); } return $this->collectionProcessor; } }