Send account confirmation email to specific customer group in magento - 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

Related

How to send password reset link in auto generated email template in magento

As shown in the screenshot, in the customer information when the password is set from admin and then changes are saved, an email is send to the customer. By default, the new password and account link is send in the email.
What I want to ask is that, is it possible to send the link of password reset also in this email?
I think the template used is:
app/locale/en_US/template/email/password_new.html
I tried to add following:
{{store url="customer/account/resetpassword/" _query_id=$customer.id _query_token=$customer.rp_token}}
But I am getting error on frontend as:
Your password reset link has expired.
Yes you can -- You can generate new reset password token & set it to customerObject - Try something like
/** #var $customer Mage_Customer_Model_Customer */
$customer = Mage::getModel('customer/customer')
->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
->loadByEmail("customer#gmail.com"); //change the email
if ($customer->getId()) {
try {
$newResetPasswordLinkToken = Mage::helper('customer')->generateResetPasswordLinkToken();
$customer->changeResetPasswordLinkToken($newResetPasswordLinkToken);
$customer->sendPasswordResetConfirmationEmail();
} catch (Exception $exception) {
Mage::log($exception);
}
}
So looks like the reset token is not generate for that email generated from the administrator.
I was able to fix this in 1.9.1.0 by creating a controller override for the app/code/core/Adminhtml/controllers/CustomerController.php files (per these instructions http://inchoo.net/magento/overriding-magento-blocks-models-helpers-and-controllers/ -- Adminhtml controller override section).
Copy the saveAction method to the override.
Inside the saveAction method, look for this block of code around line 351 (original file).
if (!empty($data['account']['new_password'])) {
$newPassword = $data['account']['new_password'];
if ($newPassword == 'auto') {
$newPassword = $customer->generatePassword();
}
$customer->changePassword($newPassword);
$customer->sendPasswordReminderEmail();
}
Change this block to
if (!empty($data['account']['new_password'])) {
$newPassword = $data['account']['new_password'];
if ($newPassword == 'auto') {
// no token generated
//~ $newPassword = $customer->generatePassword();
$newResetPasswordLinkToken = Mage::helper('admin')->generateResetPasswordLinkToken();
$customer->changeResetPasswordLinkToken($newResetPasswordLinkToken);
}
$customer->changePassword($newPassword);
$customer->sendPasswordReminderEmail();
}
To have the token generated and added to the password reset email from the admin.

Magento Newletter subscription - show error if already subscribed

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.
}

No Transaction ID in Payment Invoice

I've developed a Payment Method extension for Magento. In this extension, I've added:
protected $_canRefund = true;
However, when I click an invoice and select Credit Memo, I can only see 'Refund Offline' and not 'Refund'. All tutorials I followed insist that I only have to change that value to true to activate the button (obviously I still have to implement the refund method and the actual refund procedure) but I can't see a way to do this.
If I, within a block on the order screen, execute this line $order->getPayment()->getMethodInstance()->canRefund(); it does indeed return true, but still no luck with the actual credit memo.
Edit
I've changed the title of the question to reflect my new find.
Basically, the reason it's not appearing is because my invoices aren't created with transaction IDs - I have no idea why, but this is my capture payment method that runs when generating an invoice:
public function capturePayment($order) {
try {
if (!$order->canInvoice()) {
Mage::throwException(Mage::helper('core')->__('Cannot create an invoice.'));
}
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
if (!$invoice->getTotalQty()) {
Mage::throwException(Mage::helper('core')->__('Cannot create an invoice without products.'));
}
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
$invoice->register();
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder());
$transactionSave->save();
$order->setState('processing', 'payment_received', "Payment has been received", false);
$order->save();
} catch (Mage_Core_Exception $e) {
Mage::throwException("Error Taking Payment, Please Try Again:\n" . $e);
}
}
Why isn't a transaction ID being assigned to my capture?
check below url
http://www.spinonesolutions.com/2009/10/magento-enable-paygate-refunds/
https://magento.stackexchange.com/questions/7846/capture-void-refund-not-showed-in-magento-admin-area
http://excellencemagentoblog.com/magento-create-custom-payment-method-api-based
hope this help you

Set Error message if customer is login from different group

I want to restrict the login for particular group of customer from magento front side
So that i have put a check in loginPostAction method of customer AccountController.php file and redirect them on login page back.
But i could not able to set a error message like You are not authorize person on that page after redirection
Below is my code i made so far
$session = $this->_getSession();
if ($this->getRequest()->isPost()) {
$login = $this->getRequest()->getPost('login');
if (!empty($login['username']) && !empty($login['password'])) {
try {
$session->login($login['username'], $login['password']);
if($session->getCustomer()->getGroupId()!="4")
{
$session->logout();
$message = 'You are not authorized person';
$session->addError($message);
$this->_redirect('customer/account/login');
return;
}
}
}
So now if customer except 4 id group try to login, they will redirect back to login page but session message will not display.
I have tried this
Mage::getSingleton('customer/session')->addError($message);
and this also
$message = $this->__('Got an error');
Mage::getSingleton('core/session')->addSuccess($message);

Stop Magento from emptying the shopping cart before payment confirmation?

This is one of the most vital problems I have found since I started testing Magento for my web store. It's kind of a no-brainer that it's absolutely unnecessary and harmful to sales to empty cart before payment confirmation, which unfortunately, Magento does.
If the user selects PayPal (website standard) for payment method and for some reason clicks "Back to xxxx" (your business name at PayPal) on the PayPal payment page without paying, PayPal would redirect the user back to http://www.example.com/checkout/cart/, which now is an EMPTY cart.
I think it should be after payment confirmation / PayPal IPN that the cart be empty-ed, instead of any point before that.
Even if the user wants to continue again, he or she'd be annoyed from searching and adding all the products again and would very probably just leave.
Any idea how I can work around this?
This worked for me:
File: ~/app/code/core/Mage/Checkout/controllers/OnepageController.php
Replace this:
$this->getOnepage()->getQuote()->save();
/**
* when there is redirect to third party, we don't want to save order yet.
* we will save the order in return action.
*/
if (isset($redirectUrl)) {
$result['redirect'] = $redirectUrl;
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
With this one:
/**
* when there is redirect to third party, we don't want to save order yet.
* we will save the order in return action.
*/
if (isset($redirectUrl)) {
$result['redirect'] = $redirectUrl;
$this->getOnepage()->getQuote()->setIsActive(1) ;
}
$this->getOnepage()->getQuote()->save();
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
For Paypal I found the cancel action inside the app/code/core/Mage/Paypal/controllers/StandardController.php cancelAction
I changed the code like that for cancel action
public function cancelAction()
{
$session = Mage::getSingleton('checkout/session');
$cart = Mage::getSingleton('checkout/cart');
$session->setQuoteId($session->getPaypalStandardQuoteId(true));
if ($session->getLastRealOrderId()) {
$incrementId = $session->getLastRealOrderId();
if (empty($incrementId)) {
$session->addError($this->__('Your payment failed, Please try again later'));
$this->_redirect('checkout/cart');
return;
}
$order = Mage::getModel('sales/order')->loadByIncrementId($session->getLastRealOrderId());
$session->getQuote()->setIsActive(false)->save();
$session->clear();
try {
$order->setActionFlag(Mage_Sales_Model_Order::ACTION_FLAG_CANCEL, true);
$order->cancel()->save();
} catch (Mage_Core_Exception $e) {
Mage::logException($e);
}
$items = $order->getItemsCollection();
foreach ($items as $item) {
try {
$cart->addOrderItem($item);
} catch (Mage_Core_Exception $e) {
$session->addError($this->__($e->getMessage()));
Mage::logException($e);
continue;
}
}
$cart->save();
$session->addError($this->__('Your payment failed. Please try again later'));
}
$this->_redirect('checkout/cart');
}
It worked pretty good for me and there is no need to change any other place for that.
It marks the current order as Cancelled and restores the cart with using that order and redirects the user to cart again.
/app/code/core/Mage/Checkout/controllers/OnepageController.php this file is the actual controller file, but depends up on the payment method extensions it will change with Namespace/Modulename/Checkout/controllers/OnepageController.php
Find function saveOrderAction()
find these lines
$this->getOnepage()->getQuote()->save();
/**
* when there is redirect to third party, we don't want to save order yet.
* we will save the order in return action.
*/
if (isset($redirectUrl)) {
$result['redirect'] = $redirectUrl;
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
comment this line //$this->getOnepage()->getQuote()->save();
and add below codes inside the if condition so the condition will look like ..
//$this->getOnepage()->getQuote()->save();
if (isset($redirectUrl)) {
$result['redirect'] = $redirectUrl;
$this->getOnepage()->getQuote()->setIsActive(1) ;
}
$this->getOnepage()->getQuote()->save();
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
This is i have done with the third party Payment extension.
Since Magento version 1.6.0.0 (juli 2011) you can enable "Persistent Shopping Cart"
under
System > Configuration > Customers > Persistent Shopping Cart
This should solve this problem.
Use these settings to make it work
Enable Persistence = Yes
Persistence Lifetime (seconds) = 31536000
Enable "Remember Me" = Yes
"Remember Me" Default Value = Yes
Clear Persistence on Log Out = No
Persist Shopping Cart = Yes
Good luck :)
Your issue is with the way Mage_Checkout_OnepageController::saveOrderAction() behaves.
More specific: open app/code/core/Mage/Checkout/controllers/OnepageController.php
$this->getOnepage()->getQuote()->save();//this makes the cart empty (sets the quote as converted to order)
if (isset($redirectUrl)) {
$result['redirect'] = $redirectUrl;
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
You can replace the last part:
$this->getOnepage()->getQuote()->save();//....
with:
if (isset($redirectUrl)) {
$result['redirect'] = $redirectUrl;
$this->getOnepage()->getQuote()->setIsActive(1) ;
}
$this->getOnepage()->getQuote()->save();
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));

Resources