Skip to content

Commit

Permalink
Merge pull request #288 from mageplaza/2.4-develop
Browse files Browse the repository at this point in the history
Clean code
  • Loading branch information
haitv282 authored Nov 19, 2020
2 parents efb942b + 03576dd commit 8517e17
Show file tree
Hide file tree
Showing 29 changed files with 350 additions and 333 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
39 changes: 21 additions & 18 deletions Block/Adminhtml/AbandonedCart/Edit/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,30 @@
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

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

use Exception;
use IntlDateFormatter;
use Magento\Backend\Block\Template\Context;
use Magento\Backend\Block\Widget\Form\Generic;
use Magento\Catalog\Helper\Data as CatalogHelper;
use Magento\Config\Model\Config\Source\Email\Identity;
use Magento\Config\Model\Config\Source\Email\Template;
use Magento\Customer\Api\GroupRepositoryInterface;
use Magento\Customer\Model\Address\Config as AddressConfig;
use Magento\Framework\Data\FormFactory;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Framework\Registry;
use Magento\Quote\Model\Quote;
use Magento\Quote\Model\Quote\Address;
use Magento\Quote\Model\Quote\Item;
use Mageplaza\Smtp\Model\Source\AbandonedCartStatus;
use Magento\Catalog\Helper\Data as CatalogHelper;
use Magento\Config\Model\Config\Source\Email\Identity;
use Magento\Config\Model\Config\Source\Email\Template;
use Magento\Tax\Model\Config as TaxConfig;
use Mageplaza\Smtp\Model\ResourceModel\Log\CollectionFactory as LogCollectionFactory;
use Mageplaza\Smtp\Helper\EmailMarketing;
use Magento\Customer\Api\GroupRepositoryInterface;
use Mageplaza\Smtp\Model\ResourceModel\Log\CollectionFactory as LogCollectionFactory;
use Mageplaza\Smtp\Model\Source\AbandonedCartStatus;

/**
* Class Form
Expand Down Expand Up @@ -128,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 @@ -186,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 @@ -222,10 +225,10 @@ public function getSentDateLogs($ids)
foreach ($collection as $log) {
$logDatesHtml .= $this->formatDate(
$log->getCreatedAt(),
\IntlDateFormatter::MEDIUM,
IntlDateFormatter::MEDIUM,
true
);
$logDatesHtml.='</br>';
$logDatesHtml .= '</br>';
}
}
}
Expand Down Expand Up @@ -354,13 +357,13 @@ public function isSingleStoreMode()
* @param Quote $quote
*
* @return string
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws NoSuchEntityException
*/
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
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
38 changes: 20 additions & 18 deletions Controller/Adminhtml/Smtp/AbandonedCart/Send.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
use Magento\Email\Model\Template\SenderResolver;
use Magento\Framework\App\Area;
use Magento\Framework\App\AreaList;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Mail\Template\TransportBuilder;
use Magento\Framework\Registry;
use Magento\Quote\Model\QuoteRepository;
use Magento\Framework\View\Result\Page;
use Psr\Log\LoggerInterface;
use Magento\Quote\Model\QuoteRepository;
use Mageplaza\Smtp\Helper\EmailMarketing;
use Psr\Log\LoggerInterface;

/**
* Class Send
Expand Down Expand Up @@ -105,39 +107,39 @@ 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);
}

/**
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface|Page
* @return ResponseInterface|ResultInterface|Page
*/
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
4 changes: 3 additions & 1 deletion Controller/Adminhtml/Smtp/Marketing.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@

namespace Mageplaza\Smtp\Controller\Adminhtml\Smtp;

use Magento\Backend\App\AbstractAction;

/**
* Class Forms
* @package Mageplaza\Smtp\Controller\Adminhtml\Smtp\Marketing
*/
class Marketing extends \Magento\Backend\App\AbstractAction
class Marketing extends AbstractAction
{
/**
* Authorization level of a basic admin session
Expand Down
18 changes: 10 additions & 8 deletions Controller/Adminhtml/Smtp/Sync/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
use Exception;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\DB\Adapter\AdapterInterface;
use Mageplaza\Smtp\Helper\EmailMarketing;
use Magento\Customer\Model\CustomerFactory;
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as CustomerCollectionFactory;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\DB\Adapter\AdapterInterface;
use Mageplaza\Smtp\Helper\EmailMarketing;
use Zend_Db_Expr;

/**
Expand Down Expand Up @@ -73,13 +75,13 @@ public function __construct(
CustomerCollectionFactory $customerCollectionFactory
) {
$this->helperEmailMarketing = $helperEmailMarketing;
$this->customerFactory = $customerFactory;
$this->customerFactory = $customerFactory;
$this->customerCollectionFactory = $customerCollectionFactory;
parent::__construct($context);
}

/**
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface
* @return ResponseInterface|ResultInterface
*/
public function execute()
{
Expand All @@ -106,21 +108,21 @@ public function execute()
$data[] = $this->helperEmailMarketing->getCustomerData($customer, false, true);
$attributeData[] = [
'attribute_id' => $attribute->getId(),
'entity_id' => $customer->getId(),
'value' => 1
'entity_id' => $customer->getId(),
'value' => 1
];
}

$result['status'] = true;
$result['total'] = count($ids);
$result['total'] = count($ids);
$response = $this->helperEmailMarketing->syncCustomers($data);
if (isset($response['success'])) {
$table = $customerCollection->getTable('customer_entity_int');
$this->insertData($customerCollection->getConnection(), $attributeData, $table);
}

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

Expand Down
14 changes: 8 additions & 6 deletions Controller/Adminhtml/Smtp/Sync/EstimateCustomer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
use Exception;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as CustomerCollectionFactory;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Exception\LocalizedException;
use Mageplaza\Smtp\Helper\EmailMarketing;
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as CustomerCollectionFactory;

/**
* Class EstimateCustomer
Expand Down Expand Up @@ -64,13 +66,13 @@ public function __construct(
EmailMarketing $emailMarketing
) {
$this->customerCollectionFactory = $customerCollectionFactory;
$this->emailMarketing = $emailMarketing;
$this->emailMarketing = $emailMarketing;

parent::__construct($context);
}

/**
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface
* @return ResponseInterface|ResultInterface
*/
public function execute()
{
Expand All @@ -80,7 +82,7 @@ public function execute()
throw new LocalizedException(__('App ID or Secret Key is empty'));
}

$attribute = 'mp_smtp_is_synced';
$attribute = 'mp_smtp_is_synced';
$customerCollection = $this->customerCollectionFactory->create();
$storeId = $this->getRequest()->getParam('storeId');
$websiteId = $this->getRequest()->getParam('websiteId');
Expand All @@ -95,7 +97,7 @@ public function execute()
$ids = $customerCollection->addFieldToFilter($attribute, ['null' => 1])
->getAllIds();

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

if ($result['total'] === 0) {
Expand All @@ -106,7 +108,7 @@ public function execute()

} catch (Exception $e) {
$result = [
'status' => false,
'status' => false,
'message' => $e->getMessage()
];
}
Expand Down
12 changes: 7 additions & 5 deletions Controller/Adminhtml/Smtp/TestConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
use Exception;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\ResultInterface;
use Mageplaza\Smtp\Helper\EmailMarketing;

/**
Expand Down Expand Up @@ -59,23 +61,23 @@ public function __construct(
}

/**
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface
* @return ResponseInterface|ResultInterface
*/
public function execute()
{
try {

$result = [
'status' => true,
$result = [
'status' => true,
'content' => __('Email marketing connection is working properly.')
];
$appID = trim($this->getRequest()->getParam('appID'));
$appID = trim($this->getRequest()->getParam('appID'));
$secretKey = $this->getRequest()->getParam('secretKey');
$this->helperEmailMarketing->testConnection($appID, $secretKey);

} catch (Exception $e) {
$result = [
'status' => false,
'status' => false,
'content' => __('Can\'t connect to the email marketing app. Please check the app id and secret key.')
];
}
Expand Down
4 changes: 2 additions & 2 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
class Data extends AbstractData
{
const CONFIG_MODULE_PATH = 'smtp';
const EMAIL_MARKETING = 'email_marketing';
const CONFIG_GROUP_SMTP = 'configuration_option';
const EMAIL_MARKETING = 'email_marketing';
const CONFIG_GROUP_SMTP = 'configuration_option';
const DEVELOP_GROUP_SMTP = 'developer';

/**
Expand Down
Loading

0 comments on commit 8517e17

Please sign in to comment.