public function testToFlatArray()
 {
     //Unpack Data Object as an array and convert keys to camelCase to match property names in WSDL
     $response = DataObjectConverter::toFlatArray($this->getCustomerDetails());
     //Check if keys are correctly converted to camel case wherever necessary
     $this->assertEquals(self::FIRSTNAME, $response['firstname']);
     $this->assertEquals(self::GROUP_ID, $response['group_id']);
     $this->assertEquals(self::REGION, $response['region']);
     $this->assertEquals(self::REGION_CODE, $response['region_code']);
     $this->assertEquals(self::REGION_ID, $response['region_id']);
     //TODO : FIX toFlatArray since it has issues in converting Street array correctly as it overwrites the data.
 }
예제 #2
0
 /**
  * Load customer group collection data from service
  *
  * @param bool $printQuery
  * @param bool $logQuery
  * @return $this
  */
 public function loadData($printQuery = false, $logQuery = false)
 {
     if (!$this->isLoaded()) {
         $searchCriteria = $this->getSearchCriteria();
         $searchResults = $this->groupService->searchGroups($searchCriteria);
         $this->_totalRecords = $searchResults->getTotalCount();
         /** @var CustomerGroup[] $groups */
         $groups = $searchResults->getItems();
         foreach ($groups as $group) {
             $groupItem = new \Magento\Framework\Object();
             $groupItem->addData(\Magento\Framework\Service\DataObjectConverter::toFlatArray($group));
             $this->_addItem($groupItem);
         }
         $this->_setIsLoaded();
     }
     return $this;
 }
 /**
  * @magentoDbIsolation enabled
  */
 public function testCreateCustomerInServiceVsInModel()
 {
     $email = '*****@*****.**';
     $email2 = '*****@*****.**';
     $firstname = 'Tester';
     $lastname = 'McTest';
     $groupId = 1;
     $password = '******';
     /** @var \Magento\Customer\Model\Customer $customerModel */
     $customerModel = $this->_objectManager->create('Magento\\Customer\\Model\\CustomerFactory')->create();
     $customerModel->setEmail($email)->setFirstname($firstname)->setLastname($lastname)->setGroupId($groupId)->setPassword($password);
     $customerModel->save();
     /** @var \Magento\Customer\Model\Customer $customerModel */
     $savedModel = $this->_objectManager->create('Magento\\Customer\\Model\\CustomerFactory')->create()->load($customerModel->getId());
     $dataInModel = $savedModel->getData();
     $this->_customerBuilder->setEmail($email2)->setFirstname($firstname)->setLastname($lastname)->setGroupId($groupId);
     $newCustomerEntity = $this->_customerBuilder->create();
     $customerDetails = $this->_customerDetailsBuilder->setCustomer($newCustomerEntity)->create();
     $customerData = $this->_customerAccountService->createCustomer($customerDetails, $password);
     $this->assertNotNull($customerData->getId());
     $savedCustomer = $this->_customerAccountService->getCustomer($customerData->getId());
     $dataInService = \Magento\Framework\Service\DataObjectConverter::toFlatArray($savedCustomer);
     $expectedDifferences = ['created_at', 'updated_at', 'email', 'is_active', 'entity_id', 'entity_type_id', 'password_hash', 'attribute_set_id', 'disable_auto_group_change', 'confirmation', 'reward_update_notification', 'reward_warning_notification'];
     foreach ($dataInModel as $key => $value) {
         if (!in_array($key, $expectedDifferences)) {
             if (is_null($value)) {
                 $this->assertArrayNotHasKey($key, $dataInService);
             } else {
                 $this->assertEquals($value, $dataInService[$key], 'Failed asserting value for ' . $key);
             }
         }
     }
     $this->assertEquals($email2, $dataInService['email']);
     $this->assertArrayNotHasKey('is_active', $dataInService);
     $this->assertArrayNotHasKey('updated_at', $dataInService);
     $this->assertArrayNotHasKey('password_hash', $dataInService);
 }
예제 #4
0
 /**
  * Initialize customer form
  *
  * @return \Magento\Customer\Model\Metadata\Form $customerForm
  */
 protected function _getCustomerForm()
 {
     if (is_null($this->_customerForm)) {
         $this->_customerForm = $this->_customerFormFactory->create('customer', 'adminhtml_customer', DataObjectConverter::toFlatArray($this->_getCustomerDataObject()));
     }
     return $this->_customerForm;
 }
예제 #5
0
 /**
  * Add rendering EAV attributes to Form element
  *
  * @param \Magento\Customer\Service\V1\Data\Eav\AttributeMetadata[] $attributes
  * @param \Magento\Framework\Data\Form\AbstractForm $form
  * @return $this
  */
 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, array('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 = array();
                 foreach ($attribute->getOptions() as $optionData) {
                     $options[] = \Magento\Framework\Service\DataObjectConverter::toFlatArray($optionData);
                 }
                 $element->setValues($options);
             } elseif ($inputType == 'date') {
                 $format = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT);
                 $element->setImage($this->getViewFileUrl('images/grid-cal.gif'));
                 $element->setDateFormat($format);
             }
         }
     }
     return $this;
 }
예제 #6
0
 /**
  * @magentoDataFixture Magento/Customer/_files/customer_group.php
  */
 public function testSaveActionExistingGroup()
 {
     $groupId = $this->findGroupIdWithCode(self::CUSTOMER_GROUP_CODE);
     $this->getRequest()->setParam('tax_class', self::TAX_CLASS_ID);
     $this->getRequest()->setParam('id', $groupId);
     $this->getRequest()->setParam('code', self::CUSTOMER_GROUP_CODE);
     $this->dispatch('backend/customer/group/save');
     $this->assertSessionMessages($this->isEmpty(), MessageInterface::TYPE_ERROR);
     $this->assertSessionMessages($this->logicalNot($this->isEmpty()), MessageInterface::TYPE_SUCCESS);
     $this->assertSessionMessages($this->equalTo(['The customer group has been saved.']), MessageInterface::TYPE_SUCCESS);
     /** @var \Magento\Customer\Service\V1\CustomerGroupServiceInterface $groupService */
     $groupService = Bootstrap::getObjectManager()->get('Magento\\Customer\\Service\\V1\\CustomerGroupServiceInterface');
     $customerGroupData = \Magento\Framework\Service\DataObjectConverter::toFlatArray($groupService->getGroup($groupId));
     ksort($customerGroupData);
     $this->assertEquals(['code' => self::CUSTOMER_GROUP_CODE, 'id' => $groupId, 'tax_class_id' => self::TAX_CLASS_ID], $customerGroupData);
 }