Skip to content

Commit

Permalink
2.2.12 - identifu accepts_marketing status for new customers registra…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
bnayalivne committed Jan 31, 2018
1 parent 773b26d commit 8f3025d
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 70 deletions.
2 changes: 1 addition & 1 deletion Model/Api/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ public function setConfig($mage_store_id, $configName, $scope, $newValue)
*/
public function getVersion()
{
return '2.2.11';
return '2.2.12';
}

/**
Expand Down
7 changes: 5 additions & 2 deletions Observer/EventMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use \Magento\Customer\Model\Group;
use Magento\Store\Model\StoreManager;
use Remarkety\Mgconnector\Helper\ConfigHelper;
use \Remarkety\Mgconnector\Model\Queue;
use \Magento\Store\Model\Store;
use \Magento\Framework\UrlInterface;
use \Magento\Framework\App\Config\ScopeConfigInterface;
Expand Down Expand Up @@ -283,7 +282,7 @@ protected function _getPayloadBase($eventType)
}


protected function _prepareCustomerSubscribtionUpdateData(Subscriber $subscriber, $clientIp = null)
protected function _prepareCustomerSubscribtionUpdateData(Subscriber $subscriber, $clientIp = null, $customerId = null)
{
$arr = array(
'email' => $subscriber->getSubscriberEmail(),
Expand All @@ -295,6 +294,10 @@ protected function _prepareCustomerSubscribtionUpdateData(Subscriber $subscriber
$arr['client_ip'] = $clientIp;
}

if(!empty($customerId)){
$arr['customerId'] = $customerId;
}

return $arr;
}

Expand Down
13 changes: 0 additions & 13 deletions Observer/TriggerCustomerAddressBeforeUpdateObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,7 @@
namespace Remarkety\Mgconnector\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Customer\Model\Address;
use Magento\Customer\Model\CustomerFactory;
use \Magento\Framework\ObjectManager\ObjectManager;
use \Magento\Framework\Registry;
use Remarkety\Mgconnector\Helper\ConfigHelper;
use Remarkety\Mgconnector\Observer\EventMethods;
use \Magento\Newsletter\Model\Subscriber;
use \Magento\Customer\Model\Group;
use \Remarkety\Mgconnector\Model\Queue;
use \Magento\Store\Model\Store;
use \Magento\Framework\App\Config\ScopeConfigInterface;
use Remarkety\Mgconnector\Serializer\AddressSerializer;
use Remarkety\Mgconnector\Serializer\CustomerSerializer;
use Remarkety\Mgconnector\Serializer\OrderSerializer;


class TriggerCustomerAddressBeforeUpdateObserver extends EventMethods implements ObserverInterface
Expand Down
12 changes: 0 additions & 12 deletions Observer/TriggerCustomerAddressUpdateObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@
use Magento\Framework\Event\ObserverInterface;
use Magento\Customer\Model\Address;
use Magento\Customer\Model\CustomerFactory;
use \Magento\Framework\Registry;
use \Magento\Framework\ObjectManager\ObjectManager;
use Remarkety\Mgconnector\Helper\ConfigHelper;
use Remarkety\Mgconnector\Observer\EventMethods;
use \Magento\Newsletter\Model\Subscriber;
use \Magento\Customer\Model\Group;
use \Remarkety\Mgconnector\Model\Queue;
use \Magento\Store\Model\Store;
use \Magento\Framework\App\Config\ScopeConfigInterface;
use Remarkety\Mgconnector\Serializer\AddressSerializer;
use Remarkety\Mgconnector\Serializer\CustomerSerializer;
use Remarkety\Mgconnector\Serializer\OrderSerializer;

class TriggerCustomerAddressUpdateObserver extends EventMethods implements ObserverInterface
{
Expand Down
12 changes: 0 additions & 12 deletions Observer/TriggerCustomerDeleteObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,6 @@

use Magento\Customer\Model\Backend\Customer;
use Magento\Framework\Event\ObserverInterface;
use Remarkety\Mgconnector\Helper\ConfigHelper;
use Remarkety\Mgconnector\Observer\EventMethods;
use \Magento\Customer\Model\Session;
use \Magento\Framework\Registry;
use \Magento\Newsletter\Model\Subscriber;
use \Magento\Customer\Model\Group;
use \Remarkety\Mgconnector\Model\Queue;
use \Magento\Store\Model\Store;
use \Magento\Framework\App\Config\ScopeConfigInterface;
use Remarkety\Mgconnector\Serializer\AddressSerializer;
use Remarkety\Mgconnector\Serializer\CustomerSerializer;
use Remarkety\Mgconnector\Serializer\OrderSerializer;

class TriggerCustomerDeleteObserver extends EventMethods implements ObserverInterface {

Expand Down
12 changes: 1 addition & 11 deletions Observer/TriggerCustomerUpdateObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,7 @@
namespace Remarkety\Mgconnector\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Customer\Model\Address;
use Magento\Customer\Model\CustomerFactory;
use \Magento\Framework\Registry;
use \Magento\Newsletter\Model\Subscriber;
use \Magento\Customer\Model\Group;
use Remarkety\Mgconnector\Helper\ConfigHelper;
use \Remarkety\Mgconnector\Model\Queue;
use \Magento\Store\Model\Store;
use \Magento\Framework\App\Config\ScopeConfigInterface;
use Remarkety\Mgconnector\Serializer\AddressSerializer;
use Remarkety\Mgconnector\Serializer\CustomerSerializer;
use Remarkety\Mgconnector\Serializer\OrderSerializer;


class TriggerCustomerUpdateObserver extends EventMethods implements ObserverInterface
Expand All @@ -40,6 +29,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
*/
$customer = $backendModel->getDataModel();
$customerOld = $this->customerRepository->getById($customer->getId());
$this->_coreRegistry->register('remarkety_customer_id', $customer->getId(), true);

if($this->_coreRegistry->registry('remarkety_customer_save_observer_executed_'.$customer->getId()) || !$customer->getId()) {
return $this;
Expand Down
16 changes: 3 additions & 13 deletions Observer/TriggerSubscribeDeleteObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,21 @@
namespace Remarkety\Mgconnector\Observer;

use Magento\Framework\Event\ObserverInterface;
use \Magento\Customer\Model\Session;
use \Magento\Framework\Registry;
use \Magento\Newsletter\Model\Subscriber;
use \Magento\Customer\Model\Group;
use Remarkety\Mgconnector\Helper\ConfigHelper;
use \Remarkety\Mgconnector\Model\Queue;
use \Magento\Store\Model\Store;
use Magento\Store\Model\StoreManager;
use \Magento\Framework\App\Config\ScopeConfigInterface;
use Remarkety\Mgconnector\Serializer\AddressSerializer;
use Remarkety\Mgconnector\Serializer\CustomerSerializer;
use Remarkety\Mgconnector\Serializer\OrderSerializer;

class TriggerSubscribeDeleteObserver extends EventMethods implements ObserverInterface
{
public function execute(\Magento\Framework\Event\Observer $observer)
{
try {
$subscriber = $observer->getEvent()->getSubscriber();
if (!$this->_coreRegistry->registry('remarkety_subscriber_deleted_' . $subscriber->getEmail()) && $subscriber->getId()) {
$regKey = 'remarkety_subscriber_deleted_' . $subscriber->getEmail();
if (!$this->_coreRegistry->registry($regKey) && $subscriber->getId()) {
$this->makeRequest(
'newsletter/unsubscribed',
$this->_prepareCustomerSubscribtionDeleteData($subscriber),
$subscriber->getStoreId()
);
$this->_coreRegistry->register($regKey, 1, true);
}
} catch (\Exception $ex){
$this->logError($ex);
Expand Down
10 changes: 9 additions & 1 deletion Observer/TriggerSubscribeUpdateObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public function execute(\Magento\Framework\Event\Observer $observer){
if($subscriber->getId()) {
if ($this->_coreRegistry->registry('remarkety_subscriber_deleted_' . $subscriber->getSubscriberEmail()))
return $this;
if ($this->_coreRegistry->registry('remarkety_subscriber_updated_' . $subscriber->getSubscriberEmail()))
return $this;

$status = $subscriber->getStatus();
$eventType = 'newsletter/subscribed';
Expand All @@ -98,7 +100,12 @@ public function execute(\Magento\Framework\Event\Observer $observer){
return $this;
}

$this->makeRequest($eventType, $this->_prepareCustomerSubscribtionUpdateData($subscriber, $this->remoteAddress->getRemoteAddress()), $subscriber->getStoreId());
$customerId = $this->session->getCustomerId();
if(empty($customerId)){
$customerId = $this->_coreRegistry->registry('remarkety_customer_id');
}
$data = $this->_prepareCustomerSubscribtionUpdateData($subscriber, $this->remoteAddress->getRemoteAddress(), $customerId);
$this->makeRequest($eventType, $data, $subscriber->getStoreId());

if($this->_store->getId() != 0){
$email = $subscriber->getSubscriberEmail();
Expand All @@ -113,6 +120,7 @@ public function execute(\Magento\Framework\Event\Observer $observer){
}
}
}
$this->_coreRegistry->register('remarkety_subscriber_updated_' . $subscriber->getSubscriberEmail(), 1, true);
}
} catch (\Exception $ex){
$this->logError($ex);
Expand Down
15 changes: 12 additions & 3 deletions Serializer/CustomerSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Remarkety\Mgconnector\Serializer;


use Magento\Framework\App\RequestInterface;
use Magento\Newsletter\Model\Subscriber;
use Magento\Customer\Api\GroupRepositoryInterface as CustomerGroupRepository;

Expand All @@ -18,18 +19,26 @@ class CustomerSerializer
private $subscriber;
private $addressSerializer;
private $customerGroupRepository;
private $request;
public function __construct(
Subscriber $subscriber,
AddressSerializer $addressSerializer,
CustomerGroupRepository $customerGroupRepository
CustomerGroupRepository $customerGroupRepository,
RequestInterface $request
)
{
$this->subscriber = $subscriber;
$this->addressSerializer = $addressSerializer;
$this->customerGroupRepository = $customerGroupRepository;
$this->request = $request;
}
public function serialize(\Magento\Customer\Api\Data\CustomerInterface $customer){
$checkSubscriber = $this->subscriber->loadByEmail($customer->getEmail());
if ($this->request->getParam('is_subscribed', false)) {
$subscribed = true;
} else {
$checkSubscriber = $this->subscriber->loadByEmail($customer->getEmail());
$subscribed = $checkSubscriber->isSubscribed();
}

$created_at = new \DateTime($customer->getCreatedAt());
$updated_at = new \DateTime($customer->getUpdatedAt());
Expand All @@ -56,7 +65,7 @@ public function serialize(\Magento\Customer\Api\Data\CustomerInterface $customer
$customerInfo = [
'id' => (int)$customer->getId(),
'email' => $customer->getEmail(),
'accepts_marketing' => $checkSubscriber->isSubscribed(),
'accepts_marketing' => $subscribed,
'title' => $customer->getPrefix(),
'first_name' => $customer->getFirstname(),
'last_name' => $customer->getLastname(),
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 @@
"lib-libxml": "*"
},
"type": "magento2-module",
"version": "2.2.11",
"version": "2.2.12",
"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,5 +1,5 @@
<?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="Remarkety_Mgconnector" setup_version="2.2.11">
<module name="Remarkety_Mgconnector" setup_version="2.2.12">
</module>
</config>

0 comments on commit 8f3025d

Please sign in to comment.