_init(Location::class, LocationResource::class); } /** * Insert or update based on UNIQUE combo 'key-processing' * @param $key * @param $value */ public function insertOrUpdate($item) { $connection = $this->getConnection(); try { // Start a transaction // $connection->beginTransaction(); // Insert new item or update existing one $connection->insertOnDuplicate($this->getMainTable(), $item, ['data', 'status']); // Commit the transaction // $connection->commit(); } catch (\Exception $e) { // Rollback the transaction in case of an error $connection->rollBack(); throw new \Magento\Framework\Exception\LocalizedException( __('Error in insertOrUpdate: %1', $e->getMessage()), $e ); } } }