A few questions around the sort product function
- Portman
- Contributor
- Posts: 158
- Joined: Mon Mar 08, 2021 1:04 am
- Phoenix Version: v1.0.8.20
- Has thanked: 29 times
- Been thanked: 4 times
Re: A few questions around the sort product function
Thankyou @Kofod95 & @14Steve14 ...
I will play a little bit more with the code that you mentioned @Kofod95 and if I cant get anything to work then, yes I'll probably need to reach out to a developer.
I will play a little bit more with the code that you mentioned @Kofod95 and if I cant get anything to work then, yes I'll probably need to reach out to a developer.
- Portman
- Contributor
- Posts: 158
- Joined: Mon Mar 08, 2021 1:04 am
- Phoenix Version: v1.0.8.20
- Has thanked: 29 times
- Been thanked: 4 times
Re: A few questions around the sort product function
Hello @Kofod95,
I took your advice and started playing around with the stuff you pointed me to and I have ALMOST got the bestsellers Hook working... here is the hook...
Which actually sorts by best seller when you select it (best first) .... the only problem is it lists it from Best seller to least if you click the link again (ie it does not swap it)... also in the first instance the arrow is pointing up (is this the logical direction for best first or should it be the other way), and when you click it again the arrow changes to down but the sort order stays the same
I actually think it would be better to have no arrow at all and have it just stay in the best to least order regardless... but this won't help me when I start to work on the Date added Option...
So my question is 2 fold;
1. How do I remove the arrow?
2. How do I make it so the order flips when the sort order is selected a second time? I assume the line
is forcing it to stay Best to least.
I took your advice and started playing around with the stuff you pointed me to and I have ALMOST got the bestsellers Hook working... here is the hook...
Code: Select all
<?php
class hook_shop_siteWide_sortableBestSeller{
public function listen_filterStart($parameters) {
$parameters['column_specifications']['PRODUCT_LIST_BESTSELLER'] = [
'order_by' => " ORDER BY products_ordered DESC",
'heading' => 'Bestsellers',
'sortable' => true,
];
uksort($parameters['column_specifications'], function ($a, $b) {
return (constant($a) <=> constant($b));
});
}
}I actually think it would be better to have no arrow at all and have it just stay in the best to least order regardless... but this won't help me when I start to work on the Date added Option...
So my question is 2 fold;
1. How do I remove the arrow?
2. How do I make it so the order flips when the sort order is selected a second time? I assume the line
Code: Select all
'order_by' => " ORDER BY products_ordered DESC",-
ecartz
- Core Team
- Posts: 3084
- Joined: Tue Nov 05, 2019 6:02 pm
- Phoenix Version:
- Has thanked: 4 times
- Been thanked: 208 times
Re: A few questions around the sort product function
Code: Select all
'order_by' => " ORDER BY products_ordered%s",Code: Select all
if (BESTSELLER_COLUMN_INDEX == $parameters['sort_column']) {
$parameters['direction'] = ('a' === substr($_GET['sort'], -1)) ? ' DESC' : '';
}- Portman
- Contributor
- Posts: 158
- Joined: Mon Mar 08, 2021 1:04 am
- Phoenix Version: v1.0.8.20
- Has thanked: 29 times
- Been thanked: 4 times
Re: A few questions around the sort product function
thanks @ecartz
What sort of value should BESTSELLER_COLUMN_INDEX be? is it the number of items per page? or columns per page? or something else entirely?
What sort of value should BESTSELLER_COLUMN_INDEX be? is it the number of items per page? or columns per page? or something else entirely?
-
ecartz
- Core Team
- Posts: 3084
- Joined: Tue Nov 05, 2019 6:02 pm
- Phoenix Version:
- Has thanked: 4 times
- Been thanked: 208 times
Re: A few questions around the sort product function
It's the index of the $column_list
When you have &sort=1a in the URL, the 1 is one more than the index. So if it's 1 in the URL, it would be 0 as the sort_column. If it were 5 in the URL, it would be 4 as the sort_column. Since you can reorder the columns and hide them, it's going to be different in every store.
When you have &sort=1a in the URL, the 1 is one more than the index. So if it's 1 in the URL, it would be 0 as the sort_column. If it were 5 in the URL, it would be 4 as the sort_column. Since you can reorder the columns and hide them, it's going to be different in every store.
- Portman
- Contributor
- Posts: 158
- Joined: Mon Mar 08, 2021 1:04 am
- Phoenix Version: v1.0.8.20
- Has thanked: 29 times
- Been thanked: 4 times
Re: A few questions around the sort product function
ok, I have obvioulsy done something wrong,
this is how my hook now looks;
where sort=4 in URL so BESTSELLER_COLUMN_INDEX = 3
It now just defaults least to most - and then swaps to most to least which was what the original sort order did that got me trying to change it in the first place
this is how my hook now looks;
Code: Select all
<?php
class hook_shop_siteWide_sortableBestSeller{
public function listen_filterStart($parameters) {
$parameters['column_specifications']['PRODUCT_LIST_BESTSELLER'] = [
'order_by' => " ORDER BY products_ordered%s, products_name",
'heading' => 'Bestsellers',
'sortable' => true,
];
if (BESTSELLER_COLUMN_INDEX == $parameters['sort_column']) {
$parameters['direction'] = ('a' === substr($_GET['sort'], -1)) ? ' DESC' : '';
}
uksort($parameters['column_specifications'], function ($a, $b) {
return (constant($a) <=> constant($b));
});
}
}It now just defaults least to most - and then swaps to most to least which was what the original sort order did that got me trying to change it in the first place
- Kofod95
- Senior Contributor
- Posts: 748
- Joined: Sat Feb 06, 2021 7:38 pm
- Phoenix Version: 1.0.8.20
- Has thanked: 99 times
- Been thanked: 179 times
Re: A few questions around the sort product function
What if you turn this upside down:
So it becomes
?
//Daniel
Code: Select all
if (BESTSELLER_COLUMN_INDEX == $parameters['sort_column']) {
$parameters['direction'] = ('a' === substr($_GET['sort'], -1)) ? ' DESC' : '';
}Code: Select all
if (BESTSELLER_COLUMN_INDEX == $parameters['sort_column']) {
$parameters['direction'] = ('d' === substr($_GET['sort'], -1)) ? ' ASC' : '';
}
//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
Here are a lot of corns: Phoenix user guide
- Portman
- Contributor
- Posts: 158
- Joined: Mon Mar 08, 2021 1:04 am
- Phoenix Version: v1.0.8.20
- Has thanked: 29 times
- Been thanked: 4 times
Re: A few questions around the sort product function
No Sorry that made no difference...
Code: Select all
<?php
class hook_shop_siteWide_sortableBestSeller{
public function listen_filterStart($parameters) {
$parameters['column_specifications']['PRODUCT_LIST_BESTSELLER'] = [
'order_by' => " ORDER BY products_ordered%s, products_name",
'heading' => 'Bestsellers',
'sortable' => true,
];
if (BESTSELLER_COLUMN_INDEX == $parameters['sort_column']) {
$parameters['direction'] = ('d' === substr($_GET['sort'], -1)) ? ' ASC' : '';
}
uksort($parameters['column_specifications'], function ($a, $b) {
return (constant($a) <=> constant($b));
});
}
}-
ecartz
- Core Team
- Posts: 3084
- Joined: Tue Nov 05, 2019 6:02 pm
- Phoenix Version:
- Has thanked: 4 times
- Been thanked: 208 times
Re: A few questions around the sort product function
Code: Select all
$parameters['direction'] = ('d' === substr($_GET['sort'], -1)) ? '' : ' DESC';Code: Select all
$parameters['column_orderings']['PRODUCT_LIST_BESTSELLER'] = " ORDER BY products_ordered%s, products_name";
$parameters['column_list'][$parameters['sort_column']] = 'PRODUCT_LIST_BESTSELLER';Code: Select all
if ('d' === substr($_GET['sort'], -1)) {
$parameters['direction'] = '';
$_GET['sort'][-1] = 'a';
} else {
$parameters['direction'] = ' DESC';
$_GET['sort'][-1] = 'd';
}
uksort($parameters['column_orderings'], function ($a, $b) {
return (constant($a) <=> constant($b));
});