2424use Magento \Framework \Controller \ResultFactory ;
2525use Magento \Framework \View \Result \PageFactory ;
2626use 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
2831class 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}
0 commit comments