예제 #1
0
 /**
  * Get attribute type based on its backend model.
  * 
  * @param \Magento\Eav\Api\Data\AttributeInterface $attribute
  * @param string $serviceClass
  * @param $serviceBackendModelDataInterfaceMap array
  * @return string|null
  */
 public function getType($attribute, $serviceClass, $serviceBackendModelDataInterfaceMap)
 {
     $backendModel = $attribute->getBackendModel();
     //If empty backend model, check if it can be derived
     if (empty($backendModel)) {
         $backendModelClass = sprintf('Magento\\Eav\\Model\\Attribute\\Data\\%s', $this->stringUtility->upperCaseWords($attribute->getFrontendInput()));
         $backendModel = class_exists($backendModelClass) ? $backendModelClass : null;
     }
     $dataInterface = isset($serviceBackendModelDataInterfaceMap[$serviceClass][$backendModel]) ? $serviceBackendModelDataInterfaceMap[$serviceClass][$backendModel] : null;
     return $dataInterface;
 }
예제 #2
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;
 }
예제 #3
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'];
     }
 }