/** * @param ScopeInterface $scope * @param AbstractAttribute $attribute * @param bool $useDefault * @return string */ protected function getScopeValue(ScopeInterface $scope, AbstractAttribute $attribute, $useDefault = false) { if ($attribute instanceof CatalogEavAttribute) { $useDefault = $useDefault || $attribute->isScopeGlobal(); } return parent::getScopeValue($scope, $attribute, $useDefault); }
/** * Delete product data * * @param \Magento\Catalog\Model\Product $product * @param \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute * @return $this */ public function deleteProductData($product, $attribute) { $where = ['entity_id = ?' => (int) $product->getId(), 'attribute_id = ?' => (int) $attribute->getId()]; $connection = $this->getConnection(); if (!$attribute->isScopeGlobal()) { $storeId = $product->getStoreId(); if ($storeId) { $where['website_id IN(?)'] = [0, $this->_storeManager->getStore($storeId)->getWebsiteId()]; } } $connection->delete($this->getMainTable(), $where); return $this; }
/** * @param AbstractAttribute $attribute * @return Data\Eav\AttributeMetadata */ private function createMetadataAttribute($attribute) { $data = $this->booleanPrefixMapper($attribute->getData()); // fill options and validate rules $data[AttributeMetadata::OPTIONS] = $attribute->usesSource() ? $attribute->getSource()->getAllOptions() : array(); $data[AttributeMetadata::VALIDATION_RULES] = $attribute->getValidateRules(); // fill scope $data[AttributeMetadata::SCOPE] = $attribute->isScopeGlobal() ? 'global' : ($attribute->isScopeWebsite() ? 'website' : 'store'); $data[AttributeMetadata::FRONTEND_LABEL] = []; $data[AttributeMetadata::FRONTEND_LABEL][0] = array(FrontendLabel::STORE_ID => 0, FrontendLabel::LABEL => $attribute->getFrontendLabel()); if (is_array($attribute->getStoreLabels())) { foreach ($attribute->getStoreLabels() as $storeId => $label) { $data[AttributeMetadata::FRONTEND_LABEL][$storeId] = array(FrontendLabel::STORE_ID => $storeId, FrontendLabel::LABEL => $label); } } return $this->attributeMetadataBuilder->populateWithArray($data)->create(); }
/** * Delete product data * * @param \Magento\Catalog\Model\Product $product * @param \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute * @return $this */ public function deleteProductData($product, $attribute) { $where = array('entity_id = ?' => (int) $product->getId(), 'attribute_id = ?' => (int) $attribute->getId()); $adapter = $this->_getWriteAdapter(); if (!$attribute->isScopeGlobal()) { $storeId = $product->getStoreId(); if ($storeId) { $where['website_id IN(?)'] = array(0, $this->_storeManager->getStore($storeId)->getWebsiteId()); } } $adapter->delete($this->getMainTable(), $where); return $this; }