当前位置: 首页>>代码示例>>PHP>>正文


PHP CustomerInterfaceFactory::create方法代码示例

本文整理汇总了PHP中Magento\Customer\Api\Data\CustomerInterfaceFactory::create方法的典型用法代码示例。如果您正苦于以下问题:PHP CustomerInterfaceFactory::create方法的具体用法?PHP CustomerInterfaceFactory::create怎么用?PHP CustomerInterfaceFactory::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Customer\Api\Data\CustomerInterfaceFactory的用法示例。


在下文中一共展示了CustomerInterfaceFactory::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: prepareQuoteForNewCustomer

 /**
  * @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;
 }
开发者ID:nja78,项目名称:magento2,代码行数:38,代码来源:Quote.php

示例2: create

 /**
  * {@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;
 }
开发者ID:nja78,项目名称:magento2,代码行数:32,代码来源:Management.php

示例3: delete

 /**
  * {@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;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:15,代码来源:CustomerPersistence.php

示例4: testUpdateDataOverrideExistingData

 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());
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:13,代码来源:CustomerTest.php

示例5: getCustomer

 /**
  * 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;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:19,代码来源:Rss.php

示例6: createSampleCustomerDataObject

 /**
  * 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;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:37,代码来源:Customer.php

示例7: run

 /**
  * {@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('.');
         }
     }
 }
开发者ID:vinai-drive-by-commits,项目名称:magento2-sample-data,代码行数:34,代码来源:Customer.php

示例8: install

 /**
  * {@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']]);
         }
     }
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:37,代码来源:Customer.php

示例9: createSampleCustomerDataObject

 /**
  * 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;
 }
开发者ID:andrewhowdencom,项目名称:m2onk8s,代码行数:36,代码来源:Customer.php

示例10: testUpdateCustomerException

 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());
     }
 }
开发者ID:andrewhowdencom,项目名称:m2onk8s,代码行数:26,代码来源:CustomerRepositoryTest.php

示例11: extract

 /**
  * @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;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:21,代码来源:CustomerExtractor.php

示例12: getCustomer

 /**
  * 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;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:13,代码来源:PersonalInfo.php

示例13: _createCustomer

 /**
  * @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('email@email.com');
     $data = ['account' => $this->_dataObjectProcessor->buildOutputDataArray($customer, 'Magento\\Customer\\Api\\Data\\CustomerInterface')];
     $this->_context->getBackendSession()->setCustomerData($data);
     return $customer;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:11,代码来源:PersonalInfoTest.php

示例14: _getCustomerDataObject

 /**
  * 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;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:15,代码来源:Account.php

示例15: testUpdateCustomerDeleteAllAddressesWithEmptyArray

 /**
  * @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()));
 }
开发者ID:vasiljok,项目名称:magento2,代码行数:18,代码来源:CustomerRepositoryTest.php


注:本文中的Magento\Customer\Api\Data\CustomerInterfaceFactory::create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。