0

I have 3 stores, If i subscribe from English store one entry will create with status as 1 in db.then I changed the store from English to French and subscribe to the newsletter, instead of update the same entry new entry is creating with status 1.How to fix this issue.(Magento2.2.6 EE)

0

Pluginize/overwrite loadByCustomerData method and change select query where you need to remove store_id filter.

vendor/magento/module-newsletter/Model/ResourceModel/Subscriber.php

/**
 * Load subscriber by customer
 *
 * @param \Magento\Customer\Api\Data\CustomerInterface $customer
 * @return array
 */
public function loadByCustomerData(\Magento\Customer\Api\Data\CustomerInterface $customer)
{
    $select = $this->connection
        ->select()
        ->from($this->getMainTable())
        ->where('customer_id=:customer_id');

    $result = $this->connection
        ->fetchRow(
            $select,
            [
                'customer_id' => $customer->getId()
            ]
        );

    if ($result) {
        return $result;
    }

    $select = $this->connection
        ->select()
        ->from($this->getMainTable())
        ->where('subscriber_email=:subscriber_email');

    $result = $this->connection
        ->fetchRow(
            $select,
            [
                'subscriber_email' => $customer->getEmail()
            ]
        );

    if ($result) {
        return $result;
    }

    return [];
}
0

To fix the issue by overwriting

\Magento\Newsletter\Model\ResourceModel\Subscriber::loadByEmail() in a custom module :

public function loadByEmail($subscriberEmail)
{    
    $select = $this->connection->select()->from($this->getMainTable())->where('subscriber_email=:subscriber_email AND store_id=:store_id');

    $result = $this->connection->fetchRow($select, ['subscriber_email' => $subscriberEmail,'store_id' => $this->getStoreId()]);

    if (!$result) {
        return [];
    }

    return $result;
}

protected function getStoreId() 
{
    return $this->_storeManager->getStore()->getId();
}

Reference : https://github.com/magento/magento2/issues/13258

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.