Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

114
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda