예제 #1
0
 /**
  * {@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(__('Attribute group does not belong to provided attribute set'));
         }
     }
     try {
         $this->groupResource->save($group);
     } catch (\Exception $e) {
         throw new StateException(__('Cannot save attributeGroup'));
     }
     return $group;
 }
예제 #2
0
파일: Eav.php 프로젝트: rafaelstz/magento2
 /**
  * Loading product attributes from group
  *
  * @param AttributeGroupInterface $group
  * @return ProductAttributeInterface[]
  */
 private function loadAttributes(AttributeGroupInterface $group)
 {
     $attributes = [];
     $sortOrder = $this->sortOrderBuilder->setField('sort_order')->setAscendingDirection()->create();
     $searchCriteria = $this->searchCriteriaBuilder->addFilter(AttributeGroupInterface::GROUP_ID, $group->getAttributeGroupId())->addFilter(ProductAttributeInterface::IS_VISIBLE, 1)->addSortOrder($sortOrder)->create();
     $groupAttributes = $this->attributeRepository->getList($searchCriteria)->getItems();
     $productType = $this->getProductType();
     foreach ($groupAttributes as $attribute) {
         $applyTo = $attribute->getApplyTo();
         $isRelated = !$applyTo || in_array($productType, $applyTo);
         if ($isRelated) {
             $attributes[] = $attribute;
         }
     }
     return $attributes;
 }