Skip to content

Commit

Permalink
Update endpoint and improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
JackerNgo committed Oct 1, 2020
1 parent 03ec50e commit b1d14ee
Show file tree
Hide file tree
Showing 21 changed files with 489 additions and 503 deletions.
26 changes: 13 additions & 13 deletions Block/AbandonedCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
use Magento\Store\Model\Store;
use Magento\Tax\Helper\Data;
use Magento\Tax\Model\Config;
use Mageplaza\Smtp\Helper\AbandonedCart as HelperAbandonedCart;
use Mageplaza\Smtp\Helper\EmailMarketing;

/**
* Class AbandonedCart
Expand Down Expand Up @@ -63,9 +63,9 @@ class AbandonedCart extends Template
protected $quoteFactory;

/**
* @var HelperAbandonedCart
* @var EmailMarketing
*/
protected $helperAbandonedCart;
protected $helperEmailMarketing;

/**
* AbandonedCart constructor.
Expand All @@ -74,22 +74,22 @@ class AbandonedCart extends Template
* @param ProductRepositoryInterface $productRepository
* @param PriceCurrency $priceCurrency
* @param QuoteFactory $quoteFactory
* @param HelperAbandonedCart $helperAbandonedCart
* @param EmailMarketing $helperEmailMarketing
* @param array $data
*/
public function __construct(
Context $context,
ProductRepositoryInterface $productRepository,
PriceCurrency $priceCurrency,
QuoteFactory $quoteFactory,
HelperAbandonedCart $helperAbandonedCart,
EmailMarketing $helperEmailMarketing,
array $data = []
) {
$this->_productRepository = $productRepository;
$this->priceCurrency = $priceCurrency;
$this->taxHelper = $context->getTaxData();
$this->quoteFactory = $quoteFactory;
$this->helperAbandonedCart = $helperAbandonedCart;
$this->_productRepository = $productRepository;
$this->priceCurrency = $priceCurrency;
$this->taxHelper = $context->getTaxData();
$this->quoteFactory = $quoteFactory;
$this->helperEmailMarketing = $helperEmailMarketing;
parent::__construct($context, $data);
}

Expand All @@ -106,11 +106,11 @@ public function getQuote()
}

/**
* @return HelperAbandonedCart
* @return EmailMarketing
*/
public function getHelperAbandonedCart()
public function getHelperEmailMarketing()
{
return $this->helperAbandonedCart;
return $this->helperEmailMarketing;
}

/**
Expand Down
55 changes: 26 additions & 29 deletions Block/Adminhtml/AbandonedCart/Edit/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,27 @@
* @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\Helper\AbandonedCart;
use Mageplaza\Smtp\Model\ResourceModel\Log\CollectionFactory as LogCollectionFactory;
use Mageplaza\Smtp\Model\Source\AbandonedCartStatus;
use Mageplaza\Smtp\Helper\EmailMarketing;
use Magento\Customer\Api\GroupRepositoryInterface;

/**
* Class Form
Expand Down Expand Up @@ -90,9 +87,9 @@ class Form extends Generic
protected $logCollectionFactory;

/**
* @var AbandonedCart
* @var EmailMarketing
*/
protected $helperAbandonedCart;
protected $helperEmailMarketing;

/**
* Group service
Expand All @@ -113,7 +110,7 @@ class Form extends Generic
* @param Template $emailTemplate
* @param TaxConfig $taxConfig
* @param LogCollectionFactory $logCollectionFactory
* @param AbandonedCart $helperAbandonedCart
* @param EmailMarketing $helperEmailMarketing
* @param GroupRepositoryInterface $groupRepository
* @param array $data
*/
Expand All @@ -127,18 +124,18 @@ public function __construct(
Template $emailTemplate,
TaxConfig $taxConfig,
LogCollectionFactory $logCollectionFactory,
AbandonedCart $helperAbandonedCart,
EmailMarketing $helperEmailMarketing,
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->helperAbandonedCart = $helperAbandonedCart;
$this->groupRepository = $groupRepository;
$this->helperEmailMarketing = $helperEmailMarketing;
$this->groupRepository = $groupRepository;

parent::__construct($context, $registry, $formFactory, $data);
}
Expand Down Expand Up @@ -174,11 +171,11 @@ public function displayCartSubtotalBoth($storeId)
}

/**
* @return AbandonedCart
* @return EmailMarketing
*/
public function getHelperAbandonedCart()
public function getHelperEmailMarketing()
{
return $this->helperAbandonedCart;
return $this->helperEmailMarketing;
}

/**
Expand All @@ -189,7 +186,7 @@ public function getHelperAbandonedCart()
*/
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 @@ -225,10 +222,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 @@ -357,13 +354,13 @@ public function isSingleStoreMode()
* @param Quote $quote
*
* @return string
* @throws NoSuchEntityException
* @throws \Magento\Framework\Exception\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
22 changes: 11 additions & 11 deletions Block/Script.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
use Magento\Checkout\Model\Session;
use Magento\Framework\View\Element\Template;
use Magento\Sales\Model\Order;
use Mageplaza\Smtp\Helper\AbandonedCart as HelperAbandonedCart;
use Mageplaza\Smtp\Helper\EmailMarketing;

/**
* Class Script
Expand All @@ -34,9 +34,9 @@
class Script extends Template
{
/**
* @var HelperAbandonedCart
* @var EmailMarketing
*/
protected $helperAbandonedCart;
protected $helperEmailMarketing;

/**
* @var Session
Expand All @@ -47,27 +47,27 @@ class Script extends Template
* Script constructor.
*
* @param Context $context
* @param HelperAbandonedCart $helperAbandonedCart
* @param EmailMarketing $helperEmailMarketing
* @param Session $checkoutSession
* @param array $data
*/
public function __construct(
Context $context,
HelperAbandonedCart $helperAbandonedCart,
EmailMarketing $helperEmailMarketing,
Session $checkoutSession,
array $data = []
) {
$this->helperAbandonedCart = $helperAbandonedCart;
$this->checkoutSession = $checkoutSession;
$this->helperEmailMarketing = $helperEmailMarketing;
$this->checkoutSession = $checkoutSession;
parent::__construct($context, $data);
}

/**
* @return HelperAbandonedCart
* @return EmailMarketing
*/
public function getHelperAbandonedCart()
public function getHelperEmailMarketing()
{
return $this->helperAbandonedCart;
return $this->helperEmailMarketing;
}

/**
Expand All @@ -76,7 +76,7 @@ public function getHelperAbandonedCart()
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
48 changes: 23 additions & 25 deletions Controller/Adminhtml/Smtp/AbandonedCart/Send.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@
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\Framework\View\Result\Page;
use Magento\Quote\Model\QuoteRepository;
use Mageplaza\Smtp\Helper\AbandonedCart;
use Magento\Framework\View\Result\Page;
use Psr\Log\LoggerInterface;
use Mageplaza\Smtp\Helper\EmailMarketing;

/**
* Class Send
Expand Down Expand Up @@ -79,9 +77,9 @@ class Send extends Action
protected $registry;

/**
* @var AbandonedCart
* @var EmailMarketing
*/
protected $helperAbandonedCart;
protected $helperEmailMarketing;

/**
* Send constructor.
Expand All @@ -94,7 +92,7 @@ class Send extends Action
* @param SenderResolver $senderResolver
* @param TransportBuilder $transportBuilder
* @param Registry $registry
* @param AbandonedCart $helperAbandonedCart
* @param EmailMarketing $helperEmailMarketing
*/
public function __construct(
Context $context,
Expand All @@ -105,41 +103,41 @@ public function __construct(
SenderResolver $senderResolver,
TransportBuilder $transportBuilder,
Registry $registry,
AbandonedCart $helperAbandonedCart
EmailMarketing $helperEmailMarketing
) {
$this->quoteRepository = $quoteRepository;
$this->logger = $logger;
$this->emailTemplate = $emailTemplate;
$this->areaList = $areaList;
$this->senderResolver = $senderResolver;
$this->transportBuilder = $transportBuilder;
$this->registry = $registry;
$this->helperAbandonedCart = $helperAbandonedCart;
$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 ResponseInterface|ResultInterface|Page
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\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->helperAbandonedCart->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->helperAbandonedCart->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
Loading

0 comments on commit b1d14ee

Please sign in to comment.