- Posts: 303
- Thank you received: 18
Sales breakdown by Category broken
- mojooutdoors-holden
-
Topic Author
- Offline
-- Joomla version -- : 3.8.12
-- PHP version -- : 7.1
Situation:
I am trying to show the yearly sales for two master categories. However, some products exist within multiple subcategories. For example, Product A might exist in Master A - > Subcategory A and Master A -> subcategory B. In the reports, i would think that it would filter through this and calculate the total for a given product no matter if it exist in multiple categories. However, this is what displays for the total yearly breakdown (no category filter) and is the correct total for each month:
Is this just a config error or is something broken? Odd that the category specific case shows MUCH HIGHER totals and is definitely incorrect.
I would like to just break down the monthly sales into "products" and "parts" which are both main categories. I should also note we may have one or two products that exist in both "products" and "parts" but that shouldn't skew the data too much.
Please Log in or Create an account to join the conversation.
The fact that the products are in several categories is probably what's messing the amounts as the sales must be counted once for each category of the products in that case.
Could you turn on the "debug mode" setting of the Joomla configuration and look at the report again ?
Then, at the bottom of the page, could you search for the MySQL queries with the text hikashop_order_product in it and provide them ?
Please Log in or Create an account to join the conversation.
- mojooutdoors-holden
-
Topic Author
- Offline
- Posts: 303
- Thank you received: 18
Please Log in or Create an account to join the conversation.
Thank you for that.
From what I can see, the issue is that the code:
That way, it will calculate the sales based on the amounts of the individual products in the order instead of the whole order amount.
Please Log in or Create an account to join the conversation.
- mojooutdoors-holden
-
Topic Author
- Offline
- Posts: 303
- Thank you received: 18
Please Log in or Create an account to join the conversation.
Ok, then try to add the same code, but after the code:
That should help better.
Please Log in or Create an account to join the conversation.
- mojooutdoors-holden
-
Topic Author
- Offline
- Posts: 303
- Thank you received: 18
Please Log in or Create an account to join the conversation.
This modification will not create that error.
So I don't see why you would get that error.
First, I would recommend to revert the change and see if your still have the error.
Then, turn on the error reporting and debug mode settings of the Joomla configuration and try again. If you get that error again, you should get more information on the issue.
Please Log in or Create an account to join the conversation.
- mojooutdoors-holden
-
Topic Author
- Offline
- Posts: 303
- Thank you received: 18
For now I have removed the code. I added it to the requested location in administrator/components/com_hikashop/classes/widget.php which was around line 646.
Please Log in or Create an account to join the conversation.
So you need to keep that change but also change the line:
$pie= 'SUM('.$selectAdd.') AS total';
to:
$pie= 'SUM('.$selectAdd.') AS total, a.order_currency_id AS currency_id';
in that same file. That will avoid that query error which happens because the way the calculations are done changed with the modification I proposed.
Please Log in or Create an account to join the conversation.
- mojooutdoors-holden
-
Topic Author
- Offline
- Posts: 303
- Thank you received: 18
I should also note that some products inside "Products" and "replacement parts" are also in multiple subcategories. For example, Part 1a might be in 4 subcategories of "replacement parts."
Does this make sense?
Please Log in or Create an account to join the conversation.
Yes, the fix until now what to take the sum of the product amount for all matched orders instead of using the total amount of the order.
Now, it doesn't help if the product is in several categories of the categories selected in the "category" setting of the report as it will sum it once per category matching in that setting.
So if you select there the main category with all it's sub categories, it will sum the amount for each sub categories.
Since you're selected there the main category, I would recommend instead to not select it and leave the field empty. That way, the problem won't happen. Alternatively, you could select only the categories so that no doublon happens.
Please log in or register to see it.
I've added a fix on our end to avoid that. However, it's a big patch so I can't just give you the lines to change as there are 30 lines at different places.
Here is a zip of the widget.php with the patch:
So you can unzip it and replace the file. Note however that you're using HikaShop 3.5.0 and this file is the one from HikaShop 4.0.0. It should be ok but it might create some unforseen issues.
Please Log in or Create an account to join the conversation.
- mojooutdoors-holden
-
Topic Author
- Offline
- Posts: 303
- Thank you received: 18
In the meantime, I think I might just manually select all of the products. Surely that will prevent double counting?
Please Log in or Create an account to join the conversation.
If you don't set a category, it will work properly, yes. That's what I said in my previous message.
Please Log in or Create an account to join the conversation.
- mojooutdoors-holden
-
Topic Author
- Offline
- Posts: 303
- Thank you received: 18
Hopefully, I will be able to upgrade our hikashop version after the first of the year.
Please Log in or Create an account to join the conversation.