From 5355637ffc8d1728311d0dfe7073aa5be9a34208 Mon Sep 17 00:00:00 2001 From: "Devert.net" Date: Tue, 21 Nov 2017 13:17:59 +0100 Subject: [PATCH] fix sort value resetting If the attribute is not filled, no products will be found with this query. This will result in a wrong product order. For performance reasons you could add a if condition in the foreach. --- .../community/Meanbee/BestSellerSort/Model/Attributes.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/code/community/Meanbee/BestSellerSort/Model/Attributes.php b/app/code/community/Meanbee/BestSellerSort/Model/Attributes.php index b4f112e..823a9e6 100644 --- a/app/code/community/Meanbee/BestSellerSort/Model/Attributes.php +++ b/app/code/community/Meanbee/BestSellerSort/Model/Attributes.php @@ -19,11 +19,10 @@ public function updateQtyOrdered() * - Avoids nulls being shown before all products when ordered ascendingly */ $productCollection = Mage::getResourceModel('catalog/product_collection') - ->addAttributeToFilter(Meanbee_BestSellerSort_Helper_Data::ATTRIBUTE_NAME_QTY_ORDERED, - array('neq' => 0) - ); + ->addAttributeToSelect(array(Meanbee_BestSellerSort_Helper_Data::ATTRIBUTE_NAME_QTY_ORDERED)); - foreach($productCollection as $product) { + foreach ($productCollection as $product) + { $product->setData(Meanbee_BestSellerSort_Helper_Data::ATTRIBUTE_NAME_QTY_ORDERED, 0); $resource->saveAttribute($product, Meanbee_BestSellerSort_Helper_Data::ATTRIBUTE_NAME_QTY_ORDERED); }