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);
 }
 /**
  * @param string $givenFrontendInput
  * @param string $expectedBackendType
  * @dataProvider dataGetBackendTypeByInput
  */
 public function testGetBackendTypeByInput($givenFrontendInput, $expectedBackendType)
 {
     $this->assertEquals($expectedBackendType, $this->_model->getBackendTypeByInput($givenFrontendInput));
 }