Bug: Spanish purchasing product using purchase unit fails
See original GitHub issueSummary of the error: When there is an object whose purchase unit is different from the inventory unit (e.g. one package translates to 10 units), the purchase process using the purchase unit fails when the user uses the Spanish version of Grocy.
Error reproduction steps:
- Set the language user setting to Spanish or use the Spanish version of Grocy.
- Create an object whose purchase unit is equivalent to some inventory units as follows:
- Go to the purchase page and try to buy a purchase unit of the created product.
- Click in Okay. Nothing will happen, but errors in the console will be raised.
Details of the error: It seems like there is a problem retrieving correctly the value of the quantity. The request generated is:
{
"amount":"NaN",
"price":"0.00",
"best_before_date":"2021-12-01",
"shopping_location_id":"",
"location_id":""
}
It fails with an error 500 as the amount needs to be a number. The answer is:
{
"error_message": "Argument 2 passed to Grocy\\Services\\StockService::AddProduct() must be of the type float, string given, called in \/var\/www\/demo.grocy.info\/controllers\/StockApiController.php on line 142",
"error_details": {
"stack_trace": "#0 \/var\/www\/demo.grocy.info\/controllers\/StockApiController.php(142): Grocy\\Services\\StockService->AddProduct()\n#1 \/var\/www\/demo.grocy.info\/vendor\/slim\/slim\/Slim\/Handlers\/Strategies\/RequestResponse.php(43): Grocy\\Controllers\\StockApiController->AddProduct()\n#2 \/var\/www\/demo.grocy.info\/vendor\/slim\/slim\/Slim\/Routing\/Route.php(384): Slim\\Handlers\\Strategies\\RequestResponse->__invoke()\n#3 \/var\/www\/demo.grocy.info\/vendor\/slim\/slim\/Slim\/MiddlewareDispatcher.php(81): Slim\\Routing\\Route->handle()\n#4 \/var\/www\/demo.grocy.info\/middleware\/JsonMiddleware.php(13): Slim\\MiddlewareDispatcher->handle()\n#5 \/var\/www\/demo.grocy.info\/vendor\/slim\/slim\/Slim\/MiddlewareDispatcher.php(209): Grocy\\Middleware\\JsonMiddleware->__invoke()\n#6 \/var\/www\/demo.grocy.info\/vendor\/slim\/slim\/Slim\/MiddlewareDispatcher.php(81): class@anonymous->handle()\n#7 \/var\/www\/demo.grocy.info\/vendor\/slim\/slim\/Slim\/Routing\/Route.php(341): Slim\\MiddlewareDispatcher->handle()\n#8 \/var\/www\/demo.grocy.info\/vendor\/slim\/slim\/Slim\/Routing\/RouteRunner.php(84): Slim\\Routing\\Route->run()\n#9 \/var\/www\/demo.grocy.info\/middleware\/AuthMiddleware.php(48): Slim\\Routing\\RouteRunner->handle()\n#10 \/var\/www\/demo.grocy.info\/vendor\/slim\/slim\/Slim\/MiddlewareDispatcher.php(313): Grocy\\Middleware\\AuthMiddleware->__invoke()\n#11 \/var\/www\/demo.grocy.info\/vendor\/slim\/slim\/Slim\/Middleware\/RoutingMiddleware.php(59): class@anonymous->handle()\n#12 \/var\/www\/demo.grocy.info\/vendor\/slim\/slim\/Slim\/MiddlewareDispatcher.php(147): Slim\\Middleware\\RoutingMiddleware->process()\n#13 \/var\/www\/demo.grocy.info\/vendor\/slim\/slim\/Slim\/Middleware\/ErrorMiddleware.php(107): class@anonymous->handle()\n#14 \/var\/www\/demo.grocy.info\/vendor\/slim\/slim\/Slim\/MiddlewareDispatcher.php(147): Slim\\Middleware\\ErrorMiddleware->process()\n#15 \/var\/www\/demo.grocy.info\/middleware\/CorsMiddleware.php(30): class@anonymous->handle()\n#16 \/var\/www\/demo.grocy.info\/vendor\/slim\/slim\/Slim\/MiddlewareDispatcher.php(313): Grocy\\Middleware\\CorsMiddleware->__invoke()\n#17 \/var\/www\/demo.grocy.info\/vendor\/slim\/slim\/Slim\/MiddlewareDispatcher.php(81): class@anonymous->handle()\n#18 \/var\/www\/demo.grocy.info\/vendor\/slim\/slim\/Slim\/App.php(215): Slim\\MiddlewareDispatcher->handle()\n#19 \/var\/www\/demo.grocy.info\/vendor\/slim\/slim\/Slim\/App.php(199): Slim\\App->handle()\n#20 \/var\/www\/demo.grocy.info\/app.php(94): Slim\\App->run()\n#21 \/var\/www\/demo.grocy.info\/public\/index.php(45): require_once('\/var\/www\/demo.g...')\n#22 {main}",
"file": "\/var\/www\/demo.grocy.info\/services\/StockService.php",
"line": 105
}
}
Additionally, from the petition error, some other errors of bootstrap and jquery trying to retrieve the value seems to appear. Nothing of this happens in other languages that I have tried, like German, English and French. The error are:
Uncaught TypeError: Cannot read property 'setAttribute' of null
at Object.onLoad (bootstrap.bundle.min.js?v=3.0.1:6)
at bootstrap.bundle.min.js?v=3.0.1:6
at Array.forEach (<anonymous>)
at new t (bootstrap.bundle.min.js?v=3.0.1:6)
at t.e.show (bootstrap.bundle.min.js?v=3.0.1:6)
at t.e.toggle (bootstrap.bundle.min.js?v=3.0.1:6)
at HTMLSpanElement.<anonymous> (bootstrap.bundle.min.js?v=3.0.1:6)
at Function.each (jquery.min.js?v=3.0.1:2)
at S.fn.init.each (jquery.min.js?v=3.0.1:2)
at S.fn.init.t._jQueryInterface [as dropdown] (bootstrap.bundle.min.js?v=3.0.1:6)
Uncaught SyntaxError: [sprintf] unexpected placeholder
at sprintf.min.js?v=3.0.1:2
at y (sprintf.min.js?v=3.0.1:2)
at e (sprintf.min.js?v=3.0.1:2)
at format (translator.js?v=3.0.1:202)
at Translator.__ (translator.js?v=3.0.1:109)
at __t (grocy.js?v=3.0.1:238)
at HTMLInputElement.<anonymous> (productamountpicker.js?v=3.0.1:106)
at HTMLInputElement.dispatch (jquery.min.js?v=3.0.1:2)
at HTMLInputElement.v.handle (jquery.min.js?v=3.0.1:2)
at Object.trigger (jquery.min.js?v=3.0.1:2)
This happens both in Firefox and Chrome using Grocy 3.0.1 and the prerelease version.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
I can confirm that is the problem
I have changed the string in my local installation and it is working properly again. I have already made the change in the transifex for both Spanish translations. Therefore, an update of the Spanish translation should fix the bug.
Thanks, can already be checked on the pre-release demo (the current Transifex tranlsations are pulled every hour).
https://es.demo-prerelease.grocy.info