Proste rozwiązanie zapisania się do newslettera do kilku sklepów na ten sam adres e-mail na jednej instalacji Magento.
Plik app/code/core/Mage/Newsletter/Model/Mysql4/Subscriber.php kopiujemy do app/code/local/Mage/Newsletter/Model/Mysql4/Subscriber.php, zmieniamy funkcję loadByEmail($subscriberEmail) na:
<?php public function loadByEmail($subscriberEmail) { /** @var $customerSession Mage_Customer_Model_Session */ $customerSession = Mage::getSingleton('customer/session'); $ownerId = Mage::getModel('customer/customer') ->setWebsiteId(Mage::app()->getStore()->getWebsiteId()) ->loadByEmail($subscriberEmail) ->getId(); $storeId = $customerSession->isLoggedIn() && $ownerId == $customerSession->getId() ? $customerSession->getCustomer()->getStoreId() : Mage::app()->getStore()->getId(); $select = $this->_read->select() ->from($this->getMainTable()) ->where('subscriber_email=:subscriber_email') ->where('store_id=:store_id'); // Add store ID for newsletters $result = $this->_read->fetchRow($select, array( 'subscriber_email' => $subscriberEmail, 'store_id' => $storeId )); if (!$result) { return array(); } return $result; } ?>
oraz funkcję loadByCustomer(Mage_Customer_Model_Customer $customer) na:
<?php public function loadByCustomer(Mage_Customer_Model_Customer $customer) { $select = $this->_read->select() ->from($this->getMainTable()) ->where('customer_id=:customer_id') ->where('store_id=:store_id'); $result = $this->_read->fetchRow($select, array( 'customer_id' => $customer->getId(), 'store_id' => $customer->getStoreId() )); if ($result) { return $result; } $select = $this->_read->select() ->from($this->getMainTable()) ->where('subscriber_email=:subscriber_email') ->where('store_id=:store_id'); $result = $this->_read->fetchRow($select, array( 'subscriber_email' => $customer->getEmail(), 'store_id' => $customer->getStoreId() )); if ($result) { return $result; } return array(); } ?>
Rozwiązanie sprawdzone na wersjach Magento >= 1.4.x.x.