question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: Spanish purchasing product using purchase unit fails

See original GitHub issue

Summary 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: imagen
  • Go to the purchase page and try to buy a purchase unit of the created product. imagen
  • Click in Okay. Nothing will happen, but errors in the console will be raised. imagen

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:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
adrigrillocommented, Jan 27, 2021

I can confirm that is the problem

I have gone further, could it be that the error is generated by the translation:

* msgid "This equals %1$s %2$s". -> msgstr "Esto es igual a %1$s %2$"

Found here:

https://github.com/grocy/grocy/blob/5ecd3a585ecc34828a793bf49e2cf873bc58ddf6/localization/es/strings.po#L1362 that creates an error also in the function

https://github.com/grocy/grocy/blob/5ecd3a585ecc34828a793bf49e2cf873bc58ddf6/public/viewjs/components/productamountpicker.js#L106

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.

0reactions
berrndcommented, Jan 27, 2021

Thanks, can already be checked on the pre-release demo (the current Transifex tranlsations are pulled every hour).

https://es.demo-prerelease.grocy.info

Read more comments on GitHub >

github_iconTop Results From Across the Web

FAQs - Guarantees and returns - European Union
FAQs - How to claim the 2-year guarantee for EU purchases, get a repair, replacement or refund, how to cancel orders made outside...
Read more >
The Problem with Product Proliferation
The company gradually sold off low-margin businesses until it was down to just two units: HealthTech (health care and consumer lifestyle) and Lighting....
Read more >
Econ Ch 31 Flashcards - Quizlet
Study with Quizlet and memorize flashcards containing terms like Imports, exports, and the trade balance The following table shows the approximate value of ......
Read more >
REFILE-Hard times hurt Spanish retailer El Corte Ingles
Economic crisis has hit Spain's venerable department store group El Corte Ingles hard, sending many of its once loyal customers to cheaper ...
Read more >
Legal - Repair Terms and Conditions - Apple
Apple may use Apple Products or replacement parts for service that are ... Apple allows you to make purchases or place orders (that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found