/** * @param int $skeletonId * @return void * @throws StateException */ protected function validateSkeletonSet($skeletonId) { try { $skeletonSet = $this->attributeSetRepository->get($skeletonId); $productEntityId = $this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId(); if ($skeletonSet->getEntityTypeId() != $productEntityId) { throw new StateException(__('Can not create attribute set based on non product attribute set.')); } } catch (\Magento\Framework\Exception\NoSuchEntityException $exception) { throw new StateException(__('Can not create attribute set based on not existing attribute set')); } }
/** * {@inheritdoc} */ public function getAttributes($entityType, $attributeSetId) { /** @var \Magento\Eav\Api\Data\AttributeSetInterface $attributeSet */ $attributeSet = $this->setRepository->get($attributeSetId); $requiredEntityTypeId = $this->eavConfig->getEntityType($entityType)->getId(); if (!$attributeSet->getAttributeSetId() || $attributeSet->getEntityTypeId() != $requiredEntityTypeId) { throw NoSuchEntityException::singleField('attributeSetId', $attributeSetId); } $attributeCollection = $this->attributeCollection->setAttributeSetFilter($attributeSet->getAttributeSetId())->load(); return $attributeCollection->getItems(); }
/** * {@inheritdoc} */ public function create($entityTypeCode, AttributeSetInterface $attributeSet, $skeletonId) { /** @var \Magento\Eav\Model\Entity\Attribute\Set $attributeSet */ if ($attributeSet->getId() !== null) { throw InputException::invalidFieldValue('id', $attributeSet->getId()); } if ($skeletonId == 0) { throw InputException::invalidFieldValue('skeletonId', $skeletonId); } // Make sure that skeleton attribute set is valid (try to load it) $this->repository->get($skeletonId); try { $attributeSet->setEntityTypeId($this->eavConfig->getEntityType($entityTypeCode)->getId()); $attributeSet->validate(); } catch (\Exception $exception) { throw new InputException(__($exception->getMessage())); } $this->repository->save($attributeSet); $attributeSet->initFromSkeleton($skeletonId); return $this->repository->save($attributeSet); }
/** * {@inheritdoc} */ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria) { $attributeSetId = $this->retrieveAttributeSetIdFromSearchCriteria($searchCriteria); if (!$attributeSetId) { throw InputException::requiredField('attribute_set_id'); } try { $this->setRepository->get($attributeSetId); } catch (\Exception $exception) { throw NoSuchEntityException::singleField('attributeSetId', $attributeSetId); } $collection = $this->groupListFactory->create(); $collection->setAttributeSetFilter($attributeSetId); $collection->setSortOrder(); $searchResult = $this->searchResultsFactory->create(); $searchResult->setSearchCriteria($searchCriteria); $searchResult->setItems($collection->getItems()); $searchResult->setTotalCount($collection->getSize()); return $searchResult; }
/** * {@inheritdoc} */ public function modifyData(array $data) { /** @var \Magento\Catalog\Model\Product $product */ $product = $this->locator->getProduct(); $modelId = $product->getId(); if ($modelId) { $storeId = $this->locator->getStore()->getId(); /** @var \Magento\Framework\Currency $currency */ $currency = $this->localeCurrency->getCurrency($this->locator->getBaseCurrencyCode()); $data[$product->getId()]['links'][self::LINK_TYPE] = []; foreach ($this->productLinkRepository->getList($product) as $linkItem) { if ($linkItem->getLinkType() !== self::LINK_TYPE) { continue; } /** @var \Magento\Catalog\Api\Data\ProductInterface $linkedProduct */ $linkedProduct = $this->productRepository->get($linkItem->getLinkedProductSku(), false, $storeId); $data[$modelId]['links'][self::LINK_TYPE][] = ['id' => $linkedProduct->getId(), 'name' => $linkedProduct->getName(), 'sku' => $linkItem->getLinkedProductSku(), 'price' => $currency->toCurrency(sprintf("%f", $linkedProduct->getPrice())), 'qty' => $linkItem->getExtensionAttributes()->getQty(), 'position' => $linkItem->getPosition(), 'thumbnail' => $this->imageHelper->init($linkedProduct, 'product_listing_thumbnail')->getUrl(), 'type_id' => $linkedProduct->getTypeId(), 'status' => $this->status->getOptionText($linkedProduct->getStatus()), 'attribute_set' => $this->attributeSetRepository->get($linkedProduct->getAttributeSetId())->getAttributeSetName()]; } $data[$modelId][self::DATA_SOURCE_DEFAULT]['current_store_id'] = $storeId; } return $data; }
/** * {@inheritdoc} */ public function modifyData(array $data) { /** @var \Magento\Catalog\Model\Product $product */ $product = $this->locator->getProduct(); $productId = $product->getId(); if (!$productId) { return $data; } foreach ($this->getDataScopes() as $dataScope) { $data[$productId]['links'][$dataScope] = []; foreach ($this->productLinkRepository->getList($product) as $linkItem) { if ($linkItem->getLinkType() !== $dataScope) { continue; } /** @var \Magento\Catalog\Model\Product $linkedProduct */ $linkedProduct = $this->productRepository->get($linkItem->getLinkedProductSku(), false, $this->locator->getStore()->getId()); $data[$productId]['links'][$dataScope][] = ['id' => $linkedProduct->getId(), 'thumbnail' => $this->imageHelper->init($linkedProduct, 'product_listing_thumbnail')->getUrl(), 'name' => $linkedProduct->getName(), 'status' => $this->status->getOptionText($linkedProduct->getStatus()), 'attribute_set' => $this->attributeSetRepository->get($linkedProduct->getAttributeSetId())->getAttributeSetName(), 'sku' => $linkItem->getLinkedProductSku(), 'price' => $linkedProduct->getPrice(), 'position' => $linkItem->getPosition()]; } } $data[$productId][self::DATA_SOURCE_DEFAULT]['current_product_id'] = $productId; $data[$productId][self::DATA_SOURCE_DEFAULT]['current_store_id'] = $this->locator->getStore()->getId(); return $data; }
/** * Fill data column * * @param ProductInterface $linkedProduct * @param ProductLinkInterface $linkItem * @return array */ protected function fillData(ProductInterface $linkedProduct, ProductLinkInterface $linkItem) { /** @var \Magento\Framework\Currency $currency */ $currency = $this->localeCurrency->getCurrency($this->locator->getBaseCurrencyCode()); return ['id' => $linkedProduct->getId(), 'name' => $linkedProduct->getName(), 'sku' => $linkItem->getLinkedProductSku(), 'price' => $currency->toCurrency(sprintf("%f", $linkedProduct->getPrice())), 'qty' => $linkItem->getExtensionAttributes()->getQty(), 'position' => $linkItem->getPosition(), 'thumbnail' => $this->imageHelper->init($linkedProduct, 'product_listing_thumbnail')->getUrl(), 'type_id' => $linkedProduct->getTypeId(), 'status' => $this->status->getOptionText($linkedProduct->getStatus()), 'attribute_set' => $this->attributeSetRepository->get($linkedProduct->getAttributeSetId())->getAttributeSetName()]; }
/** * @return \Magento\Eav\Api\Data\AttributeSetInterface */ protected function loadSource() { return $this->attributeSetRespository->get($this->data['id']); }
/** * Prepare data column * * @param ProductInterface $linkedProduct * @param ProductLinkInterface $linkItem * @return array */ protected function fillData(ProductInterface $linkedProduct, ProductLinkInterface $linkItem) { return ['id' => $linkedProduct->getId(), 'thumbnail' => $this->imageHelper->init($linkedProduct, 'product_listing_thumbnail')->getUrl(), 'name' => $linkedProduct->getName(), 'status' => $this->status->getOptionText($linkedProduct->getStatus()), 'attribute_set' => $this->attributeSetRepository->get($linkedProduct->getAttributeSetId())->getAttributeSetName(), 'sku' => $linkItem->getLinkedProductSku(), 'price' => $linkedProduct->getPrice(), 'position' => $linkItem->getPosition()]; }
/** * {@inheritdoc} */ public function get($attributeSetId) { $attributeSet = $this->attributeSetRepository->get($attributeSetId); $this->validate($attributeSet); return $attributeSet; }
/** * Render column text * * @param int $attributeSetId * @return string */ protected function renderColumnText($attributeSetId) { return $this->attributeSetRepository->get($attributeSetId)->getAttributeSetName(); }