Attibutes and percent pricing
Hello Zen Cart
my first post, and I'm sure I wont be the last to say what a great piece of work.
I've been playing about with various aspects and can grasp the basis of most OK...
except Attribute Pricing!
I've read a fair bit of this area of the forum and judging by the number of confused posters it seems I'm not alone.
Honestly... The terminology doesnt help. It would be a great asset if somebody who understands how it's supposed to work could set it out very clearly at the top of a sticky and particularly explain:
how the calculations are supposed to work, what formula are applied at what points?
what a price factor is?
what a price factor offset is?
and what the diff is between a price factor and a 'one time factor'?
Here's a typical case from my situation with some general numbers:
Product with a basic price of 500 (call it Full Price, List Price, MRRP or whatever)
I want to give 20% discount off that = 100, which makes it a 400 sell price.
Lets say the product has 3 options which mean we need to:
add 5% and 15% of the price
subtract 10% of the price
To get a 5% addition I figured out that I can use a price factor of 0.05 and an offset of 0
or a price factor of 1.05 and an offset of 1
for the 15% case, a pf of 0.15 and offset of 0, or 1.15 and 1 will work.
And these work consistently on the Product Info page, and show correct %ages of the Discount price in the Options drop down. eg
400 x 5% = 20, 400 x 15% = 60
But a minus %age...? Well I can get a -10 figure to appear on the 'Edit Attributes' page by using a Price Factor 0.0000 and Offset -0.1000
But doesnt seem to be possible to get a minus 10% figure to show in a drop down on the Product Info page. It always shows up as +40
And then there appears to be a (serious) problem when an item with a %age priced att. gets added to the cart...
According to my testing it seems that the %age that gets added when the item gets bought:
If the %age is + its taken to be a percentage of the Full Price. namely 25 and 75 (not 20 and 60)
If the %age is minus (I got a -40 figure showing in the Edit Atts screen), the cart ignores it completely and just uses the 400 discount price.
The logic may or may not be correct, but none of these %ages added to the cart are what the customer has selected in a drop down.
I've tried various changing various combinations of these product table fields:
products_priced_by_attribute
products_discount_type
products_discount_type_from
But it always comes out wrong (or right?) in the cart, using the given %age of the Full Price
What else?
I didnt go rummaging about in the code yet so its all pretty much virgin. I did try Kuroi's stock by attributes but that makes no difference.
Or maybe I'm missing the obvious, and just dont get how its supposed to work.
Anyway, can anybody throw light on this please?
thanks
l.
ps - great product!
Re: Attibutes and percent pricing
If you have not read this I would https://www.zen-cart.com/tutorials/index.php?article=57
Having attempted myself to use attributes for many senarios that they were not originally intended for a basic primer on what the basic intention is/was might help - and I may have to stand corrected by one of the Dev's
Basically, these are to be used for an item that has variations/add-ons that can be up priced or not
Shirts in sizes and colors
Item with options
So knowing the above - one can add a price add in dollars or using the factor/offset provide a % change - where the offset is the the base item price
So say for a case of 12 - the factor is 1 and the offset is 11 with no discount for 12 or change the factor for a discount per item to acheive the case total discount
The std factor/offset is calc'd into each item or increment of items the onetime is calc'd "only once" per order like for a setup fee or??
From your description it appears that you want to show one price (retail) then your price and if this is so, you might be better off using the dual pricing module and just make all customers part of the discount group. One of these modules allows display of both prices and you can alter the text for these as normally done
Hope this helps
Re: Attibutes and percent pricing
Hi Kobra
thanks for your reply - I appreciate it.
I read that article already. And I have a reasonable grasp of what an attribute / option might do - or at least what I think it ought to do.
Sorry for long post, but If you can stick with me I'll explain what I want to achieve, and where it seems to go wrong...
Let's go with your analogy of Shirts as a product and Colour as the attribute - its close enough.
Let's say we have 3 Options for the Colour Attribute = Red, Green and Blue
Let's assume
The base price is 200
The base price of 200 is the Price for the Red Shirt
The majority of orders will be for Red so that 200 is the price i want to display
A Green Shirt is more expensive by 20%
A Blue Shirt is cheaper by 10%
I've setup the product, and Colour attribute & options
So if I go to Attributes Controller I can setup attributes specific to this product as follows:
Red - I do nothing just click add
Green I give a Price Factor of 1.2 and and Offset of 1 (Or 0.2 and 0 also seems to work)
Blue - I give a price factor of .9 and an Offset of 1.
Once set these Options show in the Attributes Controller screen as having cost values of 0, PLUS 40, and MINUS 20. This is correct.
In the Product Info page the options show in the Drop Down as
RED
GREEN (+ 40) - this correct
BLUE (+ 20) - this is not correct - it should display as (- 20)
However, the MINUS figure IS dealt with by the cart correctly -ie it subtracts it (200-20) giving a Price of 180. So thats a small display problem really.
But a larger problem seems to arise if I now put that product on SPECIAL OFFER.
Say we put it on offer at 100...
The Attribute Controller now shows the options as follows
Red 0 | 0
Green - 20 | 10
Blue -10 | -5
PLEASE NOTE - NOW NONE OF THESE ARE THE CORRECT VALUES
The Product Info Drop Down also shows the incorrect values
Red 0
Green (+ 10) (Should display + 20)
Blue (+ 5) (Should display - 10)
If these items are put into the cart, it doesnt use the incorrect values. Instead it seems to calculate using the Option figures from the Base Price for the product. ie we get figures in the basket of
Red = 100 (Special Offer price)
Blue = 140 (SP + 40)
Green = 80 (SP - 20)
Clearly something is not right here.
Can somebody tell me how to get it right, or where to file a bug report?
l.
Re: Attibutes and percent pricing
Re: Attibutes and percent pricing
Make sure you are not saying that the Product is Priced by Attribute as it is not ...
Re: Attibutes and percent pricing
Ajeh
I think what is sought is the "Discount" box in the attribute controller. to not calc the attribute rate in a special ...but maybe not
Re: Attibutes and percent pricing
Ajeh - thanks for reply - no the product is not 'priced by attribute'
its set to off
in the database: product.products_priced_by_attribute = 0
Kobra -
1) If your note to Ajeh was re: switching to Yes or No the Box marked Apply "Discounts Used
by Product Special/Sale:"
Checking Yes or No only affects the Displayed price in the Product Info page.
It does not seem to affect the rate used by the cart. Whichever setting is applied the cart still uses the incorrect amount when the product is on Special Offer.
2) thanks for PM.
Your demo shows the problem exactly
You have set it up so that....
Price $200
green +20% or $40
blue -10% or -$20
In your demo the price has been reduced to 100 but nevertheless the cart is applying the discount as though the price were still 200
If it were consistent I could accept that this was intended logic (even if I didnt agree with it) - but it is not consistent.
(At least in my) Attributes Controller: The discount amounts are shown incorrectly:
Red 0 | 0
Green - 20 | 10
Blue -10 | -5
Your demo does not show the Option amounts in the Product Info page, but in my test page when the Price is discounted to 100 the Options amounts are shown as Green: +10, and Blue -5
These amounts are incorrect.
But worse yet, the cart then goes and applies a different set of incorrect figures - those which apply to the Full Price (200)
So if we put the product in the basket the figures the Cart calculates are
Red: 100 = correct because no option adjustment
Green: 140 = incorrect. Should be 100 + 20% = 120
Blue: 80 = incorrect. Should be 100 - 10% = 90
As I said before: clearly something is not right here.
Ad since this is the price basis for 2000 products which I need to get into a Zen Cart this week I would really really appreciate understanding whats going wrong.
Either with the code, or my setup. So I can get it to work correctly (by which I mean: as I expect)
I didnt get a chance to try debugging the code yet, but at a quick look I can see there is a whole bunch of related decisions being made in 'zen_get_discount_qty' in includes/functions/function_price.php
Does anybody who knows, know if there might be some suspect issue in there?
thanks
l.
Re: Attibutes and percent pricing
Sorry folks, thats all a bit rambling here's a concise version
Scenario:
Product with Base Price of 200
Special Offer discounted to 100
Attribute = Colour, with 3 Options on percentage price adjustment:
Red = 0
Green = +20%
Blue = 10%
Problem:
When the Product is on Special Offer the following errors appear:
1) Attributes Controller Page:
Red: 0 | 0
Green: 20 | 10
Blue: 10 | -5
2) Product Info Page:
The Options Drop Down shows incorrect amounts:
Green: + 10 (Should be + 20)
Blue: - 5
3) Cart:
Calculates wrong discount when items are added
Green: is added at 140 (Should be 120... 100 + 20%)
Blue: is added at 80 (Should be 90... 100 - 10%)
thanks for any input
l.
Re: Attibutes and percent pricing
Sorry there s a typo in my last post...
Scenario:
Product with Base Price of 200
Special Offer discounted to 100
Attribute = Colour, with 3 Options on percentage price adjustment:
Red = 0
Green = +20%
Blue = 10%
Blue should be: Blue = -10%
Re: Attibutes and percent pricing
But anyway here's a thing...
there's a function in /includes/functions/function_prices.php
Code:
// return attributes_price_factor
function zen_get_attributes_price_factor($price, $special, $factor, $offset) {
if (ATTRIBUTES_PRICE_FACTOR_FROM_SPECIAL =='1' and $special) {
// calculate from specials_new_products_price
$calculated_price = $special * ($factor - $offset);
} else {
// calculate from products_price
$calculated_price = $price * ($factor - $offset);
}
// return '$price ' . $price . ' $special ' . $special . ' $factor ' . $factor . ' $offset ' . $offset;
return $calculated_price;
}
the CONSTANT: ATTRIBUTES_PRICE_FACTOR_FROM_SPECIAL is never set anywhere that I can find and therefore the price will never be calc'ed on the Spec Off price
But If it is set to 1 (or dropped... if($special){ )the Cart works as it should with the product on Special Offer.
It doesnt solve the Display problem tho - the wrong values still show in the drop down
Can one of the devs please have a look at this and, if it is the cause of issue, please post a fix and I can get on with my day.
thanks very much
l.
Re: Attibutes and percent pricing
This is a temp fix for Products with products_price and price factor and price factor offset where the attribute price is 0.00 ...
Edit the file:
/includes/modules/attributes.php
PHP Code:
$new_attributes_price = zen_get_attributes_price_final($products_options->fields["products_attributes_id"], 1, '', 'false');
$new_attributes_price = zen_get_discount_calc((int)$_GET['products_id'], true, $new_attributes_price);
PHP Code:
$new_attributes_price = zen_get_attributes_price_final($products_options->fields["products_attributes_id"], 1, '', 'false');
if ($products_options->fields['options_values_price'] != 0) {
$new_attributes_price = zen_get_discount_calc((int)$_GET['products_id'], true, $new_attributes_price);
}
Product Price: 200.00
Special: 100.00
Set up the Attributes as:
Red
prefix + or blank
Price: 0.00
Price Factor: 0.00
Price Factor Offset: 0.00
Green
prefix +
Price: 0.00
Price Factor: 1.2
Price Factor Offset: 1.00
Blue
prefix -
Price: 0.00
Price Factor: 0.90
Price Factor Offset: 1.00
This will display the prices as:
Red
Green ( +$20.00 )
Blue ( -$10.00 )
NOTE: this has not been tested for combinations of Attribute Price with Price Factor and Price Factor Offset ...
Re: Attibutes and percent pricing
Hi Ajeh
thanks for reply.
But that fix doesnt seem to solve the problem with the cart adding the attribute amount calc'ed on the full price.
I've applied your fix to my test site and a 100 item with a +20% attrib gets added to the cart at 140 - NOT the 120 which it should be added at.
It does fix the display issue tho.
But I think the key to the Cart issue is this constant:
ATTRIBUTES_PRICE_FACTOR_FROM_SPECIAL
its used in zen_get_attributes_price_factor - but its not set anywhere
And also about the price display issue in the attribute DropDown
I need this to work for a presentation tomorrow and I found a different solution like so:
In functions_price.php...
line-492: function zen_get_discount_calc($product_id, $attributes_id = false, $attributes_amount = false, $check_qty= false) {
If there is a special offer in place it drops into
case ($discount_type_id == 59):
line-570: $calc = ($attributes_amount * $special_price_discount);
$special_price_discount appears to be derived from:
list price / special price
which for a 200 item on special at 100 = .5
so the attrib amount is being reduced by this factor
but... $attributes_amount has already been calculated at this point so its just reducing it again needlessly
Anyway... I think thats why attributes are displaying at half the amount.
as a workaround for now I've just changed this line:
line-570: $calc = ($attributes_amount * $special_price_discount);
to this:
$calc = ($attributes_amount);
Products on Special Offer or not, with attributes calc'ed from percent factor now seem to work correctly but...
I didnt get time to look much further to see what else this breaks, so if you can please check it thru and post the correct fix I'd really appreciate it.
thanks
l.