Get Correct Price from API in a Plugin

Hello, I am currently developing a plugin. For this Plugin I am accessing the API to collect articles with predefined attributes. I want to display these Articles in my template, but I am concerned that my calculation of the price might not be correct. I get the article-object by calling the getOne($articleID) API-Method. There I have a price-Array which also has an array with entries for every customers group. Some customer groups do have included taxes, some do not. There also might be different tax amounts. Is there a method to just get the correct price for the user who is currently visiting the article I selected from the API? I started to check if the taxInput value is set and then optionally multiply the price with the tax amount. These are plenty of API calls and I can not guarantee if the shown price is correct (rounding errors, etc). I think there must be a function to get the correct price of an article, but I cannot find it in the API documentation. Am I missing something? Thanks in advance, Fabian

Hello, Every article can have multiple prices, based on, like you say, customer groups. What you need to do to get the „correct“ price is get the price for the customer group your current customer belongs to. Additionally, based on the customer group settings, it’s possible that some values have or not tax value included. Again, you need to take the customer group settings in consideration when implementing your solution. While this might, at first, sound like an overcomplication of something that can be made more simple, it will also give you more flexibility when implementing your solution and, with little effort, you can implement a solution that works for a broad range of possible shop configuration scenarios. Hope this helps Greetings

Hello, Thank you for this quick reply. Ok, this is what I have suspected. For such an important attribute like the price I find it very error-prone to calculate it every time I need it. To understand it correctly, my steps will be: 1. Get the Article from the API, there is an Array of prices included. 2. Get the correct price-array by customers group: Shopware()-\>System()-\>sUSERGROUP; 3. Check if this price is with or without taxes: check if $article[prices][X][customerGroup][Y][taxInput] equals 1 3a. If the price should be with taxes I need to select the tax-ID of the price-Array and do a seperate select of this Tax-Data. Is this correct? 3b. After I have the belonging Tax-Array I multiply the price myself with the belonging tax amount and format it (I am concerned of rounding-errors). Something like this: $finalPrice = number\_format( ($tmpNettoPrice-\>getPrice() \* (100 + $tmpNettoPrice-\>getArticle()-\>getTax()-\>getTax() ) / 100) , 2, ',', '.' ); But in the end, I have the feeling I forgot something important. What about pseudo-prices, sales discount or different variant prices? Please correct me if I am wrong Best regards, Fabian

1 „Gefällt mir“

Is this the correct way to get the article price? Or am I on the wrong way? I think I am not the first one who is trying to get the correct price over the API. A short reply would be nice, Thank’s, Fabian