コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
 /**
  * Get either first store ID from a set website or the provided as default
  *
  * @param CustomerInterface $customer
  * @param int|string|null $defaultStoreId
  * @return int
  */
 protected function getWebsiteStoreId($customer, $defaultStoreId = null)
 {
     if ($customer->getWebsiteId() != 0 && empty($defaultStoreId)) {
         $storeIds = $this->storeManager->getWebsite($customer->getWebsiteId())->getStoreIds();
         reset($storeIds);
         $defaultStoreId = current($storeIds);
     }
     return $defaultStoreId;
 }