-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
15 changed files
with
452 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
/** | ||
* Loadquote | ||
* | ||
* @copyright Copyright © 2017 Ebizmarts Corp.. All rights reserved. | ||
* @author info@ebizmarts.com | ||
*/ | ||
|
||
namespace Ebizmarts\MailChimp\Block; | ||
|
||
use Magento\Framework\View\Element\Template; | ||
|
||
class Loadquote extends Template | ||
{ | ||
/** | ||
* @var string $_template | ||
*/ | ||
protected $_template = "loadquote.phtml"; | ||
|
||
// write your methods here... | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
<?php | ||
/** | ||
* Index | ||
* | ||
* @copyright Copyright © 2017 Ebizmarts Corp.. All rights reserved. | ||
* @author info@ebizmarts.com | ||
*/ | ||
|
||
namespace Ebizmarts\MailChimp\Controller\Cart; | ||
|
||
use Magento\Framework\App\Action\Action; | ||
use Magento\Framework\Controller\ResultFactory; | ||
use Magento\Framework\View\Result\PageFactory; | ||
use Magento\Framework\App\Action\Context; | ||
|
||
class Loadquote extends Action | ||
{ | ||
/** | ||
* @var PageFactory | ||
*/ | ||
protected $pageFactory; | ||
/** | ||
* @var \Magento\Quote\Model\QuoteFactory | ||
*/ | ||
protected $_quote; | ||
/** | ||
* @var \Magento\Customer\Model\Session | ||
*/ | ||
protected $_customerSession; | ||
/** | ||
* @var \Ebizmarts\MailChimp\Helper\Data | ||
*/ | ||
protected $_helper; | ||
/** | ||
* @var \Magento\Framework\Url | ||
*/ | ||
protected $_urlHelper; | ||
/** | ||
* @var \Magento\Framework\Message\ManagerInterface | ||
*/ | ||
protected $_message; | ||
/** | ||
* @var \Magento\Customer\Model\Url | ||
*/ | ||
protected $_customerUrl; | ||
|
||
/** | ||
* Loadquote constructor. | ||
* @param Context $context | ||
* @param PageFactory $pageFactory | ||
* @param \Magento\Quote\Model\QuoteFactory $quote | ||
* @param \Magento\Customer\Model\Session $customerSession | ||
* @param \Ebizmarts\MailChimp\Helper\Data $helper | ||
* @param \Magento\Framework\Url $urlHelper | ||
* @param \Magento\Framework\Message\ManagerInterface $message | ||
* @param \Magento\Customer\Model\Url $customerUrl | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
PageFactory $pageFactory, | ||
\Magento\Quote\Model\QuoteFactory $quote, | ||
\Magento\Customer\Model\Session $customerSession, | ||
\Ebizmarts\MailChimp\Helper\Data $helper, | ||
\Magento\Framework\Url $urlHelper, | ||
\Magento\Framework\Message\ManagerInterface $message, | ||
\Magento\Customer\Model\Url $customerUrl | ||
) | ||
{ | ||
$this->pageFactory = $pageFactory; | ||
$this->_quote = $quote; | ||
$this->_customerSession = $customerSession; | ||
$this->_helper = $helper; | ||
$this->_urlHelper = $urlHelper; | ||
$this->_message = $message; | ||
$this->_customerUrl = $customerUrl; | ||
parent::__construct($context); | ||
} | ||
|
||
/** | ||
* Index Action | ||
* | ||
* @return \Magento\Framework\View\Result\Page | ||
*/ | ||
public function execute() | ||
{ | ||
/** @var \Magento\Framework\View\Result\Page $resultPage */ | ||
$resultPage = $this->pageFactory->create(); | ||
$params = $this->getRequest()->getParams(); | ||
if(isset($params['id'])) { | ||
$quote = $this->_quote->create(); | ||
$quote->getResource()->load($quote,$params['id']); | ||
$magentoStoreId = $quote->getStoreId(); | ||
$mailchimpStoreId = $this->_helper->getConfigValue( | ||
\Ebizmarts\MailChimp\Helper\Data::XML_PATH_STORE, | ||
$magentoStoreId | ||
); | ||
$syncCommerce = $this->_helper->getChimpSyncEcommerce( | ||
$mailchimpStoreId, | ||
$params['id'], | ||
\Ebizmarts\MailChimp\Helper\Data::IS_QUOTE | ||
); | ||
if (!isset($params['token']) || $params['token'] != $syncCommerce->getMailchimpToken()) { | ||
// @error | ||
$this->_message->addErrorMessage(__("You can't access this cart")); | ||
$url = $this->_urlHelper->getUrl( | ||
$this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_ABANDONEDCART_PAGE, | ||
$magentoStoreId | ||
) | ||
); | ||
$this->_redirect($url); | ||
} else { | ||
if (isset($params['mc_cid'])) { | ||
$url = $this->_urlHelper->getUrl( | ||
$this->_helper->getConfigValue( | ||
\Ebizmarts\MailChimp\Helper\Data::XML_ABANDONEDCART_PAGE, | ||
$magentoStoreId, | ||
array('mc_cid'=> $params['mc_cid']) | ||
) | ||
); | ||
} | ||
else { | ||
$url = $this->_urlHelper->getUrl( | ||
$this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_ABANDONEDCART_PAGE, | ||
$magentoStoreId | ||
) | ||
); | ||
} | ||
$quote->setData('mailchimp_abandonedcart_flag', true); | ||
$quote->getResource()->save($quote); | ||
if (!$quote->getCustomerId()) { | ||
$this->_customerSession->setQuoteId($quote->getId()); | ||
$this->_redirect($url); | ||
} else { | ||
if ($this->_customerSession->isLoggedIn()) { | ||
$this->_redirect($url); | ||
} else { | ||
$this->_message->addNoticeMessage(__("Login to complete your order")); | ||
if (isset($params['mc_cid'])) { | ||
$url = $this->_urlHelper->getUrl( | ||
$this->_customerUrl->getLoginUrl(), | ||
array('mc_cid'=>$params['mc_cid']) | ||
); | ||
} | ||
else { | ||
$url = $this->_customerUrl->getLoginUrl(); | ||
} | ||
$this->_redirect($url); | ||
} | ||
} | ||
} | ||
} | ||
return $resultPage; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
/** | ||
* mc-magento2 Magento Component | ||
* | ||
* @category Ebizmarts | ||
* @package mc-magento2 | ||
* @author Ebizmarts Team <info@ebizmarts.com> | ||
* @copyright Ebizmarts (http://ebizmarts.com) | ||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | ||
* @date: 3/14/17 11:26 PM | ||
* @file: SaveBefore.php | ||
*/ | ||
namespace Ebizmarts\MailChimp\Observer\Sales\Order; | ||
|
||
use Magento\Framework\Event\Observer; | ||
|
||
class SubmitBefore implements \Magento\Framework\Event\ObserverInterface | ||
{ | ||
private $attributes = [ | ||
'mailchimp_abandonedcart_flag' | ||
]; | ||
public function execute(\Magento\Framework\Event\Observer $observer) | ||
{ | ||
/* @var \Magento\Sales\Model\Order $order */ | ||
$order = $observer->getEvent()->getData('order'); | ||
/* @var \Magento\Quote\Model\Quote $quote */ | ||
$quote = $observer->getEvent()->getData('quote'); | ||
|
||
foreach ($this->attributes as $attribute) { | ||
if ($quote->hasData($attribute)) { | ||
$order->setData($attribute, $quote->getData($attribute)); | ||
} | ||
} | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
/** | ||
* mc-magento2 Magento Component | ||
* | ||
* @category Ebizmarts | ||
* @package mc-magento2 | ||
* @author Ebizmarts Team <info@ebizmarts.com> | ||
* @copyright Ebizmarts (http://ebizmarts.com) | ||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | ||
* @date: 3/15/17 1:23 AM | ||
* @file: Monkey.php | ||
*/ | ||
namespace Ebizmarts\MailChimp\Ui\Component\Listing\Column; | ||
|
||
use \Magento\Sales\Api\OrderRepositoryInterface; | ||
use \Magento\Framework\View\Element\UiComponent\ContextInterface; | ||
use \Magento\Framework\View\Element\UiComponentFactory; | ||
use \Magento\Ui\Component\Listing\Columns\Column; | ||
use \Magento\Framework\Api\SearchCriteriaBuilder; | ||
use \Magento\Store\Model\StoreManagerInterface; | ||
|
||
class Monkey extends Column | ||
{ | ||
/** | ||
* @var OrderRepositoryInterface | ||
*/ | ||
protected $_orderRepository; | ||
/** | ||
* @var SearchCriteriaBuilder | ||
*/ | ||
protected $_searchCriteria; | ||
/** | ||
* @var \Magento\Framework\View\Asset\Repository | ||
*/ | ||
protected $_assetRepository; | ||
/** | ||
* @var \Magento\Framework\App\RequestInterface | ||
*/ | ||
protected $_requestInterfase; | ||
|
||
/** | ||
* Monkey constructor. | ||
* @param ContextInterface $context | ||
* @param UiComponentFactory $uiComponentFactory | ||
* @param OrderRepositoryInterface $orderRepository | ||
* @param \Magento\Framework\View\Asset\Repository $assetRepository | ||
* @param \Magento\Framework\App\RequestInterface $requestInterface | ||
* @param SearchCriteriaBuilder $criteria | ||
* @param array $components | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
ContextInterface $context, | ||
UiComponentFactory $uiComponentFactory, | ||
OrderRepositoryInterface $orderRepository, | ||
\Magento\Framework\View\Asset\Repository $assetRepository, | ||
\Magento\Framework\App\RequestInterface $requestInterface, | ||
SearchCriteriaBuilder $criteria, | ||
array $components = [], | ||
array $data = [] | ||
) | ||
{ | ||
$this->_orderRepository = $orderRepository; | ||
$this->_searchCriteria = $criteria; | ||
$this->_assetRepository = $assetRepository; | ||
$this->_requestInterfase= $requestInterface; | ||
parent::__construct($context, $uiComponentFactory, $components, $data); | ||
} | ||
|
||
public function prepareDataSource(array $dataSource) | ||
{ | ||
if (isset($dataSource['data']['items'])) { | ||
foreach ($dataSource['data']['items'] as & $item) { | ||
|
||
$order = $this->_orderRepository->get($item["entity_id"]); | ||
$status = $order->getData("mailchimp_abandonedcart_flag"); | ||
$fieldName = $this->getData('name'); | ||
|
||
switch ($status) { | ||
case "0": | ||
$item[$fieldName . '_src'] = ''; | ||
$item[$fieldName . '_alt'] = ''; | ||
$item[$fieldName . '_link'] = ''; | ||
$item[$fieldName . '_orig_src'] = ''; | ||
$item[$fieldName . '_class'] = ''; | ||
break; | ||
case "1": | ||
$params = array('_secure' => $this->_requestInterfase->isSecure()); | ||
$url = $this->_assetRepository->getUrlWithParams('Ebizmarts_MailChimp::images/logo-freddie-monocolor-200.png', $params); | ||
$item[$fieldName . '_src'] = $url; | ||
$item[$fieldName . '_alt'] = 'hep hep thanks MailChimp'; | ||
$item[$fieldName . '_link'] = ''; | ||
// $item[$fieldName . '_orig_src'] = $url; | ||
break; | ||
|
||
} | ||
} | ||
} | ||
|
||
return $dataSource; | ||
} | ||
} |
Oops, something went wrong.