/**
  * Initializes Data Object with the data from array
  *
  * @param array $data
  * @return $this
  */
 protected function _setDataValues(array $data)
 {
     $dataObjectMethods = get_class_methods($this->_getDataObjectType());
     foreach ($data as $key => $value) {
         /* First, verify is there any getter for the key on the Service Data Object */
         $possibleMethods = array('get' . \Magento\Framework\Service\DataObjectConverter::snakeCaseToCamelCase($key), 'is' . \Magento\Framework\Service\DataObjectConverter::snakeCaseToCamelCase($key));
         if (array_intersect($possibleMethods, $dataObjectMethods)) {
             $this->_data[$key] = $value;
         }
     }
     return $this;
 }
 /**
  * Initializes Data Object with the data from array
  *
  * @param array $data
  * @return $this
  */
 protected function _setDataValues(array $data)
 {
     $dataObjectMethods = get_class_methods($this->_getDataObjectType());
     foreach ($data as $key => $value) {
         /* First, verify is there any getter for the key on the Service Data Object */
         $camelCaseKey = \Magento\Framework\Service\DataObjectConverter::snakeCaseToCamelCase($key);
         $possibleMethods = array('get' . $camelCaseKey, 'is' . $camelCaseKey);
         if ($key == AbstractObject::CUSTOM_ATTRIBUTES_KEY && !empty($data[$key])) {
             foreach ($data[$key] as $customAttribute) {
                 $this->setCustomAttribute($customAttribute[AttributeValue::ATTRIBUTE_CODE], $customAttribute[AttributeValue::VALUE]);
             }
         } elseif (array_intersect($possibleMethods, $dataObjectMethods)) {
             $this->_data[$key] = $value;
         } else {
             $this->setCustomAttribute($key, $value);
         }
     }
     return $this;
 }
Beispiel #3
0
 /**
  * @param string $field
  * @param StockItem $dataObject
  * @return mixed
  * @throws \BadMethodCallException
  */
 public function getDoFieldData($field, StockItem $dataObject)
 {
     $possibleMethods = array('get' . \Magento\Framework\Service\DataObjectConverter::snakeCaseToCamelCase($field), 'is' . \Magento\Framework\Service\DataObjectConverter::snakeCaseToCamelCase($field));
     foreach ($possibleMethods as $method) {
         if (method_exists($dataObject, $method)) {
             return $dataObject->{$method}();
         }
     }
     throw new \BadMethodCallException(__('Field "%1" was not found in DO "%2".', $field, get_class($dataObject)));
 }
 /**
  * @inheritdoc
  */
 public function getCustomAddressAttributeMetadata()
 {
     $customAttributes = [];
     if (!$this->addressDataObjectMethods) {
         $this->addressDataObjectMethods = array_flip(get_class_methods('Magento\\Customer\\Service\\V1\\Data\\Address'));
     }
     foreach ($this->getAllAddressAttributeMetadata() as $attributeMetadata) {
         $attributeCode = $attributeMetadata->getAttributeCode();
         $camelCaseKey = \Magento\Framework\Service\DataObjectConverter::snakeCaseToCamelCase($attributeCode);
         $isDataObjectMethod = isset($this->addressDataObjectMethods['get' . $camelCaseKey]) || isset($this->addressDataObjectMethods['is' . $camelCaseKey]);
         if (!$isDataObjectMethod && !$attributeMetadata->isSystem()) {
             $customAttributes[] = $attributeMetadata;
         }
     }
     return $customAttributes;
 }