Stopping product saving process in observer

后端 未结 5 1508
猫巷女王i
猫巷女王i 2021-01-06 05:07

I am currently developing a module working with the product edit in the backend. Its purpose is to retrieve categories the product belongs to and populate an attribute (the

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-06 05:54

    I don't think you can you stop execution the way you want via an observer, Magento doesn't pay attention to anything that you might return or set via your observer.

    One idea would be too rewrite the save method of the product model. You could check for any error flag that you set in your observer and then prevent the save from that point. Something like this:

    function save()
    {
        if( $error_detection )
        {
            return $this;
        }
        else
        {
            return parent::save();
        }
    }
    

提交回复
热议问题