Magento Newletter subscription - show error if already subscribed - magento

Hi I am using default newsletters subscription package in magento. I need to show an error if the user is already registered with Us I've seen an option like this
$emailExist = Mage::getModel('newsletter/subscriber')->load($email, 'subscriber_email');
if ($emailExist->getId()) {
Mage::throwException($this->__('This email address is already exist.'));
}
from here Show error message in guest subscriber if user already subscribe with that Id
But this is not working for me, still i am getting same thanks for subscription message. thanks

Check this............
$NewSellt= Mage::getModel('newsletter/subscriber')->subscribe($email);
if($NewSellt->getId()>0){
//if exits
}
If customer is registered user
$ownerId = Mage::getModel('customer/customer')
->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
->loadByEmail($email)
->getId();
if ($ownerId !== null && $ownerId != $customerSession->getId()) {
//'This email address is already assigned to another user.
}

Related

Redirect customer if he has an incomplete payment

I would like to create a restricted page using Cashier. In a nutshell I would like the page to start a subscription to have these limitations:
Accessible to users who do not have a subscription
Not accessible to users who have an incomplete invoice/subscription and therefore an open invoice.
This is my code:
if(Auth::user()->subscribed('default')) {
return redirect()->route('index')->with('error', 'You already have an active subscription right now.');
}
if(Auth::user()->subscribed('default') || Auth::user()->subscription('default')->hasIncompletePayment()){
return redirect()->route('account.invoices')->with('warning', 'You have a payment invoice for a pending subscription. Make payment or cancel.');
}
With this code of mine the only problem is when I try to access the page with a user who has no subscription, this error appears:
Call to a member function hasIncompletePayment() on null
if(Auth::user()->subscribed('default')) {
return redirect()->route('index')->with('error', 'You already have an active subscription right now.');
}
if(!empty(Auth::user()->subscription('default'))){
if(Auth::user()->subscribed('default') || Auth::user()->subscription('default')->hasIncompletePayment()){
return redirect()->route('account.invoices')->with('warning', 'You have a payment invoice for a pending subscription. Make payment or cancel.');
}
}
Check subscription == null with empty

Magento 2.3.3 Email Issue When Sending Email copy to multiple email

I am facing issue in the email in magento2. this issue is only faced in Magento 2.3.3.
How to produce
Go to
Store-> Configuration-> Sales-> Sales Emails -> Send Order Email Copy To -> enter multiple comma separated emails.
and change Send Order Email Copy Method BCC to separate Email
Now open any order and click on send an email you will get an error in
TypeError: Argument 1 passed to Magento\Email\Model\Template\Interceptor::setVars() must be of the type array, null given, called in /var/www/vendor/magento/framework/Mail/Template/TransportBuilder.php on line 368
have any one faced or fixed it??
I found a fix for it.
vendor/magento/module-sales/model/order/email/SenderBuilder.php
if (!empty($copyTo)) {
$this->configureEmailTemplate();
foreach ($copyTo as $email) {
$this->transportBuilder->addTo($email);
$transport = $this->transportBuilder->getTransport();
$transport->sendMessage();
replace above code as below
if (!empty($copyTo)) {
foreach ($copyTo as $email) {
$this->configureEmailTemplate();
$this->transportBuilder->addTo($email);
$transport = $this->transportBuilder->getTransport();
$transport->sendMessage();
Note: please dont do code in core file.

Sent Mail checking if it is delivered and open to recipient in Laravel

I want help in scaffolding code with Laravel default Mail package to send an email to the recipient with an enhancement that checks the status either mail is delivered to recipient and then check that either recipient opened the mail or not and then change the status of that email in my db_email_list. I googled it that to add headers just like follow the example but could not get it how to get the status
$message->getHeaders()->addTextHeader('X-Confirm-Reading-To','recipient_mail');
$sendEmail->getHeaders()->addTextHeader('Disposition-Notification-To','recipient_mail');
$sendEmail->getHeaders()->addTextHeader('Return-Receipt-To','recipient_mail');
When the user has gotten the email: Simply use this piece of code:
if (count(Mail::failures())) {
return false;
} else {
return true;
}
true=delivered, false=not delivered
When user reads the email: Hm sounds like you need to include a trick in your email in order to know if user has opened/read the email by simply adding for instance including an image on your email with a route defined in your end and passing user id as query param.
<img src="http://www.example.com/user-read-email?user_id=20" />
So whenever the user opens the email img src will fire a call to your url and simmply get the user id from the url, and set the flag for that user in db.

Send account confirmation email to specific customer group in magento

How to send account confirmation email to specific customer group in magento
I want to send confirmation email only a specific customer group. please any one can help in this issue....
I already save the customer group during registration or new account creation by using below link:-
http://phpmagento.blogspot.in/2012/01/how-to-show-customer-group-selecter-in.html
Go to the \app\code\core\Mage\Customer\Model\Customer.php
replace
<pre>
public function isConfirmationRequired()
{
if ($this->canSkipConfirmation()) {
return false;
}
if (self::$_isConfirmationRequired === null) {
$storeId = $this->getStoreId() ? $this->getStoreId() : null;
self::$_isConfirmationRequired = (bool)Mage::getStoreConfig(self::XML_PATH_IS_CONFIRM, $storeId);
}
return self::$_isConfirmationRequired;
}
</pre>
with:
public function isConfirmationRequired()
{
if ($this->canSkipConfirmation()) {
return false;
}
if (self::$_isConfirmationRequired === null) {
$storeId = $this->getStoreId() ? $this->getStoreId() : null;
if($this->getGroupId() == 2) {
self::$_isConfirmationRequired = (bool)Mage::getStoreConfig(self::XML_PATH_IS_CONFIRM, $storeId);
}
}
return self::$_isConfirmationRequired;
}
</pre>
Where 2 is the wholesale group Id.
Account confirmation email is sent when creating customer.
Customer group is added to customer after customer account is created.
So it's not possible to send confirmation email to only a specifik customer groep.
I Don't think you can without do some customization in magento.
Try
Disable All Email Confirmation. see How To Enable/Disable Email confirmation for New Account
Then create an observer for on customer save. see magento customer_save_after model / observer not called, catch customer -> edit -> save function
Check to see if the customer is a new customer and in the correct group (may need to check if the got confirmation email before)
Copy the logic that send Email confirmation from base magento into your observer

Show error message in guest subscriber if user already subscribe with that Id

I am using magento default newsletter subscriber. I found that the error There was a problem with the subscription: This email address is already assigned to another user. will be shown only if the subscriber has an account in magento store. If the subscriber is a guest customer then the error will not be shown, A success msg will be shown stating Newsletter Has been subscribed. How can I show message in guest subscriber also.
You should edit the following file :
/app/code/core/Mage/Newsletter/controllers/SubscriberController.php
in line #63 above this line of code :
$status = Mage::getModel('newsletter/subscriber')->subscribe($email);
add the following codes :
$emailExist = Mage::getModel('newsletter/subscriber')->load($email, 'subscriber_email');
if ($emailExist->getId()) {
Mage::throwException($this->__('This email address is already exist.'));
}

Resources