Skip to content

Commit

Permalink
[2.4.6] Fix bug eqp
Browse files Browse the repository at this point in the history
  • Loading branch information
HuyPhuc98 committed Jun 6, 2023
1 parent cdf2213 commit af7e8a7
Show file tree
Hide file tree
Showing 3 changed files with 228 additions and 1 deletion.
177 changes: 177 additions & 0 deletions Setup/Patch/Data/UpgradeAttributeData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<?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\Setup\Patch\Data;

use Magento\Config\Model\ResourceModel\Config\Data\Collection;
use Magento\Customer\Model\Customer;
use Magento\Customer\Setup\CustomerSetup;
use Magento\Customer\Setup\CustomerSetupFactory;
use Magento\Eav\Model\Entity\Attribute\Set as AttributeSet;
use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory;
use Magento\Framework\App\Cache\TypeListInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchRevertableInterface;
use Magento\Framework\Validator\ValidateException;

/**
* Class UpgradeAttributeData
* @package Mageplaza\Smtp\Setup\Patch\Data
*/
class UpgradeAttributeData implements DataPatchInterface, PatchRevertableInterface
{
/**
* @var ModuleDataSetupInterface $moduleDataSetup
*/
private $moduleDataSetup;

/**
* @var AttributeSetFactory
*/
protected $attributeSetFactory;

/**
* @var CustomerSetupFactory
*/
protected $customerSetupFactory;

/**
* @var Collection
*/
protected $configCollection;

/**
* @var TypeListInterface
*/
protected $_cacheTypeList;

/**
* UpgradeData constructor.
*
* @param AttributeSetFactory $attributeSetFactory
* @param CustomerSetupFactory $customerSetupFactory
* @param Collection $configCollection
* @param TypeListInterface $cacheTypeList
*/
public function __construct(
ModuleDataSetupInterface $moduleDataSetup,
AttributeSetFactory $attributeSetFactory,
CustomerSetupFactory $customerSetupFactory,
Collection $configCollection,
TypeListInterface $cacheTypeList
) {
$this->moduleDataSetup = $moduleDataSetup;
$this->attributeSetFactory = $attributeSetFactory;
$this->customerSetupFactory = $customerSetupFactory;
$this->configCollection = $configCollection;
$this->_cacheTypeList = $cacheTypeList;
}

/**
* {@inheritdoc}
*
* @throws LocalizedException
* @throws ValidateException
*/
public function apply()
{
$setup = $this->moduleDataSetup;

$setup->startSetup();

/** @var CustomerSetup $customerSetup */
$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);

$customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
$attributeSetId = $customerEntity->getDefaultAttributeSetId();

/** @var $attributeSet AttributeSet */
$attributeSet = $this->attributeSetFactory->create();
$attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);

$customerSetup->addAttribute(Customer::ENTITY, 'mp_smtp_is_synced', [
'type' => 'int',
'label' => 'Mp SMTP is synced',
'input' => 'hidden',
'required' => false,
'visible' => false,
'user_defined' => false,
'sort_order' => 90,
'position' => 90,
'system' => 0,
'is_used_in_grid' => false,
]);

$customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'mp_smtp_is_synced')
->addData([
'attribute_set_id' => $attributeSetId,
'attribute_group_id' => $attributeGroupId,
'used_in_forms' => ['adminhtml_customer']
])
->save();

$connection = $setup->getConnection();
$configCollection = $this->configCollection->addPathFilter('smtp/abandoned_cart');
if ($configCollection->getSize() > 0) {
$table = $this->configCollection->getMainTable();
$paths = [
'smtp/abandoned_cart/enabled' => 'email_marketing/general/enabled',
'smtp/abandoned_cart/app_id' => 'email_marketing/general/app_id',
'smtp/abandoned_cart/secret_key' => 'email_marketing/general/secret_key'
];

foreach ($paths as $oldPath => $newPath) {
$connection->update(
$table,
['path' => $newPath],
['path = ?' => $oldPath]
);
}
$this->_cacheTypeList->cleanType('config');
}
}

/**
* @return array
*/
public static function getDependencies()
{
return [];
}

/**
* @return array
*/
public function getAliases()
{
return [];
}

/**
* @return array
*/
public function revert()
{
return [];
}
}
50 changes: 50 additions & 0 deletions etc/db_schema.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<table name="mageplaza_smtp_log" resource="default" engine="innodb" comment="mageplaza_smtp_log">
<column xsi:type="int" name="id" padding="10" unsigned="true" nullable="false" identity="true" comment="Log ID"/>
<column xsi:type="varchar" name="subject" nullable="true" length="255" comment="Email Subject"/>
<column xsi:type="text" name="email_content" nullable="true" comment="Email Content"/>
<column xsi:type="smallint" name="status" padding="6" unsigned="false" nullable="false" identity="false" comment="Status"/>
<column xsi:type="timestamp" name="created_at" on_update="false" nullable="true" comment="Created At"/>
<column xsi:type="varchar" name="from" nullable="true" length="255" comment="Sender" disabled="true"/>
<column xsi:type="varchar" name="to" nullable="true" length="255" comment="Recipient" disabled="true"/>
<column xsi:type="varchar" name="cc" nullable="true" length="255" comment="Cc"/>
<column xsi:type="varchar" name="bcc" nullable="true" length="255" comment="Bcc"/>
<column xsi:type="varchar" name="sender" nullable="true" length="255" comment="Sender" onCreate="migrateDataFrom(from)"/>
<column xsi:type="varchar" name="recipient" nullable="true" length="255" comment="Recipient" onCreate="migrateDataFrom(to)"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="id"/>
</constraint>
<index referenceId="MAGEPLAZA_SMTP_LOG_STATUS" indexType="btree">
<column name="status"/>
</index>
</table>
<table name="mageplaza_smtp_abandonedcart" resource="default" engine="innodb" comment="SMTP Abandoned Cart">
<column xsi:type="int" name="id" padding="10" unsigned="true" nullable="false" identity="true" comment="Log Id"/>
<column xsi:type="varchar" name="log_ids" nullable="true" length="255" comment="Log Ids"/>
<column xsi:type="varchar" name="token" nullable="true" length="255" comment="Token"/>
<column xsi:type="int" name="quote_id" padding="10" unsigned="true" nullable="false" identity="false" default="0" comment="Quote Id"/>
<column xsi:type="smallint" name="status" padding="6" unsigned="false" nullable="false" identity="false" comment="Status"/>
<column xsi:type="timestamp" name="created_at" on_update="false" nullable="true" default="CURRENT_TIMESTAMP" comment="Created At"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="id"/>
</constraint>
<constraint xsi:type="foreign" referenceId="MAGEPLAZA_SMTP_ABANDONEDCART_QUOTE_ID_QUOTE_ENTITY_ID" table="mageplaza_smtp_abandonedcart" column="quote_id" referenceTable="quote" referenceColumn="entity_id" onDelete="CASCADE"/>
</table>
<table name="quote" resource="default" engine="innodb" comment="quote">
<column xsi:type="smallint" name="mp_smtp_ace_token" nullable="true" comment="ACE Token"/>
<column xsi:type="smallint" name="mp_smtp_ace_sent" nullable="true" default="0" comment="ACE Sent"/>
<column xsi:type="text" name="mp_smtp_ace_log_ids" nullable="true" comment="ACE Log Ids"/>
<column xsi:type="text" name="mp_smtp_ace_log_data" nullable="true" comment="ACE Log Data"/>
</table>
<table name="sales_order" resource="default" engine="innodb" comment="sales_order">
<column xsi:type="smallint" name="mp_smtp_email_marketing_synced" nullable="true" default="0" comment="Mp SMTP Email Marketing synced"/>
<column xsi:type="smallint" name="mp_smtp_email_marketing_order_created" nullable="true" default="0" comment="Mp SMTP Email Marketing order created"/>
</table>
<table name="customer_entity" resource="default" engine="innodb" comment="customer_entity">
<column xsi:type="smallint" name="mp_smtp_email_marketing_synced" nullable="true" default="0" comment="Mp SMTP Email Marketing synced"/>
</table>
<table name="newsletter_subscriber" resource="default" engine="innodb" comment="newsletter_subscriber">
<column xsi:type="smallint" name="mp_smtp_email_marketing_synced" nullable="true" default="0" comment="Mp SMTP Email Marketing synced"/>
</table>
</schema>
2 changes: 1 addition & 1 deletion view/adminhtml/web/js/grid/columns/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ define([
var row = this.rows[action.rowIndex],
modalHtml = '<iframe srcdoc="' + row['email_content'] + '" style="width: 100%; height: 100%"></iframe>';

this.modal[action.rowIndex] = $('<div/>')
this.modal[action.rowIndex] = $('<div>')
.html(modalHtml)
.modal({
type: 'slide',
Expand Down

0 comments on commit af7e8a7

Please sign in to comment.