Skip to content

Commit a44b306

Browse files
committed
updated new code for abandoned cart
1 parent 8a80e80 commit a44b306

33 files changed

+1238
-53
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
./dev
33
.test
44
.test/*
5+
.ideal
6+
.ideal/
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
namespace Lof\Mautic\Block\Adminhtml\System\Config;
3+
4+
class Date extends \Magento\Config\Block\System\Config\Form\Field
5+
{
6+
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
7+
{
8+
$element->setDateFormat(\Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT);
9+
$element->setTimeFormat(null);
10+
return parent::render($element);
11+
}
12+
13+
}

Block/Loadquote.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
22+
namespace Lof\Mautic\Block;
23+
24+
use Magento\Framework\View\Element\Template;
25+
26+
class Loadquote extends Template
27+
{
28+
/**
29+
* @var string $_template
30+
*/
31+
protected $_template = "Lof_Mautic::loadquote.phtml";
32+
33+
// write your methods here...
34+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
3+
namespace Lof\Mautic\Console\Command;
4+
5+
use Lof\Mautic\Queue\Processor\AbandonedCartProcessorFactory;
6+
use Magento\Framework\App\Area;
7+
use Magento\Framework\App\State;
8+
use Magento\Framework\Registry;
9+
use Symfony\Component\Console\Command\Command;
10+
use Symfony\Component\Console\Input\InputInterface;
11+
use Symfony\Component\Console\Output\OutputInterface;
12+
13+
/**
14+
* Class AbandonedCartCommand
15+
*/
16+
class AbandonedCartCommand extends Command
17+
{
18+
/**
19+
* @var AbandonedCartProcessorFactory
20+
*/
21+
private $abandonedCartProcessorFactory;
22+
/**
23+
* @var State
24+
*/
25+
private $state;
26+
27+
/**
28+
* @var Registry
29+
*/
30+
private $registry;
31+
32+
/**
33+
* CategoryImport constructor.
34+
*
35+
* @param ExportCustomersProcessorFactory $abandonedCartProcessorFactory
36+
* @param State $state
37+
* @param Registry $registry
38+
* @param null $name
39+
*/
40+
public function __construct(
41+
ExportCustomersProcessorFactory $abandonedCartProcessorFactory,
42+
State $state,
43+
Registry $registry,
44+
$name = null
45+
) {
46+
parent::__construct($name);
47+
48+
$this->abandonedCartProcessorFactory = $abandonedCartProcessorFactory;
49+
$this->state = $state;
50+
$this->registry = $registry;
51+
}
52+
53+
/**
54+
* Configures the current command.a
55+
*
56+
* @return void
57+
*/
58+
public function configure()
59+
{
60+
$this->setName('lofmautic:export:abandoned');
61+
$this->setDescription('Process export all contacts Data from Abandoned Cart to Mautic');
62+
}
63+
64+
/**
65+
* @param InputInterface $input
66+
* @param OutputInterface $output
67+
*
68+
* @return int|null
69+
*
70+
*/
71+
protected function execute(InputInterface $input, OutputInterface $output)
72+
{
73+
try {
74+
$this->state->setAreaCode(Area::AREA_ADMINHTML);
75+
} catch (\Exception $ex) {
76+
// fail gracefully
77+
}
78+
79+
if (!$this->registry->registry('isSecureArea')) {
80+
$this->registry->register('isSecureArea', true);
81+
}
82+
83+
$start = $this->getCurrentMs();
84+
85+
$output->writeln('<info>Initialization exporting of contacts of all customers.</info>');
86+
$output->writeln(sprintf('<info>Started at %s</info>', (new \DateTime())->format('Y-m-d H:i:s')));
87+
$output->writeln('Exporting...');
88+
89+
$abandonedCartProcessor = $this->abandonedCartProcessorFactory->create();
90+
91+
$abandonedCartProcessor->process();
92+
93+
$end = $this->getCurrentMs();
94+
95+
$output->writeln(sprintf('<info>Finished at %s</info>', (new \DateTime())->format('Y-m-d H:i:s')));
96+
$output->writeln(sprintf('<info>Total execution time %sms</info>', $end - $start));
97+
98+
return 0;
99+
}
100+
101+
/**
102+
*
103+
* @return float|int
104+
*/
105+
private function getCurrentMs()
106+
{
107+
$mt = explode(' ', microtime());
108+
109+
return ((int) $mt[1]) * 1000 + ((int) round($mt[0] * 1000));
110+
}
111+
}

Controller/Cart/Loadquote.php

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
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+
}

Controller/MauticAbstract.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11
<?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+
*/
221
namespace Lof\Mautic\Controller;
322

423
use Magento\Framework\App\Action\Action;

Controller/Webhook/Index.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
<?php
2-
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+
*/
321
namespace Lof\Mautic\Controller\Webhook;
422

523
use Magento\Framework\DataObject;

0 commit comments

Comments
 (0)