Magento - Adminhtml - Get id of order just created - magento

I want to do some post processing on an order, made using admin panel.
I have subscribed to the controller_action_postdispatch_adminhtml_sales_order_create_save event, and the correct function of this observer is being invoked.
How can I get the id of the order just saved in the saveAction in my function.

Mage_Adminhtml_Model_Sales_Order doesn't appear to save the order in the session anywhere, so this may be tough with the event you've chosen. In fact, the controller action you specified calls _getSession()->clear() to lose all the data from the session.
I would suggest finding a different event to use.

Related

How to create custom error when convert cart to order in Shopware6?

I'm trying to make plugin for Shopware6 that adds choice of period of delivery (for example, user can chose product to be delivered March 07 9:00-11:00). Problem is that can't be more than 15 orders in each period. So if used proceeds to make Order from Cart, and if period he chose has more than 15 orders, I must somehow invalidate form and tell to user to chose another period.
So I must:
somehow subscribe to the event "user makes an order from card",
check if chosen period is correct,
if not, tell it to user and don't create an order.
Is there any way to do it? In Symfony, I would just add validation to entity PeriodOfDelivery. But in Shopware I cannot do it because controller is in Shopware Core and I cannot edit it.
You can subscribe on CartConvertedEvent::class event. You can get original and converted cart data from the event.
In subscriber, you can do any check that you need and throw a specific exception.
You can implement your own exception class. use \Shopware\Core\Checkout\Order\Exception\DeliveryWithoutAddressException as template. In your own exception, you can specify own error code and message.

Registered user First visit url displays flash message

I would like to create middleware and check if registered user has already visited current URL and if not display flash message.
This feature i need just to show up tour on particular page so new user can understand what to do next.
I do realize that i can do it by store data in user table for each user but maybe there is another way to do such thing?
Thank you.
This may go quite complex depending on number of your routes. Why
don't you just make it simple:
1. Whenever user signup just store a session say session()->put('show_tour', true);
2. Now, show the flash-message on every page for registered user by checking this session value.
3. Make a button to disable this tour in your flash message. Make an AJAX call to destroy this session.

When do I call mixpanel.people.identify

How do I tell mixpanel the userID of my logged on user?
Do I need to call mixpanel.people.identify() everytime my user logs in, or only the first time that I'm creating them on mixpanel?
If only the first time, how does mixpanel know who to associate events to?
Also, once I have identified the person, will all events be tracable to that person, or do I need to call people.set() explicitly to track a generic event separately from a user-specific event?
You should call mixpanel.people.identify() every time a user logs in. You can even call it every time a page loads in a logged in state if you want.
identify sets some data in a cookie about what distinct_id the library should use when sending people data.
If you have called mixpanel.identify with the same distinct_id as mixpanel.people.identify, events that you send (with mixpanel.track) will show up under the user's profile on the Customers tab. In order for the user to show up at all, though, you will need to call mixpanel.people.set (or .add) at least once.
EDIT: mixpanel.people.identify is no longer necessary; you can just call mixpanel.identify and it will set both.

Prevent Observer method called twice

i am using Magento 1.5.1.0 and the "mPAY24 Payment Gateway" Extension.
I have an Observer class for the event "sales_order_payment_pay" sending notification
E-Mails to the manufacturer of the items.
This solution has some strange behavour:
When logged as a registered user - the observer method is called as expected
When checking out as a guest user, the "sales_order_payment_pay" Event is
fired when the "payment transaction" (Mastercard, VISA) was successful" and
a second time after clicking the "return Button" to get back to the Magento Shop.
because this behavior the E-Mail is sent twice.
Is there a way to prevent the observer method from beeing executed twice?
Kind Regards,
Bertie
No. As a client (vs. system) developer, you don't get to decide when an event fires.
Here's some general jumping off points for solving this problem:
Instead, you need to change the behavior of your observer method. Instead of blindly firing off an email in the observer method, you'll need to examine the state of the system and/or the objects in the $observer->getData() array, and determine if the event was fired after a payment transaction, or if it was fired after clicking the "clicking the return Button".
If it's the former, send your email as expected. If it's the later, just return from the observer method and/or skip the email with a conditional.
If this isn't your own observer method that's the problem (it's a core observer or a an observer that's part of the module), use a class rewrite to replace the observer method with your own. If you detect the correct state, call the return parent::observerMethodName, if it's the "clicking the return Button" state, just return null and skip calling the parent.
If the observer was setup with a hard-coded class name (not a class alias), then you'll need to use a code pool override to change the behavior of your method.

Magento event always dispatched when order is placed successfully?

I'm finding Magento event dispatching is quite a frustrating area. I suppose a lot of that frustration is, as usual, down to the lack of documentation.
I would like my code to be triggered at various stages as a visitor traverses through a site. So I put some debug in Mage::dispatchEvent, and I walked through the site to see what events are fired at each stage. There are a lot!
Two places I am interested in are:
when the visitor had selected a billing address and moved on to the next stage of the checkout process.
when a user successfully places an order
For the billing address one, the events that I saw being fired that look relevant are:
controller_action_predispatch_checkout_onepage_saveBilling
controller_action_postdispatch_checkout_onepage_saveBilling
The 'pre' and 'post' suggested to me that there is actually a 'checkout_onepage_saveBilling' event, but there isn't, so my first question is why the 'pre' and 'post'?
For the successful order, the events that look good are:
checkout_onepage_controller_success_action
checkout_multishipping_controller_success_action
My second question is will these events be fired for all payment methods? For example, if using Google Checkout, or PayPal (standard redirect), will the event fire, and at what point? When returning to the site from PayPal? If so that would beg the question what if the user does not return after completing payment.
Thanks for any help.
Sadly, I've noticed that checkout_submit_all_after does not fire for Paypal Express orders.
Short of modifying the Paypal models to add this (or perhaps hooking into events they may fire - I haven't checked on that yet), I think checkout_onepage_controller_success_action may really be the only event you can absolutely count on for every type of order.
The predispatch event will fire before the action has been called, the postdispatch event will fire after the action has been completed. So if you need to know what the result of the action was, you should use the postdispatch event.
For successful orders, checkout the checkout_submit_all_after event.
If you haven't seen it, https://www.nicksays.co.uk/magento-events-cheat-sheet-1-9/, is a handy reference for Magento events.

Resources