[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date
][Minivend by thread
]
Re: [mv] problems sorting by price
Quoting Jeroen de Koning (jdkoning@mediata.nl):
> 15,95
> 24,95
> 169,95
>
> Really good, but as soon is I want to sort search results by the poductprice
> I get in trouble. I use the following syntax to do so (first sort by category
> then by price):
>
> [search-list]
> [sort products:category products:price]
> ...
>
> The category sort is going fine, but the price sort is doing something weird.
> For this example the sort would look like this:
>
> 15,95
> 169,95
> 24,95
>
> My guess is that Minivend sorts these prices as a string, in that case
> 16(9,95) comes before 24(,95). But these are prices and 169,95 comes after
> 24,95. Anyone any suggestions!!
I note this but I don't see much I can do about it at first thought. The
data in the database is not mutable in MiniVend 3, and Perl doesn't
have numerical data types. The ugly workaround is to add a column with comma
Wait, we *can* add a sorting type. Currently:
my %Sort = (
'' => sub { $a cmp $b },
none => sub { $a cmp $b },
f => sub { (lc $a) cmp (lc $b) },
fr => sub { (lc $b) cmp (lc $a) },
n => sub { $a <=> $b },
nr => sub { $b <=> $a },
r => sub { $b cmp $a },
rf => sub { (lc $b) cmp (lc $a) },
rn => sub { $b <=> $a },
);
Add these three:
l => sub {
my ($a1,$a2) = split /[,.]/, $a, 2;
my ($b1,$b2) = split /[,.]/, $b, 2;
return $a1 <=> $b1 || $a2 <=> $b2;
},
lr => sub {
my ($a1,$a2) = split /[,.]/, $a, 2;
my ($b1,$b2) = split /[,.]/, $b, 2;
return $b1 <=> $a1 || $b2 <=> $a2;
},
rl => sub {
my ($a1,$a2) = split /[,.]/, $a, 2;
my ($b1,$b2) = split /[,.]/, $b, 2;
return $b1 <=> $a1 || $b2 <=> $a2;
},
They should sort either style of decimal number, even intermixed as
it turns out.
You will find a few of these sprinkled about, notably in Interpolate.pm
and Search.pm. Add these and then use sort:price:l; I have added these
and optimized the storage a bit in MV4.
Thanks for adding to MiniVend 4!
--
Mike Heins http://www.minivend.com/ ___
Internet Robotics |_ _|____
I don't buy from direct 131 Willow Lane, Floor 2 | || _ \
telephone or email marketers. Oxford, OH 45056 | || |_) |
This makes it hard for <mikeh@minivend.com> |___| _ <
me to find a phone company. ;> 513.523.7621 FAX 7501 |_| \_\