public function testPrepareDataSource()
 {
     $dataSource = ['data' => ['items' => [[AttributeSetText::NAME => self::ATTRIBUTE_SET_ID]]]];
     $expectedDataSource = ['data' => ['items' => [[AttributeSetText::NAME => self::ATTRIBUTE_SET_ID, '' => self::ATTRIBUTE_SET_NAME]]]];
     $this->attributeSetMock->expects($this->once())->method('getAttributeSetName')->willReturn(self::ATTRIBUTE_SET_NAME);
     $this->attributeSetRepositoryMock->expects($this->once())->method('get')->with(self::ATTRIBUTE_SET_ID)->willReturn($this->attributeSetMock);
     $this->assertEquals($expectedDataSource, $this->getModel()->prepareDataSource($dataSource));
 }
예제 #2
0
 /**
  * @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'));
     }
 }
예제 #3
0
 /**
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 public function execute()
 {
     $setId = $this->getRequest()->getParam('id');
     $resultRedirect = $this->resultRedirectFactory->create();
     try {
         $this->attributeSetRepository->deleteById($setId);
         $this->messageManager->addSuccess(__('The attribute set has been removed.'));
         $resultRedirect->setPath('catalog/*/');
     } catch (\Exception $e) {
         $this->messageManager->addError(__('We can\'t delete this set right now.'));
         $resultRedirect->setUrl($this->_redirect->getRedirectUrl($this->getUrl('*')));
     }
     return $resultRedirect;
 }
예제 #4
0
 /**
  * {@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();
 }
예제 #5
0
 /**
  * {@inheritdoc}
  */
 protected function createModel()
 {
     $this->currencyMock = $this->getMockBuilder(CurrencyInterface::class)->setMethods(['getCurrency', 'toCurrency'])->getMockForAbstractClass();
     $this->currencyMock->expects($this->any())->method('getCurrency')->willReturn($this->currencyMock);
     $this->imageHelperMock = $this->getMockBuilder(ImageHelper::class)->setMethods(['init', 'getUrl'])->disableOriginalConstructor()->getMock();
     $this->imageHelperMock->expects($this->any())->method('init')->willReturn($this->imageHelperMock);
     $this->attributeSetRepositoryMock = $this->getMockBuilder(AttributeSetRepositoryInterface::class)->setMethods(['get'])->getMockForAbstractClass();
     $attributeSetMock = $this->getMockBuilder(AttributeSetInterface::class)->setMethods(['getAttributeSetName'])->getMockForAbstractClass();
     $this->attributeSetRepositoryMock->expects($this->any())->method('get')->willReturn($attributeSetMock);
     return $this->objectManager->getObject(Grouped::class, ['locator' => $this->locatorMock, 'productLinkRepository' => $this->linkRepositoryMock, 'productRepository' => $this->productRepositoryMock, 'localeCurrency' => $this->currencyMock, 'imageHelper' => $this->imageHelperMock, 'attributeSetRepository' => $this->attributeSetRepositoryMock]);
 }
예제 #6
0
 /**
  * {@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);
 }
예제 #7
0
 /**
  * {@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;
 }
예제 #10
0
 /**
  * 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']);
 }
예제 #12
0
 /**
  * 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()];
 }
예제 #13
0
 /**
  * {@inheritdoc}
  */
 public function deleteById($attributeSetId)
 {
     $this->get($attributeSetId);
     return $this->attributeSetRepository->deleteById($attributeSetId);
 }
예제 #14
0
 /**
  * Render column text
  *
  * @param int $attributeSetId
  * @return string
  */
 protected function renderColumnText($attributeSetId)
 {
     return $this->attributeSetRepository->get($attributeSetId)->getAttributeSetName();
 }