Ejemplo n.º 1
0
 public function renderAddress($address)
 {
     /** @var \Magento\Customer\Block\Address\Renderer\RendererInterface $renderer */
     $renderer = $this->_addressConfig->getFormatByCode('html')->getRenderer();
     $addressData = \Magento\Framework\Convert\ConvertArray::toFlatArray($address->getData());
     return $renderer->renderArray($addressData);
 }
Ejemplo n.º 2
0
 public function testToFlatArray()
 {
     $input = ['key1' => 'value1', 'key2' => ['key21' => 'value21', 'key22' => 'value22', 'key23' => ['key231' => 'value231']], 'key3' => ['key31' => 'value31', 'key3' => 'value3'], 'key4' => ['key4' => 'value4']];
     $expectedOutput = ['key1' => 'value1', 'key21' => 'value21', 'key22' => 'value22', 'key231' => 'value231', 'key31' => 'value31', 'key3' => 'value3', 'key4' => 'value4'];
     $output = ConvertArray::toFlatArray($input);
     $this->assertEquals($expectedOutput, $output, 'Array is converted to flat structure incorrectly.');
 }
 /**
  * Convert nested array into flat array.
  *
  * @param ExtensibleDataInterface $dataObject
  * @param string $dataObjectType
  * @return array
  */
 public function toFlatArray(ExtensibleDataInterface $dataObject, $dataObjectType = null)
 {
     if ($dataObjectType === null) {
         $dataObjectType = get_class($dataObject);
     }
     $data = $this->dataObjectProcessor->buildOutputDataArray($dataObject, $dataObjectType);
     return ConvertArray::toFlatArray($data);
 }
 /**
  * Convert AbstractObject into flat array.
  *
  * @param AbstractObject $dataObject
  * @return array
  */
 public static function toFlatArray(AbstractObject $dataObject)
 {
     $dataObjectArray = $dataObject->__toArray();
     //process custom attributes if present
     if (!empty($dataObjectArray[AbstractObject::CUSTOM_ATTRIBUTES_KEY])) {
         /** @var AttributeValue[] $customAttributes */
         $customAttributes = $dataObjectArray[AbstractObject::CUSTOM_ATTRIBUTES_KEY];
         unset($dataObjectArray[AbstractObject::CUSTOM_ATTRIBUTES_KEY]);
         foreach ($customAttributes as $attributeValue) {
             $dataObjectArray[$attributeValue[AttributeValue::ATTRIBUTE_CODE]] = $attributeValue[AttributeValue::VALUE];
         }
     }
     return ConvertArray::toFlatArray($dataObjectArray);
 }
Ejemplo n.º 5
0
 /**
  * Save package file to var/connect.
  *
  * @return boolean
  */
 public function savePackage()
 {
     if ($this->getData('file_name') != '') {
         $fileName = $this->getData('file_name');
         $this->unsetData('file_name');
     } else {
         $fileName = $this->getName();
     }
     if (!preg_match('/^[a-z0-9]+[a-z0-9\\-\\_\\.]*([\\/\\\\]{1}[a-z0-9]+[a-z0-9\\-\\_\\.]*)*$/i', $fileName)) {
         return false;
     }
     if (!$this->getPackageXml()) {
         $this->generatePackageXml();
     }
     if (!$this->getPackageXml()) {
         return false;
     }
     try {
         //            $path = $this->writeDirectory->getAbsolutePath();
         $this->writeDirectory->writeFile(sprintf('connect/%s', 'package.xml'), $this->getPackageXml());
         $this->unsPackageXml();
         $this->unsTargets();
         $xml = $this->_convertArray->assocToXml($this->getData());
         $xml = new \Magento\Framework\Simplexml\Element($xml->asXML());
         // prepare dir to save
         $parts = explode('/', $fileName);
         array_pop($parts);
         $directoryPath = implode('/', $parts);
         if (!empty($directoryPath)) {
             $this->writeDirectory->create(sprintf('connect/%s', $directoryPath));
         }
         $this->writeDirectory->writeFile(sprintf('connect/%s.xml', $fileName), $xml->asNiceXml());
     } catch (\Magento\Framework\Filesystem\FilesystemException $e) {
         $this->logger->addStreamLog(\Magento\Framework\Logger::LOGGER_EXCEPTION);
         $this->logger->log($e->getMessage());
         return false;
     }
     return true;
 }
Ejemplo n.º 6
0
 /**
  * Convert Category model into flat array.
  *
  * @return array
  */
 public function toFlatArray()
 {
     $dataArray = $this->__toArray();
     //process custom attributes if present
     if (array_key_exists('custom_attributes', $dataArray) && !empty($dataArray['custom_attributes'])) {
         /** @var \Magento\Framework\Api\AttributeInterface[] $customAttributes */
         $customAttributes = $dataArray['custom_attributes'];
         unset($dataArray['custom_attributes']);
         foreach ($customAttributes as $attributeValue) {
             $dataArray[$attributeValue[\Magento\Framework\Api\AttributeInterface::ATTRIBUTE_CODE]] = $attributeValue[\Magento\Framework\Api\AttributeInterface::VALUE];
         }
     }
     return ConvertArray::toFlatArray($dataArray);
 }
 /**
  * Convert nested array into flat array.
  *
  * @param AbstractExtensibleObject $dataObject
  * @return array
  */
 public static function toFlatArray(AbstractExtensibleObject $dataObject)
 {
     $data = $dataObject->__toArray();
     return ConvertArray::toFlatArray($data);
 }
 /**
  * Convert AbstractExtensibleObject into flat array.
  *
  * @param ExtensibleDataInterface $dataObject
  * @param string[] $skipCustomAttributes
  * @param string $dataObjectType
  * @return array
  */
 public function toFlatArray(ExtensibleDataInterface $dataObject, $skipCustomAttributes = [], $dataObjectType = null)
 {
     $dataObjectArray = $this->toNestedArray($dataObject, $skipCustomAttributes, $dataObjectType);
     return ConvertArray::toFlatArray($dataObjectArray);
 }
Ejemplo n.º 9
0
 public function testGetAttributes()
 {
     $customerData = $this->_createCustomerData();
     $customer = $this->_customerBuilder->populateWithArray($customerData)->create();
     $actualAttributes = \Magento\Framework\Convert\ConvertArray::toFlatArray($customer->__toArray());
     $this->assertEquals(array('id' => self::ID, 'confirmation' => self::CONFIRMATION, 'created_at' => self::CREATED_AT, 'created_in' => self::STORE_NAME, 'dob' => self::DOB, 'email' => self::EMAIL, 'firstname' => self::FIRSTNAME, 'gender' => self::GENDER, 'group_id' => self::GROUP_ID, 'lastname' => self::LASTNAME, 'middlename' => self::MIDDLENAME, 'prefix' => self::PREFIX, 'store_id' => self::STORE_ID, 'suffix' => self::SUFFIX, 'taxvat' => self::TAXVAT, 'website_id' => self::WEBSITE_ID), $actualAttributes);
 }
Ejemplo n.º 10
0
 /**
  * Add rendering EAV attributes to Form element
  *
  * @param \Magento\Customer\Api\Data\AttributeMetadataInterface[] $attributes
  * @param \Magento\Framework\Data\Form\AbstractForm $form
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function _addAttributesToForm($attributes, \Magento\Framework\Data\Form\AbstractForm $form)
 {
     // add additional form types
     $types = $this->_getAdditionalFormElementTypes();
     foreach ($types as $type => $className) {
         $form->addType($type, $className);
     }
     $renderers = $this->_getAdditionalFormElementRenderers();
     foreach ($attributes as $attribute) {
         $inputType = $attribute->getFrontendInput();
         if ($inputType) {
             $element = $form->addField($attribute->getAttributeCode(), $inputType, ['name' => $attribute->getAttributeCode(), 'label' => __($attribute->getStoreLabel()), 'class' => $attribute->getFrontendClass(), 'required' => $attribute->isRequired()]);
             if ($inputType == 'multiline') {
                 $element->setLineCount($attribute->getMultilineCount());
             }
             $element->setEntityAttribute($attribute);
             $this->_addAdditionalFormElementData($element);
             if (!empty($renderers[$attribute->getAttributeCode()])) {
                 $element->setRenderer($renderers[$attribute->getAttributeCode()]);
             }
             if ($inputType == 'select' || $inputType == 'multiselect') {
                 $options = [];
                 foreach ($attribute->getOptions() as $optionData) {
                     $options[] = ConvertArray::toFlatArray($this->dataObjectProcessor->buildOutputDataArray($optionData, '\\Magento\\Customer\\Api\\Data\\OptionInterface'));
                 }
                 $element->setValues($options);
             } elseif ($inputType == 'date') {
                 $format = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT);
                 $element->setDateFormat($format);
             }
         }
     }
     return $this;
 }
Ejemplo n.º 11
0
 /**
  * Convert address data object to a flat array
  *
  * @param CustomerInterface $customer
  * @return array
  */
 public function toFlatArray(CustomerInterface $customer)
 {
     $flatArray = $this->extensibleDataObjectConverter->toNestedArray($customer, [], '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     unset($flatArray["addresses"]);
     return ConvertArray::toFlatArray($flatArray);
 }