/**
  * Creates a collection item that represents a customer for the customer Grid.
  *
  * @param CustomerInterface $customer Input data for creating the item.
  * @return \Magento\Framework\Object Collection item that represents a customer
  */
 protected function createCustomerItem(CustomerInterface $customer)
 {
     $customerNameParts = [$customer->getPrefix(), $customer->getFirstname(), $customer->getMiddlename(), $customer->getLastname(), $customer->getSuffix()];
     $customerItem = new \Magento\Framework\Object();
     $customerItem->setId($customer->getId());
     $customerItem->setEntityId($customer->getId());
     // All parts of the customer name must be displayed in the name column of the grid
     $customerItem->setName(implode(' ', array_filter($customerNameParts)));
     $customerItem->setEmail($customer->getEmail());
     $customerItem->setWebsiteId($customer->getWebsiteId());
     $customerItem->setCreatedAt($customer->getCreatedAt());
     $customerItem->setGroupId($customer->getGroupId());
     $billingAddress = null;
     foreach ($customer->getAddresses() as $address) {
         if ($address->isDefaultBilling()) {
             $billingAddress = $address;
             break;
         }
     }
     if ($billingAddress !== null) {
         $customerItem->setBillingTelephone($billingAddress->getTelephone());
         $customerItem->setBillingPostcode($billingAddress->getPostcode());
         $customerItem->setBillingCountryId($billingAddress->getCountryId());
         $region = $billingAddress->getRegion() === null ? '' : $billingAddress->getRegion()->getRegion();
         $customerItem->setBillingRegion($region);
     }
     return $customerItem;
 }
Example #2
0
 /**
  * @param CustomerInterface $entity
  * @param array $arguments
  * @return CustomerInterface
  * @throws \Exception
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute($entity, $arguments = [])
 {
     $newAddresses = [];
     foreach ($entity->getAddresses() as $address) {
         $address->setCustomerId($entity->getId());
         $newAddresses[] = $this->entityManager->save($address);
     }
     $entity->setAddresses($newAddresses);
     return $entity;
 }
 /**
  * Get address by id
  *
  * @param CustomerInterface $customer
  * @param int $addressId
  * @return AddressInterface|null
  */
 protected function getAddressById(CustomerInterface $customer, $addressId)
 {
     foreach ($customer->getAddresses() as $address) {
         if ($address->getId() == $addressId) {
             return $address;
         }
     }
     return null;
 }
Example #4
0
 /**
  * Define customer object
  *
  * @param \Magento\Customer\Api\Data\CustomerInterface $customer
  * @return $this
  */
 public function setCustomer(\Magento\Customer\Api\Data\CustomerInterface $customer = null)
 {
     /* @TODO: Remove the method after all external usages are refactored in MAGETWO-19930 */
     $this->_customer = $customer;
     $this->setCustomerId($customer->getId());
     $origAddresses = $customer->getAddresses();
     $customer->setAddresses([]);
     $customerDataFlatArray = $this->objectFactory->create($this->extensibleDataObjectConverter->toFlatArray($customer, [], '\\Magento\\Customer\\Api\\Data\\CustomerInterface'));
     $customer->setAddresses($origAddresses);
     $this->_objectCopyService->copyFieldsetToTarget('customer_account', 'to_quote', $customerDataFlatArray, $this);
     return $this;
 }
Example #5
0
 /**
  * Create Data Transfer Object of customer candidate
  *
  * @param \Magento\Framework\App\RequestInterface $inputData
  * @param \Magento\Customer\Api\Data\CustomerInterface $currentCustomerData
  * @return \Magento\Customer\Api\Data\CustomerInterface
  */
 private function populateNewCustomerDataObject(\Magento\Framework\App\RequestInterface $inputData, \Magento\Customer\Api\Data\CustomerInterface $currentCustomerData)
 {
     $customerDto = $this->customerExtractor->extract(self::FORM_DATA_EXTRACTOR_CODE, $inputData);
     $customerDto->setId($currentCustomerData->getId());
     if (!$customerDto->getAddresses()) {
         $customerDto->setAddresses($currentCustomerData->getAddresses());
     }
     if (!$inputData->getParam('change_email')) {
         $customerDto->setEmail($currentCustomerData->getEmail());
     }
     return $customerDto;
 }