magento "X bought" count on deals
I managed to modify some of magento's code to implement our own 3rd party gateway, but I'm having trouble with incorrect "bought" count on the deal when someone does the order, the count is increasing directly when saveOrderAction runs (before success or fail page - on fail the count is decreasing back again, which is right - but I do not want it to increase before success page) at this stage, the order is saved as 'processing' in the system
the code I have no basically is: in the "saveOrderAction" I have a condition that checks the payment method selected,
if it is our 3rd party, it redirects to the 3rd party page, then I pass some parameters from the 3rd party page back to magento to the 'successAction' or 'failureAction' (whichever is the case),
then accordingly save the order, set its state as complete, and so on...
what I want to do is only increase the 'bought' count after payment is successful, if someone can give me insight of the logic of how the 'bought' is implemented in magento
I do know this occurs in the function saveOrder() in model mage\checkout\model\type\onepage.php :
$service = Mage::getModel('sales/se开发者_如何学JAVArvice_quote', $this->getQuote());
$service->submitAll();
but I can't figure out where in submitAll it is occuring... I assume maybe at first I should not save the order, or maybe set it at a different state where it is not counted or I don't know what?
any help/suggestion would be greatly appreciated! thanks :)
One way to do this, that might save some trouble, would be to add an Observer to an event that matches your need. Particularly, there are several events for Mage_Sales_Model_Order_Payment that might be appropriate:
sales_order_payment_save_after
sales_order_payment_capture
sales_order_payment_pay
... several more ...
If you take a look at these events, you may find that one of them is a reasonable time to add to your sold count. Similarly, there are events on that object for cancelling or refunding orders, which you could use to decrement sales as necessary.
I usually avoid hooking into controller actions for this type of behavior because I cannot guarantee that Magento will always use that action in the way that I assume.
Anyway, let me know if that was helpful or if you still have the same question. Hope that helps!
Thanks, Joe
精彩评论