-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from outeredge/remove-layout-module-and-more
Remove layout module and more
- Loading branch information
Showing
9 changed files
with
247 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace OuterEdge\Multiplenewsletter\Helper; | ||
|
||
use Magento\Framework\App\Helper\AbstractHelper; | ||
|
||
class Data extends AbstractHelper | ||
{ | ||
CONST CORE_NEWSLETTER_SUBSCRIBE = 'all'; | ||
|
||
CONST CORE_NEWSLETTER_UNSUBSCRIBE = 'null'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace OuterEdge\Multiplenewsletter\Observer; | ||
|
||
use Magento\Framework\Event\Observer; | ||
use Magento\Framework\Event\ObserverInterface; | ||
use Magento\Customer\Api\CustomerRepositoryInterface; | ||
use OuterEdge\Multiplenewsletter\Helper\Data; | ||
|
||
class UpdateFromAdmin implements ObserverInterface | ||
{ | ||
/** | ||
* @var CustomerRepositoryInterface | ||
*/ | ||
protected $customerRepositoryInterface; | ||
|
||
/** | ||
* @param CustomerRepositoryInterface $customerRepositoryInterface | ||
*/ | ||
public function __construct( | ||
CustomerRepositoryInterface $customerRepositoryInterface | ||
) { | ||
$this->customerRepositoryInterface = $customerRepositoryInterface; | ||
} | ||
|
||
/** | ||
* @param Observer $observer | ||
*/ | ||
public function execute(Observer $observer) | ||
{ | ||
$customerId = $observer->getCustomer()->getId(); | ||
$subscriptionStatus = (array)$observer->getRequest()->getParam('subscription_status'); | ||
|
||
if (empty($subscriptionStatus)) { | ||
return; | ||
} | ||
|
||
$customer = $this->customerRepositoryInterface->getById((int)$customerId); | ||
|
||
foreach ($subscriptionStatus as $status) { | ||
if ($status) { | ||
$customer->setCustomAttribute('newsletter_options', Data::CORE_NEWSLETTER_SUBSCRIBE); | ||
} else { | ||
$customer->setCustomAttribute('newsletter_options', Data::CORE_NEWSLETTER_UNSUBSCRIBE); | ||
} | ||
|
||
try { | ||
$this->customerRepositoryInterface->save($customer); | ||
} catch (\Exception $e) { | ||
throw new \Exception('Error saving multiple newsletter'); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
|
||
namespace OuterEdge\Multiplenewsletter\Setup; | ||
|
||
use Magento\Framework\Setup\UpgradeDataInterface; | ||
use Magento\Framework\Setup\ModuleDataSetupInterface; | ||
use Magento\Framework\Setup\ModuleContextInterface; | ||
use Magento\Newsletter\Model\ResourceModel\Subscriber\CollectionFactory as NewsCollectionFactory; | ||
use Magento\Customer\Api\CustomerRepositoryInterface; | ||
use OuterEdge\Multiplenewsletter\Helper\Data; | ||
use Magento\Framework\App\State; | ||
use Magento\Framework\App\ResourceConnection; | ||
use Magento\Eav\Model\ResourceModel\Entity\Attribute; | ||
|
||
class UpgradeData implements UpgradeDataInterface | ||
{ | ||
/** | ||
* @var NewsCollectionFactory | ||
*/ | ||
protected $subscriberCollection; | ||
|
||
/** | ||
* @var CustomerRepositoryInterface | ||
*/ | ||
protected $customerRepositoryInterface; | ||
|
||
/** | ||
* @var \Magento\Framework\App\State | ||
*/ | ||
private $state; | ||
|
||
/** | ||
* @var ResourceConnection | ||
*/ | ||
protected $resource; | ||
|
||
/** | ||
* @var Attribute | ||
*/ | ||
protected $eavAttribute; | ||
|
||
/** | ||
* @param NewsCollectionFactory $subscriberCollection | ||
* @param CustomerRepositoryInterface $customerRepositoryInterface | ||
* @param State $state | ||
* @param ResourceConnection $resource | ||
* @param Attribute $eavAttribute | ||
*/ | ||
public function __construct( | ||
NewsCollectionFactory $subscriberCollection, | ||
CustomerRepositoryInterface $customerRepositoryInterface, | ||
State $state, | ||
ResourceConnection $resource, | ||
Attribute $eavAttribute | ||
) { | ||
$this->subscriberCollection = $subscriberCollection; | ||
$this->customerRepositoryInterface = $customerRepositoryInterface; | ||
$this->state = $state; | ||
$this->resource = $resource; | ||
$this->eavAttribute = $eavAttribute; | ||
} | ||
|
||
public function getSubscriberCollection() | ||
{ | ||
return $this->subscriberCollection->create(); | ||
} | ||
|
||
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) | ||
{ | ||
$this->state->setAreaCode(\Magento\Framework\App\Area::AREA_FRONTEND); | ||
|
||
if (version_compare($context->getVersion(), '1.0.1', '<')) { | ||
|
||
$setup->startSetup(); | ||
$connection = $this->resource->getConnection(\Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION); | ||
$customerEntity = $connection->getTableName('customer_entity'); | ||
$customerEntityVarchar = $connection->getTableName('customer_entity_varchar'); | ||
$attributeId = $this->eavAttribute->getIdByCode(\Magento\Customer\Model\Customer::ENTITY, 'newsletter_options'); | ||
|
||
foreach ($this->getSubscriberCollection() as $customerNewsletter) { | ||
|
||
if (!$customerNewsletter['customer_id']) { | ||
continue; | ||
} | ||
|
||
$selectCustomer = "SELECT entity_id FROM $customerEntity WHERE entity_id LIKE ".$customerNewsletter['customer_id']; | ||
$customerExist = $connection->fetchRow($selectCustomer); | ||
if (!$customerExist) { | ||
continue; | ||
} | ||
|
||
try { | ||
$customer = $this->customerRepositoryInterface->getById($customerNewsletter['customer_id']); | ||
//Only update if newsletter_options is empty | ||
if ($customer->getCustomAttribute('newsletter_options')) { | ||
continue; | ||
} | ||
|
||
$connection->fetchAll("INSERT INTO `".$customerEntityVarchar."` | ||
(`value_id`, `attribute_id`, `entity_id`, `value`) | ||
VALUES (NULL, '".$attributeId."', '".$customer->getId()."', '".Data::CORE_NEWSLETTER_SUBSCRIBE."')"); | ||
|
||
} catch (\Exception $e) { | ||
throw new \Exception('Error on multiple newsletter with customer: ' | ||
.$customerNewsletter['customer_id'].' Reason: '.$e->getMessage()); | ||
} | ||
} | ||
$setup->endSetup(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> | ||
<event name="adminhtml_customer_save_after"> | ||
<observer name="update_multinewsletter_field" instance="OuterEdge\Multiplenewsletter\Observer\UpdateFromAdmin" /> | ||
</event> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd"> | ||
<system> | ||
<tab id="outeredge" translate="label" sortOrder="2000" class="outeredge-tab"> | ||
<label>outer/edge</label> | ||
</tab> | ||
<section id="multinewletteroptions" translate="label" type="text" sortOrder="11" showInDefault="1" showInWebsite="1" showInStore="0"> | ||
<label>Multi Newsletter Emails</label> | ||
<tab>outeredge</tab> | ||
<resource>OuterEdge_Multiplenewsletter::MultiplenewsletterSettings</resource> | ||
<group id="list" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="0"> | ||
<label>Multi Newsletter Emails list</label> | ||
<field id="options" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1"> | ||
<label>Newsletter options</label> | ||
<comment>newsletter one, newsletter two, newsletter three</comment> | ||
</field> | ||
</group> | ||
</section> | ||
</system> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters