diff --git a/Helper/Data.php b/Helper/Data.php index e8cc6c9..9403772 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -224,9 +224,9 @@ public function getRemoteIpAddress($customerId = null) $ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); $remoteIp = trim($ips[count($ips) - 1]); //real IP address behind proxy IP } - else + elseif(!empty($_SERVER['REMOTE_ADDR'])) { - $remoteIp = $_SERVER['REMOTE_ADDR']; //no proxy found + $remoteIp = $_SERVER['REMOTE_ADDR']; //no proxy found } } return $remoteIp; @@ -424,6 +424,10 @@ protected function _getCustomerAttributeValue($attributeCode, $customer) { $value = $customer->getEntityId(); } + elseif($attributeCode == 'email') + { + $value = $customer->getEmail(); + } else { try { diff --git a/Model/Event/Strategy/Register.php b/Model/Event/Strategy/Register.php index 9f3924c..79273a9 100644 --- a/Model/Event/Strategy/Register.php +++ b/Model/Event/Strategy/Register.php @@ -28,13 +28,20 @@ public function build() $eventData = array(); $data['name'] = self::HUB_EVENT_NAME; $data['scope'] = self::HUB_EVENT_SCOPE; - //$data['need_update_identity'] = true; - $data['identity_email'] = $context['email']; - $data['store_id'] = $context['store_id']; + if(array_key_exists('need_update_identity', $context)) + { + $data['need_update_identity'] = $context['need_update_identity']; + } + if(array_key_exists('created_at', $context)) + { + $data['created_at'] = $context['created_at']; + } if(array_key_exists('remote_ip', $context)) { $data['env_remote_ip'] = $context['remote_ip']; } + $data['identity_email'] = $context['email']; + $data['store_id'] = $context['store_id']; $data['event_data'] = $eventData; } return $data; diff --git a/Model/Service/Event.php b/Model/Service/Event.php index e10e9d8..5028abc 100644 --- a/Model/Service/Event.php +++ b/Model/Service/Event.php @@ -73,7 +73,7 @@ public function collectEvent(EventStrategyInterface $strategy, $arguments = []) $websiteId = $this->_helper->getStore($data['store_id'])->getWebsiteId(); $customer = $this->_customerFactory->create(); $customer->setWebsiteId($websiteId) - ->loadByEmail($event->getIdentityEmail()); + ->loadByEmail($data['identity_email']); if ($customer->getEntityId() || $this->_helper->canSendAnonymousEvents($data['store_id'])) { diff --git a/Model/Service/Hub.php b/Model/Service/Hub.php index 1b226ae..274fc2e 100644 --- a/Model/Service/Hub.php +++ b/Model/Service/Hub.php @@ -181,6 +181,7 @@ public function composeHubEvent(EventInterface $event) * * @param EventInterface $event * @return \stdClass + * @throws \Magento\Framework\Exception\LocalizedException */ public function composeHubCustomer(EventInterface $event) { @@ -203,28 +204,6 @@ public function composeHubCustomer(EventInterface $event) ->loadByEmail($event->getIdentityEmail()); if ($customer) { - /* - if ($customer->getPrefix()) - { - $base->title = $customer->getPrefix(); - } - if ($customer->getFirstname()) - { - $base->firstName = $customer->getFirstname(); - } - if ($customer->getLastname()) - { - $base->lastName = $customer->getLastname(); - } - if ($customer->getGender()) - { - $base->gender = $customer->getGender() == 1 ? 'Male' : 'Female'; - } - if ($customer->getDob()) - { - $base->dob = date('Y-m-d', strtotime($customer->getDob())); - } - */ $customerAddressId = $customer->getDefaultBilling(); if ($customerAddressId) { @@ -258,11 +237,7 @@ public function composeHubCustomer(EventInterface $event) $extraBaseProperties = $this->_helper->getCustomerExtraProperties($customer, 'base'); $base = (object) array_merge( (array)$base, $extraBaseProperties ); - $externalId = $this->_helper->getExternalId($customer); - if($externalId) - { - $hubCustomer->externalId = $externalId; - } + $hubCustomer->externalId = $this->_helper->getExternalId($customer); $extraExtendedProperties = $this->_helper->getCustomerExtraProperties($customer, 'extended'); if (count($extraExtendedProperties) > 0) @@ -302,7 +277,10 @@ public function composeHubCustomer(EventInterface $event) $subscriptions[] = $subscriberObj; $base->subscriptions = $subscriptions; - + if(!$hubCustomer->externalId) + { + $hubCustomer->externalId = $subscriber->getSubscriberEmail(); + } } } $hubCustomer->base = $base; diff --git a/Model/Service/PreviousCustomer.php b/Model/Service/PreviousCustomer.php index 4eae37d..1b47a64 100644 --- a/Model/Service/PreviousCustomer.php +++ b/Model/Service/PreviousCustomer.php @@ -97,7 +97,7 @@ public function collectPreviousCustomers($pageSize = 1) { foreach ($this->_storeInterface->getStores() as $storeId => $store) { - //if ($this->_helper->isEnabledPreviousCustomer($storeId)) + if ($this->_helper->isEnabledPreviousCustomer($storeId)) { $fromDate = $this->_helper->getPreviousDate($storeId); $this->_getPreviousCustomersFromDate($fromDate, $storeId, $pageSize); @@ -173,14 +173,16 @@ protected function _createEventsFromPreviousCustomers($fromDate, $storeId) ->getItems(); foreach ($previousCustomers as $previousCustomer) { + $data = null; if($previousCustomer['customer_id']) { /* $this->_strategyLogin->setContext($previousCustomer->getData()); $this->_eventService->collectEvent($this->_strategyLogin); */ - $previousCustomer->setNeedUpdateIdentity(true); - $this->_strategyRegister->setContext($previousCustomer->getData()); + $data = $previousCustomer->getData(); + $data['need_update_identity'] = true; + $this->_strategyRegister->setContext($data); $this->_eventService->collectEvent($this->_strategyRegister); if($this->_helper->canExportPreviousOrders($storeId)) @@ -194,8 +196,10 @@ protected function _createEventsFromPreviousCustomers($fromDate, $storeId) } else { + $data = $previousCustomer->getData(); $data['subscriber_email'] = $data['email']; + $data['need_update_identity'] = true; $this->_strategySubscriber->setContext($data); $this->_eventService->collectEvent($this->_strategySubscriber); } diff --git a/composer.json b/composer.json index 4d4c6f6..4bb80f2 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ }, "type": "magento2-module", - "version": "1.3.0", + "version": "1.4.0", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/etc/module.xml b/etc/module.xml index 2b5a833..a48efa4 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,7 +1,7 @@ - +