1+ <?php
2+ /**
3+ * Landofcoder
4+ *
5+ * NOTICE OF LICENSE
6+ *
7+ * This source file is subject to the Landofcoder.com license that is
8+ * available through the world-wide-web at this URL:
9+ * https://landofcoder.com/terms
10+ *
11+ * DISCLAIMER
12+ *
13+ * Do not edit or add to this file if you wish to upgrade this extension to newer
14+ * version in the future.
15+ *
16+ * @category Landofcoder
17+ * @package Lof_Mautic
18+ * @copyright Copyright (c) 2021 Landofcoder (https://www.landofcoder.com/)
19+ * @license https://landofcoder.com/terms
20+ */
21+ namespace Lof \Mautic \Controller \Cart ;
22+
23+ use Magento \Framework \App \Action \Action ;
24+ use Magento \Framework \Controller \ResultFactory ;
25+ use Magento \Framework \View \Result \PageFactory ;
26+ use Magento \Framework \App \Action \Context ;
27+
28+ class Loadquote extends \Magento \Framework \App \Action \Action
29+ {
30+ /**
31+ * @var PageFactory
32+ */
33+ protected $ pageFactory ;
34+ /**
35+ * @var \Magento\Quote\Model\QuoteFactory
36+ */
37+ protected $ _quote ;
38+ /**
39+ * @var \Magento\Customer\Model\Session
40+ */
41+ protected $ _customerSession ;
42+ /**
43+ * @var \Ebizmarts\MailChimp\Helper\Data
44+ */
45+ protected $ _helper ;
46+ /**
47+ * @var \Magento\Framework\Url
48+ */
49+ protected $ _urlHelper ;
50+ /**
51+ * @var \Magento\Framework\Message\ManagerInterface
52+ */
53+ protected $ _message ;
54+ /**
55+ * @var \Magento\Customer\Model\Url
56+ */
57+ protected $ _customerUrl ;
58+ /**
59+ * @var \Magento\Checkout\Model\Session
60+ */
61+ protected $ _checkoutSession ;
62+
63+ /**
64+ * Loadquote constructor.
65+ * @param Context $context
66+ * @param PageFactory $pageFactory
67+ * @param \Magento\Quote\Model\QuoteFactory $quote
68+ * @param \Magento\Customer\Model\Session $customerSession
69+ * @param \Magento\Checkout\Model\Session $checkoutSession
70+ * @param \Lof\Mautic\Helper\Data $helper
71+ * @param \Magento\Framework\Url $urlHelper
72+ * @param \Magento\Customer\Model\Url $customerUrl
73+ */
74+ public function __construct (
75+ Context $ context ,
76+ PageFactory $ pageFactory ,
77+ \Magento \Quote \Model \QuoteFactory $ quote ,
78+ \Magento \Customer \Model \Session $ customerSession ,
79+ \Magento \Checkout \Model \Session $ checkoutSession ,
80+ \Lof \Mautic \Helper \Data $ helper ,
81+ \Magento \Framework \Url $ urlHelper ,
82+ \Magento \Customer \Model \Url $ customerUrl
83+ ) {
84+
85+ $ this ->pageFactory = $ pageFactory ;
86+ $ this ->_quote = $ quote ;
87+ $ this ->_customerSession = $ customerSession ;
88+ $ this ->_helper = $ helper ;
89+ $ this ->_urlHelper = $ urlHelper ;
90+ $ this ->_message = $ context ->getMessageManager ();
91+ $ this ->_customerUrl = $ customerUrl ;
92+ $ this ->_checkoutSession = $ checkoutSession ;
93+ parent ::__construct ($ context );
94+ }
95+
96+ public function execute ()
97+ {
98+ /** @var \Magento\Framework\View\Result\Page $resultPage */
99+ $ resultPage = $ this ->pageFactory ->create ();
100+ $ params = $ this ->getRequest ()->getParams ();
101+ if (isset ($ params ['id ' ]) && $ params ['id ' ]) {
102+ $ quote = $ this ->_quote ->create ();
103+ $ quote ->getResource ()->load ($ quote , $ params ['id ' ]);
104+ $ magentoStoreId = $ quote ->getStoreId ();
105+ $ configSecretKey = $ this ->_helper ->getConfig ("general/webhook_secret " );
106+
107+ if (!isset ($ params ['token ' ]) || $ params ['token ' ] != $ configSecretKey ) {
108+ // @error
109+ $ this ->_message ->addErrorMessage (__ ("You can't access this cart " ));
110+ $ url = $ this ->_urlHelper ->getUrl (
111+ $ this ->_helper ->getConfig (
112+ \Lof \Mautic \Helper \Data::MODULE_ABANDONEDCART_PAGE ,
113+ $ magentoStoreId
114+ )
115+ );
116+ $ this ->_redirect ($ url );
117+ } else {
118+ if (isset ($ params ['mt_cid ' ])) {
119+ $ url = $ this ->_urlHelper ->getUrl (
120+ $ this ->_helper ->getConfig (
121+ \Lof \Mautic \Helper \Data::MODULE_ABANDONEDCART_PAGE ,
122+ $ magentoStoreId
123+ ),
124+ ['mt_cid ' => $ params ['mt_cid ' ]]
125+ );
126+ $ quote ->setData ('mautic_campaign_id ' , $ params ['mt_cid ' ]);
127+ } else {
128+ $ url = $ this ->_urlHelper ->getUrl (
129+ $ this ->_helper ->getConfig (
130+ \Lof \Mautic \Helper \Data::MODULE_ABANDONEDCART_PAGE ,
131+ $ magentoStoreId
132+ )
133+ );
134+ }
135+
136+ $ quote ->getResource ()->save ($ quote );
137+
138+ if (!$ quote ->getCustomerId ()) {
139+ $ this ->_checkoutSession ->setQuoteId ($ quote ->getId ());
140+ $ this ->_redirect ($ url );
141+ } else {
142+ if ($ this ->_customerSession ->isLoggedIn ()) {
143+ $ this ->_redirect ($ url );
144+ } else {
145+ $ this ->_message ->addNoticeMessage (__ ("Login to complete your order " ));
146+ if (isset ($ params ['mt_cid ' ])) {
147+ $ url = $ this ->_urlHelper ->getUrl (
148+ $ this ->_customerUrl ->getLoginUrl (),
149+ ['mt_cid ' =>$ params ['mt_cid ' ]]
150+ );
151+ } else {
152+ $ url = $ this ->_customerUrl ->getLoginUrl ();
153+ }
154+ $ this ->_redirect ($ url );
155+ }
156+ }
157+ }
158+ }
159+ return $ resultPage ;
160+ }
161+ }
0 commit comments