Im using one page checkout and I need to pass few information after payment has been successfully made. I have used sales_order_payment_pay, checkout_type_onepage_save_order_after, sales_order_payment_place_end & checkout_onepage_controller_success_action events. But these events are triggered as soon as clicking on place order. Even if the payment is failure also its triggering that event. I need to pass information only on successful payment.
sales_order_payment_place_end should be good enough. Just add whatever logic you need to use. You can grab the $payment from the $observer and the $order from the $payment
Try looking into $payment->getAmountAuthorized If the payment succeeded this should be greater then 0.
EDIT: $observer->getEvent()->getPayment(); (should work)
Normally the Status of an Order changes After Payment notification. You can watch for Status change have a Look at:
http://www.cartware.de/blog/detail/article/kein-magento-event-fuer-statusaenderung/
Its written in german Language but by watching the Code you may get the clue
Related
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.
There is a choice of “SALE” or “AUTHORISATION” in the Magento Paypal settings. We ideally wish to stay with “SALE” as that covers 99.9% of anything we do (we always have goods in stock). The “Authorisation” option worries me with the 3 day limit, plus it adds an extra “capture” step that could go wrong later.
So…….
“SALE" works fine but in Magento it automatically creates an INVOICE in the system. Other payment systems we use such as Sofort AG make this setting optional and for a very good reason.
Magento is set so that once you have produced an INVOICE and a SHIPMENT it automatically marks any order as COMPLETE.
We create UPS labels, with a tracking number which of course is added to the SHIPMENT details. So my problem is:
As soon as we try to create a UPS label (without even printing) Magento sets the Paypal orders to COMPLETE. This is because it has seen an INVOICE
and a SHIPMENT for an order.
We need to disable a Paypal “SALE” from producing an invoice. We can easily produce and send the invoice once the shipment has been produced
and sent, and then set it finally to Complete.
Is there a setting I have missed to disable this forced invoice? I can see a company used to make a module for this purpose but it is out of date for Magento 1.9. (I did try it just in case!!)
http://www.magentocommerce.com/magento-connect/disable-automatic-generation-of-invoice.html
No, there is no setting to fix this: paypal create an object called transaction and this kind of object should be created with the object invoice. It's not a good practice to don't create invoice and I suggest you to stay away to any component that don't create a transaction.
Probably it works well, but in the flow of order creation when you will evalutate to play with order status. Anyway there is not a setting to do this.
I've built an observer that listens to the registration_success_observer event that is emitted upon new user registration (from the accounts page). The observer handles various functionality, most importantly upgrading the user to a membership group if a membership id is passed in.
The problem is that I need to have the same functionality for users who are checking out AND signing up as a new customer. I somehow need a way to figure out if they are signing up as a new customer (via event?) from the one page checkout screen, in addition to re-calculating the totals -- some items in our store have special pricing for groups.
Does anyone know the best way to go about this? Specific events that I should listen for, or any other code snippets for handling functionality within the one page checkout screen would be helpful.
** Update **
It just occurred to me that a customer isn't actually created until after the order is complete. Any workarounds for this?
You could create your own 'custom event' using the logic below to check which method they use to check out on success.phtml or incorporate it in sales_order_place_before
$quoteId = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId())->getQuoteId();
$quote = Mage::getModel('sales/quote')->load($quoteId);
$method = $quote->getCheckoutMethod(true);
if ($method == 'register'){
//the customer registered...do your stuff
}
Source : http://www.magentocommerce.com/boards/viewthread/273690/#t375160
But what your trying to do may not be possible without rewriting the onepage checkout, because a customer is created before order is store in the db but after processing the credit card so the amount the credit card is bill for wouldn't equal the order total.
You could try to add a third option to the first step in the checkout process ('register as a member') that allow them to create an account before start checking out.
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.
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.