public function testResolve() { $documentIds = [1, 2, 3]; $attributeSetIds = [4, 5]; $requestName = 'request_name'; $this->attributeSetFinder->expects($this->once())->method('findAttributeSetIdsByProductIds')->with($documentIds)->willReturn($attributeSetIds); $searchCriteria = $this->getMock(SearchCriteriaInterface::class); $this->searchCriteriaBuilder->expects($this->once())->method('addFilter')->with('attribute_set_id', $attributeSetIds, 'in')->willReturnSelf(); $this->searchCriteriaBuilder->expects($this->once())->method('create')->willReturn($searchCriteria); $attributeFirst = $this->getMock(ProductAttributeInterface::class); $attributeFirst->expects($this->once())->method('getAttributeCode')->willReturn('code_1'); $attributeSecond = $this->getMock(ProductAttributeInterface::class); $attributeSecond->expects($this->once())->method('getAttributeCode')->willReturn('code_2'); $searchResult = $this->getMock(ProductAttributeSearchResultsInterface::class); $searchResult->expects($this->once())->method('getItems')->willReturn([$attributeFirst, $attributeSecond]); $this->productAttributeRepository->expects($this->once())->method('getList')->with($searchCriteria)->willReturn($searchResult); $bucketFirst = $this->getMock(BucketInterface::class); $bucketFirst->expects($this->once())->method('getField')->willReturn('code_1'); $bucketSecond = $this->getMock(BucketInterface::class); $bucketSecond->expects($this->once())->method('getField')->willReturn('some_another_code'); $bucketThird = $this->getMock(BucketInterface::class); $bucketThird->expects($this->once())->method('getName')->willReturn('custom_not_attribute_field'); $this->request->expects($this->once())->method('getAggregation')->willReturn([$bucketFirst, $bucketSecond, $bucketThird]); $this->request->expects($this->once())->method('getName')->willReturn($requestName); $this->config->expects($this->once())->method('get')->with($requestName)->willReturn(['aggregations' => ['custom_not_attribute_field' => []]]); $this->assertEquals([$bucketFirst, $bucketThird], $this->aggregationResolver->resolve($this->request, $documentIds)); }
/** * @return \Magento\Catalog\Api\Data\ProductAttributeInterface */ public function getAttribute() { if (!$this->attribute) { $this->attribute = $this->attributeRepository->get('media_gallery'); } return $this->attribute; }
/** * @param ProductRepositoryInterface $subject * @param callable $proceed * @param ProductInterface $product * @param bool $saveOptions * @return ProductInterface * @throws CouldNotSaveException * @throws InputException * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundSave(ProductRepositoryInterface $subject, \Closure $proceed, ProductInterface $product, $saveOptions = false) { /** @var ProductInterface $result */ $result = $proceed($product, $saveOptions); if ($product->getTypeId() !== Configurable::TYPE_CODE) { return $result; } $extensionAttributes = $result->getExtensionAttributes(); if ($extensionAttributes === null) { return $result; } $configurableLinks = (array) $extensionAttributes->getConfigurableProductLinks(); $configurableOptions = (array) $extensionAttributes->getConfigurableProductOptions(); if (empty($configurableLinks) && empty($configurableOptions)) { return $result; } $attributeCodes = []; /** @var OptionInterface $configurableOption */ foreach ($configurableOptions as $configurableOption) { $eavAttribute = $this->productAttributeRepository->get($configurableOption->getAttributeId()); $attributeCode = $eavAttribute->getAttributeCode(); $attributeCodes[] = $attributeCode; } $this->validateProductLinks($attributeCodes, $configurableLinks); return $subject->get($result->getSku(), false, $result->getStoreId(), true); }
public function testPrepareDataSource() { $name = 'some_name'; $initialData = ['data' => ['items' => [['attribute1_1_code' => 'attribute1_1_option2'], ['attribute2_1_code' => 'attribute2_1_option3'], ['attribute3_1_code' => 'attribute3_1_option3', 'attribute3_2_code' => 'attribute3_2_option1']]]]; $attributes = [$this->createAttributeMock('attribute1_1_code', 'attribute1_1_label', [$this->createAttributeOptionMock('attribute1_1_option1', 'attribute1_1_option1_label'), $this->createAttributeOptionMock('attribute1_1_option2', 'attribute1_1_option2_label')]), $this->createAttributeMock('attribute2_1_code', 'attribute2_1_label', [$this->createAttributeOptionMock('attribute2_1_option1', 'attribute2_1_option1_label'), $this->createAttributeOptionMock('attribute2_1_option2', 'attribute2_1_option2_label')]), $this->createAttributeMock('attribute3_1_code', 'attribute3_1_label', [$this->createAttributeOptionMock('attribute3_1_option1', 'attribute3_1_option1_label'), $this->createAttributeOptionMock('attribute3_1_option2', 'attribute3_1_option2_label'), $this->createAttributeOptionMock('attribute3_1_option3', 'attribute3_1_option3_label')]), $this->createAttributeMock('attribute3_2_code', 'attribute3_2_label', [$this->createAttributeOptionMock('attribute3_2_option1', 'attribute3_2_option1_label'), $this->createAttributeOptionMock('attribute3_2_option2', 'attribute3_2_option2_label'), $this->createAttributeOptionMock('attribute3_2_option3', 'attribute3_2_option3_label')]), $this->createAttributeMock('attribute4_1_code', 'attribute4_1_label')]; $resultData = ['data' => ['items' => [['attribute1_1_code' => 'attribute1_1_option2', $name => 'attribute1_1_label: attribute1_1_option2_label'], ['attribute2_1_code' => 'attribute2_1_option3', $name => ''], ['attribute3_1_code' => 'attribute3_1_option3', 'attribute3_2_code' => 'attribute3_2_option1', $name => 'attribute3_1_label: attribute3_1_option3_label,' . ' attribute3_2_label: attribute3_2_option1_label']]]]; $this->attributesColumn->setData('name', $name); $this->attributeRepositoryMock->expects(static::any())->method('getList')->with($this->searchCriteriaMock)->willReturn($this->searchResultsMock); $this->searchResultsMock->expects(static::any())->method('getItems')->willReturn($attributes); $this->assertSame($resultData, $this->attributesColumn->prepareDataSource($initialData)); }
/** * Get applicable attributes * * @param array $documentIds * @return array */ private function getApplicableAttributeCodes(array $documentIds) { $attributeSetIds = $this->attributeSetFinder->findAttributeSetIdsByProductIds($documentIds); $searchCriteria = $this->searchCriteriaBuilder->addFilter('attribute_set_id', $attributeSetIds, 'in')->create(); $result = $this->productAttributeRepository->getList($searchCriteria); $attributeCodes = []; foreach ($result->getItems() as $attribute) { $attributeCodes[] = $attribute->getAttributeCode(); } return $attributeCodes; }
/** * Save attributes for configurable product * * @param ProductInterface $product * @param array $attributes * @return array */ private function saveConfigurableProductAttributes(ProductInterface $product, array $attributes) { $ids = []; /** @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute $attribute */ foreach ($attributes as $attribute) { $eavAttribute = $this->productAttributeRepository->get($attribute->getAttributeId()); $data = $attribute->getData(); $attribute->loadByProductAndAttribute($product, $eavAttribute); $attribute->setData(array_replace_recursive($attribute->getData(), $data)); $ids[] = $this->optionRepository->save($product->getSku(), $attribute); } return $ids; }
/** * Create configurable product options * * @param array $attributesData * @return OptionInterface[] * @throws \InvalidArgumentException */ public function create(array $attributesData) { $options = []; foreach ($attributesData as $item) { $attribute = $this->attributeFactory->create(); $eavAttribute = $this->productAttributeRepository->get($item[Attribute::KEY_ATTRIBUTE_ID]); if (!$this->productType->canUseAttribute($eavAttribute)) { throw new \InvalidArgumentException('Provided attribute can not be used with configurable product.'); } $this->updateAttributeData($attribute, $item); $options[] = $attribute; } return $options; }
/** * Get array of attributes information * * Array contains attribute label and options labels * * @return array */ private function getAttributes() { $attributes = []; foreach ($this->attributeRepository->getList($this->getSearchCriteria())->getItems() as $attribute) { $attributeCode = $attribute->getAttributeCode(); $attributes[$attributeCode] = ['label' => $attribute->getDefaultFrontendLabel()]; $options = $attribute->getOptions(); if (is_array($options)) { foreach ($options as $option) { $attributes[$attributeCode]['options'][$option->getValue()] = $option->getLabel(); } } } return $attributes; }
/** * * Creates a configurable product with child simple products * * @throws \Exception */ public function createConfigurableProduct() { if ($this->processedProducts >= $this->getCount()) { return; } $configurableAttribute = $this->attributeRepository->get(self::CONFIGURABLE_ATTRIBUTE); if (null == $configurableAttribute) { throw new \Exception("Selected configurable attribute {self::CONFIGURABLE_ATTRIBUTE} is not available"); } $childProductsData = $this->createConfigurableChildren($configurableAttribute); /** @var \Magento\Catalog\Model\Product $configurableProduct */ $configurableProduct = $this->objectManager->create('Magento\\Catalog\\Model\\Product'); $configurableProduct->setStoreId(self::DEFAULT_STORE_ID)->setTypeId('configurable')->setAttributeSetId(self::ATTRIBUTE_SET)->setName(self::NAMES_PREFIX . $this->titlesGenerator->generateProductTitle() . ' configurable')->setPrice(self::DEFAULT_PRODUCT_PRICE)->setWeight(self::DEFAULT_PRODUCT_WEIGHT)->setSku(uniqid())->setCategoriesIds([$this->getProductCategory()]); $configurableOption = $this->configurableOption; $configurableOption->setAttributeId($configurableAttribute->getAttributeId())->setLabel('Color')->setValues($childProductsData['configurable_options_values']); $extensionAttributes = $configurableProduct->getExtensionAttributes(); if (!$extensionAttributes) { $extensionAttributes = $this->productExtensionFactory->create(); } $extensionAttributes->setConfigurableProductLinks($childProductsData['child_products_ids']); $extensionAttributes->setConfigurableProductOptions([$configurableOption]); $configurableProduct->setExtensionAttributes($extensionAttributes); $this->productRepository->save($configurableProduct); $this->processedProducts++; }
/** * {@inheritdoc} */ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria) { /** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $collection */ $collection = $this->collectionFactory->create(); $this->extensionAttributesJoinProcessor->process($collection); foreach ($this->metadataService->getList($this->searchCriteriaBuilder->create())->getItems() as $metadata) { $collection->addAttributeToSelect($metadata->getAttributeCode()); } $collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner'); $collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner'); //Add filters from root filter group to the collection foreach ($searchCriteria->getFilterGroups() as $group) { $this->addFilterGroupToCollection($group, $collection); } /** @var SortOrder $sortOrder */ foreach ((array) $searchCriteria->getSortOrders() as $sortOrder) { $field = $sortOrder->getField(); $collection->addOrder($field, $sortOrder->getDirection() == SortOrder::SORT_ASC ? 'ASC' : 'DESC'); } $collection->setCurPage($searchCriteria->getCurrentPage()); $collection->setPageSize($searchCriteria->getPageSize()); $collection->load(); $searchResult = $this->searchResultsFactory->create(); $searchResult->setSearchCriteria($searchCriteria); $searchResult->setItems($collection->getItems()); $searchResult->setTotalCount($collection->getSize()); return $searchResult; }
public function testGenerateVariation() { $data = ['someKey' => 'someValue']; $attributeOption = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Attribute\\Option', [], [], '', false); $attributeOption->expects($this->once())->method('getData')->willReturn(['key' => 'value']); $attribute = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', [], [], '', false); $attribute->expects($this->any())->method('getOptions')->willReturn([$attributeOption]); $attribute->expects($this->once())->method('getAttributeCode')->willReturn(10); $this->option->expects($this->any())->method('getAttributeId')->willReturn(1); $this->attributeRepository->expects($this->once())->method('get')->with(1)->willReturn($attribute); $this->option->expects($this->any())->method('getData')->willReturn($data); $expectedAttributes = [1 => ['someKey' => 'someValue', 'options' => [['key' => 'value']], 'attribute_code' => 10]]; $this->productVariationBuilder->expects($this->once())->method('create')->with($this->product, $expectedAttributes)->willReturn(['someObject']); $expected = ['someObject']; $this->assertEquals($expected, $this->model->generateVariation($this->product, [$this->option])); }
/** * {@inheritdoc} */ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria) { /** @var \Magento\Catalog\Model\Resource\Product\Collection $collection */ $collection = $this->collectionFactory->create(); $defaultAttributeSetId = $this->eavConfig->getEntityType(\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE)->getDefaultAttributeSetId(); $extendedSearchCriteria = $this->searchCriteriaBuilder->addFilter([$this->filterBuilder->setField('attribute_set_id')->setValue($defaultAttributeSetId)->create()]); foreach ($this->metadataService->getList($extendedSearchCriteria->create())->getItems() as $metadata) { $collection->addAttributeToSelect($metadata->getAttributeCode()); } $collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner'); $collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner'); //Add filters from root filter group to the collection foreach ($searchCriteria->getFilterGroups() as $group) { $this->addFilterGroupToCollection($group, $collection); } /** @var SortOrder $sortOrder */ foreach ((array) $searchCriteria->getSortOrders() as $sortOrder) { $field = $sortOrder->getField(); $collection->addOrder($field, $sortOrder->getDirection() == SearchCriteriaInterface::SORT_ASC ? 'ASC' : 'DESC'); } $collection->setCurPage($searchCriteria->getCurrentPage()); $collection->setPageSize($searchCriteria->getPageSize()); $collection->load(); $searchResult = $this->searchResultsFactory->create(); $searchResult->setSearchCriteria($searchCriteria); $searchResult->setItems($collection->getItems()); $searchResult->setTotalCount($collection->getSize()); return $searchResult; }
/** * Mock for options save * * @param MockObject $attribute * @param MockObject $product * @param $attributeId * @param $sku * @param $id * @return void */ private function processSaveOptions(MockObject $attribute, MockObject $product, $attributeId, $sku, $id) { $attribute->expects(static::once())->method('getAttributeId')->willReturn($attributeId); $eavAttribute = $this->getMock(ProductAttributeInterface::class); $this->productAttributeRepository->expects(static::once())->method('get')->with($attributeId)->willReturn($eavAttribute); $attribute->expects(static::once())->method('loadByProductAndAttribute')->with($product, $eavAttribute)->willReturnSelf(); $this->optionRepository->expects(static::once())->method('save')->with($sku, $attribute)->willReturn($id); }
/** * Prepare attribute info for variation matrix generation * * @param \Magento\ConfigurableProduct\Api\Data\OptionInterface[] $options * @return array */ private function getAttributesForMatrix($options) { $attributes = []; /** @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute $option */ foreach ($options as $option) { $configurable = $this->objectToArray($option); /** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute */ $attribute = $this->attributeRepository->get($option->getAttributeId()); $attributeOptions = $attribute->getOptions() !== null ? $attribute->getOptions() : []; foreach ($attributeOptions as $attributeOption) { $configurable['options'][] = $this->objectToArray($attributeOption); } $configurable['attribute_code'] = $attribute->getAttributeCode(); $attributes[$option->getAttributeId()] = $configurable; } return $attributes; }
/** * Get attribute codes of prev set * * @return array * @throws \Magento\Framework\Exception\LocalizedException */ private function getPreviousSetAttributes() { if ($this->prevSetAttributes === null) { $searchCriteria = $this->searchCriteriaBuilder->addFilter('attribute_set_id', $this->getPreviousSetId())->create(); $attributes = $this->attributeRepository->getList($searchCriteria)->getItems(); $this->prevSetAttributes = []; foreach ($attributes as $attribute) { $this->prevSetAttributes[] = $attribute->getAttributeCode(); } } return $this->prevSetAttributes; }
/** * @return array * @throws \Magento\Framework\Exception\LocalizedException */ private function getAttributeTables() { $searchResult = $this->productAttributeRepository->getList($this->searchCriteriaBuilder->create()); $attributeTables = []; /** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $productAttribute */ foreach ($searchResult->getItems() as $productAttribute) { $attributeTable = $productAttribute->getBackend()->getTable(); if (!in_array($attributeTable, $attributeTables) && $attributeTable != $this->attributeResource->getTable('catalog_product_entity')) { $attributeTables[] = $attributeTable; } } return $attributeTables; }
/** * {@inheritdoc} * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function save($sku, OptionInterface $option) { /** @var $configurableAttribute \Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute */ $configurableAttribute = $this->configurableAttributeFactory->create(); if ($option->getId()) { /** @var Product $product */ $product = $this->getProduct($sku); $configurableAttribute->load($option->getId()); if (!$configurableAttribute->getId() || $configurableAttribute->getProductId() != $product->getId()) { throw new NoSuchEntityException(__('Option with id "%1" not found', $option->getId())); } $configurableAttribute->addData($option->getData()); $configurableAttribute->setValues($option->getValues() !== null ? $option->getValues() : $configurableAttribute->getPrices()); try { $configurableAttribute->save(); } catch (\Exception $e) { throw new CouldNotSaveException(__('Could not update option with id "%1"', $option->getId())); } } else { $this->validateNewOptionData($option); /** @var Product $product */ $product = $this->productRepository->get($sku); $allowedTypes = [ProductType::TYPE_SIMPLE, ProductType::TYPE_VIRTUAL, ConfigurableType::TYPE_CODE]; if (!in_array($product->getTypeId(), $allowedTypes)) { throw new \InvalidArgumentException('Incompatible product type'); } $eavAttribute = $this->productAttributeRepository->get($option->getAttributeId()); $configurableAttribute->loadByProductAndAttribute($product, $eavAttribute); if ($configurableAttribute->getId()) { throw new CouldNotSaveException(__('Product already has this option')); } $configurableAttributesData = ['attribute_id' => $option->getAttributeId(), 'position' => $option->getPosition(), 'use_default' => $option->getIsUseDefault(), 'label' => $option->getLabel(), 'values' => $option->getValues()]; try { $product->setTypeId(ConfigurableType::TYPE_CODE); $product->setConfigurableAttributesData([$configurableAttributesData]); $product->setStoreId($this->storeManager->getStore(Store::ADMIN_CODE)->getId()); $product->save(); } catch (\Exception $e) { throw new CouldNotSaveException(__('An error occurred while saving option')); } $configurableAttribute = $this->configurableAttributeFactory->create(); $configurableAttribute->loadByProductAndAttribute($product, $eavAttribute); } if (!$configurableAttribute->getId()) { throw new CouldNotSaveException(__('An error occurred while saving option')); } return $configurableAttribute->getId(); }
/** * @expectedException \Magento\Framework\Exception\InputException * @expectedExceptionMessage Products "5" and "4" have the same set of attribute values. */ public function testAroundSaveWithLinksWithDuplicateAttributes() { $links = [4, 5]; $attributeCode = 'color'; $attributeId = 23; $this->option->expects(static::once())->method('getAttributeId')->willReturn($attributeId); $this->product->expects(static::once())->method('getTypeId')->willReturn(Configurable::TYPE_CODE); $this->result->expects(static::once())->method('getExtensionAttributes')->willReturn($this->extensionAttributes); $this->extensionAttributes->expects(static::once())->method('getConfigurableProductOptions')->willReturn([$this->option]); $this->extensionAttributes->expects(static::once())->method('getConfigurableProductLinks')->willReturn($links); $this->productAttributeRepository->expects(static::once())->method('get')->willReturn($this->eavAttribute); $this->eavAttribute->expects(static::once())->method('getAttributeCode')->willReturn($attributeCode); $product = $this->getMockBuilder(Product::class)->disableOriginalConstructor()->setMethods(['load', 'getData', '__wakeup'])->getMock(); $this->productFactory->expects(static::exactly(2))->method('create')->willReturn($product); $product->expects(static::exactly(2))->method('load')->willReturnSelf(); $product->expects(static::exactly(4))->method('getData')->with($attributeCode)->willReturn($attributeId); $this->plugin->aroundSave($this->productRepository, $this->closure, $this->product); }
/** * {@inheritdoc} */ public function getList($sku) { $result = []; /** @var \Magento\Catalog\Model\Product $product */ $product = $this->productRepository->get($sku); /** @var \Magento\Catalog\Api\Data\ProductAttributeInterface $galleryAttribute */ $galleryAttribute = $this->attributeRepository->get('media_gallery'); $container = new \Magento\Framework\Object(['attribute' => $galleryAttribute]); $gallery = $this->mediaGallery->loadGallery($product, $container); $productImages = $this->getMediaAttributeValues($product); foreach ($gallery as $image) { /** @var \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface $entry */ $entry = $this->entryFactory->create(); $entry->setId($image['value_id'])->setLabel($image['label_default'])->setTypes(array_keys($productImages, $image['file']))->setDisabled($image['disabled_default'])->setPosition($image['position_default'])->setFile($image['file']); $result[] = $entry; } return $result; }
/** * @covers \Magento\ConfigurableProduct\Helper\Product\Options\Factory::create */ public function testCreate() { $attributeId = 90; $valueIndex = 12; $item = ['attribute_id' => $attributeId, 'values' => [['value_index' => $valueIndex]]]; $data = [$item]; $attribute = $this->getMockBuilder(Attribute::class)->disableOriginalConstructor()->setMethods(['setValues', 'setData', '__wakeup'])->getMock(); $this->attributeFactory->expects(static::once())->method('create')->willReturn($attribute); $eavAttribute = $this->getMockBuilder(EavAttribute::class)->disableOriginalConstructor()->getMock(); $this->productAttributeRepository->expects(static::once())->method('get')->with($attributeId)->willReturn($eavAttribute); $this->configurable->expects(static::once())->method('canUseAttribute')->with($eavAttribute)->willReturn(true); $option = $this->getMock(OptionValueInterface::class); $option->expects(static::once())->method('setValueIndex')->with($valueIndex)->willReturnSelf(); $this->optionValueFactory->expects(static::once())->method('create')->willReturn($option); $attribute->expects(static::once())->method('setData')->with($item); $attribute->expects(static::once())->method('setValues')->with([$option]); $result = $this->factory->create($data); static::assertSame([$attribute], $result); }
public function testModifyData() { $sourceData = ['1' => ['product' => [ProductAttributeInterface::CODE_PRICE => '19.99']]]; $this->locatorMock->expects($this->any())->method('getProduct')->willReturn($this->productMock); $this->productMock->expects($this->any())->method('getId')->willReturn(1); $this->productMock->expects($this->once())->method('getAttributeSetId')->willReturn(4); $this->productMock->expects($this->once())->method('getData')->with(ProductAttributeInterface::CODE_PRICE)->willReturn('19.9900'); $this->searchCriteriaBuilderMock->expects($this->any())->method('addFilter')->willReturnSelf(); $this->searchCriteriaBuilderMock->expects($this->any())->method('create')->willReturn($this->searchCriteriaMock); $this->attributeGroupRepositoryMock->expects($this->any())->method('getList')->willReturn($this->searchCriteriaMock); $this->searchCriteriaMock->expects($this->once())->method('getItems')->willReturn([$this->attributeGroupMock]); $this->sortOrderBuilderMock->expects($this->once())->method('setField')->willReturnSelf(); $this->sortOrderBuilderMock->expects($this->once())->method('setAscendingDirection')->willReturnSelf(); $dataObjectMock = $this->getMock('\\Magento\\Framework\\Api\\AbstractSimpleObject', [], [], '', false); $this->sortOrderBuilderMock->expects($this->once())->method('create')->willReturn($dataObjectMock); $this->searchCriteriaBuilderMock->expects($this->any())->method('addFilter')->willReturnSelf(); $this->searchCriteriaBuilderMock->expects($this->once())->method('addSortOrder')->willReturnSelf(); $this->searchCriteriaBuilderMock->expects($this->any())->method('create')->willReturn($this->searchCriteriaMock); $this->attributeRepositoryMock->expects($this->once())->method('getList')->with($this->searchCriteriaMock)->willReturn($this->searchResultsMock); $this->eavAttributeMock->expects($this->any())->method('getAttributeGroupCode')->willReturn('product-details'); $this->eavAttributeMock->expects($this->once())->method('getApplyTo')->willReturn([]); $this->eavAttributeMock->expects($this->once())->method('getFrontendInput')->willReturn('price'); $this->eavAttributeMock->expects($this->any())->method('getAttributeCode')->willReturn(ProductAttributeInterface::CODE_PRICE); $this->searchResultsMock->expects($this->once())->method('getItems')->willReturn([$this->eavAttributeMock]); $this->storeMock->expects($this->once())->method('getBaseCurrencyCode')->willReturn('en_US'); $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock); $this->currencyMock->expects($this->once())->method('toCurrency')->willReturn('19.99'); $this->currencyLocaleMock->expects($this->once())->method('getCurrency')->willReturn($this->currencyMock); $this->assertEquals($sourceData, $this->eav->modifyData([])); }
/** * Returns attributes * * @return \Magento\Catalog\Api\Data\ProductAttributeInterface[] */ protected function getAttributes() { return $this->productAttributeRepository->getList($this->searchCriteria)->getItems(); }