Skip to content

Commit

Permalink
Merge branch '2.4-develop' into 2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
JackerNgo committed Jan 18, 2021
2 parents 1300380 + edd67de commit f0e2cf3
Show file tree
Hide file tree
Showing 24 changed files with 1,215 additions and 398 deletions.
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;
}
}
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();
}
37 changes: 2 additions & 35 deletions Controller/Adminhtml/Smtp/Sync/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
use Exception;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
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 All @@ -43,18 +41,13 @@ class Customer extends Action
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'Mageplaza_Smtp::smtp';
const ADMIN_RESOURCE = 'Mageplaza_Smtp::email_marketing';

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

/**
* @var CustomerFactory
*/
protected $customerFactory;

/**
* @var CustomerCollectionFactory
*/
Expand All @@ -65,17 +58,14 @@ class Customer extends Action
*
* @param Context $context
* @param EmailMarketing $helperEmailMarketing
* @param CustomerFactory $customerFactory
* @param CustomerCollectionFactory $customerCollectionFactory
*/
public function __construct(
Context $context,
EmailMarketing $helperEmailMarketing,
CustomerFactory $customerFactory,
CustomerCollectionFactory $customerCollectionFactory
) {
$this->helperEmailMarketing = $helperEmailMarketing;
$this->customerFactory = $customerFactory;
$this->customerCollectionFactory = $customerCollectionFactory;
parent::__construct($context);
}
Expand Down Expand Up @@ -115,11 +105,7 @@ public function execute()

$result['status'] = true;
$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);
}
$this->helperEmailMarketing->syncCustomers($data);

} catch (Exception $e) {
$result['status'] = false;
Expand All @@ -128,23 +114,4 @@ public function execute()

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

/**
* @param AdapterInterface $connection
* @param array $data
* @param string $table
*
* @throws Exception
*/
public function insertData($connection, $data, $table)
{
$connection->beginTransaction();
try {
$connection->insertMultiple($table, $data);
$connection->commit();
} catch (Exception $e) {
$connection->rollBack();
throw $e;
}
}
}
Loading

0 comments on commit f0e2cf3

Please sign in to comment.