Jump to content
thirty bees forum

Adding a ‘sort by sales’ option


SLiCK_303

Recommended Posts

Offering the possibility to order products by sales when browsing categories is a great way to have your customers know about your best items. The following guide by @Nemo works in thirty bees. As he is talking about an old PS version in it, don't bother with his Download Project Files, just follow his manual directions and it will work great. Thanks @Nemo!

Link to comment
Share on other sites

Hi,

I get a right best sales sort, with some little modifications, i ll try to don't forget some there, there is 4 files to modifify:

In Tools.php, replace the function getProductsOrder() by: ``` public static function getProductsOrder($type, $value = null, $prefix = false) { switch ($type) { case 'by': $list = [0 => 'name', 1 => 'price', 2 => 'dateadd', 3 => 'dateupd', 4 => 'position', 5 => 'manufacturername', 6 => 'quantity', 7 => 'reference', 8 => 'sales']; $value = (isnull($value) || $value === false || $value === '') ? (int) Configuration::get('PSPRODUCTSORDERBY') : $value; $value = (isset($list[$value])) ? $list[$value] : ((inarray($value, $list)) ? $value : 'position'); $orderbyprefix = ''; if ($prefix) { if ($value == 'idproduct' || $value == 'dateadd' || $value == 'dateupd' || $value == 'price') { $orderbyprefix = 'p.'; } elseif ($value == 'name') { $orderbyprefix = 'pl.'; } elseif ($value == 'sales') { $orderbyprefix = 'psa.'; $value = 'quantity desc, psa.salenbr'; } elseif ($value == 'manufacturername' && $prefix) { $orderbyprefix = 'm.'; $value = 'name'; } elseif ($value == 'position' || empty($value)) { $orderbyprefix = 'cp.'; } } return $orderby_prefix.$value; break;

        case 'way':
            $value = (is_null($value) || $value === false || $value === '') ? (int) Configuration::get('PS_PRODUCTS_ORDER_WAY') : $value;
            $list = [0 => 'asc', 1 => 'desc'];

            return ((isset($list[$value])) ? $list[$value] : ((in_array($value, $list)) ? $value : 'asc'));
            break;
    }
}

```

In modules/blocklayered/blocklayered.php, line 3146, insert just after 'LEFT JOIN '.DBPREFIX.'manufacturer m ON [...]' and before 'WHERE '.$aliaswhere [...]': LEFT JOIN `'._DB_PREFIX_.'product_sale` psa ON psa.id_product = p.id_product so you get: LEFT JOIN '._DB_PREFIX_.'manufacturer m ON (m.id_manufacturer = p.id_manufacturer) '.Product::sqlStock('p', 0).' LEFT JOIN `'._DB_PREFIX_.'product_sale` psa ON psa.id_product = p.id_product WHERE '.$alias_where.'.`active` = 1 AND '.$alias_where.'.`visibility` IN ("both", "catalog") And in themes/community-theme-default/product-sort.tpl, add this line, where you want in the select tag: {if $page_name == 'category'} <option value="sales:desc"{if $orderby eq 'sales' AND $orderway eq 'desc'} selected="selected"{/if}>{l s='Best Sales'}</option> {/if} Last file, in 'themes/community-theme-default/js/modules/blocklayered/blocklayered.js', Line 637 and 643, find this line :

reloadContent('forceSlide'); and replace by : reloadContent('&forceSlide'); That's all, clear your cache-file, and run. Regards.

Edit: One more file to change, and delete wrong uploads.

Link to comment
Share on other sites

@lathaneo said in Adding a ‘sort by sales’ option:

In modules/blocklayered/blocklayered.php, just before the 'where [...]' line 3146, insert: LEFT JOIN `'._DB_PREFIX_.'product_sale` psa ON psa.id_product = p.id_product so you get: LEFT JOIN '._DB_PREFIX_.'manufacturer m ON (m.id_manufacturer = p.id_manufacturer) '.Product::sqlStock('p', 0).' LEFT JOIN `'._DB_PREFIX_.'product_sale` psa ON psa.id_product = p.id_product WHERE '.$alias_where.'.`active` = 1 AND '.$alias_where.'.`visibility` IN ("both", "catalog") there are two instances of that code, nether are on line 3146, do you change one, or both?

[01515061457658blocklayered.php](Uploading 100%)

[01515061485981product-sort.tpl](Uploading 100%) [01515061499590Tools.php](Uploading 100%)

Your files didnt show up, might wanna try again.

Link to comment
Share on other sites

Hi,

Sorry for the uploaded files, I don't have enough privileges to share them. I edited and added some modifications.

You can download file in my git repository, but have still have to change the template file manually. (I changed the file name of blocklayered.js in blocklayered_mod.js cause the template override)

https://github.com/Lathanao/blocklayered

Regards.

Link to comment
Share on other sites

@Nemo, I have an issue with this, and that is, in best-sales, new-products, and prices-drop, the sort by sales does not work. When viewing any category it works fine, but in those 'special' pages, it just doesn't work. You can see this at my website. Any thoughts?

Link to comment
Share on other sites

Hi,

@SLiCK_303, you're right, that why i add the select option only for category page. {if $page_name == 'category'} <option value="sales:desc"{if $orderby eq 'sales' AND $orderway eq 'desc'} selected="selected"{/if}>{l s='Best Sales'}</option> {/if} The sort in category page is made only by the blocklayered module. If you want add the sort 'Best Sales' on other pages, you have just to modify the class which is doing the sort. For BestSales page, it's in Productsale::getBestSales(), etc... so, each page get it's own sort function.

And, yes it's should be really cool to get only one function, fully parameterizable, for all this sorts. And, yes, of course it's faisable.

Regards.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...