Skip to content

Commit

Permalink
Merge pull request #335 from mageplaza/2.3-develop
Browse files Browse the repository at this point in the history
2.3 develop
  • Loading branch information
Victor-Mageplaza authored Sep 22, 2021
2 parents aada72b + df6db20 commit 4064016
Show file tree
Hide file tree
Showing 37 changed files with 1,222 additions and 1,376 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,25 @@

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

use Mageplaza\Smtp\Model\Config\Source\SyncType;

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

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

/**
Expand All @@ -57,34 +59,30 @@ public function getStoreId()
}

/**
* @return mixed
* @return array
*/
public function getSyncSuccessMessage()
{
return __('Customer synchronization has been completed.');
return [
SyncType::CUSTOMERS => __('Customer synchronization has been completed.'),
SyncType::ORDERS => __('Order synchronization has been completed.'),
SyncType::SUBSCRIBERS => __('Subscriber synchronization has been completed.')
];
}

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

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

/**
* @return bool
*/
public function isRenderCss()
{
return true;
return 'Mageplaza_Smtp/js/sync/sync';
}
}
90 changes: 0 additions & 90 deletions Block/Adminhtml/System/Config/SyncOrder.php

This file was deleted.

90 changes: 0 additions & 90 deletions Block/Adminhtml/System/Config/SyncSubscriber.php

This file was deleted.

68 changes: 57 additions & 11 deletions Block/Script.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@
namespace Mageplaza\Smtp\Block;

use Magento\Catalog\Block\Product\Context;
use Magento\Customer\Model\Context as CustomerContext;
use Magento\Catalog\Helper\Data;
use Magento\Catalog\Model\Product;
use Magento\Customer\Model\SessionFactory as CustomerSession;
use Magento\Checkout\Model\Session;
use Magento\Framework\App\Http\Context as HttpContext;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Framework\UrlInterface;
use Magento\Framework\View\Element\Template;
use Magento\Sales\Model\Order;
Expand Down Expand Up @@ -63,6 +68,16 @@ class Script extends Template
*/
protected $httpContext;

/**
* @var Data
*/
protected $taxHelper;

/**
* @var PriceCurrencyInterface
*/
protected $priceCurrency;

/**
* Script constructor.
*
Expand All @@ -72,6 +87,8 @@ class Script extends Template
* @param CustomerSession $customerSession
* @param Registry $registry
* @param HttpContext $httpContext
* @param Data $taxHelper
* @param PriceCurrencyInterface $priceCurrency
* @param array $data
*/
public function __construct(
Expand All @@ -81,13 +98,18 @@ public function __construct(
CustomerSession $customerSession,
Registry $registry,
HttpContext $httpContext,
Data $taxHelper,
PriceCurrencyInterface $priceCurrency,
array $data = []
) {
$this->helperEmailMarketing = $helperEmailMarketing;
$this->checkoutSession = $checkoutSession;
$this->customerSession = $customerSession;
$this->registry = $registry;
$this->httpContext = $httpContext;
$this->taxHelper = $taxHelper;
$this->priceCurrency = $priceCurrency;

parent::__construct($context, $data);
}

Expand Down Expand Up @@ -141,33 +163,37 @@ public function getCurrencyCode()

/**
* @return array
* @throws LocalizedException
* @throws NoSuchEntityException
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getCustomerData()
{
$isLoggedIn = $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH);
$isLoggedIn = $this->httpContext->getValue(CustomerContext::CONTEXT_AUTH);
if (!$isLoggedIn) {
$shippingAddress = $this->checkoutSession->getQuote()->getShippingAddress();
$data = [
'email' => $shippingAddress->getData('email') === null ? '' : $shippingAddress->getData('email'),
'firstname' => $shippingAddress->getData('firstname') === null ? '' : $shippingAddress->getData('firstname'),
'lastname' => $shippingAddress->getData('lastname') === null ? '' : $shippingAddress->getData('lastname')
$data = [
'email' => $shippingAddress->getData('email') === null ? '' : $shippingAddress->getData('email'),
'firstname' => $shippingAddress->getData('firstname') === null ?
'' : $shippingAddress->getData('firstname'),
'lastname' => $shippingAddress->getData('lastname') === null ?
'' : $shippingAddress->getData('lastname')
];

return $data;
} else {
$customer = $this->customerSession->create()->getCustomer();
$data = [
'email' => $customer->getData('email') === null ? '' : $customer->getData('email'),
$data = [
'email' => $customer->getData('email') === null ? '' : $customer->getData('email'),
'firstname' => $customer->getData('firstname') === null ? '' : $customer->getData('firstname'),
'lastname' => $customer->getData('lastname') === null ? '' : $customer->getData('lastname')
'lastname' => $customer->getData('lastname') === null ? '' : $customer->getData('lastname')
];

return $data;
}
}

/**
* @return array|false
* @return array|bool
* @throws NoSuchEntityException
*/
public function productAbandoned()
Expand All @@ -181,7 +207,8 @@ public function productAbandoned()
'collections' => [],
'id' => $product->getId(),
'image' => $imageUrl,
'price' => $product->getFinalPrice(),
'price' => $this->getPrice($product),
'priceTax' => $this->getPrice($product, true),
'productType' => $product->getTypeId(),
'tags' => [],
'title' => $product->getName(),
Expand All @@ -192,4 +219,23 @@ public function productAbandoned()

return false;
}

/**
* @param Product $product
* @param bool $includeTax
*
* @return float
*/
public function getPrice($product, $includeTax = false)
{
$price = number_format($this->priceCurrency->convert($product->getFinalPrice()), 2);

if ($includeTax) {
$price = number_format($this->priceCurrency->convert(
$this->taxHelper->getTaxPrice($product, $product->getFinalPrice(), true)
), 2);
}

return $price;
}
}
Loading

0 comments on commit 4064016

Please sign in to comment.