示例#1
0
 /**
  * Get attribute type based on its frontend input and backend type.
  *
  * @param \Magento\Eav\Api\Data\AttributeInterface $attribute
  * @return string
  */
 public function getType($attribute)
 {
     if (in_array($attribute->getAttributeCode(), $this->anyTypeAttributes)) {
         return TypeProcessor::NORMALIZED_ANY_TYPE;
     }
     $frontendInput = $attribute->getFrontendInput();
     $backendType = $attribute->getBackendType();
     $backendTypeMap = ['static' => TypeProcessor::NORMALIZED_ANY_TYPE, 'int' => TypeProcessor::NORMALIZED_INT_TYPE, 'text' => TypeProcessor::NORMALIZED_STRING_TYPE, 'varchar' => TypeProcessor::NORMALIZED_STRING_TYPE, 'datetime' => TypeProcessor::NORMALIZED_STRING_TYPE, 'decimal' => TypeProcessor::NORMALIZED_DOUBLE_TYPE];
     $arrayFrontendInputs = ['multiselect'];
     $type = $backendTypeMap[$backendType];
     if (in_array($frontendInput, $arrayFrontendInputs)) {
         $type .= '[]';
     }
     return $type;
 }
示例#2
0
 /**
  * Process attributes by frontend input type
  *
  * @param AttributeInterface $attribute
  * @param array $meta
  * @return array
  */
 private function processFrontendInput(AttributeInterface $attribute, array &$meta)
 {
     $code = $attribute->getAttributeCode();
     if ($attribute->getFrontendInput() === 'boolean') {
         $meta[$code]['arguments']['data']['config']['prefer'] = 'toggle';
         $meta[$code]['arguments']['data']['config']['valueMap'] = ['true' => '1', 'false' => '0'];
     }
 }
 /**
  * @param \Magento\Eav\Api\Data\AttributeInterface $attribute
  * @param int $optionId
  * @throws NoSuchEntityException
  * @return void
  */
 protected function validateOption($attribute, $optionId)
 {
     if (!$attribute->getSource()->getOptionText($optionId)) {
         throw new NoSuchEntityException(__('Attribute %1 does not contain option with Id %2', $attribute->getAttributeCode(), $optionId));
     }
 }