Register barcode in Grocy after creating product via "Create Product"#297
Open
pacso wants to merge 1 commit into
Open
Register barcode in Grocy after creating product via "Create Product"#297pacso wants to merge 1 commit into
pacso wants to merge 1 commit into
Conversation
When the user clicks "Create Product" on an unknown barcode, BB opens Grocy's new-product page (with the OFF name prefilled) in a new tab. After Grocy's tab closes, processRefreshedBarcode() updates BB's local Barcodes table with the new product id, but it does not register the barcode itself in Grocy. The barcode only got written to Grocy if the user then clicked Add or Consume, which calls API::addBarcode(). Users reasonably expect "Create Product" to fully integrate the product, including the barcode. This adds an API::addBarcode() call in processRefreshedBarcode so the barcode is registered immediately, and emits the corresponding EVENT_TYPE_ASSOCIATE_PRODUCT log entry. Subsequent Add/Consume clicks will still call API::addBarcode (now a duplicate); Grocy returns an error which is already swallowed by processError, so the inventory action proceeds. A future change could guard the addBarcode call in index.php with a known-barcode check.
pacso
added a commit
to pacso/barcodebuddy-docker
that referenced
this pull request
May 10, 2026
Adds a patches/ directory and a Dockerfile step that applies each *.patch against /app/bbuddy with --forward --silent, so patches that have already been merged upstream become a no-op rather than a build failure. First patch (register-barcode-after-create.patch) is the one open as Forceu/barcodebuddy#297 — it makes processRefreshedBarcode register the barcode in Grocy after the user creates a product via BB's "Create Product" flow, instead of leaving it for a follow-up Add/Consume click. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When the user clicks Create Product on an unknown barcode in BB, BB opens Grocy's new-product page in a new tab with the OpenFoodFacts-derived name prefilled. After the Grocy tab closes, BB's
processRefreshedBarcode()updates the localBarcodestable to point the scanned barcode at the just-created Grocy product — but it never registers the barcode against the product in Grocy itself.The barcode only ends up in Grocy if the user also clicks Add or Consume in BB, which routes through
API::addBarcode(). Reasonable users expect "Create Product" to fully integrate the new product, including the barcode, in a single action.This adds the
API::addBarcode()call insideprocessRefreshedBarcode(), immediately after the local-match update, plus the correspondingEVENT_TYPE_ASSOCIATE_PRODUCTlog entry to match the existing pattern inindex.php.Side note
Subsequent Add/Consume clicks for the same row will still call
API::addBarcode()(now a duplicate). Grocy returns an error whichAPI::processError()already swallows, so the inventory action proceeds; the only effect is a stray "Could not set Grocy barcode" log line and a slightly misleading "Associated barcode" log entry. A nice follow-up would be to guard theindex.phpaddBarcodecall with a known-barcode check, but I've kept this PR focused on the user-facing bug.Test plan
$productInfo != nullshould preserve the current behaviour)