Skip to content

Commit 94ce0a6

Browse files
committed
remove abandoned tags when load quote
1 parent a44b306 commit 94ce0a6

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

Controller/Cart/Loadquote.php

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,22 @@
2424
use Magento\Framework\Controller\ResultFactory;
2525
use Magento\Framework\View\Result\PageFactory;
2626
use Magento\Framework\App\Action\Context;
27+
use Lof\Mautic\Queue\MessageQueues\Order\Publisher;
28+
use Lof\Mautic\Model\Mautic\Contact;
29+
use Lof\Mautic\Helper\Data;
2730

2831
class Loadquote extends \Magento\Framework\App\Action\Action
2932
{
33+
/**
34+
* @var Publisher|null
35+
*/
36+
private $_publisher = null;
37+
38+
/**
39+
* @var Lof\Mautic\Model\Mautic\Contact|null
40+
*/
41+
protected $_mauticContact = null;
42+
3043
/**
3144
* @var PageFactory
3245
*/
@@ -70,6 +83,8 @@ class Loadquote extends \Magento\Framework\App\Action\Action
7083
* @param \Lof\Mautic\Helper\Data $helper
7184
* @param \Magento\Framework\Url $urlHelper
7285
* @param \Magento\Customer\Model\Url $customerUrl
86+
* @param Publisher $publisher
87+
* @param Contact $mauticContact
7388
*/
7489
public function __construct(
7590
Context $context,
@@ -79,7 +94,9 @@ public function __construct(
7994
\Magento\Checkout\Model\Session $checkoutSession,
8095
\Lof\Mautic\Helper\Data $helper,
8196
\Magento\Framework\Url $urlHelper,
82-
\Magento\Customer\Model\Url $customerUrl
97+
\Magento\Customer\Model\Url $customerUrl,
98+
Publisher $publisher,
99+
Contact $mauticContact
83100
) {
84101

85102
$this->pageFactory = $pageFactory;
@@ -90,6 +107,9 @@ public function __construct(
90107
$this->_message = $context->getMessageManager();
91108
$this->_customerUrl = $customerUrl;
92109
$this->_checkoutSession = $checkoutSession;
110+
$this->_publisher = $publisher;
111+
$this->_mauticContact = $mauticContact;
112+
93113
parent::__construct($context);
94114
}
95115

@@ -135,6 +155,10 @@ public function execute()
135155

136156
$quote->getResource()->save($quote);
137157

158+
if ($emailAddress = $quote->getCustomerEmail()) {
159+
$this->processUpdateContactTag($emailAddress, $quote->getStoreId());
160+
}
161+
138162
if (!$quote->getCustomerId()) {
139163
$this->_checkoutSession->setQuoteId($quote->getId());
140164
$this->_redirect($url);
@@ -158,4 +182,30 @@ public function execute()
158182
}
159183
return $resultPage;
160184
}
185+
186+
/**
187+
* process update contact tags
188+
*
189+
* @param string $email
190+
* @param int|string|null $storeId
191+
* @return bool
192+
*/
193+
protected function processUpdateContactTag($email, $storeId = null)
194+
{
195+
if ($this->_helper->isEnabled($storeId)) {
196+
$removeTags = "-".(Data::ABANDONED_CART_TAGS);
197+
$data = [
198+
"email" => $email,
199+
"tags" => $removeTags
200+
];
201+
if (!$this->_helper->isAyncApi($storeId)) {
202+
$this->_mauticContact->exportContact($data);
203+
} else {
204+
$this->_publisher->execute(
205+
$this->_helper->encodeData($data)
206+
);
207+
}
208+
}
209+
return true;
210+
}
161211
}

Helper/Data.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ class Data extends AbstractHelper
126126
*/
127127
const XML_PATH_BASE_URL = 'web/unsecure/base_url';
128128

129+
/**
130+
* Default tags for abandoned cart
131+
*/
132+
const ABANDONED_CART_TAGS = 'AbandonedCart';
133+
129134
protected $_storeManager;
130135
protected $_directoryList;
131136
protected $encryptor;

Queue/Processor/AbandonedCartProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ protected function _processAbandoned($storeId)
120120
"email" => $cart->getCustomerEmail(),
121121
"firstname" => $cart->getFirstname(),
122122
"lastname" => $cart->getLastname(),
123-
"tags" => "Abandoned Cart"
123+
"tags" => Data::ABANDONED_CART_TAGS
124124
];
125125
$customer = $this->helperData->getCustomerById($cart->getCustomerId());
126126
if (!$this->helperData->isAyncApi()) {

0 commit comments

Comments
 (0)