[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date
][Minivend by thread
]
discount based on category quantity instead of item quantity
Hi All,
I am a minivend newbie, just getting up to speed. I am trying to
figure out how to calculate an items discount based on the number of
items ordered in the same category and not just the quantity of that
particular item.
item category price_1-9 price_10+ qty_ordered
A X 1.10 1.00 4
B X 2.50 2.00 7
C Y 3.00 2.80 4
D X 1.40 1.00 3
E Z 2.30 2.00 12
F Y 3.40 3.00 4
Because there have been more than 10 items in category X ordered,
I want to use that quantity discount for both items A and B.
Item C and F will not get the qty price break because it is in a different
category (Y) which did not meet the price break of 11. Item E will
get the quantity discount on its own (minivend handles this case
with no problems).
I have already modified the minivend example to do the basic shopping
cart. And have even updated the pricing database to get the per
product discounts correct. I have figured out how to get at the
discount database and pull out the different prices directly,
[data pricing q10 [item-code]]
[data pricing q1 [item-code]]
I have even figured out a way to count the number of items in a
given category (there may be much better ways of doing this).
[calc]
[item-list]
$category_count{"[item-field category]"} += [item-quantity]
[/item-list]
return '';
[/calc]
But I cant seem to use these values that way I want to later on.
I can display them, but I cant seem to conditionally set a value
based on the category count (see discount attempt below).
I am then trying to use this info to set the discount-price
[item-list]
[discount code="[item-code]"]
return [data pricing q10 [item-code]] if $category_count{"[item-field
category]"} > 9;
return [data pricing q1 [item-code]] if $category_count{"[item-field
category]"} > 1;
[/discount]
... more basket code ...
It seems like the $category_count hash is out of scope somehow within the
discount tag, even though I can output the value to the html page within
a calc command.
I tried also using scratch variables, but with about the same level of
success. I have seen some of the perl examples using $Safe, and I will
see if I can do any better with that. But this is rapidly getting
frustrating (well actually I'm already there). I have access to the info
I want, but I cant seem to use it.
Or better yet, is there some way to do this inside minivends framework
without having to add all this stuff by hand. I have looked at MixMatch,
CommonAdjust, PriceAdjustment, PriceBreaks etc.... Nothing seems to be
able to do exactly what I need it to do.
Also, do I need to duplicate the code in both basket and checkout? Is there
some way that I can save this info between pages? Can I set the values that
minivend uses in my code (ie: can I set [item-price] somehow?)?
much thanks
Tyler K.