Ejemplo n.º 1
0
 /**
  * Return customer code according to the admin configured format
  *
  * @param \Magento\Quote\Api\Data\CartInterface|\Magento\Sales\Api\Data\OrderInterface $data
  * @return string
  */
 protected function getCustomerCode($data)
 {
     switch ($this->config->getCustomerCodeFormat($data->getStoreId())) {
         case Config::CUSTOMER_FORMAT_OPTION_EMAIL:
             $email = $data->getCustomerEmail();
             return $email ?: Config::CUSTOMER_MISSING_EMAIL;
             break;
         case Config::CUSTOMER_FORMAT_OPTION_NAME_ID:
             $customer = $this->getCustomerById($data->getCustomerId());
             if ($customer && $customer->getId()) {
                 $name = $customer->getFirstname() . ' ' . $customer->getLastname();
                 $id = $customer->getId();
             } else {
                 if (!$data->getIsVirtual()) {
                     $address = $data->getShippingAddress();
                 } else {
                     $address = $data->getBillingAddress();
                 }
                 $name = $address->getFirstname() . ' ' . $address->getLastname();
                 if (!trim($name)) {
                     $name = Config::CUSTOMER_MISSING_NAME;
                 }
                 $id = Config::CUSTOMER_GUEST_ID;
             }
             return sprintf(Config::CUSTOMER_FORMAT_NAME_ID, $name, $id);
             break;
         case Config::CUSTOMER_FORMAT_OPTION_ID:
         default:
             return $data->getCustomerId() ?: strtolower(Config::CUSTOMER_GUEST_ID) . '-' . $data->getId();
             break;
     }
 }