public function setUp() { if (!function_exists('libxml_set_external_entity_loader')) { $this->markTestSkipped('Skipped on HHVM. Will be fixed in MAGETWO-45033'); } $this->customer = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\CustomerInterface', [], '', false, true, true); $this->customer->expects($this->once())->method('getWebsiteId')->willReturn(2); $this->customerDataFactory = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterfaceFactory', ['create'], [], '', false); $this->customerDataFactory->expects($this->once())->method('create')->willReturn($this->customer); $this->form = $this->getMock('Magento\\Customer\\Model\\Metadata\\Form', [], [], '', false); $this->request = $this->getMockForAbstractClass('Magento\\Framework\\App\\RequestInterface', [], '', false, true, true, ['getPost']); $this->response = $this->getMockForAbstractClass('Magento\\Framework\\App\\ResponseInterface', [], '', false); $this->formFactory = $this->getMock('Magento\\Customer\\Model\\Metadata\\FormFactory', ['create'], [], '', false); $this->formFactory->expects($this->atLeastOnce())->method('create')->willReturn($this->form); $this->extensibleDataObjectConverter = $this->getMock('Magento\\Framework\\Api\\ExtensibleDataObjectConverter', [], [], '', false); $this->dataObjectHelper = $this->getMock('Magento\\Framework\\Api\\DataObjectHelper', [], [], '', false); $this->dataObjectHelper->expects($this->once())->method('populateWithArray'); $this->customerAccountManagement = $this->getMockForAbstractClass('Magento\\Customer\\Api\\AccountManagementInterface', [], '', false, true, true); $this->resultJson = $this->getMock('Magento\\Framework\\Controller\\Result\\Json', [], [], '', false); $this->resultJson->expects($this->once())->method('setData'); $this->resultJsonFactory = $this->getMock('Magento\\Framework\\Controller\\Result\\JsonFactory', ['create'], [], '', false); $this->resultJsonFactory->expects($this->once())->method('create')->willReturn($this->resultJson); $objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->controller = $objectHelper->getObject('Magento\\Customer\\Controller\\Adminhtml\\Index\\Validate', ['request' => $this->request, 'response' => $this->response, 'customerDataFactory' => $this->customerDataFactory, 'formFactory' => $this->formFactory, 'extensibleDataObjectConverter' => $this->extensibleDataObjectConverter, 'customerAccountManagement' => $this->customerAccountManagement, 'resultJsonFactory' => $this->resultJsonFactory, 'dataObjectHelper' => $this->dataObjectHelper]); }
/** * {@inheritdoc} */ public function create($orderId) { $order = $this->orderRepository->get($orderId); if ($order->getCustomerId()) { throw new AlreadyExistsException(__("This order already has associated customer account")); } $customerData = $this->objectCopyService->copyFieldsetToTarget('order_address', 'to_customer', $order->getBillingAddress(), []); $addresses = $order->getAddresses(); foreach ($addresses as $address) { $addressData = $this->objectCopyService->copyFieldsetToTarget('order_address', 'to_customer_address', $address, []); /** @var \Magento\Customer\Api\Data\AddressInterface $customerAddress */ $customerAddress = $this->addressFactory->create(['data' => $addressData]); if (is_string($address->getRegion())) { /** @var \Magento\Customer\Api\Data\RegionInterface $region */ $region = $this->regionFactory->create(); $region->setRegion($address->getRegion()); $region->setRegionCode($address->getRegionCode()); $region->setRegionId($address->getRegionId()); $customerAddress->setRegion($region); } $customerData['addresses'][] = $customerAddress; } /** @var \Magento\Customer\Api\Data\CustomerInterface $customer */ $customer = $this->customerFactory->create(['data' => $customerData]); $account = $this->accountManagement->createAccount($customer); $order->setCustomerId($account->getId()); $this->orderRepository->save($order); return $account; }
/** * @param \Magento\Quote\Model\Quote $quote * @return \Magento\Quote\Model\Quote */ public function prepareQuoteForNewCustomer(\Magento\Quote\Model\Quote $quote) { $billing = $quote->getBillingAddress(); $shipping = $quote->isVirtual() ? null : $quote->getShippingAddress(); $billing->setDefaultBilling(true); if ($shipping && !$shipping->getSameAsBilling()) { $shipping->setDefaultShipping(true); $address = $shipping->exportCustomerAddress(); $shipping->setCustomerAddressData($address); } elseif ($shipping) { $billing->setDefaultShipping(true); } $address = $shipping->exportCustomerAddress(); $billing->setCustomerAddressData($address); foreach (['customer_dob', 'customer_taxvat', 'customer_gender'] as $attribute) { if ($quote->getData($attribute) && !$billing->getData($attribute)) { $billing->setData($attribute, $quote->getData($attribute)); } } $customer = $this->customerFactory->create(); $this->dataObjectHelper->populateWithArray($customer, $this->copyObject->getDataFromFieldset('checkout_onepage_billing', 'to_customer', $billing), '\\Magento\\Customer\\Api\\Data\\CustomerInterface'); $customer->setEmail($quote->getCustomerEmail()); $customer->setPrefix($quote->getCustomerPrefix()); $customer->setFirstname($quote->getCustomerFirstname()); $customer->setMiddlename($quote->getCustomerMiddlename()); $customer->setLastname($quote->getCustomerLastname()); $customer->setSuffix($quote->getCustomerSuffix()); $quote->setCustomer($customer); $quote->addCustomerAddress($billing->exportCustomerAddress()); if ($shipping->hasCustomerAddress()) { $quote->addCustomerAddress($shipping->exportCustomerAddress()); } return $quote; }
/** * test getCustomer method, method returns depersonalized customer Data */ public function testGetCustomerDepersonalizeCustomerData() { $this->requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(false)); $this->layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue(true)); $this->viewMock->expects($this->once())->method('isLayoutLoaded')->will($this->returnValue(true)); $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->will($this->returnValue(true)); $this->customerSessionMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue($this->customerGroupId)); $this->customerInterfaceFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->customerDataMock)); $this->customerDataMock->expects($this->once())->method('setGroupId')->with($this->equalTo($this->customerGroupId))->will($this->returnSelf()); $this->assertEquals($this->customerDataMock, $this->currentCustomer->getCustomer()); }
/** * {@inheritdoc} */ public function delete($id) { /** @var \Magento\Customer\Api\Data\CustomerInterface $customer */ $customer = $this->customerDataFactory->create(); $customer = $this->entityManager->load($customer, $id); try { $this->entityManager->delete($customer); } catch (\Exception $e) { return false; } return true; }
public function testUpdateDataOverrideExistingData() { /** @var \Magento\Customer\Model\Data\Customer $customerData */ $customerData = $this->customerFactory->create()->setId(2)->setFirstname('John')->setLastname('Doe')->setDefaultBilling(1); $this->customerModel->updateData($customerData); /** @var \Magento\Customer\Model\Data\Customer $updatedCustomerData */ $updatedCustomerData = $this->customerFactory->create()->setId(3)->setFirstname('Jane')->setLastname('Smith')->setDefaultBilling(0); $updatedCustomerData = $this->customerModel->updateData($updatedCustomerData)->getDataModel(); $this->assertEquals(3, $updatedCustomerData->getId()); $this->assertEquals('Jane', $updatedCustomerData->getFirstname()); $this->assertEquals('Smith', $updatedCustomerData->getLastname()); $this->assertEquals(0, $updatedCustomerData->getDefaultBilling()); }
/** * Retrieve Customer instance * * @return \Magento\Customer\Api\Data\CustomerInterface */ public function getCustomer() { if ($this->_customer === null) { $params = $this->urlDecoder->decode($this->_getRequest()->getParam('data')); $data = explode(',', $params); $customerId = abs(intval($data[0])); if ($customerId && $customerId == $this->_customerSession->getCustomerId()) { $this->_customer = $this->_customerRepository->getById($customerId); } else { $this->_customer = $this->_customerFactory->create(); } } return $this->_customer; }
public function testPrepareQuoteForNewCustomer() { $customerAddressMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterface')->disableOriginalConstructor()->getMock(); $this->addressMock->expects($this->any())->method('exportCustomerAddress')->willReturn($customerAddressMock); $this->addressMock->expects($this->any())->method('getData')->willReturn([]); $this->addressFactoryMock->expects($this->any())->method('create')->willReturn($this->addressMock); $this->quoteMock->expects($this->any())->method('isVirtual')->willReturn(false); $this->quoteMock->expects($this->once())->method('getBillingAddress')->willReturn($this->addressMock); $this->quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($this->addressMock); $customerDataMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock(); $this->customerFactoryMock->expects($this->once())->method('create')->willReturn($customerDataMock); $this->copyObjectMock->expects($this->any())->method('getDataFromFieldset')->willReturn([]); $this->dataObjectHelper->expects($this->any())->method('populateWithArray')->willReturnSelf(); $this->assertInstanceOf('Magento\\Quote\\Model\\Quote', $this->quote->prepareQuoteForNewCustomer($this->quoteMock)); }
/** * Create customer using setters. * * @param array $additional * @return CustomerInterface */ public function createSampleCustomerDataObject(array $additional = []) { $customerAddress1 = $this->customerAddressFactory->create(); $customerAddress1->setCountryId('US'); $customerAddress1->setIsDefaultBilling(true); $customerAddress1->setIsDefaultShipping(true); $customerAddress1->setPostcode('75477'); $customerAddress1->setRegion(Bootstrap::getObjectManager()->create('Magento\\Customer\\Api\\Data\\RegionInterfaceFactory')->create()->setRegionCode(self::ADDRESS_REGION_CODE1)->setRegion('Alabama')->setRegionId(1)); $customerAddress1->setStreet(['Green str, 67']); $customerAddress1->setTelephone('3468676'); $customerAddress1->setCity(self::ADDRESS_CITY1); $customerAddress1->setFirstname('John'); $customerAddress1->setLastname('Smith'); $address1 = $this->dataObjectProcessor->buildOutputDataArray($customerAddress1, 'Magento\\Customer\\Api\\Data\\AddressInterface'); $customerAddress2 = $this->customerAddressFactory->create(); $customerAddress2->setCountryId('US'); $customerAddress2->setIsDefaultBilling(false); $customerAddress2->setIsDefaultShipping(false); $customerAddress2->setPostcode('47676'); $customerAddress2->setRegion(Bootstrap::getObjectManager()->create('Magento\\Customer\\Api\\Data\\RegionInterfaceFactory')->create()->setRegionCode(self::ADDRESS_REGION_CODE2)->setRegion('Alabama')->setRegionId(1)); $customerAddress2->setStreet(['Black str, 48', 'Building D']); $customerAddress2->setTelephone('3234676'); $customerAddress2->setCity(self::ADDRESS_CITY2); $customerAddress2->setFirstname('John'); $customerAddress2->setLastname('Smith'); $address2 = $this->dataObjectProcessor->buildOutputDataArray($customerAddress2, 'Magento\\Customer\\Api\\Data\\AddressInterface'); $customerData = $this->getCustomerSampleData(array_merge([CustomerData::KEY_ADDRESSES => [$address1, $address2]], $additional)); $customer = $this->customerDataFactory->create(); $this->dataObjectHelper->populateWithArray($customer, $customerData, '\\Magento\\Customer\\Api\\Data\\CustomerInterface'); return $customer; }
public function testSetAccountData() { $taxClassId = 1; $attributes = [['email', '*****@*****.**'], ['group_id', 1]]; $attributeMocks = []; foreach ($attributes as $attribute) { $attributeMock = $this->getMock('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface', [], [], '', false); $attributeMock->expects($this->any())->method('getAttributeCode')->will($this->returnValue($attribute[0])); $attributeMocks[] = $attributeMock; } $customerGroupMock = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\GroupInterface', [], '', false, true, true, ['getTaxClassId']); $customerGroupMock->expects($this->once())->method('getTaxClassId')->will($this->returnValue($taxClassId)); $customerFormMock = $this->getMock('Magento\\Customer\\Model\\Metadata\\Form', [], [], '', false); $customerFormMock->expects($this->any())->method('getAttributes')->will($this->returnValue($attributeMocks)); $customerFormMock->expects($this->any())->method('extractData')->will($this->returnValue([])); $customerFormMock->expects($this->any())->method('restoreData')->will($this->returnValue([])); $customerFormMock->expects($this->any())->method('prepareRequest')->will($this->returnValue($this->getMock('Magento\\Framework\\App\\RequestInterface'))); $customerMock = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false); $this->customerMapper->expects($this->atLeastOnce())->method('toFlatArray')->willReturn(['email' => '*****@*****.**', 'group_id' => 1, 'gender' => 1]); $quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', [], [], '', false); $quoteMock->expects($this->any())->method('getCustomer')->will($this->returnValue($customerMock)); $quoteMock->expects($this->once())->method('addData')->with(['customer_email' => $attributes[0][1], 'customer_group_id' => $attributes[1][1], 'customer_tax_class_id' => $taxClassId]); $this->dataObjectHelper->expects($this->once())->method('populateWithArray')->with($customerMock, ['email' => '*****@*****.**', 'group_id' => 1, 'gender' => 1], '\\Magento\\Customer\\Api\\Data\\CustomerInterface'); $this->formFactoryMock->expects($this->any())->method('create')->will($this->returnValue($customerFormMock)); $this->sessionQuoteMock->expects($this->any())->method('getQuote')->will($this->returnValue($quoteMock)); $this->customerFactoryMock->expects($this->any())->method('create')->will($this->returnValue($customerMock)); $this->groupRepositoryMock->expects($this->once())->method('getById')->will($this->returnValue($customerGroupMock)); $this->adminOrderCreate->setAccountData([]); }
/** * {@inheritdoc} */ public function install($fixtures) { foreach ($fixtures as $fixture) { $filePath = $this->fixtureManager->getFixture($fixture); $rows = $this->csvReader->getData($filePath); $header = array_shift($rows); foreach ($rows as $row) { $data = []; foreach ($row as $key => $value) { $data[$header[$key]] = $value; } $row = $data; // Collect customer profile and addresses data $customerData['profile'] = $this->convertRowData($row, $this->getDefaultCustomerProfile()); if (!$this->accountManagement->isEmailAvailable($customerData['profile']['email'])) { continue; } $customerData['address'] = $this->convertRowData($row, $this->getDefaultCustomerAddress()); $customerData['address']['region_id'] = $this->getRegionId($customerData['address']); $address = $customerData['address']; $regionData = [RegionInterface::REGION_ID => $address['region_id'], RegionInterface::REGION => !empty($address['region']) ? $address['region'] : null, RegionInterface::REGION_CODE => !empty($address['region_code']) ? $address['region_code'] : null]; $region = $this->regionFactory->create(); $this->dataObjectHelper->populateWithArray($region, $regionData, '\\Magento\\Customer\\Api\\Data\\RegionInterface'); $addresses = $this->addressFactory->create(); unset($customerData['address']['region']); $this->dataObjectHelper->populateWithArray($addresses, $customerData['address'], '\\Magento\\Customer\\Api\\Data\\AddressInterface'); $addresses->setRegion($region)->setIsDefaultBilling(true)->setIsDefaultShipping(true); $customer = $this->customerFactory->create(); $this->dataObjectHelper->populateWithArray($customer, $customerData['profile'], '\\Magento\\Customer\\Api\\Data\\CustomerInterface'); $customer->setAddresses([$addresses]); $this->appState->emulateAreaCode('frontend', [$this->accountManagement, 'createAccount'], [$customer, $row['password']]); } } }
/** * Create customer using setters. * * @return CustomerInterface */ public function createSampleCustomerDataObject() { $customerAddress1 = $this->customerAddressFactory->create(); $customerAddress1->setCountryId('US'); $customerAddress1->setIsDefaultBilling(true); $customerAddress1->setIsDefaultShipping(true); $customerAddress1->setPostcode('75477'); $customerAddress1->setRegion(Bootstrap::getObjectManager()->create('Magento\\Customer\\Api\\Data\\RegionInterfaceFactory')->create()->setRegionCode(self::ADDRESS_REGION_CODE1)->setRegion('Alabama')->setRegionId(1)); $customerAddress1->setStreet(['Green str, 67']); $customerAddress1->setTelephone('3468676'); $customerAddress1->setCity(self::ADDRESS_CITY1); $customerAddress1->setFirstname('John'); $customerAddress1->setLastname('Smith'); $address1 = $this->dataObjectProcessor->buildOutputDataArray($customerAddress1, 'Magento\\Customer\\Api\\Data\\AddressInterface'); $customerAddress2 = $this->customerAddressFactory->create(); $customerAddress2->setCountryId('US'); $customerAddress2->setIsDefaultBilling(false); $customerAddress2->setIsDefaultShipping(false); $customerAddress2->setPostcode('47676'); $customerAddress2->setRegion(Bootstrap::getObjectManager()->create('Magento\\Customer\\Api\\Data\\RegionInterfaceFactory')->create()->setRegionCode(self::ADDRESS_REGION_CODE2)->setRegion('Alabama')->setRegionId(1)); $customerAddress2->setStreet(['Black str, 48', 'Building D']); $customerAddress2->setTelephone('3234676'); $customerAddress2->setCity(self::ADDRESS_CITY2); $customerAddress2->setFirstname('John'); $customerAddress2->setLastname('Smith'); $address2 = $this->dataObjectProcessor->buildOutputDataArray($customerAddress2, 'Magento\\Customer\\Api\\Data\\AddressInterface'); $customerData = [CustomerData::FIRSTNAME => self::FIRSTNAME, CustomerData::LASTNAME => self::LASTNAME, CustomerData::EMAIL => 'janedoe' . uniqid() . '@example.com', CustomerData::CONFIRMATION => self::CONFIRMATION, CustomerData::CREATED_AT => self::CREATED_AT, CustomerData::CREATED_IN => self::STORE_NAME, CustomerData::DOB => self::DOB, CustomerData::GENDER => self::GENDER, CustomerData::GROUP_ID => self::GROUP_ID, CustomerData::MIDDLENAME => self::MIDDLENAME, CustomerData::PREFIX => self::PREFIX, CustomerData::STORE_ID => self::STORE_ID, CustomerData::SUFFIX => self::SUFFIX, CustomerData::TAXVAT => self::TAXVAT, CustomerData::WEBSITE_ID => self::WEBSITE_ID, CustomerData::KEY_ADDRESSES => [$address1, $address2], 'custom_attributes' => [['attribute_code' => 'disable_auto_group_change', 'value' => '0']]]; $customer = $this->customerDataFactory->create(); $this->dataObjectHelper->populateWithArray($customer, $customerData, '\\Magento\\Customer\\Api\\Data\\CustomerInterface'); return $customer; }
public function testUpdateCustomerException() { $customerData = $this->_createCustomer(); $existingCustomerDataObject = $this->_getCustomerData($customerData[Customer::ID]); $lastName = $existingCustomerDataObject->getLastname(); //Set non-existent id = -1 $customerData[Customer::LASTNAME] = $lastName . 'Updated'; $customerData[Customer::ID] = -1; $newCustomerDataObject = $this->customerDataFactory->create(); $this->dataObjectHelper->populateWithArray($newCustomerDataObject, $customerData, '\\Magento\\Customer\\Api\\Data\\CustomerInterface'); $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . "/-1", 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'Save']]; $newCustomerDataObject = $this->dataObjectProcessor->buildOutputDataArray($newCustomerDataObject, 'Magento\\Customer\\Api\\Data\\CustomerInterface'); $requestData = ['customer' => $newCustomerDataObject]; $expectedMessage = 'No such entity with %fieldName = %fieldValue'; try { $this->_webApiCall($serviceInfo, $requestData); $this->fail("Expected exception."); } catch (\SoapFault $e) { $this->assertContains($expectedMessage, $e->getMessage(), "SoapFault does not contain expected message."); } catch (\Exception $e) { $errorObj = $this->processRestExceptionResult($e); $this->assertEquals($expectedMessage, $errorObj['message']); $this->assertEquals(['fieldName' => 'customerId', 'fieldValue' => -1], $errorObj['parameters']); $this->assertEquals(HTTPExceptionCodes::HTTP_NOT_FOUND, $e->getCode()); } }
/** * {@inheritdoc} */ public function run() { $this->logger->log('Installing customers:'); foreach ($this->fixtures as $file) { /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */ $fileName = $this->fixtureHelper->getPath($file); $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']); foreach ($csvReader as $row) { // Collect customer profile and addresses data $customerData['profile'] = $this->convertRowData($row, $this->getDefaultCustomerProfile()); if (!$this->accountManagement->isEmailAvailable($customerData['profile']['email'])) { continue; } $customerData['address'] = $this->convertRowData($row, $this->getDefaultCustomerAddress()); $customerData['address']['region_id'] = $this->getRegionId($customerData['address']); $address = $customerData['address']; $regionData = [RegionInterface::REGION_ID => $address['region_id'], RegionInterface::REGION => !empty($address['region']) ? $address['region'] : null, RegionInterface::REGION_CODE => !empty($address['region_code']) ? $address['region_code'] : null]; $region = $this->regionFactory->create(); $this->dataObjectHelper->populateWithArray($region, $regionData, '\\Magento\\Customer\\Api\\Data\\RegionInterface'); $addresses = $this->addressFactory->create(); unset($customerData['address']['region']); $this->dataObjectHelper->populateWithArray($addresses, $customerData['address'], '\\Magento\\Customer\\Api\\Data\\AddressInterface'); $addresses->setRegion($region)->setIsDefaultBilling(true)->setIsDefaultShipping(true); $customer = $this->customerFactory->create(); $this->dataObjectHelper->populateWithArray($customer, $customerData['profile'], '\\Magento\\Customer\\Api\\Data\\CustomerInterface'); $customer->setAddresses([$addresses]); $this->accountManagement->createAccount($customer, $row['password']); $this->logger->logInline('.'); } } }
/** * @param string $formCode * @param RequestInterface $request * @return \Magento\Customer\Api\Data\CustomerInterface */ public function extract($formCode, RequestInterface $request) { $customerForm = $this->formFactory->create('customer', $formCode); $customerData = $customerForm->extractData($request); $allowedAttributes = $customerForm->getAllowedAttributes(); $isGroupIdEmpty = isset($allowedAttributes['group_id']); $customerDataObject = $this->customerFactory->create(); $this->dataObjectHelper->populateWithArray($customerDataObject, $customerData, '\\Magento\\Customer\\Api\\Data\\CustomerInterface'); $store = $this->storeManager->getStore(); if ($isGroupIdEmpty) { $customerDataObject->setGroupId($this->customerGroupManagement->getDefaultGroup($store->getId())->getId()); } $customerDataObject->setWebsiteId($store->getWebsiteId()); $customerDataObject->setStoreId($store->getId()); return $customerDataObject; }
/** * Retrieve customer object * * @return \Magento\Customer\Api\Data\CustomerInterface */ public function getCustomer() { if (!$this->customer) { $this->customer = $this->customerDataFactory->create(); $this->dataObjectHelper->populateWithArray($this->customer, $this->_backendSession->getCustomerData()['account'], '\\Magento\\Customer\\Api\\Data\\CustomerInterface'); } return $this->customer; }
/** * @return \Magento\Customer\Api\Data\CustomerInterface */ private function _createCustomer() { /** @var \Magento\Customer\Api\Data\CustomerInterface $customer */ $customer = $this->_customerFactory->create()->setFirstname('firstname')->setLastname('lastname')->setEmail('*****@*****.**'); $data = ['account' => $this->_dataObjectProcessor->buildOutputDataArray($customer, 'Magento\\Customer\\Api\\Data\\CustomerInterface')]; $this->_context->getBackendSession()->setCustomerData($data); return $customer; }
/** * @dataProvider saveBillingDataProvider * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.ExcessiveParameterList) * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.UnusedFormalParameter) * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function testSaveBilling($data, $customerAddressId, $quoteCustomerId, $addressCustomerId, $isAddress, $validateDataResult, $validateResult, $checkoutMethod, $customerPassword, $confirmPassword, $validationResultMessages, $isEmailAvailable, $isVirtual, $getStepDataResult, $expected) { $useForShipping = (int) $data['use_for_shipping']; $passwordHash = 'password hash'; $this->requestMock->expects($this->any())->method('isAjax')->will($this->returnValue(false)); $customerValidationResultMock = $this->getMock('Magento\\Customer\\Api\\Data\\ValidationResultsInterface', [], [], '', false); $customerValidationResultMock->expects($this->any())->method('isValid')->will($this->returnValue(empty($validationResultMessages))); $customerValidationResultMock->expects($this->any())->method('getMessages')->will($this->returnValue($validationResultMessages)); $this->accountManagementMock->expects($this->any())->method('getPasswordHash')->with($customerPassword)->will($this->returnValue($passwordHash)); $this->accountManagementMock->expects($this->any())->method('validate')->will($this->returnValue($customerValidationResultMock)); $this->accountManagementMock->expects($this->any())->method('isEmailAvailable')->will($this->returnValue($isEmailAvailable)); /** @var \Magento\Quote\Model\Quote|\PHPUnit_Framework_MockObject_MockObject $quoteMock */ $quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', ['getData', 'getCustomerId', '__wakeup', 'getBillingAddress', 'setPasswordHash', 'getCheckoutMethod', 'isVirtual', 'getShippingAddress', 'getCustomerData', 'collectTotals', 'save', 'getCustomer'], [], '', false); $customerMock = $this->getMockForAbstractClass('Magento\\Framework\\Api\\AbstractExtensibleObject', [], '', false, true, true, ['__toArray']); $shippingAddressMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', ['setSameAsBilling', 'save', 'collectTotals', 'addData', 'setShippingMethod', 'setCollectShippingRates', '__wakeup'], [], '', false); $quoteMock->expects($this->any())->method('getShippingAddress')->will($this->returnValue($shippingAddressMock)); $shippingAddressMock->expects($useForShipping ? $this->any() : $this->once())->method('setSameAsBilling')->with($useForShipping)->will($this->returnSelf()); $expects = !$useForShipping || $checkoutMethod != Onepage::METHOD_REGISTER ? $this->once() : $this->never(); $shippingAddressMock->expects($expects)->method('save'); $shippingAddressMock->expects($useForShipping ? $this->once() : $this->never())->method('addData')->will($this->returnSelf()); $shippingAddressMock->expects($this->any())->method('setSaveInAddressBook')->will($this->returnSelf()); $shippingAddressMock->expects($useForShipping ? $this->once() : $this->never())->method('setShippingMethod')->will($this->returnSelf()); $shippingAddressMock->expects($useForShipping ? $this->once() : $this->never())->method('setCollectShippingRates')->will($this->returnSelf()); $shippingAddressMock->expects($useForShipping ? $this->once() : $this->never())->method('collectTotals'); $quoteMock->expects($this->any())->method('setPasswordHash')->with($passwordHash); $quoteMock->expects($this->any())->method('getCheckoutMethod')->will($this->returnValue($checkoutMethod)); $quoteMock->expects($this->any())->method('isVirtual')->will($this->returnValue($isVirtual)); $addressMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', ['setSaveInAddressBook', 'getData', 'setEmail', '__wakeup', 'importCustomerAddressData', 'validate', 'save'], [], '', false); $addressMock->expects($this->any())->method('importCustomerAddressData')->will($this->returnSelf()); $addressMock->expects($this->atLeastOnce())->method('validate')->will($this->returnValue($validateResult)); $addressMock->expects($this->any())->method('getData')->will($this->returnValue([])); $quoteMock->expects($this->any())->method('getBillingAddress')->will($this->returnValue($addressMock)); $quoteMock->expects($this->any())->method('getCustomerId')->will($this->returnValue($quoteCustomerId)); $this->quoteRepositoryMock->expects($checkoutMethod === Onepage::METHOD_REGISTER ? $this->once() : $this->never())->method('save')->with($quoteMock); $addressMock->expects($checkoutMethod === Onepage::METHOD_REGISTER ? $this->never() : $this->once())->method('save'); $quoteMock->expects($this->any())->method('getCustomer')->will($this->returnValue($customerMock)); $data1 = []; $extensibleDataObjectConverterMock = $this->getMock('Magento\\Framework\\Api\\ExtensibleDataObjectConverter', ['toFlatArray'], [], '', false); $extensibleDataObjectConverterMock->expects($this->any())->method('toFlatArray')->with($customerMock)->will($this->returnValue($data1)); $formMock = $this->getMock('Magento\\Customer\\Model\\Metadata\\Form', [], [], '', false); $formMock->expects($this->atLeastOnce())->method('validateData')->will($this->returnValue($validateDataResult)); $this->formFactoryMock->expects($this->any())->method('create')->will($this->returnValue($formMock)); $formMock->expects($this->any())->method('prepareRequest')->will($this->returnValue($this->requestMock)); $formMock->expects($this->any())->method('extractData')->with($this->requestMock)->will($this->returnValue([])); $formMock->expects($this->any())->method('validateData')->with([])->will($this->returnValue(false)); $customerDataMock = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false); $this->customerDataFactoryMock->expects($this->any())->method('create')->will($this->returnValue($customerDataMock)); $this->checkoutSessionMock->expects($this->any())->method('getQuote')->will($this->returnValue($quoteMock)); $this->checkoutSessionMock->expects($this->any())->method('getStepData')->will($this->returnValue($useForShipping ? true : $getStepDataResult)); $this->checkoutSessionMock->expects($this->any())->method('setStepData')->will($this->returnSelf()); $customerAddressMock = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AddressInterface', [], '', false); $customerAddressMock->expects($this->any())->method('getCustomerId')->will($this->returnValue($addressCustomerId)); $this->addressRepositoryMock->expects($this->any())->method('getById')->will($isAddress ? $this->returnValue($customerAddressMock) : $this->throwException(new \Exception())); $websiteMock = $this->getMock('Magento\\Store\\Model\\Website', [], [], '', false); $this->storeManagerMock->expects($this->any())->method('getWebsite')->will($this->returnValue($websiteMock)); $this->assertEquals($expected, $this->onepage->saveBilling($data, $customerAddressId)); }
public function testExtract() { $customerData = ['firstname' => 'firstname', 'lastname' => 'firstname', 'email' => 'email.example.com']; $this->formFactory->expects($this->once())->method('create')->with('customer', 'form-code')->willReturn($this->customerForm); $this->customerForm->expects($this->once())->method('extractData')->with($this->request)->willReturn($customerData); $this->customerForm->expects($this->once())->method('getAllowedAttributes')->willReturn(['group_id' => 'attribute object']); $this->customerFactory->expects($this->once())->method('create')->willReturn($this->customerData); $this->dataObjectHelper->expects($this->once())->method('populateWithArray')->with($this->customerData, $customerData, '\\Magento\\Customer\\Api\\Data\\CustomerInterface')->willReturn($this->customerData); $this->storeManager->expects($this->once())->method('getStore')->willReturn($this->store); $this->store->expects($this->exactly(2))->method('getId')->willReturn(1); $this->customerGroupManagement->expects($this->once())->method('getDefaultGroup')->with(1)->willReturn($this->customerGroup); $this->customerGroup->expects($this->once())->method('getId')->willReturn(1); $this->customerData->expects($this->once())->method('setGroupId')->with(1); $this->store->expects($this->once())->method('getWebsiteId')->willReturn(1); $this->customerData->expects($this->once())->method('setWebsiteId')->with(1); $this->customerData->expects($this->once())->method('setStoreId')->with(1); $this->assertSame($this->customerData, $this->customerExtractor->extract('form-code', $this->request)); }
/** * Obtain customer data from session and create customer object * * @return \Magento\Customer\Api\Data\CustomerInterface */ protected function _getCustomerDataObject() { if ($this->_customerDataObject === null) { $customerData = $this->_backendSession->getCustomerData(); $accountData = isset($customerData['account']) ? $customerData['account'] : []; $this->_customerDataObject = $this->customerDataFactory->create(); $this->dataObjectHelper->populateWithArray($this->_customerDataObject, $accountData, '\\Magento\\Customer\\Api\\Data\\CustomerInterface'); } return $this->_customerDataObject; }
/** * @magentoAppArea frontend * @magentoDataFixture Magento/Customer/_files/customer.php * @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php */ public function testUpdateCustomerDeleteAllAddressesWithEmptyArray() { $customerId = 1; $customer = $this->customerRepository->getById($customerId); $customerDetails = $customer->__toArray(); $newCustomerEntity = $this->customerFactory->create(); $this->dataObjectHelper->populateWithArray($newCustomerEntity, $customerDetails, '\\Magento\\Customer\\Api\\Data\\CustomerInterface'); $newCustomerEntity->setId($customer->getId())->setAddresses([]); $this->customerRepository->save($newCustomerEntity); $newCustomerDetails = $this->customerRepository->getById($customerId); //Verify that old addresses are removed $this->assertEquals(0, count($newCustomerDetails->getAddresses())); }
public function testGetCustomerWithSession() { $customerId = 1; $data = $customerId . ',2'; $this->urlDecoderMock->expects($this->any())->method('decode')->willReturnArgument(0); $this->requestMock->expects($this->once())->method('getParam')->with('data', null)->willReturn($data); $this->customerSessionMock->expects($this->once())->method('getCustomerId')->willReturn($customerId); $customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock(); $this->customerRepositoryMock->expects($this->once())->method('getById')->with($customerId)->willReturn($customer); $this->customerFactoryMock->expects($this->never())->method('create'); $this->assertEquals($customer, $this->model->getCustomer()); // Check that customer is cached $this->assertSame($customer, $this->model->getCustomer()); }
/** * @Given customer accounts: */ public function customerAccounts(TableNode $customerAccountTable) { foreach ($customerAccountTable as $row) { // Check if the customer already exists. If it does, no need to // re-create it. If it doesn't, catch the exception and create // the customer account. try { $customer = $this->customerRepository->get($row['email_address']); } catch (NoSuchEntityException $e) { $customer = $this->customerFactory->create(); $customer->setFirstname($row['firstname'])->setLastname($row['lastname'])->setEmail($row['email_address']); $this->customerRepository->save($customer); } } }
/** * @magentoAppArea frontend * @magentoDataFixture Magento/Customer/_files/customer.php */ public function testCreateNewCustomerFromClone() { $email = '*****@*****.**'; $firstName = 'Firstsave'; $lastname = 'Lastsave'; $existingCustId = 1; $existingCustomer = $this->customerRepository->getById($existingCustId); $customerEntity = $this->customerFactory->create(); $this->dataObjectHelper->mergeDataObjects('\\Magento\\Customer\\Api\\Data\\CustomerInterface', $customerEntity, $existingCustomer); $customerEntity->setEmail($email)->setFirstname($firstName)->setLastname($lastname)->setId(null); $customer = $this->accountManagement->createAccount($customerEntity, 'aPassword'); $this->assertNotEmpty($customer->getId()); $this->assertEquals($email, $customer->getEmail()); $this->assertEquals($firstName, $customer->getFirstname()); $this->assertEquals($lastname, $customer->getLastname()); $this->accountManagement->authenticate($customer->getEmail(), 'aPassword', true); }
/** * @param $customerData * @param $isSingleStoreMode * @param $canModifyCustomer * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ private function _setupStoreMode($customerData, $isSingleStoreMode, $canModifyCustomer) { $backendSessionMock = $this->getMock('\\Magento\\Backend\\Model\\Session', ['getCustomerData'], [], '', false); $backendSessionMock->expects($this->any())->method('getCustomerData')->will($this->returnValue([])); $layoutMock = $this->getMock('\\Magento\\Framework\\View\\Layout\\Element\\Layout', ['createBlock'], [], '', false); $layoutMock->expects($this->at(0))->method('createBlock')->with('Magento\\Customer\\Block\\Adminhtml\\Edit\\Renderer\\Attribute\\Group')->will($this->returnValue($this->objectManagerHelper->getObject('Magento\\Customer\\Block\\Adminhtml\\Edit\\Renderer\\Attribute\\Group'))); $layoutMock->expects($this->at(1))->method('createBlock')->with('Magento\\Backend\\Block\\Store\\Switcher\\Form\\Renderer\\Fieldset\\Element')->will($this->returnValue($this->objectManagerHelper->getObject('Magento\\Backend\\Block\\Store\\Switcher\\Form\\Renderer\\Fieldset\\Element'))); if (empty($customerData['id'])) { $layoutMock->expects($this->at(2))->method('createBlock')->with('Magento\\Customer\\Block\\Adminhtml\\Edit\\Renderer\\Attribute\\Sendemail')->will($this->returnValue($this->objectManagerHelper->getObject('Magento\\Customer\\Block\\Adminhtml\\Edit\\Renderer\\Attribute\\Sendemail'))); } $urlBuilderMock = $this->getMock('\\Magento\\Backend\\Model\\Url', ['getBaseUrl'], [], '', false); $urlBuilderMock->expects($this->once())->method('getBaseUrl')->will($this->returnValue('someUrl')); $storeManagerMock = $this->getMock('Magento\\Store\\Model\\StoreManager', [], [], '', false); $storeManagerMock->expects($this->any())->method('isSingleStoreMode')->will($this->returnValue($isSingleStoreMode)); $customerObject = $this->getMock('\\Magento\\Customer\\Api\\Data\\CustomerInterface'); if (!empty($customerData['id'])) { $customerObject->expects($this->any())->method('getId')->will($this->returnValue($customerData['id'])); } $fieldset = $this->getMockBuilder('\\Magento\\Framework\\Data\\Form\\Element\\Fieldset')->setMethods(['getForm', 'addField', 'removeField'])->disableOriginalConstructor()->getMock(); $accountForm = $this->getMockBuilder('Magento\\Framework\\Data\\Form')->setMethods(['create', 'addFieldset', 'getElement', 'setValues'])->disableOriginalConstructor()->getMock(); $accountForm->expects($this->any())->method('addFieldset')->with('base_fieldset')->will($this->returnValue($fieldset)); $accountForm->expects($this->any())->method('setValues')->will($this->returnValue($accountForm)); $fieldset->expects($this->any())->method('getForm')->will($this->returnValue($accountForm)); $formElement = $this->getMockBuilder('\\Magento\\Framework\\Data\\Form\\Element\\Select')->setMethods(['setRenderer', 'addClass', 'setDisabled'])->disableOriginalConstructor()->getMock(); $formElement->expects($this->any())->method('setRenderer')->will($this->returnValue(null)); $formElement->expects($this->any())->method('addClass')->will($this->returnValue(null)); $formElement->expects($this->any())->method('setDisabled')->will($this->returnValue(null)); $accountForm->expects($this->any())->method('getElement')->withAnyParameters()->will($this->returnValue($formElement)); $fieldset->expects($this->any())->method('addField')->will($this->returnValue($formElement)); $customerForm = $this->getMock('\\Magento\\Customer\\Model\\Metadata\\Form', ['getAttributes'], [], '', false); $customerForm->expects($this->any())->method('getAttributes')->will($this->returnValue([])); $this->contextMock->expects($this->any())->method('getBackendSession')->will($this->returnValue($backendSessionMock)); $this->contextMock->expects($this->any())->method('getLayout')->will($this->returnValue($layoutMock)); $this->contextMock->expects($this->any())->method('getUrlBuilder')->will($this->returnValue($urlBuilderMock)); $this->contextMock->expects($this->any())->method('getStoreManager')->will($this->returnValue($storeManagerMock)); $this->customerFactoryMock->expects($this->any())->method('create')->will($this->returnValue($customerObject)); $this->dataObjectHelperMock->expects($this->once())->method('populateWithArray'); $this->options->expects($this->any())->method('getNamePrefixOptions')->will($this->returnValue(['Pref1', 'Pref2'])); $this->options->expects($this->any())->method('getNameSuffixOptions')->will($this->returnValue(['Suf1', 'Suf2'])); $this->formFactoryMock->expects($this->any())->method('create')->will($this->returnValue($accountForm)); $this->extensibleDataObjectConverterMock->expects($this->any())->method('toFlatArray')->will($this->returnValue($customerData)); $this->customerFormFactoryMock->expects($this->any())->method('create')->with('customer', 'adminhtml_customer', $this->extensibleDataObjectConverterMock->toFlatArray($customerObject, [], '\\Magento\\Customer\\Api\\Data\\CustomerInterface'))->will($this->returnValue($customerForm)); $this->accountManagementMock->expects($this->any())->method('isReadOnly')->withAnyParameters()->will($this->returnValue(!$canModifyCustomer)); $this->accountManagementMock->expects($this->any())->method('getConfirmationStatus')->withAnyParameters()->will($this->returnValue(AccountManagementInterface::ACCOUNT_CONFIRMED)); }
/** * @covers \Magento\Customer\Controller\Adminhtml\Index\Index::execute * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testExecuteWithNewCustomerAndException() { $subscription = 'false'; $postValue = ['customer' => ['coolness' => false, 'disable_auto_group_change' => 'false'], 'subscription' => $subscription]; $filteredData = ['coolness' => false, 'disable_auto_group_change' => 'false']; /** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $formMock */ $attributeMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface')->disableOriginalConstructor()->getMock(); $attributeMock->expects($this->once())->method('getAttributeCode')->willReturn('coolness'); $attributeMock->expects($this->once())->method('getFrontendInput')->willReturn('int'); $attributes = [$attributeMock]; $this->requestMock->expects($this->exactly(2))->method('getPostValue')->willReturn($postValue); $this->requestMock->expects($this->exactly(2))->method('getPost')->willReturnMap([['customer', null, $postValue['customer']], ['address', null, null]]); /** @var \Magento\Customer\Model\Metadata\Form|\PHPUnit_Framework_MockObject_MockObject $formMock */ $formMock = $this->getMockBuilder('Magento\\Customer\\Model\\Metadata\\Form')->disableOriginalConstructor()->getMock(); $this->formFactoryMock->expects($this->once())->method('create')->with(\Magento\Customer\Api\CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, 'adminhtml_customer', [], false, \Magento\Customer\Model\Metadata\Form::DONT_IGNORE_INVISIBLE)->willReturn($formMock); $formMock->expects($this->once())->method('extractData')->with($this->requestMock, 'customer')->willReturn($filteredData); /** @var \Magento\Framework\DataObject|\PHPUnit_Framework_MockObject_MockObject $objectMock */ $objectMock = $this->getMockBuilder('Magento\\Framework\\DataObject')->disableOriginalConstructor()->getMock(); $this->objectFactoryMock->expects($this->once())->method('create')->with(['data' => $postValue])->willReturn($objectMock); $objectMock->expects($this->once())->method('getData')->with('customer')->willReturn($postValue['customer']); $formMock->expects($this->once())->method('getAttributes')->willReturn($attributes); /** @var \Magento\Customer\Api\Data\CustomerInterface|\PHPUnit_Framework_MockObject_MockObject $customerMock */ $customerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock(); $this->customerDataFactoryMock->expects($this->once())->method('create')->willReturn($customerMock); $exception = new \Exception(__('Exception')); $this->managementMock->expects($this->once())->method('createAccount')->with($customerMock, null, '')->willThrowException($exception); $customerMock->expects($this->never())->method('getId'); $this->authorizationMock->expects($this->never())->method('isAllowed'); $this->subscriberFactoryMock->expects($this->never())->method('create'); $this->sessionMock->expects($this->never())->method('unsCustomerData'); $this->registryMock->expects($this->never())->method('register'); $this->messageManagerMock->expects($this->never())->method('addSuccess'); $this->messageManagerMock->expects($this->once())->method('addException')->with($exception, __('Something went wrong while saving the customer.')); $this->sessionMock->expects($this->once())->method('setCustomerData')->with($postValue); /** @var Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */ $redirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock(); $this->redirectFactoryMock->expects($this->once())->method('create')->with([])->willReturn($redirectMock); $redirectMock->expects($this->once())->method('setPath')->with('customer/*/new', ['_current' => true])->willReturn(true); $this->assertEquals($redirectMock, $this->model->execute()); }
/** * Validate customer data and set some its data for further usage in quote * * Will return either true or array with error messages * * @param array $data * @return bool|array */ protected function _validateCustomerData(array $data) { $quote = $this->getQuote(); $isCustomerNew = !$quote->getCustomerId(); $customer = $quote->getCustomer(); $customerData = $this->extensibleDataObjectConverter->toFlatArray($customer, [], '\\Magento\\Customer\\Api\\Data\\CustomerInterface'); /** @var Form $customerForm */ $customerForm = $this->_formFactory->create(\Magento\Customer\Api\CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, 'checkout_register', $customerData, $this->_request->isAjax(), Form::IGNORE_INVISIBLE, []); if ($isCustomerNew) { $customerRequest = $customerForm->prepareRequest($data); $customerData = $customerForm->extractData($customerRequest); } $customerErrors = $customerForm->validateData($customerData); if ($customerErrors !== true) { return ['error' => -1, 'message' => implode(', ', $customerErrors)]; } if (!$isCustomerNew) { return true; } $customer = $this->customerDataFactory->create(); $this->dataObjectHelper->populateWithArray($customer, $customerData, '\\Magento\\Customer\\Api\\Data\\CustomerInterface'); if ($quote->getCheckoutMethod() == self::METHOD_REGISTER) { // We always have $customerRequest here, otherwise we would have been kicked off the function several // lines above $password = $customerRequest->getParam('customer_password'); if ($password != $customerRequest->getParam('confirm_password')) { return ['error' => -1, 'message' => __('Password and password confirmation are not equal.')]; } $quote->setPasswordHash($this->accountManagement->getPasswordHash($password)); } else { // set NOT LOGGED IN group id explicitly, // otherwise copyFieldsetToTarget('customer_account', 'to_quote') will fill it with default group id value $customer->setGroupId(GroupInterface::NOT_LOGGED_IN_ID); } //validate customer $result = $this->accountManagement->validate($customer); if (!$result->isValid()) { return ['error' => -1, 'message' => implode(', ', $result->getMessages())]; } // copy customer/guest email to address $quote->getBillingAddress()->setEmail($customer->getEmail()); // copy customer data to quote $this->_objectCopyService->copyFieldsetToTarget('customer_account', 'to_quote', $this->extensibleDataObjectConverter->toFlatArray($customer, [], '\\Magento\\Customer\\Api\\Data\\CustomerInterface'), $quote); return true; }
/** * Add account data to quote * * @param array $accountData * @return $this */ public function setAccountData($accountData) { $customer = $this->getQuote()->getCustomer(); $form = $this->_createCustomerForm($customer); // emulate request $request = $form->prepareRequest($accountData); $data = $form->extractData($request); $data = $form->restoreData($data); $customer = $this->customerFactory->create(); $this->dataObjectHelper->populateWithArray($customer, $data, '\\Magento\\Customer\\Api\\Data\\CustomerInterface'); $this->getQuote()->updateCustomerData($customer); $data = []; $customerData = $this->customerMapper->toFlatArray($customer); foreach ($form->getAttributes() as $attribute) { $code = sprintf('customer_%s', $attribute->getAttributeCode()); $data[$code] = isset($customerData[$attribute->getAttributeCode()]) ? $customerData[$attribute->getAttributeCode()] : null; } if (isset($data['customer_group_id'])) { $customerGroup = $this->groupRepository->getById($data['customer_group_id']); $data['customer_tax_class_id'] = $customerGroup->getTaxClassId(); $this->setRecollect(true); } $this->getQuote()->addData($data); return $this; }
/** * Retrieve customer model object * * @return \Magento\Customer\Api\Data\CustomerInterface|\Magento\Framework\Api\ExtensibleDataInterface */ public function getCustomer() { /** * @TODO: Remove the method after all external usages are refactored in MAGETWO-19930 * _customer and _customerFactory variables should be eliminated as well */ if (null === $this->_customer) { try { $this->_customer = $this->customerRepository->getById($this->getCustomerId()); } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { $this->_customer = $this->customerDataFactory->create(); $this->_customer->setId(null); } } return $this->_customer; }
/** * @return \Magento\Customer\Api\Data\CustomerInterface */ protected function _getCustomer() { $customerDataObject = $this->customerDataFactory->create(); $this->dataObjectHelper->populateWithArray($customerDataObject, $this->_backendSession->getCustomerData()['account'], '\\Magento\\Customer\\Api\\Data\\CustomerInterface'); return $customerDataObject; }