Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
magento 2 catalog_product_save_before unable to save product but keeps loading

I'm trying to save the product in the observer of event catalog_product_save_before, but somehow the admin panel is just loading, it's not saving the product.

Can anyone please suggest the solution for this?

    /**
     * Execute observer
     *
     * @param \Magento\Framework\Event\Observer $observer
     * @return void
     */
    public function execute(
        \Magento\Framework\Event\Observer $observer
    ) {
        $_product = $observer->getProduct(); // you will get product object
        $_sku = $_product->getSku(); // for sku
        $_product->setSku("testNew1");
        $_product->save();
    }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

This approach will cause a loop. Because the catalog_product_save_before is dispatched before every product save. And in this observer you do $_product->save(); which again will dispatch this event and come in this observer where the save() method is called again, etc.

As you get the $product in the observer before its save, it should just work to adjust the product object and it will be saved afterwards.

So remove the line $_product->save(); and it should work fine.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!