Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

Commit

Permalink
- fixed api call for external_id
Browse files Browse the repository at this point in the history
  • Loading branch information
ildelux committed Dec 17, 2018
1 parent 3b2897b commit 8e18249
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 39 deletions.
8 changes: 6 additions & 2 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -424,6 +424,10 @@ protected function _getCustomerAttributeValue($attributeCode, $customer)
{
$value = $customer->getEntityId();
}
elseif($attributeCode == 'email')
{
$value = $customer->getEmail();
}
else
{
try {
Expand Down
13 changes: 10 additions & 3 deletions Model/Event/Strategy/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Model/Service/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']))
{

Expand Down
34 changes: 6 additions & 28 deletions Model/Service/Hub.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public function composeHubEvent(EventInterface $event)
*
* @param EventInterface $event
* @return \stdClass
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function composeHubCustomer(EventInterface $event)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -302,7 +277,10 @@ public function composeHubCustomer(EventInterface $event)
$subscriptions[] = $subscriberObj;
$base->subscriptions = $subscriptions;


if(!$hubCustomer->externalId)
{
$hubCustomer->externalId = $subscriber->getSubscriberEmail();
}
}
}
$hubCustomer->base = $base;
Expand Down
10 changes: 7 additions & 3 deletions Model/Service/PreviousCustomer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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))
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

},
"type": "magento2-module",
"version": "1.3.0",
"version": "1.4.0",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Contactlab_Hub" setup_version="1.3.0">
<module name="Contactlab_Hub" setup_version="1.4.0">
<sequence>
<module name="Contactlab_Core"/>
</sequence>
Expand Down

0 comments on commit 8e18249

Please sign in to comment.