1

I need to call a webservice to ckeck the stock of products in my cart. I added this observer:

MyModule/etc/events.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="controller_action_postdispatch_checkout_index_index">
        <observer name="checkout_page" instance="Fcnet\Order\Observer\CheckStockBeforeValidateCart" />
     </event>
</config>

MyModule/Observer/CheckStockBeforeValidateCart

class CheckStockBeforeValidateCart implements ObserverInterface
{
....
 public function execute(EventObserver $observer)
    {

        $this->_logger->debug('------- OK -------');

    }

}

This observer is not called all the time, it is completely random. Is there another event or should I change something for this call to be made each time the cart is validated?

  • simicart.com/blog/magento-2-events-list refer this link for list of events and call the observer on cart checkout event i hope it will help you – Harsh Jayswal Apr 15 at 4:46
  • do you want to check the product stock whiile adding to cart or while proceeding to checkout ? – Manashvi Birla Apr 15 at 5:56
  • while proceding to checkout – Mathieu Apr 15 at 11:16
  • I cannot find any event in this list (simicart.com/blog/magento-2-events-list) corresponding to the validation of the basket. – Mathieu Apr 15 at 11:37
  • I tested with controller_action_predispatch_checkout_index_index instead of controller_action_postdispatch_checkout_index_index, same issue, my is randomly executed. We are using Fatsly, do you think it could be the problem ? – Mathieu Apr 19 at 5:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.