/**
  * 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);
     }
 }
Exemple #2
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);
     }
 }
Exemple #3
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;
 }
 /**
  * {@inheritdoc}
  */
 public function getId()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getId');
     if (!$pluginInfo) {
         return parent::getId();
     } else {
         return $this->___callPlugins('getId', func_get_args(), $pluginInfo);
     }
 }
 /**
  * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
  * @param array $data
  * @return array
  */
 protected function getOption($attribute, $data)
 {
     $result = [];
     $data['option'] = explode("\n", $data['option']);
     /** @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection $options */
     $options = $this->attrOptionCollectionFactory->create()->setAttributeFilter($attribute->getId())->setPositionOrder('asc', true)->load();
     foreach ($data['option'] as $value) {
         if (!$options->getItemByColumnValue('value', $value)) {
             $result[] = $value;
         }
     }
     return $result ? $this->convertOption($result) : $result;
 }
 /**
  * @param eavAttribute $attribute
  * @return array
  */
 private function addExistingOptions(eavAttribute $attribute)
 {
     $options = [];
     $attributeId = $attribute->getId();
     if ($attributeId) {
         $this->loadOptionCollection($attributeId);
         /** @var \Magento\Eav\Model\Entity\Attribute\Option $option */
         foreach ($this->optionCollection[$attributeId] as $option) {
             $options[$option->getId()] = $option->getValue();
         }
     }
     return $options;
 }