I'm developing some functionality using events, observers to determine if certain conditions for an order are met. If not, the user is redirected back to the cart screen with a message.
The conditions are that the first order must be at least 500 and the user must be in a certain customer group. This works fine. Now when i click the order button, stock gets decreased but no order is made. I'm trying to find a way to have this stock decrease not happen.
I'm using an observer on the following event:
"sales_model_service_quote_submit_before"
The observer sits in a custom module. I was trying to find an event "before" stock decrease but i couldn't find it. I'm happy if you provide me with the right event, also with a solution to this stock decrease. I'll show you some of my code:
part of config.xml
<frontend>
<events>
<sales_model_service_quote_submit_before>
<observers>
<company_firstorder>
<type>singleton</type>
<class>COMPANY_FirstOrder_Model_Observer</class>
<method>firstOrder</method>
</company_firstorder>
</observers>
</sales_model_service_quote_submit_before>
</events>
</frontend>
Part of my observer.php
if ($isActive){
if ($customer->isLoggedIn() && $customerGroupId === $currentCustomerGroupId){
if ($ordersCount < 1){
if ($orderGrandTotal < $minimumOrderAmount){
// Here, something should happen that fixes my stock decrease problem
Mage::getSingleton('checkout/session')->addNotice('Custom error notice - To Do: Add field in backend for this notice');
Mage::app()->getResponse()->setRedirect(Mage::getUrl('checkout/cart'))->sendResponse();
exit;
}
}
}
}
I have been stuck on this issue the whole day so any help is greatly appreciated :)
P.s. There is a post about programatically increasing the stock but this is not a good solution to my problem. I checked loads of stack posts before writing this one.
EDIT Due to complexity i used a different approach. I'm performing these checks now on the checkout page. This will hide/show my checkout button and display a message. This alternative works for me. Case closed