Exemplo n.º 1
0
 /**
  * @param \Magento\Catalog\Api\Data\ProductAttributeInterface $attribute
  * @param \Magento\Framework\View\Element\UiComponent\ContextInterface $context
  * @param array $config
  * @return \Magento\Ui\Component\Listing\Columns\ColumnInterface
  */
 public function create($attribute, $context, array $config = [])
 {
     $columnName = $attribute->getAttributeCode();
     $config = array_merge(['label' => __($attribute->getDefaultFrontendLabel()), 'dataType' => $this->getDataType($attribute), 'sorting' => 'asc', 'align' => 'left', 'add_field' => true, 'visible' => $attribute->getIsVisibleInGrid()], $config);
     if ($attribute->usesSource()) {
         $config['options'] = $attribute->getSource()->getAllOptions();
     }
     $arguments = ['data' => ['js_config' => ['component' => $this->getJsComponent($config['dataType'])], 'config' => $config], 'context' => $context];
     return $this->componentFactory->create($columnName, 'column', $arguments);
 }
Exemplo n.º 2
0
 /**
  * @param \Magento\Catalog\Api\Data\ProductAttributeInterface $attribute
  * @param \Magento\Framework\View\Element\UiComponent\ContextInterface $context
  * @param array $config
  * @return \Magento\Ui\Component\Listing\Columns\ColumnInterface
  */
 public function create($attribute, $context, array $config = [])
 {
     $columnName = $attribute->getAttributeCode();
     $config = array_merge(['label' => __($attribute->getDefaultFrontendLabel()), 'dataType' => $this->getDataType($attribute), 'add_field' => true, 'visible' => $attribute->getIsVisibleInGrid(), 'filter' => $attribute->getIsFilterableInGrid() ? $this->getFilterType($attribute->getFrontendInput()) : null], $config);
     if ($attribute->usesSource()) {
         $config['options'] = $attribute->getSource()->getAllOptions();
     }
     $config['component'] = $this->getJsComponent($config['dataType']);
     $arguments = ['data' => ['config' => $config], 'context' => $context];
     return $this->componentFactory->create($columnName, 'column', $arguments);
 }
Exemplo n.º 3
0
 /**
  * @param \Magento\Catalog\Api\Data\ProductAttributeInterface $attribute
  * @param \Magento\Framework\View\Element\UiComponent\ContextInterface $context
  * @param array $config
  * @return \Magento\Ui\Component\Listing\Columns\ColumnInterface
  */
 public function create($attribute, $context, $config = [])
 {
     $columnName = $attribute->getAttributeCode();
     $config = array_merge(['dataScope' => $columnName, 'label' => __($attribute->getDefaultFrontendLabel())], $config);
     if ($attribute->usesSource() && $attribute->getSourceModel()) {
         $config['options'] = $attribute->getSource()->getAllOptions();
         $config['caption'] = __('Select...');
     }
     $arguments = ['data' => ['config' => $config], 'context' => $context];
     return $this->componentFactory->create($columnName, $this->getFilterType($attribute), $arguments);
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function save(\Magento\Catalog\Api\Data\ProductAttributeInterface $attribute)
 {
     if ($attribute->getAttributeId()) {
         $existingModel = $this->get($attribute->getAttributeCode());
         if (!$existingModel->getAttributeId()) {
             throw NoSuchEntityException::singleField('attribute_code', $existingModel->getAttributeCode());
         }
         $attribute->setAttributeId($existingModel->getAttributeId());
         $attribute->setIsUserDefined($existingModel->getIsUserDefined());
         $attribute->setFrontendInput($existingModel->getFrontendInput());
         if (is_array($attribute->getFrontendLabels())) {
             $frontendLabel[0] = $existingModel->getDefaultFrontendLabel();
             foreach ($attribute->getFrontendLabels() as $item) {
                 $frontendLabel[$item->getStoreId()] = $item->getLabel();
             }
             $attribute->setDefaultFrontendLabel($frontendLabel);
         }
         if (!$attribute->getIsUserDefined()) {
             // Unset attribute field for system attributes
             $attribute->setApplyTo(null);
         }
     } else {
         $attribute->setAttributeId(null);
         if (!$attribute->getFrontendLabels() && !$attribute->getDefaultFrontendLabel()) {
             throw InputException::requiredField('frontend_label');
         }
         $frontendLabels = [];
         if ($attribute->getDefaultFrontendLabel()) {
             $frontendLabels[0] = $attribute->getDefaultFrontendLabel();
         }
         if ($attribute->getFrontendLabels() && is_array($attribute->getFrontendLabels())) {
             foreach ($attribute->getFrontendLabels() as $label) {
                 $frontendLabels[$label->getStoreId()] = $label->getLabel();
             }
             if (!isset($frontendLabels[0]) || !$frontendLabels[0]) {
                 throw InputException::invalidFieldValue('frontend_label', null);
             }
             $attribute->setDefaultFrontendLabel($frontendLabels);
         }
         $attribute->setAttributeCode($attribute->getAttributeCode() ?: $this->generateCode($frontendLabels[0]));
         $this->validateCode($attribute->getAttributeCode());
         $this->validateFrontendInput($attribute->getFrontendInput());
         $attribute->setBackendType($attribute->getBackendTypeByInput($attribute->getFrontendInput()));
         $attribute->setSourceModel($this->productHelper->getAttributeSourceModelByInputType($attribute->getFrontendInput()));
         $attribute->setBackendModel($this->productHelper->getAttributeBackendModelByInputType($attribute->getFrontendInput()));
         $attribute->setEntityTypeId($this->eavConfig->getEntityType(\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE)->getId());
         $attribute->setIsUserDefined(1);
     }
     $this->attributeResource->save($attribute);
     return $attribute;
 }
Exemplo n.º 5
0
 /**
  * Setup attribute container meta
  *
  * @param ProductAttributeInterface $attribute
  * @return array
  * @api
  */
 public function setupAttributeContainerMeta(ProductAttributeInterface $attribute)
 {
     $containerMeta = $this->arrayManager->set('arguments/data/config', [], ['formElement' => 'container', 'componentType' => 'container', 'breakLine' => false, 'label' => $attribute->getDefaultFrontendLabel(), 'required' => $attribute->getIsRequired()]);
     if ($attribute->getIsWysiwygEnabled()) {
         $containerMeta = $this->arrayManager->merge('arguments/data/config', $containerMeta, ['component' => 'Magento_Ui/js/form/components/group']);
     }
     return $containerMeta;
 }
Exemplo n.º 6
0
 /**
  * Initial meta setup
  *
  * @param ProductAttributeInterface $attribute
  * @return array
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function setupMetaProperties(ProductAttributeInterface $attribute)
 {
     $meta = ['arguments' => ['data' => ['config' => ['dataType' => $attribute->getFrontendInput(), 'formElement' => $this->getFormElementsMapValue($attribute->getFrontendInput()), 'visible' => $attribute->getIsVisible(), 'required' => $attribute->getIsRequired(), 'notice' => $attribute->getNote(), 'default' => $attribute->getDefaultValue(), 'label' => __('%1', $attribute->getDefaultFrontendLabel())]]]];
     foreach ($meta as $key => $value) {
         if ($value === null) {
             unset($meta[$key]);
         }
     }
     // TODO: Refactor to $attribute->getOptions() when MAGETWO-48289 is done
     $attributeModel = $this->getAttributeModel($attribute);
     if ($attributeModel->usesSource()) {
         $meta['arguments']['data']['config']['options'] = $attributeModel->getSource()->getAllOptions();
     }
     $meta = $this->addWysiwyg($attribute, $meta);
     $meta = $this->customizeCheckbox($attribute, $meta);
     $meta = $this->customizePriceAttribute($attribute, $meta);
     $meta = $this->addUseDefaultValueCheckbox($attribute, $meta);
     return $meta;
 }