Esempio n. 1
0
 private function saveAttribute()
 {
     if ($this->attributeObj->getId()) {
         return array('result' => true, 'obj' => $this->attributeObj);
     }
     if (!$this->validate()) {
         return array('result' => false, 'error' => 'Attribute builder. Validation failed.');
     }
     $this->attributeObj = $this->catalogAttributeFactory->create();
     $data = $this->params;
     $data['attribute_code'] = $this->code;
     $data['frontend_label'] = array(\Magento\Store\Model\Store::DEFAULT_STORE_ID => $this->primaryLabel);
     $data['frontend_input'] = $this->inputType;
     $data['entity_type_id'] = $this->entityTypeId;
     $data['is_user_defined'] = 1;
     $data['source_model'] = $this->productHelper->getAttributeSourceModelByInputType($this->inputType);
     $data['backend_model'] = $this->productHelper->getAttributeBackendModelByInputType($this->inputType);
     $data['backend_type'] = $this->attributeObj->getBackendTypeByInput($this->inputType);
     !isset($data['is_global']) && ($data['is_global'] = self::SCOPE_STORE);
     !isset($data['is_configurable']) && ($data['is_configurable'] = 0);
     !isset($data['is_filterable']) && ($data['is_filterable'] = 0);
     !isset($data['is_filterable_in_search']) && ($data['is_filterable_in_search'] = 0);
     !isset($data['apply_to']) && ($data['apply_to'] = array());
     $this->prepareOptions($data);
     $this->prepareDefault($data);
     $this->attributeObj->addData($data);
     try {
         $this->attributeObj->save();
     } catch (\Exception $e) {
         return array('result' => false, 'error' => $e->getMessage());
     }
     return array('result' => true, 'obj' => $this->attributeObj);
 }
Esempio n. 2
0
 /**
  * Return entities where attribute value is
  *
  * @param array|int $entityIdsFilter
  * @param \Magento\Eav\Model\Entity\Attribute $attribute
  * @param mixed $expectedValue
  * @return array
  */
 public function findWhereAttributeIs($entityIdsFilter, $attribute, $expectedValue)
 {
     $bind = array('attribute_id' => $attribute->getId(), 'value' => $expectedValue);
     $select = $this->_getReadAdapter()->select()->from($attribute->getBackend()->getTable(), array('entity_id'))->where('attribute_id = :attribute_id')->where('value = :value')->where('entity_id IN(?)', $entityIdsFilter);
     return $this->_getReadAdapter()->fetchCol($select, $bind);
 }
Esempio n. 3
0
 /**
  * Return entities where attribute value is
  *
  * @param array|int $entityIdsFilter
  * @param \Magento\Eav\Model\Entity\Attribute $attribute
  * @param mixed $expectedValue
  * @return array
  */
 public function findWhereAttributeIs($entityIdsFilter, $attribute, $expectedValue)
 {
     $linkField = $this->getLinkField();
     $bind = ['attribute_id' => $attribute->getId(), 'value' => $expectedValue];
     $selectEntities = $this->getConnection()->select()->from(['ce' => $this->getTable('catalog_category_entity')], ['entity_id'])->joinLeft(['ci' => $attribute->getBackend()->getTable()], "ci.{$linkField} = ce.{$linkField} AND attribute_id = :attribute_id", ['value'])->where('ci.value = :value')->where('ce.entity_id IN (?)', $entityIdsFilter);
     return $this->getConnection()->fetchCol($selectEntities, $bind);
 }
Esempio n. 4
0
 private function checkIsAlreadyInSet()
 {
     /* @var $collection \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection */
     $collection = $this->attributeFactory->create()->getResourceCollection()->setAttributeSetFilter($this->setId)->addFieldToFilter('entity_attribute.attribute_id', $this->attributeObj->getId());
     return $collection->getSize() > 0;
 }
Esempio n. 5
0
 /**
  * {@inheritDoc}
  */
 public function next()
 {
     \next($this->products);
     if (\key($this->products) === null) {
         // check if storage has more items to process
         $this->products = $this->dataProvider->getSearchableProducts($this->storeId, $this->staticFields, $this->productIds, $this->lastProductId);
         if (!count($this->products)) {
             $this->isValid = false;
             return;
         }
         $productAttributes = [];
         $this->productRelations = [];
         foreach ($this->products as $productData) {
             $this->lastProductId = $productData['entity_id'];
             $productAttributes[$productData['entity_id']] = $productData['entity_id'];
             $productChildren = $this->dataProvider->getProductChildIds($productData['entity_id'], $productData['type_id']);
             $this->productRelations[$productData['entity_id']] = $productChildren;
             if ($productChildren) {
                 foreach ($productChildren as $productChildId) {
                     $productAttributes[$productChildId] = $productChildId;
                 }
             }
         }
         \reset($this->products);
         $this->productAttributes = $this->dataProvider->getProductAttributes($this->storeId, $productAttributes, $this->dynamicFields);
     }
     $productData = \current($this->products);
     if (!isset($this->productAttributes[$productData['entity_id']])) {
         $this->next();
         return;
     }
     $productAttr = $this->productAttributes[$productData['entity_id']];
     if (!isset($productAttr[$this->visibility->getId()]) || !in_array($productAttr[$this->visibility->getId()], $this->allowedVisibility)) {
         $this->next();
         return;
     }
     if (!isset($productAttr[$this->status->getId()]) || !in_array($productAttr[$this->status->getId()], $this->statusIds)) {
         $this->next();
         return;
     }
     $productIndex = [$productData['entity_id'] => $productAttr];
     $hasChildren = false;
     $productChildren = $this->productRelations[$productData['entity_id']];
     if ($productChildren) {
         foreach ($productChildren as $productChildId) {
             if (isset($this->productAttributes[$productChildId])) {
                 $productChildAttr = $this->productAttributes[$productChildId];
                 if (!isset($productChildAttr[$this->status->getId()]) || !in_array($productChildAttr[$this->status->getId()], $this->statusIds)) {
                     continue;
                 }
                 $hasChildren = true;
                 $productIndex[$productChildId] = $productChildAttr;
             }
         }
     }
     if ($productChildren !== null && !$hasChildren) {
         $this->next();
         return;
     }
     $index = $this->dataProvider->prepareProductIndex($productIndex, $productData, $this->storeId);
     $this->current = $index;
     $this->key = $productData['entity_id'];
 }