How to send email notification after creating lead in sugarcrm through webservice(nusoap) - sugarcrm

I have successfully created a lead in sugarcrm 6.5 using nusoap. But now problem is, How to send email notification to assigned user?
Please help me!!

Based on your situation, what I would do is use a after_save logic hook to send your email. Logic Hooks allow you to plug into the SugarCRM logic. The code below allows you to do something after a Lead is saved.
Create a logic_hooks.php or add the following if it already exists in custom/modules/Leads/logic_hooks.php
<?php
$hook_version = 1;
$hook_array = Array();
$hook_array['after_save'] = Array();
$hook_array['after_save'][] = Array(1, 'Send Notification', 'custom/modules/Leads/Leads_custom.php','Leads_custom', 'send_notification');
After any Lead is saved, it'll run the following code in custom/modules/Leads/Leads_custom.php
<?php
class Leads_custom
{
function send_notification($bean, $event, $arguments)
{
// write your code here to send the notification to the head(Manager)
}
}
This will fire anytime Leads are created or edited. If you need to only send notifications on new Leads, you can use this technique: http://developers.sugarcrm.com/wordpress/2013/08/21/doing-beforeafter-field-comparisons-in-after_save-logic-hooks/

If you have the process manager available in your Sugar Version (entrprise+) then you just have to create a process definition that triggers an email when a new lead is created. If not then it's a logic hook.

Related

Resend order confirmation emails for some orders in Shopware 6

Because of an error which is now fixed, our customers did not received order confirmation emails for a while.
Is there a way to resent the order emails for some orders once?
We know about the plugin, but as this is supposed be needed only once, it's kind of overkill to install, test and deploy a plugin.
Are there some code snippets or a bin/console command to accomplish this task?
Or is it even possible via the admin panel?
It is possible to define a flowbuilder flow to send order confirmation mails, but you'd to define an appropriate trigger action of course, that you can trigger yourself for the affected orders. After the oneshot command you could disable/delete the flow.
Not sure if this fits your needs...
You could write your own CLI command to re-fire the event when an order is placed.
// $this->orderRepostitory - DI service `order.repository`
// $this->orderConverter - DI service `Shopware\Core\Checkout\Cart\Order\OrderConverter`
// $this->eventDispatcher - DI service `event_dispatcher`
$criteria = new Criteria();
$criteria
->addAssociation('orderCustomer.customer')
->addAssociation('orderCustomer.salutation')
->addAssociation('deliveries.shippingMethod')
->addAssociation('deliveries.shippingOrderAddress.country')
->addAssociation('deliveries.shippingOrderAddress.countryState')
->addAssociation('transactions.paymentMethod')
->addAssociation('lineItems.cover')
->addAssociation('currency')
->addAssociation('addresses.country')
->addAssociation('addresses.countryState')
->getAssociation('transactions')->addSorting(new FieldSorting('createdAt'));
// add a filter for the orders for which no mail has been sent before
$criteria->addFilter(new RangeFilter('createdAt', [RangeFilter::LTE => (new \DateTime('2020-01-01'))->format(\DATE_ATOM)]));
$orderEntities = $this->orderRepository->search($criteria, $context->getContext())->getEntities();
foreach ($orderEntities as $orderEntity) {
$salesChannelContext = $this->orderConverter->assembleSalesChannelContext($orderEntity, Context::createDefaultContext());
$event = new CheckoutOrderPlacedEvent(
$salesChannelContext->getContext(),
$orderEntity,
$salesChannelContext->getSalesChannel()->getId()
);
$this->eventDispatcher->dispatch($event);
}
This should in theory also trigger the mails to be sent once more. Obviously try this with a test order before mass dispatching events like this. Also you should probably do this in smaller batches to avoid memory issues.

WooCommerce Hook to Trigger Email in Refund inside Email Class

By default, WooCommerce does not send Refund emails because refunding is, as Mike Jolley says, "a manual process". However, I need to send one!
My problem is: I can't find a hook that will fire inside my extended email class to do this.
I followed this tutorial, wrote a class to extend WC_Email and got everything working except that I need a hook to trigger the class when an order status is changed and saved as "refunded":
http://www.skyverge.com/blog/how-to-add-a-custom-woocommerce-email/
I tried various hooks like woocommerce_order_status_refund in place of the woocommerce_order_status_pending_to_processing_notification hook on line 39-40.
The problem is that woocommerce_order_status_refund doesn't trigger inside email class. It works fine elsewhere, but not in this context.
I tried replacing the hook with woocommerce_order_actions_end as a sort of "generic". I added an if (! $order->status == 'refunded') to filter for "refunded" only. But now the hook fired every time an order with a status of 'refunded' is loaded.
(I also tried adding a custom action with woocommerce_order_actions to the actions menu, but the problem is here I don't know how to trigger my class with this. It seems to load before the class so that doesn't work either.)
Is there any way to trigger an email send via an extended class only when order status is changed to 'refunded'?
Referencing this question there are two things you must do to get the refund status to trigger an email.
First you must register the woocommerce_order_status_refunded hook as a hook that will trigger an email. By default, it does not.
/**
* Register the "woocommerce_order_status_refunded" hook which is necessary to
* allow automatic email notifications when the order is changed to refunded.
*
* #modified from https://stackoverflow.com/a/26413223/2078474 to remove anonymous function
*/
add_action( 'woocommerce_init', 'so_25353766_register_email' );
function so_25353766_register_email(){
add_action( 'woocommerce_order_status_refunded', array( WC(), 'send_transactional_email' ), 10, 10 );
}
EDIT for WooCommerce 2.3
After merging in my pull request, the next version of WooCommerce (2.3) should support filtering of the actions that trigger emails. So you would add the refund status via filter:
add_filter( 'woocommerce_init', 'so_26483961_filter_email_actions' );
function so_26483961_filter_email_actions( $emails ){
$emails[] = 'woocommerce_order_status_refunded';
return $emails;
}
Then in your custom email class's _construct method, you can use this as the trigger:
add_action( 'woocommerce_order_status_refunded', array( $this, 'trigger' ) );

Zend -> ZfcUser create new user after email verification/activation

I am working on a website, which already has a working registration form, using the ZfcUser module.
However,
I need to also be able to create a user via the admin page i've created.
Step by step it goes something like this:
Admin adds user by filling in first name, last name and email.
email gets sent to user.
user clicks validation link and gets redirected to website.
now the user only has to enter his desired password and he is done.
How would i be able to do this, if at all possible?
first of all, im not sure what would be the best aproach, but a few come to my mind.
I think the easier would be to load the register form in your admin, remember you can load it from any controller with the service manager, something like
$form = $sm->get('zfcuser_register_form');
and then you can work with it as you would do with any form, sending it to the view, and so.
You would have the full register form, with all the fields you have set as required in your zfcuser.global.php, including the password. I think it is good to set a temp password, and have the user change it later. also you could have its status as unconfirmed until the first password change.
If you dont want an specific field, you can take it out as you would with any form, by means of
$form->remove('element_name');
You would want to check the element names at ZfcUser\Form\Register
Also, remember that if you remove any field, you would have to modify the input filter, otherwise the validation will fail. For this, in your module's bootstrap, you should attach an event listener, something like this:
$em = $e->getApplication ()->getEventManager ();
$em->attach ( 'ZfcUser\Form\RegisterFilter', 'init', function ($e) {
$filter = $e->getTarget ();
//now modify the inputfilter as you need
});
Then, you will have to send the mail to the user. For that i will also use the event manager, at your bootstrap you register a listener for when the user is created, this is by means of
$sm = $e->getApplication ()->getServiceManager ();
$zfcServiceEvents = $sm->get ( 'zfcuser_user_service' )->getEventManager ();
$zfcServiceEvents->attach ( 'register.post', function ($e) {
$form = $e->getParam ( 'form' );
$user = $e->getParam ( 'user' );
//now you have all the info from the form and the already created user, so you can send the mail and whatever you need.
The last step, is to let the user change his password. To do this, i will send him to a module where you show the change password form, that you can retrieve with:
$sm->get('zfcuser_change_password_form');
or directly, sending him to the /user/change-password url that is one of the predefined with zfc-user.
I think this will be the cleanest way.
Another approach
If you dont like it that way, you can use another approach where you create your own form, fill it, save the data to a temp table, send the mail and then...when the user comes to set his password, you build a register form, with the fields pre-filled (and hidden, changing the input type to hidden, or by css) and let him send the form, so while he thinks he is sending just the password, actually he is sending all the registration form, and from here everything is like in normal registration.
For this solution you will also have to use the events, but probably you'd have to take a look at the register event,that is triggered when the form is sent, before the user is saved in the database, so you can modify any data you could need.
$zfcServiceEvents->attach ( 'register', function ($e) {
$form = $e->getParam ( 'form' );
And also you should take a look to the already mentioned init event, where you can retrieve the form before you show it to the user, and prefill any data from the temp table.
$events->attach ( 'ZfcUser\Form\Register', 'init', function ($e) {
$form = $e->getTarget ();
//now you set form element values from the temp table
Probably this is so confusing, but i hope you at least get a clue of where start from!

Where to put the business logic in a magento module for an email form?

I'm new to magento and I'm trying to create a module for an email form.
In classic MVC I would send the request to the Controller, but in Magento a controller is only responsible for one URL. So when I want to put my email form on the productpage I cant use the controller, is that right?
I inlcude my block element via layout xml in the productpage. So I have to validate my form und send the email in the class of my block element? Or would I have to write one or more helpers for that?
What is the magento way?
Thanks a lot. Sorry if my question is lame, but I'm a beginner and I want to learn the right way and I have seen so much tutorials with the wrong one.
Just while submitting the form give action to controller like:
<?php echo Mage::getUrl()?>bpartner/index/mailbpartner
bpartner your module name
Index your controller name
mailbpartner your function in INDEX NAMED CONTROLLER FILE.
Get all details through POST and send mail like below + redirect with success
$to = "abc#abc.com";
$dt = date('d-m-Y');
$subject = "Become A Partner Details on date $dt";
$mail = new Zend_Mail('utf-8');
$mail->setBodyHtml($message)
->setFrom($data['email'], $data['firstname'])
->addTo($to, 'Site Admin')
->setSubject($subject);
try {
$mail->send();
Mage::getSingleton('core/session')->addSuccess('Mail sent successfully. We will contact you shortly');
}
catch(Exception $e) {
Mage::getSingleton('core/session')->addError('Unable to send email.');
}
$this->_redirect('bpartner');
Some above data are POST DATA which is self understandable

programmatically mark a shipping email as sent

I have set up an observer to send out an email as soon as a tracking number is added to a shipment, but I need to be able to some how show in the admin that the email has been sent instead of displaying "the shipment email is not sent."
Here is the code I am currently using. There is an issue with it because it some how ends up sending out a ton of emails, as if it is some how stuck in a loop. I could really use some help in figuring out why this is happening.
class WR_TrackingEmail_Model_Observer
{
public function sendTrackEmail($observer)
{
$track = $observer->getEvent()->getTrack();
$shipment = $track->getShipment(true);
$shipment->sendEmail();
$shipment->setEmailSent(true);
$saveTransaction = Mage::getModel('core/resource_transaction')
->addObject($shipment)
->addObject($shipment->getOrder())
->save();
}
}
You are calling save() on the shipment object. The shipment class has an _afterSave() function that triggers save on the track objects. Since you are creating an observer for track_save_after, you are very likely causing a loop.