Esempio n. 1
0
 /**
  * Load counfigurable attribute by product and product's attribute
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute  $attribute
  * @return void
  */
 public function loadByProductAndAttribute($product, $attribute)
 {
     $id = $this->_getResource()->getIdByProductIdAndAttributeId($this, $product->getId(), $attribute->getId());
     if ($id) {
         $this->load($id);
     }
 }
Esempio n. 2
0
 /**
  * Prepare search condition for attribute
  *
  * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
  * @param string|array $value
  * @return string|array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function prepareCondition($attribute, $value)
 {
     $condition = false;
     if (is_array($value)) {
         if ($attribute->getBackendType() == 'varchar') {
             // multiselect
             // multiselect
             $condition = ['in_set' => $value];
         } elseif (!isset($value['from']) && !isset($value['to'])) {
             // select
             // select
             $condition = ['in' => $value];
         } elseif (isset($value['from']) && '' !== $value['from'] || isset($value['to']) && '' !== $value['to']) {
             // range
             $condition = $value;
         }
     } else {
         if (strlen($value) > 0) {
             if (in_array($attribute->getBackendType(), ['varchar', 'text', 'static'])) {
                 $condition = ['like' => '%' . $value . '%'];
                 // text search
             } else {
                 $condition = $value;
             }
         }
     }
     return $condition;
 }
Esempio n. 3
0
 /**
  * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $subject
  * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
  * @return \Magento\Catalog\Model\ResourceModel\Eav\Attribute
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterDelete(\Magento\Catalog\Model\ResourceModel\Eav\Attribute $subject, \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute)
 {
     if ($attribute->getIsUsedForPromoRules()) {
         $this->checkCatalogRulesAvailability($attribute->getAttributeCode());
     }
     return $attribute;
 }
Esempio n. 4
0
 /**
  * Redefine Attribute scope
  *
  * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
  * @return $this
  */
 public function setScope($attribute)
 {
     if ($this->_helper->isPriceGlobal()) {
         $attribute->setIsGlobal(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_GLOBAL);
     } else {
         $attribute->setIsGlobal(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE);
     }
     return $this;
 }
Esempio n. 5
0
 protected function canReplaceImageWithSwatch($expected)
 {
     $this->swatchesHelperMock->expects($this->once())->method('isSwatchAttribute')->with($this->attributeMock)->willReturn($expected['isSwatchAttribute']);
     $this->attributeMock->expects($this->exactly($expected['getUsedInProductListing_count']))->method('getUsedInProductListing')->willReturn($expected['getUsedInProductListing']);
     $this->attributeMock->expects($this->exactly($expected['getIsFilterable_count']))->method('getIsFilterable')->willReturn($expected['getIsFilterable']);
     if ($expected['update_product_preview_image__count'] == 1) {
         $this->attributeMock->method('getData')->with('update_product_preview_image')->willReturn($expected['update_product_preview_image']);
     }
 }
Esempio n. 6
0
 /**
  * Redefine Attribute scope
  *
  * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
  * @return $this
  */
 public function setScope($attribute)
 {
     if ($this->_helper->isPriceGlobal()) {
         $attribute->setIsGlobal(ScopedAttributeInterface::SCOPE_GLOBAL);
     } else {
         $attribute->setIsGlobal(ScopedAttributeInterface::SCOPE_WEBSITE);
     }
     return $this;
 }
 public function testGetValues()
 {
     $expected = [1, 2, 3];
     $this->source->expects($this->once())->method('getAllOptions')->with(true, true)->willReturn($expected);
     $this->attribute->expects($this->once())->method('getSource')->willReturn($this->source);
     $this->swatch->expects($this->once())->method('getData')->with('entity_attribute')->willReturn($this->attribute);
     $method = new \ReflectionMethod('Magento\\Swatches\\Model\\Form\\Element\\AbstractSwatch', 'getValues');
     $method->setAccessible(true);
     $this->assertEquals($expected, $method->invoke($this->swatch));
 }
Esempio n. 8
0
 protected function setUp()
 {
     parent::setUp();
     $this->sourceCountryMock = $this->getMockBuilder(SourceCountry::class)->disableOriginalConstructor()->getMock();
     $this->eavAttributeFactoryMock = $this->getMockBuilder(EavAttributeFactory::class)->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $this->eavAttributeMock = $this->getMockBuilder(EavAttribute::class)->disableOriginalConstructor()->getMock();
     $this->websiteManagerMock = $this->getMockBuilder(WebsiteManager::class)->disableOriginalConstructor()->getMock();
     $this->eavAttributeFactoryMock->expects($this->any())->method('create')->willReturn($this->eavAttributeMock);
     $this->eavAttributeMock->expects($this->any())->method('loadByCode')->willReturn($this->eavAttributeMock);
 }
Esempio n. 9
0
 /**
  * Get Attribute Filter Class Name
  *
  * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
  * @return string
  */
 protected function getAttributeFilterClass(\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute)
 {
     $filterClassName = $this->filterTypes[self::ATTRIBUTE_FILTER];
     if ($attribute->getAttributeCode() == 'price') {
         $filterClassName = $this->filterTypes[self::PRICE_FILTER];
     } elseif ($attribute->getBackendType() == 'decimal') {
         $filterClassName = $this->filterTypes[self::DECIMAL_FILTER];
     }
     return $filterClassName;
 }
Esempio n. 10
0
 public function testExecute()
 {
     $this->attributeMock->expects($this->any())->method('offsetGet')->with('attribute_code')->willReturn('color');
     $this->productMock->expects($this->once())->method('load')->with(59)->willReturn($this->productMock);
     $this->productModelFactoryMock->expects($this->once())->method('create')->willReturn($this->productMock);
     $this->swatchHelperMock->expects($this->once())->method('getAttributesFromConfigurable')->with($this->productMock)->willReturn([$this->attributeMock]);
     $this->swatchHelperMock->expects($this->once())->method('loadVariationByFallback')->with($this->productMock, ['size' => 454, 'color' => 43])->willReturn($this->productMock);
     $this->swatchHelperMock->expects($this->once())->method('getProductMediaGallery')->with($this->productMock)->willReturn($this->mediaGallery);
     $this->jsonMock->expects($this->once())->method('setData')->with($this->mediaGallery)->will($this->returnSelf());
     $result = $this->controller->execute();
     $this->assertInstanceOf('\\Magento\\Framework\\Controller\\Result\\Json', $result);
 }
Esempio n. 11
0
 /**
  * Add additional data to attribute.
  *
  * @param Attribute $attribute
  * @return bool
  */
 public function overrideAttribute(Attribute $attribute)
 {
     if (!empty($this->_attributeOverrides[$attribute->getAttributeCode()])) {
         $data = $this->_attributeOverrides[$attribute->getAttributeCode()];
         if (isset($data['options_method']) && method_exists($this, $data['options_method'])) {
             $data['filter_options'] = $this->{$data['options_method']}();
         }
         $attribute->addData($data);
         return true;
     }
     return false;
 }
 public function testGetAttributes()
 {
     $ids = [1];
     $result = [['id' => 'id', 'label' => 'label', 'code' => 'code', 'options' => ['options']]];
     $this->collectionMock->expects($this->any())->method('addFieldToFilter')->with('main_table.attribute_id', $ids);
     $this->attributeMock->expects($this->once())->method('getId')->will($this->returnValue('id'));
     $this->attributeMock->expects($this->once())->method('getFrontendLabel')->will($this->returnValue('label'));
     $this->attributeMock->expects($this->once())->method('getAttributeCode')->will($this->returnValue('code'));
     $source = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\Source\\AbstractSource', [], [], '', false);
     $source->expects($this->once())->method('getAllOptions')->with(false)->will($this->returnValue(['options']));
     $this->attributeMock->expects($this->once())->method('getSource')->will($this->returnValue($source));
     $this->assertEquals($result, $this->attributeListModel->getAttributes($ids));
 }
Esempio n. 13
0
 public function testExecute()
 {
     $this->requestMock->expects($this->any())->method('getParam')->willReturnMap([['frontend_label', null, 'test_frontend_label'], ['attribute_code', null, 'test_attribute_code'], ['new_attribute_set_name', null, 'test_attribute_set_name']]);
     $this->objectManagerMock->expects($this->exactly(2))->method('create')->willReturnMap([['Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', [], $this->attributeMock], ['Magento\\Eav\\Model\\Entity\\Attribute\\Set', [], $this->attributeSetMock]]);
     $this->attributeMock->expects($this->once())->method('loadByCode')->willReturnSelf();
     $this->requestMock->expects($this->once())->method('has')->with('new_attribute_set_name')->willReturn(true);
     $this->attributeSetMock->expects($this->once())->method('setEntityTypeId')->willReturnSelf();
     $this->attributeSetMock->expects($this->once())->method('load')->willReturnSelf();
     $this->attributeSetMock->expects($this->once())->method('getId')->willReturn(false);
     $this->resultJsonFactoryMock->expects($this->once())->method('create')->willReturn($this->resultJson);
     $this->resultJson->expects($this->once())->method('setJsonData')->willReturnSelf();
     $this->assertInstanceOf(ResultJson::class, $this->getModel()->execute());
 }
Esempio n. 14
0
 public function testUpdateAttributes()
 {
     $productIds = [1, 2, 2, 4];
     $productIdsUnique = [0 => 1, 1 => 2, 3 => 4];
     $attrData = [1];
     $storeId = 1;
     $this->resource->expects($this->any())->method('updateAttributes')->with($productIds, $attrData, $storeId)->will($this->returnSelf());
     $this->categoryIndexer->expects($this->any())->method('isScheduled')->will($this->returnValue(false));
     $this->categoryIndexer->expects($this->any())->method('reindexList')->will($this->returnValue($productIds));
     $this->prepareIndexer();
     $this->eavConfig->expects($this->any())->method('getAttribute')->will($this->returnValue($this->eavAttribute));
     $this->eavAttribute->expects($this->any())->method('isIndexable')->will($this->returnValue(false));
     $this->assertEquals($this->model, $this->model->updateAttributes($productIds, $attrData, $storeId));
     $this->assertEquals($this->model->getDataByKey('product_ids'), $productIdsUnique);
     $this->assertEquals($this->model->getDataByKey('attributes_data'), $attrData);
     $this->assertEquals($this->model->getDataByKey('store_id'), $storeId);
 }
 /**
  * @dataProvider validateDataProvider
  *
  * @param string $attributeValue
  * @param string|array $parsedValue
  * @param string $newValue
  * @param string $operator
  * @param array $input
  * @return void
  */
 public function testValidateWithDatetimeValue($attributeValue, $parsedValue, $newValue, $operator, $input)
 {
     $this->product->setData('attribute', 'attribute_key');
     $this->product->setData('value_parsed', $parsedValue);
     $this->product->setData('operator', $operator);
     $this->config->expects($this->any())->method('getAttribute')->will($this->returnValue($this->eavAttributeResource));
     $this->eavAttributeResource->expects($this->any())->method('isScopeGlobal')->will($this->returnValue(false));
     $this->eavAttributeResource->expects($this->any())->method($input['method'])->will($this->returnValue($input['type']));
     $this->productModel->expects($this->any())->method('hasData')->will($this->returnValue(true));
     $this->productModel->expects($this->at(0))->method('getData')->will($this->returnValue(['1' => ['1' => $attributeValue]]));
     $this->productModel->expects($this->any())->method('getData')->will($this->returnValue($newValue));
     $this->productModel->expects($this->any())->method('getId')->will($this->returnValue('1'));
     $this->productModel->expects($this->once())->method('getStoreId')->will($this->returnValue('1'));
     $this->productModel->expects($this->any())->method('getResource')->will($this->returnValue($this->productResource));
     $this->productResource->expects($this->any())->method('getAttribute')->will($this->returnValue($this->eavAttributeResource));
     $this->product->collectValidatedAttributes($this->productModel);
     $this->assertTrue($this->product->validate($this->productModel));
 }
Esempio n. 16
0
 /**
  * {@inheritdoc}
  */
 public function delete()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'delete');
     if (!$pluginInfo) {
         return parent::delete();
     } else {
         return $this->___callPlugins('delete', func_get_args(), $pluginInfo);
     }
 }
Esempio n. 17
0
 /**
  * @dataProvider dataIsSwatchAttribute
  */
 public function testIsSwatchAttribute($times, $swatchType, $boolResult)
 {
     $this->attributeMock->method('hasData')->with('swatch_input_type')->willReturn(true);
     $this->attributeMock->expects($this->exactly($times))->method('getData')->with('swatch_input_type')->willReturn($swatchType);
     $result = $this->swatchHelperObject->isSwatchAttribute($this->attributeMock);
     if ($boolResult) {
         $this->assertTrue($result);
     } else {
         $this->assertFalse($result);
     }
 }
Esempio n. 18
0
 /**
  * Retrieve websites
  *
  * @param ProductInterface $product
  * @param EavAttribute $eavAttribute
  * @return array
  */
 public function getWebsites(ProductInterface $product, EavAttribute $eavAttribute)
 {
     if (null !== $this->websites) {
         return $this->websites;
     }
     $websites = [['value' => 0, 'label' => $this->formatLabel(__('All Websites'), $this->directoryHelper->getBaseCurrencyCode())]];
     if ($this->storeManager->hasSingleStore() || $eavAttribute->getEntityAttribute() && $eavAttribute->getEntityAttribute()->isScopeGlobal()) {
         return $this->websites = $websites;
     }
     if ($storeId = $this->locator->getStore()->getId()) {
         /** @var WebsiteInterface $website */
         $website = $this->storeManager->getStore($storeId)->getWebsite();
         $websites[$website->getId()] = ['value' => $website->getId(), 'label' => $this->formatLabel($website->getName(), $website->getConfig(Currency::XML_PATH_CURRENCY_BASE))];
     } else {
         /** @var WebsiteInterface $website */
         foreach ($this->storeManager->getWebsites() as $website) {
             if (!in_array($website->getId(), $product->getWebsiteIds())) {
                 continue;
             }
             $websites[$website->getId()] = ['value' => $website->getId(), 'label' => $this->formatLabel($website->getName(), $website->getConfig(Currency::XML_PATH_CURRENCY_BASE))];
         }
     }
     return $this->websites = $websites;
 }
 public function testAfterAfterSaveNotSwatchAttribute()
 {
     $this->abstractSource->expects($this->once())->method('getAllOptions')->willReturn($this->allOptions);
     $this->swatch->expects($this->once())->method('getId')->willReturn(1);
     $this->swatch->expects($this->once())->method('save');
     $this->swatch->expects($this->once())->method('isDeleted')->with(false);
     $this->swatch->expects($this->exactly(2))->method('setData')->withConsecutive(['type', Swatch::SWATCH_TYPE_TEXTUAL], ['value', null]);
     $this->collection->expects($this->exactly(2))->method('addFieldToFilter')->withConsecutive(['option_id', self::OPTION_ID], ['store_id', self::OPTION_ID])->willReturnSelf();
     $this->collection->expects($this->once())->method('getFirstItem')->willReturn($this->swatch);
     $this->collectionFactory->expects($this->once())->method('create')->willReturn($this->collection);
     $this->attribute->expects($this->at(0))->method('getData')->with('option')->willReturn($this->optionIds);
     $this->attribute->expects($this->at(1))->method('getSource')->willReturn($this->abstractSource);
     $this->attribute->expects($this->at(2))->method('getData')->with('swatch/value')->willReturn([self::STORE_ID => [self::OPTION_ID => null]]);
     $this->attribute->expects($this->at(3))->method('getData')->with('option/delete/' . self::OPTION_ID)->willReturn(false);
     $this->swatchHelper->expects($this->exactly(2))->method('isSwatchAttribute')->with($this->attribute)->will($this->onConsecutiveCalls(true, false));
     $this->swatchHelper->expects($this->once())->method('isVisualSwatch')->with($this->attribute)->willReturn(false);
     $this->swatchHelper->expects($this->once())->method('isTextSwatch')->with($this->attribute)->willReturn(true);
     $this->eavAttribute->afterAfterSave($this->attribute);
 }
Esempio n. 20
0
 public function testExecuteNoPopup()
 {
     $attributesData = ['frontend_label' => ''];
     $this->request->expects($this->any())->method('getParam')->willReturnMap([['attribute_id', null, null], ['attribute', null, $attributesData], ['popup', null, false]]);
     $this->objectManagerMock->expects($this->any())->method('create')->with('Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute')->willReturn($this->eavAttribute);
     $this->objectManagerMock->expects($this->any())->method('get')->with('Magento\\Backend\\Model\\Session')->willReturn($this->session);
     $this->eavAttribute->expects($this->once())->method('setEntityTypeId')->willReturnSelf();
     $this->eavAttribute->expects($this->once())->method('addData')->with($attributesData)->willReturnSelf();
     $this->registry->expects($this->any())->method('register')->with('entity_attribute', $this->eavAttribute);
     $this->resultPage->expects($this->any())->method('addBreadcrumb')->willReturnSelf();
     $this->resultPage->expects($this->once())->method('setActiveMenu')->with('Magento_Catalog::catalog_attributes_attributes')->willReturnSelf();
     $this->resultPage->expects($this->any())->method('getConfig')->willReturn($this->pageConfig);
     $this->resultPage->expects($this->once())->method('getLayout')->willReturn($this->layout);
     $this->resultPageFactory->expects($this->atLeastOnce())->method('create')->willReturn($this->resultPage);
     $this->pageConfig->expects($this->any())->method('getTitle')->willReturn($this->pageTitle);
     $this->pageTitle->expects($this->any())->method('prepend')->willReturnSelf();
     $this->eavAttribute->expects($this->any())->method('getName')->willReturn(null);
     $this->layout->expects($this->once())->method('getBlock')->willReturn($this->blockTemplate);
     $this->blockTemplate->expects($this->any())->method('setIsPopup')->willReturnSelf();
     $this->assertSame($this->resultPage, $this->editController->execute());
 }
Esempio n. 21
0
 /**
  * Load counfigurable attribute by product and product's attribute
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute  $attribute
  * @return void
  */
 public function loadByProductAndAttribute($product, $attribute)
 {
     $metadata = $this->metadataPool->getMetadata(ProductInterface::class);
     $id = $this->_getResource()->getIdByProductIdAndAttributeId($this, $product->getData($metadata->getLinkField()), $attribute->getId());
     if ($id) {
         $this->load($id);
     }
 }
 /**
  * Check attribute availability for super product creation
  *
  * @param  \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
  * @return bool
  */
 public function canUseAttribute(\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute)
 {
     return $attribute->getIsGlobal() == \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL && $attribute->getIsVisible() && $attribute->usesSource() && $attribute->getIsUserDefined();
 }
Esempio n. 23
0
 /**
  * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
  * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
  * @return $this
  */
 protected function addGlobalAttribute(\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute, \Magento\Catalog\Model\ResourceModel\Product\Collection $collection)
 {
     $storeId = $this->storeManager->getStore()->getId();
     switch ($attribute->getBackendType()) {
         case 'decimal':
         case 'datetime':
         case 'int':
             $alias = 'at_' . $attribute->getAttributeCode();
             $collection->addAttributeToSelect($attribute->getAttributeCode(), 'inner');
             break;
         default:
             $alias = 'at_' . md5($this->getId()) . $attribute->getAttributeCode();
             $collection->getSelect()->join([$alias => $collection->getTable('catalog_product_index_eav')], "({$alias}.entity_id = e.entity_id) AND ({$alias}.store_id = {$storeId})" . " AND ({$alias}.attribute_id = {$attribute->getId()})", []);
     }
     $this->joinedAttributes[$attribute->getAttributeCode()] = $alias . '.value';
     return $this;
 }
Esempio n. 24
0
 public function testGetScopeStore()
 {
     $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->_model = $objectManagerHelper->getObject('\\Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', ['context' => $this->contextMock, 'productFlatIndexerProcessor' => $this->_processor, 'indexerEavProcessor' => $this->_eavProcessor, 'resource' => $this->resourceMock, 'data' => ['is_global' => 'some value']]);
     $this->assertEquals('store', $this->_model->getScope());
 }
Esempio n. 25
0
 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([]));
 }
Esempio n. 26
0
 /**
  * {@inheritdoc}
  */
 public function offsetGet($offset)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'offsetGet');
     if (!$pluginInfo) {
         return parent::offsetGet($offset);
     } else {
         return $this->___callPlugins('offsetGet', func_get_args(), $pluginInfo);
     }
 }
 /**
  * Check whether specified attribute can be used in LN
  *
  * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
  * @return int
  */
 protected function getAttributeIsFilterable($attribute)
 {
     return $attribute->getIsFilterable();
 }
 /**
  * Check whether the attribute is Applicable to the object
  *
  * @param \Magento\Framework\DataObject $object
  * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
  * @return boolean
  */
 protected function _isApplicableAttribute($object, $attribute)
 {
     $applyTo = $attribute->getApplyTo();
     return (count($applyTo) == 0 || in_array($object->getTypeId(), $applyTo)) && $attribute->isInSet($object->getAttributeSetId());
 }
Esempio n. 29
0
 /**
  * Retrieve Product Attribute Value
  *
  * @param Product $product
  * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
  * @return \Magento\Framework\Phrase|string
  */
 public function getProductAttributeValue($product, $attribute)
 {
     if (!$product->hasData($attribute->getAttributeCode())) {
         return __('N/A');
     }
     if ($attribute->getSourceModel() || in_array($attribute->getFrontendInput(), ['select', 'boolean', 'multiselect'])) {
         //$value = $attribute->getSource()->getOptionText($product->getData($attribute->getAttributeCode()));
         $value = $attribute->getFrontend()->getValue($product);
     } else {
         $value = $product->getData($attribute->getAttributeCode());
     }
     return (string) $value == '' ? __('No') : $value;
 }
Esempio n. 30
0
 /**
  * Check if is option for delete
  *
  * @param Attribute $attribute
  * @param integer $optionId
  * @return bool
  */
 protected function isOptionForDelete(Attribute $attribute, $optionId)
 {
     $isOptionForDelete = $attribute->getData('option/delete/' . $optionId);
     return isset($isOptionForDelete) && $isOptionForDelete;
 }