Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.4-develop' into 2.3-develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	Block/Script.php
#	Controller/Adminhtml/Smtp/Sync/Customer.php
#	Controller/Adminhtml/Smtp/Sync/EstimateCustomer.php
#	Controller/Adminhtml/Smtp/TestConnection.php
#	Helper/EmailMarketing.php
#	Observer/Customer/SubscriberSaveCommitAfter.php
#	Observer/Order/OrderComplete.php
#	Observer/Order/OrderCreate.php
#	Observer/Order/ShipmentCreate.php
#	Observer/Quote/DeleteQuote.php
#	Observer/Quote/SyncQuote.php
#	Setup/UpgradeData.php
#	composer.json
#	etc/adminhtml/menu.xml
#	i18n/en_US.csv
  • Loading branch information
JackerNgo committed Jan 18, 2021
2 parents f8597ce + bb4ff7e commit c5a97d7
Show file tree
Hide file tree
Showing 36 changed files with 1,504 additions and 675 deletions.
8 changes: 4 additions & 4 deletions Block/AbandonedCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ public function __construct(
EmailMarketing $helperEmailMarketing,
array $data = []
) {
$this->_productRepository = $productRepository;
$this->priceCurrency = $priceCurrency;
$this->taxHelper = $context->getTaxData();
$this->quoteFactory = $quoteFactory;
$this->_productRepository = $productRepository;
$this->priceCurrency = $priceCurrency;
$this->taxHelper = $context->getTaxData();
$this->quoteFactory = $quoteFactory;
$this->helperEmailMarketing = $helperEmailMarketing;
parent::__construct($context, $data);
}
Expand Down
19 changes: 10 additions & 9 deletions Block/Adminhtml/AbandonedCart/Edit/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

namespace Mageplaza\Smtp\Block\Adminhtml\AbandonedCart\Edit;

use Exception;
Expand Down Expand Up @@ -130,14 +131,14 @@ public function __construct(
GroupRepositoryInterface $groupRepository,
array $data = []
) {
$this->addressConfig = $addressConfig;
$this->priceCurrency = $priceCurrency;
$this->emailIdentity = $emailIdentity;
$this->emailTemplate = $emailTemplate;
$this->taxConfig = $taxConfig;
$this->addressConfig = $addressConfig;
$this->priceCurrency = $priceCurrency;
$this->emailIdentity = $emailIdentity;
$this->emailTemplate = $emailTemplate;
$this->taxConfig = $taxConfig;
$this->logCollectionFactory = $logCollectionFactory;
$this->helperEmailMarketing = $helperEmailMarketing;
$this->groupRepository = $groupRepository;
$this->groupRepository = $groupRepository;

parent::__construct($context, $registry, $formFactory, $data);
}
Expand Down Expand Up @@ -188,7 +189,7 @@ public function getHelperEmailMarketing()
*/
public function getSubtotal(Quote $quote, $inclTax = false)
{
$address = $quote->isVirtual() ? $quote->getBillingAddress() : $quote->getShippingAddress();
$address = $quote->isVirtual() ? $quote->getBillingAddress() : $quote->getShippingAddress();
$subtotal = $inclTax ? $address->getSubtotalInclTax() : $address->getSubtotal();

return $this->formatPrice($subtotal, $quote->getId());
Expand Down Expand Up @@ -361,8 +362,8 @@ public function isSingleStoreMode()
public function getStoreName(Quote $quote)
{
$storeId = $quote->getStoreId();
$store = $this->_storeManager->getStore($storeId);
$name = [$store->getWebsite()->getName(), $store->getGroup()->getName(), $store->getName()];
$store = $this->_storeManager->getStore($storeId);
$name = [$store->getWebsite()->getName(), $store->getGroup()->getName(), $store->getName()];

return implode('<br/>', $name);
}
Expand Down
26 changes: 25 additions & 1 deletion Block/Adminhtml/System/Config/SyncCustomer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SyncCustomer extends Button
/**
* @var string
*/
protected $_template = 'system/config/sync-customer.phtml';
protected $_template = 'system/config/sync-template.phtml';

/**
* @return string
Expand Down Expand Up @@ -63,4 +63,28 @@ public function getSyncSuccessMessage()
{
return __('Customer synchronization has been completed.');
}

/**
* @return string
*/
public function getElementId()
{
return 'mp-sync-customer';
}

/**
* @return string
*/
public function getComponent()
{
return 'Mageplaza_Smtp/js/sync/customer';
}

/**
* @return bool
*/
public function isRenderCss()
{
return true;
}
}
90 changes: 90 additions & 0 deletions Block/Adminhtml/System/Config/SyncOrder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Smtp
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

namespace Mageplaza\Smtp\Block\Adminhtml\System\Config;

/**
* Class SyncOrder
* @package Mageplaza\Smtp\Block\Adminhtml\System\Config
*/
class SyncOrder extends Button
{
/**
* @var string
*/
protected $_template = 'system/config/sync-template.phtml';

/**
* @return string
*/
public function getEstimateUrl()
{
return $this->getUrl('adminhtml/smtp_sync/estimateorder', ['_current' => true]);
}

/**
* @return mixed
*/
public function getWebsiteId()
{
return $this->getRequest()->getParam('website');
}

/**
* @return mixed
*/
public function getStoreId()
{
return $this->getRequest()->getParam('store');
}

/**
* @return mixed
*/
public function getSyncSuccessMessage()
{
return __('Order synchronization has been completed.');
}

/**
* @return string
*/
public function getElementId()
{
return 'mp-sync-order';
}

/**
* @return string
*/
public function getComponent()
{
return 'Mageplaza_Smtp/js/sync/order';
}

/**
* @return bool
*/
public function isRenderCss()
{
return false;
}
}
4 changes: 2 additions & 2 deletions Block/Script.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct(
array $data = []
) {
$this->helperEmailMarketing = $helperEmailMarketing;
$this->checkoutSession = $checkoutSession;
$this->checkoutSession = $checkoutSession;
parent::__construct($context, $data);
}

Expand All @@ -76,7 +76,7 @@ public function getHelperEmailMarketing()
public function isSuccessPage()
{
$fullActionName = $this->getRequest()->getFullActionName();
$pages = ['checkout_onepage_success', 'mpthankyoupage_index_index'];
$pages = ['checkout_onepage_success', 'mpthankyoupage_index_index'];

return in_array($fullActionName, $pages);
}
Expand Down
30 changes: 15 additions & 15 deletions Controller/Adminhtml/Smtp/AbandonedCart/Send.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ public function __construct(
Registry $registry,
EmailMarketing $helperEmailMarketing
) {
$this->quoteRepository = $quoteRepository;
$this->logger = $logger;
$this->emailTemplate = $emailTemplate;
$this->areaList = $areaList;
$this->senderResolver = $senderResolver;
$this->transportBuilder = $transportBuilder;
$this->registry = $registry;
$this->quoteRepository = $quoteRepository;
$this->logger = $logger;
$this->emailTemplate = $emailTemplate;
$this->areaList = $areaList;
$this->senderResolver = $senderResolver;
$this->transportBuilder = $transportBuilder;
$this->registry = $registry;
$this->helperEmailMarketing = $helperEmailMarketing;

parent::__construct($context);
Expand All @@ -127,19 +127,19 @@ public function execute()
$id = $this->getRequest()->getParam('id', 0);

try {
$quote = $this->quoteRepository->get($id);
$quote = $this->quoteRepository->get($id);
$customerEmail = $quote->getCustomerEmail();
$customerName = $this->helperEmailMarketing->getCustomerName($quote);
$customerName = $this->helperEmailMarketing->getCustomerName($quote);

$from = $this->getRequest()->getParam('sender');
$templateId = $this->getRequest()->getParam('email_template');
$from = $this->getRequest()->getParam('sender');
$templateId = $this->getRequest()->getParam('email_template');
$additionalMessage = $this->getRequest()->getParam('additional_message');
$from = $this->senderResolver->resolve($from, $quote->getStoreId());
$recoveryUrl = $this->helperEmailMarketing->getRecoveryUrl($quote);
$from = $this->senderResolver->resolve($from, $quote->getStoreId());
$recoveryUrl = $this->helperEmailMarketing->getRecoveryUrl($quote);

$vars = [
'quote_id' => $quote->getId(),
'customer_name' => ucfirst($customerName),
'quote_id' => $quote->getId(),
'customer_name' => ucfirst($customerName),
'additional_message' => trim(strip_tags($additionalMessage)),
'cart_recovery_link' => $recoveryUrl
];
Expand Down
119 changes: 119 additions & 0 deletions Controller/Adminhtml/Smtp/Sync/AbstractEstimate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Smtp
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

namespace Mageplaza\Smtp\Controller\Adminhtml\Smtp\Sync;

use Exception;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Exception\LocalizedException;
use Mageplaza\Smtp\Helper\EmailMarketing;
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
use Magento\Framework\Phrase;

/**
* Class AbstractEstimate
* @package Mageplaza\Smtp\Controller\Adminhtml\Smtp\Sync
*/
abstract class AbstractEstimate extends Action
{
/**
* Authorization level of a basic admin session
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'Mageplaza_Smtp::email_marketing';

/**
* @var EmailMarketing
*/
protected $emailMarketing;

/**
* AbstractEstimate constructor.
*
* @param Context $context
* @param EmailMarketing $emailMarketing
*/
public function __construct(
Context $context,
EmailMarketing $emailMarketing
) {
$this->emailMarketing = $emailMarketing;

parent::__construct($context);
}

/**
* @return ResponseInterface|ResultInterface
*/
public function execute()
{
try {

if (!$this->emailMarketing->getAppID() || !$this->emailMarketing->getSecretKey()) {
throw new LocalizedException(__('App ID or Secret Key is empty'));
}

$collection = $this->prepareCollection();
$storeId = $this->getRequest()->getParam('storeId');
$websiteId = $this->getRequest()->getParam('websiteId');
if ($storeId) {
$collection->addFieldToFilter('store_id', $storeId);
}

if ($websiteId) {
$collection->addFieldToFilter('website_id', $websiteId);
}

$ids = $collection->getAllIds();

$result['ids'] = $ids;
$result['total'] = count($ids);

if ($result['total'] === 0) {
$result['message'] = $this->getZeroMessage();
}

$result['status'] = true;

} catch (Exception $e) {
$result = [
'status' => false,
'message' => $e->getMessage()
];
}

return $this->getResponse()->representJson(EmailMarketing::jsonEncode($result));
}

/**
* @return AbstractCollection
*/
abstract public function prepareCollection();

/**
* @return Phrase
*/
abstract public function getZeroMessage();
}
Loading

0 comments on commit c5a97d7

Please sign in to comment.