manuel-rw / grocy-scanner

Your Grocy companion to scan and add products to your stock with a single click.
GNU General Public License v3.0
23 stars 2 forks source link

Purchase Greyedout #12

Open wuast94 opened 4 months ago

wuast94 commented 4 months ago

image as you can see i cant click on the button sadly

 info: System.Net.Http.HttpClient.Default.ClientHandler[101]
      Received HTTP response headers after 174.5176ms - 200
info: System.Net.Http.HttpClient.Default.LogicalHandler[101]
      End processing HTTP request after 174.5878ms - 200
fail: GrocyScanner.Core.Providers.MigrosProductProvider[0]
      Unexpected count for gtin 4311501692912: 0
info: System.Net.Http.HttpClient.Default.LogicalHandler[100]
      Start processing HTTP request GET https://grocy.wuast24.de/api/objects/product_barcodes?query%5B%5D=barcode%3D4104420031326
info: System.Net.Http.HttpClient.Default.ClientHandler[100]
      Sending HTTP request GET https://grocy.wuast24.de/api/objects/product_barcodes?query%5B%5D=barcode%3D4104420031326
info: System.Net.Http.HttpClient.Default.ClientHandler[101]
      Received HTTP response headers after 293.0908ms - 200
info: System.Net.Http.HttpClient.Default.LogicalHandler[101]
      End processing HTTP request after 293.2446ms - 200
info: System.Net.Http.HttpClient.Default.LogicalHandler[100]
      Start processing HTTP request GET https://www.coop.ch/de/dynamic-pageload/searchresultJson?componentName=searchresultJson&url=%2Fde%2Fsearch%2F%3Ftext%3D4104420031326&displayUrl=%2Fde%2Fsearch%2F%3Ftext%3D4104420031326&compiledTemplates%5B%5D=productTile-new&compiledTemplates%5B%5D=sellingBanner&_=1720496541931
info: System.Net.Http.HttpClient.Default.ClientHandler[100]
      Sending HTTP request GET https://www.coop.ch/de/dynamic-pageload/searchresultJson?componentName=searchresultJson&url=%2Fde%2Fsearch%2F%3Ftext%3D4104420031326&displayUrl=%2Fde%2Fsearch%2F%3Ftext%3D4104420031326&compiledTemplates%5B%5D=productTile-new&compiledTemplates%5B%5D=sellingBanner&_=1720496541931
info: System.Net.Http.HttpClient.Default.LogicalHandler[100]
      Start processing HTTP request POST https://www.migros.ch/onesearch-oc-seaapi/public/v5/search
info: System.Net.Http.HttpClient.Default.ClientHandler[100]
      Sending HTTP request POST https://www.migros.ch/onesearch-oc-seaapi/public/v5/search
info: System.Net.Http.HttpClient.Default.ClientHandler[101]
      Received HTTP response headers after 148.6009ms - 403
info: System.Net.Http.HttpClient.Default.LogicalHandler[101]
      End processing HTTP request after 148.758ms - 403
fail: GrocyScanner.Core.Providers.CoopProductProvider[0]
      Failed to fetch coop product: 4104420031326 - <html><head><title>coop.ch</title><style>#cmsg{animation: A 1.5s;}@keyframes A{0%{opacity:0;}99%{opacity:0;}100%{opacity:1;}}</style></head><body style="margin:0"><p id="cmsg">Please enable JS and disable any ad blocker</p><script data-cfasync="false">var dd={'rt':'c','cid':'AHrlqAAAAAMAt_6G4TanD3sAT8BR1g==','hsh':'4E2D21855D176C1885A97CE16C8EC3','t':'fe','s':49043,'e':'a86b27ec9f6edacd8808adf897e33c84043756059e6a3533679ce8c90fd29f01','host':'geo.captcha-delivery.com'}</script><script data-cfasync="false" src="https://ct.captcha-delivery.com/c.js"></script></body></html>
      System.Net.Http.HttpRequestException: Response status code does not indicate success: 403 (Forbidden).
         at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
         at GrocyScanner.Core.Providers.CoopProductProvider.GetProductByGtin(String gtin) in /src/GrocyScanner.Core/Providers/CoopProductProvider.cs:line 37
info: System.Net.Http.HttpClient.Default.ClientHandler[101]
      Received HTTP response headers after 186.5021ms - 200
info: System.Net.Http.HttpClient.Default.LogicalHandler[101]
      End processing HTTP request after 186.5668ms - 200
info: System.Net.Http.HttpClient.Default.LogicalHandler[100]
      Start processing HTTP request POST https://www.migros.ch/product-display/public/v4/product-cards
info: System.Net.Http.HttpClient.Default.ClientHandler[100]
      Sending HTTP request POST https://www.migros.ch/product-display/public/v4/product-cards
  hope this project isnt dead already because its exactly what i want, just a quick way to add items to grocy, thanks for the awesome work so far 😊
GoodOldJack12 commented 3 months ago

Looks like one of the providers changed something. I'm also having this issue. If I have time I'll see if it can be fixed. Either way a broken provider shouldn't break in this way

manuel-rw commented 2 months ago

Will look into this.

zsmitchell commented 2 months ago

I could be way off base, but as I was looking through the code in OpenFoodFactsProductProvider.cs, it appears to be looking for the JSON to come in as product.code, product.ProductName and product.CategoriesTags (as the OpenFoodFacts V2 API documentation states) however, when I was playing around with it, it seemes to be coming in as products.code, products.ProductName...etc (Notice the "S" at the end of product)

Again, I could be wayyyy off base, but I thought it was worth passing along to save you guys time if this was the issue.

This is what I tested...

https://world.openfoodfacts.org/api/v2/search?code=0028400189224&fields=code,product_name,categories_tags

{ "count": 1, "page": 1, "page_count": 1, "page_size": 20, "products": [ { "categories_tags": [ "en:plant-based-foods-and-beverages", "en:plant-based-foods", "en:snacks", "en:cereals-and-potatoes", "en:salty-snacks", "en:appetizers", "en:chips-and-fries", "en:crisps", "en:potato-crisps" ], "code": "0028400189224", "product_name": "Potato chips" } ], "skip": 0 }

GoodOldJack12 commented 2 months ago

So when it comes to coop request for that product, the logs say its this URL: https://www.coop.ch/de/dynamic-pageload/searchresultJson?componentName=searchresultJson&url=%2Fde%2Fsearch%2F%3Ftext%3D4104420031326&displayUrl=%2Fde%2Fsearch%2F%3Ftext%3D4104420031326&compiledTemplates%5B%5D=productTile-new&compiledTemplates%5B%5D=sellingBanner&_=1724517556832

Running this in a regular browser works fine. Tt does not find the product: Leider keine Treffer für \"4104420031326\" but the error still happens with a product that is in their database.

If I run a curl however, I get the same as the error message:

<html><head><title>coop.ch</title><style>#cmsg{animation: A 1.5s;}@keyframes A{0%{opacity:0;}99%{opacity:0;}100%{opacity:1;}}</style></head><body style="margin:0"><p id="cmsg">Please enable JS and disable any ad blocker</p><script data-cfasync="false">var dd={'rt':'c','cid':'AHrlqAAAAAMAu_bs3UZxaO0AUVO16g==','hsh':'4E2D21855D176C1885A97CE16C8EC3','t':'bv','s':49043,'e':'abedece9c06f121ba3667587a50a98752519a9b2d91689a9d68833c9a9cb25ab','host':'geo.captcha-delivery.com'}</script><script data-cfasync="false" src="https://ct.captcha-delivery.com/c.js"></script></body></html>

Maybe they've implemented more protections against crawling? I'm also not the most knowledgeable about this.

In any case: This error is entirely unrelated to the bug. I've run the debugger and I've even disabled the coop provider and the button remains grayed out.

GoodOldJack12 commented 2 months ago

I found the issue. Im working on a PR fix but git is fighting me

manuel-rw commented 2 months ago

Thanks a lot. I will review asap. I'm currently so busy at work that I can't focus on this project. Sorry.

GoodOldJack12 commented 2 months ago

@wuast94 can you pull the latest docker and confirm that it's working for you now? If so, I think we can close this issue.

GoodOldJack12 commented 2 months ago

I've just discovered a new regression: now products that are in grocy get the grayed out. Will send a fix soon