Exemple #1
0
 /**
  * Concatenate all customer name parts into full customer name.
  *
  * @param \Magento\Customer\Service\V1\Data\Customer $customerData
  * @return string
  */
 public function getCustomerName(\Magento\Customer\Service\V1\Data\Customer $customerData)
 {
     $name = '';
     $prefixMetadata = $this->_customerMetadataService->getAttributeMetadata('customer', 'prefix');
     if ($prefixMetadata->isVisible() && $customerData->getPrefix()) {
         $name .= $customerData->getPrefix() . ' ';
     }
     $name .= $customerData->getFirstname();
     $middleNameMetadata = $this->_customerMetadataService->getAttributeMetadata('customer', 'middlename');
     if ($middleNameMetadata->isVisible() && $customerData->getMiddlename()) {
         $name .= ' ' . $customerData->getMiddlename();
     }
     $name .= ' ' . $customerData->getLastname();
     $suffixMetadata = $this->_customerMetadataService->getAttributeMetadata('customer', 'suffix');
     if ($suffixMetadata->isVisible() && $customerData->getSuffix()) {
         $name .= ' ' . $customerData->getSuffix();
     }
     return $name;
 }
Exemple #2
0
 /**
  * Send customer email
  *
  * @return bool
  */
 public function send()
 {
     if (is_null($this->_website) || is_null($this->_customer)) {
         return false;
     }
     if ($this->_type == 'price' && count($this->_priceProducts) == 0 || $this->_type == 'stock' && count($this->_stockProducts) == 0) {
         return false;
     }
     if (!$this->_website->getDefaultGroup() || !$this->_website->getDefaultGroup()->getDefaultStore()) {
         return false;
     }
     $store = $this->_website->getDefaultStore();
     $storeId = $store->getId();
     if ($this->_type == 'price' && !$this->_scopeConfig->getValue(self::XML_PATH_EMAIL_PRICE_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)) {
         return false;
     } elseif ($this->_type == 'stock' && !$this->_scopeConfig->getValue(self::XML_PATH_EMAIL_STOCK_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)) {
         return false;
     }
     if ($this->_type != 'price' && $this->_type != 'stock') {
         return false;
     }
     $initialEnvironmentInfo = $this->_appEmulation->startEnvironmentEmulation($storeId);
     if ($this->_type == 'price') {
         $this->_getPriceBlock()->setStore($store)->reset();
         foreach ($this->_priceProducts as $product) {
             $product->setCustomerGroupId($this->_customer->getGroupId());
             $this->_getPriceBlock()->addProduct($product);
         }
         $block = $this->_getPriceBlock();
         $templateId = $this->_scopeConfig->getValue(self::XML_PATH_EMAIL_PRICE_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
     } else {
         $this->_getStockBlock()->setStore($store)->reset();
         foreach ($this->_stockProducts as $product) {
             $product->setCustomerGroupId($this->_customer->getGroupId());
             $this->_getStockBlock()->addProduct($product);
         }
         $block = $this->_getStockBlock();
         $templateId = $this->_scopeConfig->getValue(self::XML_PATH_EMAIL_STOCK_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
     }
     $alertGrid = $this->_appState->emulateAreaCode(\Magento\Framework\App\Area::AREA_FRONTEND, array($block, 'toHtml'));
     $this->_appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
     $transport = $this->_transportBuilder->setTemplateIdentifier($templateId)->setTemplateOptions(array('area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId))->setTemplateVars(array('customerName' => $this->_customerHelper->getCustomerName($this->_customer), 'alertGrid' => $alertGrid))->setFrom($this->_scopeConfig->getValue(self::XML_PATH_EMAIL_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId))->addTo($this->_customer->getEmail(), $this->_customerHelper->getCustomerName($this->_customer))->getTransport();
     $transport->sendMessage();
     return true;
 }
Exemple #3
0
 /**
  * Set Customer data object with the customer information
  *
  * @param CustomerData $customerData
  * @return $this
  */
 public function setCustomerDataObject(CustomerData $customerData)
 {
     $this->setId($customerData->getId());
     $this->_converter->updateCustomerModel($this->getCustomer(), $customerData);
     return $this;
 }
Exemple #4
0
 /**
  * Create customerAddressDataObject and save it in the Model\Quote so that it can be used to persist later.
  *
  * @param CustomerDataObject $customerDataObject
  * @param \Magento\Sales\Model\Quote\Address $quoteCustomerAddress
  * @return void
  * @throws \InvalidArgumentException
  */
 protected function _prepareCustomerAddress($customerDataObject, $quoteCustomerAddress)
 {
     // Possible that customerId is null for new customers
     $customerId = $customerDataObject->getId();
     $quoteCustomerAddress->setCustomerId($customerId);
     $customerAddressDataObject = $quoteCustomerAddress->exportCustomerAddressData();
     $quoteAddressId = $quoteCustomerAddress->getCustomerAddressId();
     $addressType = $quoteCustomerAddress->getAddressType();
     if ($quoteAddressId) {
         /** Update existing address */
         $existingAddressDataObject = $this->_customerAddressService->getAddress($quoteAddressId);
         /** Update customer address data */
         $customerAddressDataObject = $this->_customerAddressBuilder->mergeDataObjects($existingAddressDataObject, $customerAddressDataObject);
     } elseif ($addressType == CustomerAddressDataObject::ADDRESS_TYPE_SHIPPING) {
         try {
             $billingAddressDataObject = $this->_customerAddressService->getDefaultBillingAddress($customerId);
         } catch (\Exception $e) {
             /** Billing address does not exist. */
         }
         $isShippingAsBilling = $quoteCustomerAddress->getSameAsBilling();
         if (isset($billingAddressDataObject) && $isShippingAsBilling) {
             /** Set existing billing address as default shipping */
             $customerAddressDataObject = $this->_customerAddressBuilder->populate($billingAddressDataObject)->setDefaultShipping(true)->create();
         }
     }
     switch ($addressType) {
         case CustomerAddressDataObject::ADDRESS_TYPE_BILLING:
             if (is_null($customerDataObject->getDefaultBilling())) {
                 $customerAddressDataObject = $this->_customerAddressBuilder->populate($customerAddressDataObject)->setDefaultBilling(true)->create();
             }
             break;
         case CustomerAddressDataObject::ADDRESS_TYPE_SHIPPING:
             if (is_null($customerDataObject->getDefaultShipping())) {
                 $customerAddressDataObject = $this->_customerAddressBuilder->populate($customerAddressDataObject)->setDefaultShipping(true)->create();
             }
             break;
         default:
             throw new \InvalidArgumentException('Customer address type is invalid.');
     }
     $this->getQuote()->addCustomerAddressData($customerAddressDataObject);
 }
 /**
  * Send either confirmation or welcome email after an account creation
  *
  * @param CustomerModel $customerModel
  * @param Data\Customer $customer
  * @param string        $redirectUrl
  * @return void
  */
 protected function _sendEmailConfirmation(CustomerModel $customerModel, Data\Customer $customer, $redirectUrl)
 {
     try {
         if ($customerModel->isConfirmationRequired()) {
             $customerModel->sendNewAccountEmail(self::NEW_ACCOUNT_EMAIL_CONFIRMATION, $redirectUrl, $customer->getStoreId());
         } else {
             $customerModel->sendNewAccountEmail(self::NEW_ACCOUNT_EMAIL_REGISTERED, $redirectUrl, $customer->getStoreId());
         }
     } catch (MailException $e) {
         // If we are not able to send a new account email, this should be ignored
         $this->logger->logException($e);
     }
 }
Exemple #6
0
 /**
  * Plugin after create customer that updates any newsletter subscription that may have existed.
  *
  * @param CustomerAccountServiceInterface $subject
  * @param Customer $customer
  * @return Customer
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterCreateCustomer(CustomerAccountServiceInterface $subject, Customer $customer)
 {
     $this->subscriberFactory->create()->updateSubscription($customer->getId());
     return $customer;
 }
Exemple #7
0
 /**
  * Get checkout quote instance by current session
  *
  * @return Quote
  */
 public function getQuote()
 {
     $this->_eventManager->dispatch('custom_quote_process', array('checkout_session' => $this));
     if ($this->_quote === null) {
         /** @var $quote Quote */
         $quote = $this->_quoteFactory->create()->setStoreId($this->_storeManager->getStore()->getId());
         if ($this->getQuoteId()) {
             if ($this->_loadInactive) {
                 $quote->load($this->getQuoteId());
             } else {
                 $quote->loadActive($this->getQuoteId());
             }
             if ($quote->getId()) {
                 /**
                  * If current currency code of quote is not equal current currency code of store,
                  * need recalculate totals of quote. It is possible if customer use currency switcher or
                  * store switcher.
                  */
                 if ($quote->getQuoteCurrencyCode() != $this->_storeManager->getStore()->getCurrentCurrencyCode()) {
                     $quote->setStore($this->_storeManager->getStore());
                     $quote->collectTotals()->save();
                     /*
                      * We mast to create new quote object, because collectTotals()
                      * can to create links with other objects.
                      */
                     $quote = $this->_quoteFactory->create()->setStoreId($this->_storeManager->getStore()->getId());
                     $quote->load($this->getQuoteId());
                 }
             } else {
                 $this->setQuoteId(null);
             }
         }
         if (!$this->getQuoteId()) {
             if ($this->_customerSession->isLoggedIn() || $this->_customer) {
                 $customerId = $this->_customer ? $this->_customer->getId() : $this->_customerSession->getCustomerId();
                 $quote->loadByCustomer($customerId);
                 $this->setQuoteId($quote->getId());
             } else {
                 $quote->setIsCheckoutCart(true);
                 $this->_eventManager->dispatch('checkout_quote_init', array('quote' => $quote));
             }
         }
         if ($this->getQuoteId()) {
             if ($this->_customer) {
                 $quote->setCustomerData($this->_customer);
             } else {
                 if ($this->_customerSession->isLoggedIn()) {
                     $quote->setCustomerData($this->_customerSession->getCustomerDataObject());
                 }
             }
         }
         $quote->setStore($this->_storeManager->getStore());
         $this->_quote = $quote;
     }
     if ($remoteAddr = $this->_remoteAddress->getRemoteAddress()) {
         $this->_quote->setRemoteIp($remoteAddr);
         $xForwardIp = $this->request->getServer('HTTP_X_FORWARDED_FOR');
         $this->_quote->setXForwardedFor($xForwardIp);
     }
     return $this->_quote;
 }
Exemple #8
0
 /**
  * Load subscriber by customer
  *
  * @param \Magento\Customer\Service\V1\Data\Customer $customer
  * @return array
  */
 public function loadByCustomerData(\Magento\Customer\Service\V1\Data\Customer $customer)
 {
     $select = $this->_read->select()->from($this->getMainTable())->where('customer_id=:customer_id');
     $result = $this->_read->fetchRow($select, array('customer_id' => $customer->getId()));
     if ($result) {
         return $result;
     }
     $select = $this->_read->select()->from($this->getMainTable())->where('subscriber_email=:subscriber_email');
     $result = $this->_read->fetchRow($select, array('subscriber_email' => $customer->getEmail()));
     if ($result) {
         return $result;
     }
     return array();
 }