create invoice and email in Magento - email

I want to automate the creation of invoice and email in Magento. Invoice creation seems to work but I am having getting the email part working...
Mage::app();
$order = Mage::getModel('sales/order')->loadByIncrementId($orderid);
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();
}
catch (Mage_Core_Exception $e) {
}
}

I know my reaction is kinda late but for others who find this page:
You need to add the code for sending the email.
Do this after the register line:
$invoice->register();
$invoice->getOrder()->setCustomerNoteNotify(true);
$invoice->getOrder()->setIsInProcess(true);
$invoice->sendEmail();
setCustomerNoteNotify is used to say if the customer has to get the email.
setIsInProcess will change the order state to processing

Related

Magento 2.0.7: Something went wrong with the subscription.

get error whe subscription Newsletter. How can fix?
Here is the problem and the solution to this bug:
When we enter an new email address (one that is not connected to an extisting subscriber), the subscriber object ($this) has no id ($this->getId(); // null) yet in Magento\Newsletter\Model\Subscriber::subscribe.
The verification email is sent out before the subscriber is saved, thus the subscriber id is missing from the verification link. The link does not do anything when you click on it because the verification method in Magento\Newsletter\Controller\Subscriber\Confirm::execute rejects the link because of the missing id.
You can easily mend the problem by calling $this->save() before calling $this->sendConfirmationRequestEmail();
try {
$this->save();
if($isConfirmNeed === true && $isOwnSubscribes === false)
{
$this->sendConfirmationRequestEmail();
} else {
$this->sendConfirmationSuccessEmail();
}
return $this->getStatus();
} catch (\Exception $e) {
throw new \Exception($e->getMessage());
}
I simply moved the ''save'''- call a few lines up. sendConfirmationRequestEmail and sendConfirmationSuccessEmail do not seem to alter the $thisobject, so this is a valid change that does not break anything else.
I just changed the "Disable Email Communications" to yes in Magento 2 ( Stores > Configuration > Advanced > System > Mail Sending Settings > Disable Email Communications).

Is there anyway to restrict registration on a ninja form (wordpress) to allow only a certain email address to register?

this is a wordpress related question. I was wondering while using the ninja forms plugin, if it is possible to restrict the submission process to only allow #example.com email address to successfully submit the form.
Any ideas? I appreciate the time and responses from you all.
Please post the code for your form (even the generated html) so that the question stands the test of time!
You can do something like this in jQuery:
$('#signup').submit(function() {
validateEmail($('input').val());
return false;
});
function validateEmail(email) {
var re = /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\#[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/;
if (re.test(email)) {
if (email.indexOf('#c-e.com', email.length - '#c-e.com'.length) !== -1) {
alert('Submission was successful.');
} else {
alert('Email must be a CE e-mail address (your.name#c-e.com).');
}
} else {
alert('Not a valid e-mail address.');
}
}
I found it in this working fiddle by Erik Woods:
http://jsfiddle.net/AkuXC/86/

Skype4COM edited sent messages

I would like to use the API 'Skype4COM' to edit already sent messages, I have approached this before but seem to not have any luck in finding a solution that will let me access/edit my last message sent.
I'm sure it has to do with the MessageStatus event but I cannot work out how to edit them/remove them after they have sent.
public void MessageStatus(SKYPE4COMLib.ChatMessage pMessage, SKYPE4COMLib.TChatMessageStatus Status)
{
if (Status.Equals(TChatMessageStatus.cmsSent))
{
if (pMessage.IsEditable)
{
//Remove message/edit message?
}
}
}
In the Skype4Py API you can simply do pMessage.Body = "your text" which will call the pMessage objects SetBody() function. You should try that.

Magento: Core sends welcome mail after customer is saved

I noticed the following bug:
When I add an address to a customer using the admin backend, or if I change an address and i save the customer, the Magento Costumer AccountController sends a standard email to the updated customer. The email template used is the template for the customer event "confirmed". This always happens when I update the customer.
Had someone the same problem or a solution for this? I can't understand why magento sends an email for this event...
Class: Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
Methode: saveAction()
Solution: It's a core bug from older versions. The condition for sending a mail after saving a customer uses isset($sendPassToEmail). But if you notice, the sendPassToEmail variable is always set and has the values true or false. Because of the isset() the condition is always true and an email will be send every time a customer is saved.
...
$sendPassToEmail = false;
// force new customer active
if ($isNewCustomer) {
$customer->setPassword($data['account']['password']);
$customer->setForceConfirmed(true);
if ($customer->getPassword() == 'auto') {
$sendPassToEmail = true;
$customer->setPassword($customer->generatePassword());
}
}
Mage::dispatchEvent('adminhtml_customer_prepare_save', array(
'customer' => $customer,
'request' => $this->getRequest()
));
$customer->save();
// send welcome email
if ($customer->getWebsiteId() && (!empty($data['account']['sendemail']) || isset($sendPassToEmail))) {
$storeId = $customer->getSendemailStoreId();
if ($isNewCustomer) {
$customer->sendNewAccountEmail('registered', '', $storeId);
}
// confirm not confirmed customer
else if ((!$customer->getConfirmation())) {
$customer->sendNewAccountEmail('confirmed', '', $storeId);
}
}

SharePoint 2010 send WorkFlow email on form submit/save click

Could you please help me understand how to send a workflow email, when user submits a task form. The process is to automate the sending of email to "BI Owners", when user fills out a form and once he/she clicks "save"/"submit", then the email should be sent out.
Thanks in advance.
Do you need to understand the Worfklow's configuration?
In that case, check this out:
Send e-mail in a workflow
How do you build up your form? It is an aspx, a webpart, some kind of magic?
Well, this is important, 'cause you have different ways to fire up your workflow, depending on that.
If you have all the form's control, well, this is my sending emails class:
protected void sendEmail()
{
try
{
string mailTo = dudeToSendMail;
MailMessage message = new MailMessage();
message.From = new MailAddress(mailSender);
message.To.Add(new MailAddress(mailTo));
message.Subject = mailSubject;
message.Body = buildMail(); // hey, dude, build up your mail here!
message.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.Send(message);
}
catch (System.Exception)
{
throw;
}
}
Hope it helps.