Skip to content

Magento, Saved data not in DB after throw new LocalizedException

save some records to DB and after throw LocalizedException, the saved data does not show in the table. auto increment ID is assigned

$data = [
‘sku’ => $f_sku,
‘user’ => $adminUsername, // Assuming admin is saving the product
‘product_status’ => $f_product_status, // Product status from submission
‘log’ => $product_type .”n” .str_replace( “
“, “n” , $comment),
‘product_id’ => $product->getId(),
‘status’ => $save_status, // Validation status
];

    /** @var EfBundleModelBundleLog $bundleLog */
    $bundleLog = $this->bundleLogFactory->create();
    $bundleLog->setData($data);
    try {

        $this->bundleLogRepository->save($bundleLog);
        $this->addLogs->add_error('event_before_save_products', $data, 'validate_products');

    } catch (Exception $e) {
        throw new LocalizedException(__('Error saving bundle log: %1', $e->getMessage()));
    }

    if($error  ) { // if having a error
        throw new LocalizedException(__($comment));
    }