{"id":4552,"date":"2021-03-24T10:00:35","date_gmt":"2021-03-24T16:00:35","guid":{"rendered":"https:\/\/www.whitefirdesign.com\/blog\/?p=4552"},"modified":"2021-03-24T08:56:57","modified_gmt":"2021-03-24T14:56:57","slug":"dealing-with-incorrect-results-in-zen-carts-best-product-purchased-report-after-upgrade","status":"publish","type":"post","link":"https:\/\/www.whitefirdesign.com\/blog\/2021\/03\/24\/dealing-with-incorrect-results-in-zen-carts-best-product-purchased-report-after-upgrade\/","title":{"rendered":"Dealing With Incorrect Results in Zen Cart&#8217;s Best Products Purchased Report After Upgrade"},"content":{"rendered":"<p>While the Zen Cart team usually resolves bug introduced in to new versions quickly, an issue with the Best Products Purchased report has existed for over two years. The issue produces obviously incorrect data in the report. Here was the result it was producing on a website we just <a href=\"https:\/\/www.whitefirdesign.com\/services\/zen-cart-upgrade.html\">upgraded to the latest version of Zen Cart<\/a>, 1.5.7c:<\/p>\n<p><a href=\"https:\/\/www.whitefirdesign.com\/blog\/wp-content\/uploads\/2021\/03\/best-products-purchase-inaccurate.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4561\" src=\"https:\/\/www.whitefirdesign.com\/blog\/wp-content\/uploads\/2021\/03\/best-products-purchase-inaccurate.png\" alt=\"\" width=\"747\" height=\"413\" srcset=\"https:\/\/www.whitefirdesign.com\/blog\/wp-content\/uploads\/2021\/03\/best-products-purchase-inaccurate.png 747w, https:\/\/www.whitefirdesign.com\/blog\/wp-content\/uploads\/2021\/03\/best-products-purchase-inaccurate-300x166.png 300w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/a>While there are only 7 products shown, the stats at the bottom of the table say there are 20 shown out of 27,899.<\/p>\n<p>Previously the report showed three products:<\/p>\n<p><a href=\"https:\/\/www.whitefirdesign.com\/blog\/wp-content\/uploads\/2021\/03\/best-products-purchase-accurate.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4563\" src=\"https:\/\/www.whitefirdesign.com\/blog\/wp-content\/uploads\/2021\/03\/best-products-purchase-accurate.png\" alt=\"\" width=\"759\" height=\"282\" srcset=\"https:\/\/www.whitefirdesign.com\/blog\/wp-content\/uploads\/2021\/03\/best-products-purchase-accurate.png 759w, https:\/\/www.whitefirdesign.com\/blog\/wp-content\/uploads\/2021\/03\/best-products-purchase-accurate-300x111.png 300w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/a>The different result is due to a change made to the query used to get the relevant data from the database. The comment included with the changed code that caused this is &#8220;new query uses real order info from the orders_products table, and is theoretically more accurate&#8221;. The results are clearly not always more accurate, though.<\/p>\n<p>A quick fix for this is to restore the SQL query used to generate the results as of the last working version, 1.5.5f. In the file \/[admin directory]\/stats_products_purchased.php, the relevant line to change looks like this in version 1.5.7c:<\/p>\n<pre lang=\"php\" line=\"161\">          $products_query_raw = \"SELECT SUM(products_quantity) AS products_ordered, products_name, products_id\r\n                                 FROM \" . TABLE_ORDERS_PRODUCTS . \"\r\n                                 GROUP BY products_id, products_name\r\n                                 ORDER BY products_ordered DESC, products_name\";<\/pre>\n<p>The previous version looks like this:<\/p>\n<pre lang=\"php\" line=\"193\">  $products_query_raw = \"SELECT p.products_id, sum(p.products_ordered) as products_ordered, pd.products_name\r\n                         FROM \" . TABLE_PRODUCTS . \" p, \" . TABLE_PRODUCTS_DESCRIPTION . \" pd\r\n                         WHERE pd.products_id = p.products_id\r\n                         AND pd.language_id = '\" . $_SESSION['languages_id']. \"'\r\n                         AND p.products_ordered &gt; 0\r\n                         GROUP BY p.products_id, pd.products_name\r\n                         ORDER BY p.products_ordered DESC, pd.products_name\";<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>While the Zen Cart team usually resolves bug introduced in to new versions quickly, an issue with the Best Products Purchased report has existed for over two years. The issue produces obviously incorrect data in the report. Here was the result it was producing on a website we just upgraded to the latest version of &hellip; <a href=\"https:\/\/www.whitefirdesign.com\/blog\/2021\/03\/24\/dealing-with-incorrect-results-in-zen-carts-best-product-purchased-report-after-upgrade\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Dealing With Incorrect Results in Zen Cart&#8217;s Best Products Purchased Report After Upgrade&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[220],"tags":[],"class_list":["post-4552","post","type-post","status-publish","format-standard","hentry","category-zen-cart-issues"],"_links":{"self":[{"href":"https:\/\/www.whitefirdesign.com\/blog\/wp-json\/wp\/v2\/posts\/4552","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.whitefirdesign.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.whitefirdesign.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.whitefirdesign.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.whitefirdesign.com\/blog\/wp-json\/wp\/v2\/comments?post=4552"}],"version-history":[{"count":10,"href":"https:\/\/www.whitefirdesign.com\/blog\/wp-json\/wp\/v2\/posts\/4552\/revisions"}],"predecessor-version":[{"id":4567,"href":"https:\/\/www.whitefirdesign.com\/blog\/wp-json\/wp\/v2\/posts\/4552\/revisions\/4567"}],"wp:attachment":[{"href":"https:\/\/www.whitefirdesign.com\/blog\/wp-json\/wp\/v2\/media?parent=4552"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.whitefirdesign.com\/blog\/wp-json\/wp\/v2\/categories?post=4552"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.whitefirdesign.com\/blog\/wp-json\/wp\/v2\/tags?post=4552"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}