Skip to content

Commit

Permalink
Merge pull request #342 from mageplaza/2.4-develop
Browse files Browse the repository at this point in the history
2.4 develop
  • Loading branch information
Victor-Mageplaza authored Oct 12, 2021
2 parents 8576120 + d956be8 commit 5130054
Show file tree
Hide file tree
Showing 12 changed files with 354 additions and 91 deletions.
22 changes: 21 additions & 1 deletion Block/Script.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Magento\Customer\Model\SessionFactory as CustomerSession;
use Magento\Checkout\Model\Session;
use Magento\Framework\App\Http\Context as HttpContext;
use Magento\Framework\DataObject\IdentityInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Pricing\PriceCurrencyInterface;
Expand All @@ -41,7 +42,7 @@
* Class Script
* @package Mageplaza\Smtp\Block
*/
class Script extends Template
class Script extends Template implements IdentityInterface
{
/**
* @var EmailMarketing
Expand Down Expand Up @@ -230,12 +231,31 @@ public function getPrice($product, $includeTax = false)
{
$price = number_format($this->priceCurrency->convert($product->getFinalPrice()), 2);

if ($product->getTypeId() === 'configurable') {
$price = number_format($product->getFinalPrice(), 2);
}

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

if ($product->getTypeId() === 'configurable') {
$price = number_format(
$this->taxHelper->getTaxPrice($product, $product->getFinalPrice(), true),
2
);
}
}

return $price;
}

/**
* @return array|string[]
*/
public function getIdentities()
{
return [EmailMarketing::CACHE_TAG];
}
}
27 changes: 24 additions & 3 deletions Controller/Proxy/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\Result\RawFactory;
use Magento\Framework\Controller\ResultInterface;
use Mageplaza\Smtp\Helper\Data;
use Mageplaza\Smtp\Helper\EmailMarketing;
Expand All @@ -40,17 +41,25 @@ class Index extends Action
*/
protected $helperEmailMarketing;

/**
* @var RawFactory
*/
protected $resultRawFactory;

/**
* Index constructor.
*
* @param Context $context
* @param EmailMarketing $helperEmailMarketing
* @param RawFactory $resultRawFactory
*/
public function __construct(
Context $context,
EmailMarketing $helperEmailMarketing
EmailMarketing $helperEmailMarketing,
RawFactory $resultRawFactory
) {
$this->helperEmailMarketing = $helperEmailMarketing;
$this->resultRawFactory = $resultRawFactory;

parent::__construct($context);
}
Expand All @@ -61,8 +70,20 @@ public function __construct(
public function execute()
{
try {
$params = $this->getRequest()->getParams();
$response = $this->helperEmailMarketing->sendRequestProxy($params);
$params = $this->getRequest()->getParams();
$url = EmailMarketing::PROXY_URL;
if (isset($params['path'])) {
$url = EmailMarketing::PROXY_URL . $params['path'];
}

$response = $this->helperEmailMarketing->sendRequestProxy($url, $params);
if (isset($params['type'])) {
$result = $this->resultRawFactory->create();
$result->setHeader('content-type', $params['type']);
$result->setContents($response);

return $result;
}
} catch (Exception $e) {
$response = [];
}
Expand Down
24 changes: 13 additions & 11 deletions Helper/EmailMarketing.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
*/
class EmailMarketing extends Data
{
const CACHE_TAG = 'mp_smtp_script';
const IS_SYNCED_ATTRIBUTE = 'mp_smtp_is_synced';
const API_URL = 'https://app.avada.io';
const APP_URL = self::API_URL . '/app/api/v1/connects';
Expand Down Expand Up @@ -1680,30 +1681,31 @@ public function isTracking($storeId = null)
}

/**
* @param array $data
* @param string $url
* @param array|null $data
*
* @return mixed
* @throws LocalizedException
* @throws NoSuchEntityException
*/
public function sendRequestProxy($data)
public function sendRequestProxy($url, $data)
{
$url = self::PROXY_URL;
if (isset($data['path'])) {
$url = self::PROXY_URL . $data['path'];
}
$params = $this->_request->getParams();

$this->initCurl();

if ($this->_request->getMethod() === 'POST') {
$body = $this->setHeaders($data, $url);
$this->_curl->post($this->url, $body);
$this->_curl->post($url, $body);
} else {
$this->_curl->get($this->url);
$this->_curl->get($url);
}

$body = $this->_curl->getBody();
$bodyData = self::jsonDecode($body);
if (isset($params['type'])) {
$bodyData = $body;
}

$body = $this->_curl->getBody();
$bodyData = self::jsonDecode($body);
$this->_curl = '';

return $bodyData;
Expand Down
2 changes: 1 addition & 1 deletion Model/Config/Source/SyncType.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function toOptionArray()
],
[
'value' => self::ALL,
'label' => __('Every Thing')
'label' => __('Everything')
]
];

Expand Down
85 changes: 85 additions & 0 deletions Observer/Customer/LoginSuccess.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?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\Observer\Customer;

use Exception;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\PageCache\Model\Cache\Type;
use Mageplaza\Smtp\Helper\Data;
use Mageplaza\Smtp\Helper\EmailMarketing;
use Zend_Cache;

/**
* Class LoginSuccess
* @package Mageplaza\Smtp\Observer\Customer
*/
class LoginSuccess implements ObserverInterface
{
/**
* @var Type
*/
protected $fullPageCache;

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

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

/**
* LoginSuccess constructor.
*
* @param Type $fullPageCache
* @param Data $helperData
* @param EmailMarketing $helperEmailMarketing
*/
public function __construct(
Type $fullPageCache,
Data $helperData,
EmailMarketing $helperEmailMarketing
) {
$this->fullPageCache = $fullPageCache;
$this->helperData = $helperData;
$this->helperEmailMarketing = $helperEmailMarketing;
}

/**
* @param Observer $observer
*/
public function execute(Observer $observer)
{
try {
$scopeId = $this->helperData->getScopeId();
} catch (Exception $e) {
$scopeId = null;
}

if ($this->helperEmailMarketing->isEnableEmailMarketing($scopeId)) {
$this->fullPageCache->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, [EmailMarketing::CACHE_TAG]);
}
}
}
45 changes: 45 additions & 0 deletions Plugin/Model/Template/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?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\Plugin\Model\Template;

use Magento\Email\Model\Template\Config as EmailConfig;

/**
* Class Config
* @package Mageplaza\Smtp\Plugin\Model\Template
*/
class Config
{
/**
* @param EmailConfig $subject
* @param array $templates
*
* @return array
*/
public function afterGetAvailableTemplates(EmailConfig $subject, $templates)
{
$key = array_search('mpsmtp_abandoned_cart_email_template', array_column($templates, 'value'));
unset($templates[$key]);

return $templates;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"mageplaza/module-core": "^1.4.11"
},
"type": "magento2-module",
"version": "4.6.0",
"version": "4.6.1",
"license": "proprietary",
"authors": [
{
Expand Down
26 changes: 26 additions & 0 deletions etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" ?><!--
/**
* 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
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Email\Model\Template\Config">
<plugin name="mageplaza_smtp_template_abandoned_cart" type="Mageplaza\Smtp\Plugin\Model\Template\Config" />
</type>
</config>
Loading

0 comments on commit 5130054

Please sign in to comment.