Beispiel #1
0
 /**
  * @param \Magento\Sales\Model\Quote\Address $address
  * @return \Magento\Checkout\Service\V1\Data\Cart\Address
  */
 public function convertModelToDataObject(\Magento\Sales\Model\Quote\Address $address)
 {
     $data = [Address::KEY_COUNTRY_ID => $address->getCountryId(), Address::KEY_ID => $address->getId(), Address::KEY_CUSTOMER_ID => $address->getCustomerId(), Address::KEY_REGION => array(Region::KEY_REGION => $address->getRegion(), Region::KEY_REGION_ID => $address->getRegionId(), Region::KEY_REGION_CODE => $address->getRegionCode()), Address::KEY_STREET => $address->getStreet(), Address::KEY_COMPANY => $address->getCompany(), Address::KEY_TELEPHONE => $address->getTelephone(), Address::KEY_FAX => $address->getFax(), Address::KEY_POSTCODE => $address->getPostcode(), Address::KEY_CITY => $address->getCity(), Address::KEY_FIRSTNAME => $address->getFirstname(), Address::KEY_LASTNAME => $address->getLastname(), Address::KEY_MIDDLENAME => $address->getMiddlename(), Address::KEY_PREFIX => $address->getPrefix(), Address::KEY_SUFFIX => $address->getSuffix(), Address::KEY_EMAIL => $address->getEmail(), Address::KEY_VAT_ID => $address->getVatId()];
     foreach ($this->metadataService->getCustomAttributesMetadata() as $attributeMetadata) {
         $attributeCode = $attributeMetadata->getAttributeCode();
         $method = 'get' . SimpleDataObjectConverter::snakeCaseToCamelCase($attributeCode);
         $data[Address::CUSTOM_ATTRIBUTES_KEY][] = [AttributeValue::ATTRIBUTE_CODE => $attributeCode, AttributeValue::VALUE => $address->{$method}()];
     }
     return $this->addressBuilder->populateWithArray($data)->create();
 }
Beispiel #2
0
 /**
  * @param string $field
  * @param StockItem $dataObject
  * @return mixed
  * @throws \BadMethodCallException
  */
 public function getDoFieldData($field, StockItem $dataObject)
 {
     $possibleMethods = array('get' . \Magento\Framework\Service\SimpleDataObjectConverter::snakeCaseToCamelCase($field), 'is' . \Magento\Framework\Service\SimpleDataObjectConverter::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 getCustomAttributesMetadata($dataObjectClassName = self::DATA_OBJECT_CLASS_NAME)
 {
     $customAttributes = [];
     if (!$this->customerDataObjectMethods) {
         $this->customerDataObjectMethods = array_flip(get_class_methods($dataObjectClassName));
     }
     foreach ($this->getAllAttributesMetadata() as $attributeMetadata) {
         $attributeCode = $attributeMetadata->getAttributeCode();
         $camelCaseKey = \Magento\Framework\Service\SimpleDataObjectConverter::snakeCaseToCamelCase($attributeCode);
         $isDataObjectMethod = isset($this->customerDataObjectMethods['get' . $camelCaseKey]) || isset($this->customerDataObjectMethods['is' . $camelCaseKey]);
         /** Even though disable_auto_group_change is system attribute, it should be available to the clients */
         if (!$isDataObjectMethod && (!$attributeMetadata->isSystem() || $attributeCode == 'disable_auto_group_change')) {
             $customAttributes[] = $attributeMetadata;
         }
     }
     return array_merge($customAttributes, $this->metadataConfig->getCustomAttributesMetadata($dataObjectClassName));
 }
 /**
  * {@inheritdoc}
  */
 public function getCustomAttributesMetadata($dataObjectClassName = self::DATA_OBJECT_CLASS_NAME)
 {
     $customAttributes = [];
     if (!$this->addressDataObjectMethods) {
         $this->addressDataObjectMethods = array_flip(get_class_methods($dataObjectClassName));
     }
     foreach ($this->getAllAttributesMetadata() as $attributeMetadata) {
         $attributeCode = $attributeMetadata->getAttributeCode();
         $camelCaseKey = \Magento\Framework\Service\SimpleDataObjectConverter::snakeCaseToCamelCase($attributeCode);
         $isDataObjectMethod = isset($this->addressDataObjectMethods['get' . $camelCaseKey]) || isset($this->addressDataObjectMethods['is' . $camelCaseKey]);
         if (!$isDataObjectMethod && !$attributeMetadata->isSystem()) {
             $customAttributes[] = $attributeMetadata;
         }
     }
     return array_merge($customAttributes, $this->metadataConfig->getCustomAttributesMetadata($dataObjectClassName));
 }
Beispiel #5
0
 /**
  * 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\SimpleDataObjectConverter::snakeCaseToCamelCase($key);
         $possibleMethods = array('get' . $camelCaseKey, 'is' . $camelCaseKey);
         if ($key == AbstractExtensibleObject::CUSTOM_ATTRIBUTES_KEY && is_array($data[$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 #6
0
 /**
  * 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\SimpleDataObjectConverter::snakeCaseToCamelCase($key), 'is' . \Magento\Framework\Service\SimpleDataObjectConverter::snakeCaseToCamelCase($key));
         if (array_intersect($possibleMethods, $dataObjectMethods)) {
             $this->_data[$key] = $value;
         }
     }
     return $this;
 }