Zen Cart Logo
If this is your first visit, check our documentation. To post, register or login.
Forums / Code Matters / Bug Reports / negative price of attributes add onto base price, not subtract

negative price of attributes add onto base price, not subtract

Locked

Started by shaztesting on 17 Mar 2010, 2:32 AM · Views: 9,804

Results 1 to 18 of 18
This thread is locked. New replies are disabled.
17 Mar 2010, 2:32 AM
#1
shaztesting avatar

shaztesting

New Zenner

Join Date:
Jun 2009
Posts:
71
Plugin Contributions:
0

Post #1 by shaztesting

Hi guys,

One of my attributes a discount and for that attribute value I have -$30. The item is completely priced by attributes.

Although zen cart calculates the correct total in the checkout, it adds that $30 instead of subtracting it for the products base price.

Am i doing it correctly? All i am placing in the price_prefix field is '-'

e.g Product price = 0

Attribute 1 = + 70
Attribute 2 = - 30

Final Checkout Price = 40
The problem is that zencart has the base price set to $100! It doesn't take into account the prefix (-) rather just adds the price field into the base price.

How do i fix this?

I have tried this out on clean installs and it has the same bug. Where is the price product by attribute code? can we add a conditional statement along the lines of:

for name="price_prefix" if value="-" then SUBTRACT from base price, else if value="+", then ADD?

17 Mar 2010, 10:10 AM
#2
stevesh avatar

stevesh

Black Belt

Join Date:
Feb 2005
Location:
Lansing, Michigan USA
Posts:
19,793
Plugin Contributions:
2

Post #2 by stevesh

If you're pricing the item by attributes, the Attribute 1 value would be $70 and the Attribute 2 value would be $40. If you don't have a base price specified, there's nothing to subtract from.

If you set the base price to $70, then have an attribute with a value of -$30, it will work.

18 Mar 2010, 12:29 AM
#3
shaztesting avatar

shaztesting

New Zenner

Join Date:
Jun 2009
Posts:
71
Plugin Contributions:
0

Post #3 by shaztesting

oh ok. i tried that and it still doesn't work.

e.g Product price = 70

Attribute 1 = + 0
Attribute 2 = - 30

Final Checkout Price = 40

Zen Cart base Price: 100!

Any thoughts?

18 Mar 2010, 3:56 AM
#4
shaztesting avatar

shaztesting

New Zenner

Join Date:
Jun 2009
Posts:
71
Plugin Contributions:
0

Post #4 by shaztesting

After more testing on clean installs I am convinced that it is a bug in the zen cart code. I just need some direction in going about to fix it. I assume there is faulty logic where if value is > 0 then ADD, wheras we will need to do a check to see if the prefix is '+' or '-'.
I would really appreciate some feedback,
regards,
Shaztesting

18 Mar 2010, 4:01 AM
#5
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Post #5 by drbyte

shaztesting:

zen cart calculates the correct total in the checkoutSo ... you're saying it actually DOES work properly, right?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

18 Mar 2010, 4:14 AM
#6
shaztesting avatar

shaztesting

New Zenner

Join Date:
Jun 2009
Posts:
71
Plugin Contributions:
0

Post #6 by shaztesting

Yes,

But at the top of the product page, on every other page of the site where the product price is listed, on the page title, etc. They are all incorrect.

No one will click on the product and go out to checkout to see the final price if the whole time a $40 item is showing at $100.

Even google picks up the title tag and shows the price in the SERP results.

18 Mar 2010, 8:56 AM
#7
shaztesting avatar

shaztesting

New Zenner

Join Date:
Jun 2009
Posts:
71
Plugin Contributions:
0

Post #7 by shaztesting

does anyone know where the base price calculation logic is even done?

is this in the admin attributes php file or is it in the catalogue section?

***any ***direction will help,

thanks!

18 Mar 2010, 9:05 AM
#8
stevesh avatar

stevesh

Black Belt

Join Date:
Feb 2005
Location:
Lansing, Michigan USA
Posts:
19,793
Plugin Contributions:
2

Post #8 by stevesh

Sorry, I'm not programmer enough to point you to where you would hack the code, but I'll disagree with the idea that customers pay much attention to whatever price is showing in the page title. As long as the price is right in the cart, and the negative attribute is clearly shown to be such, I think it's good.

If you can't find where to make your changes, you can turn off the price in the title in admin.

18 Mar 2010, 9:35 AM
#9
shaztesting avatar

shaztesting

New Zenner

Join Date:
Jun 2009
Posts:
71
Plugin Contributions:
0

Post #9 by shaztesting

stevesh:

but I'll disagree with the idea that customers pay much attention to whatever price is showing in the page title.

I'll agree with that statement but i submit to you that *everyone *will pay attention to the other sections :

shaztesting:

But at the top of the product page, on every other page of the site where the product price is listed,

by 'top of page' i mean just under the heading and above the description. Basically the main huge number that everyone uses to decide whether to add to the cart or not too.

stevesh:

you can turn off the price in the title in admin.

which menu? i can't believe i missed this one, thanks.

i agree that in checkout the prices are calculating and charging the credit card properly. however you must see that having grossly overpriced products *throughout *the site (featured, specials, new product pages, etc) will cause a lot of people to never get to the checkout and see that i'm charging $40 and not $100

so far i am searching through all the mentions of price_prefix but i admit that this search method could be flawed if the code in question doesn't refer to fields['price_prefix'] at all when deciding to + all the values.

18 Mar 2010, 10:42 AM
#10
stevesh avatar

stevesh

Black Belt

Join Date:
Feb 2005
Location:
Lansing, Michigan USA
Posts:
19,793
Plugin Contributions:
2

Post #10 by stevesh

It's in Admin - Configuration - Product Info, near the bottom.

I'll admit I might not understand exactly what you need to do with attributes, so when you get things set up, you might post a URL to the site so we can see the situation.

18 Mar 2010, 11:21 AM
#11
shaztesting avatar

shaztesting

New Zenner

Join Date:
Jun 2009
Posts:
71
Plugin Contributions:
0

Post #11 by shaztesting

Thanks for the title help.

stevesh:

I'll admit I might not understand exactly what you need to do with attributes, so when you get things set up, you might post a URL to the site so we can see the situation.

I'm sorry, this due to my poor explanation of what I'm trying to accomplish.

  1. The product I sell also includes supplier provided cashback offers.
  2. These change frequently and differ in amount by the customer's location.
  3. I provide them as an instant cash discount at point of sale and then the supplier reimburses me afterwards.
  4. I do this via a dropdown box where visitors choose their location and hence the cashback amount that they are entitled to.
  5. The product is intensly price sensitive so i need to show the best possible price that I do offer.

Here's an example.
Product price = $70

Rebate Location A = - $30
Rebate Location B = - $28
Rebate Location C = - $25

Final Checkout Price (A) = $40
Final Checkout Price (B) = $42
Final Checkout Price (C) = $45

Zen Cart Base Price Currently Showing: $100
Correct Zen Cart Base Price Needed (A): $40

Please let me know if any more information would help solve this dillema,

Thanks

18 Mar 2010, 12:34 PM
#12
stevesh avatar

stevesh

Black Belt

Join Date:
Feb 2005
Location:
Lansing, Michigan USA
Posts:
19,793
Plugin Contributions:
2

Post #12 by stevesh

How about this:

Price the product by attributes.

Set the attributes to the discounted price:

A) $40
B) $42
C) $45

(with neither plus or minus in the attribute setup)

Remove the price from the title.

Remove the price from Admin - Configuration - Product Listing

Add #productPrices {display:none;} to the stylesheet to turn off the Starting At: price on the product info page.

Otherwise, you're looking at rewriting code or fiddling with some kind of Javascript, I think.

19 Mar 2010, 2:40 PM
#13
IDEASLady avatar

IDEASLady

Totally Zenned

Join Date:
Aug 2005
Location:
Trujillo Alto, Puerto Rico
Posts:
1,456
Plugin Contributions:
4

Post #13 by IDEASLady

Ok I see the problem, which is only on the title price and yes it is a bug because as you said it doesn't matter if its a minus or plus the cart will always ADD the amount to the "starting price".

Option:
-Base price on the product page $70 (priced by attributes)
-When adding the attributes DON'T insert the minus on the box for it, instead add it to the quantity: [ ] [-30.00]

It will show on frontend as positive but it will do the addition/substraction correctly.

See it here:
http://www.ideascg.com/sandbox/index.php?main_page=product_info&cPath=1_4&products_id=181

You can name the attribute as "discount" to make sense to the shoppers.

Hope that helps....

IDEASLady
IDEAS Creative Studio

Your image... our business!

20 Mar 2010, 6:18 AM
#14
shaztesting avatar

shaztesting

New Zenner

Join Date:
Jun 2009
Posts:
71
Plugin Contributions:
0

Post #14 by shaztesting

stevesh:

How about this:

Price the product by attributes.

Set the attributes to the discounted price:

A) $40
B) $42
C) $45

thanks for the option, that's what we had earlier and customers kept calling up to see if that was the after cashback offer or not.

one good option to be completely transparent with our pricing is was to use the dynamic pricing update mod. unfortunately that showed this pricing hack and would confuse buyers even more.

i am still keen to look into fixing this for 1.39, i see no reason why this problem should continue.

ideasgirl:

Ok I see the problem, which is only on the title price and yes it is a bug because as you said it doesn't matter if its a minus or plus the cart will always ADD the amount to the "starting price".

it's not limited to the title. it's incorrect on EVERY page of the website. on the specials, page, the featured prooducts page, on the homepage, etc. fixing this bug to take into consideration of the price_prefix field would also fix the bug across the site as well, hence my facination in trying to understand where all these calculations take place.

ideasgirl:

Option:
-Base price on the product page $70 (priced by attributes)
-When adding the attributes DON'T insert the minus on the box for it, instead add it to the quantity: [ ] [-30.00]

It will show on frontend as positive but it will do the addition/substraction correctly.

sounds like a promising workaround. i couldn't see any reference to it inthe link you provided.

DrByte, a point in the right direction please?

20 Mar 2010, 2:09 PM
#15
IDEASLady avatar

IDEASLady

Totally Zenned

Join Date:
Aug 2005
Location:
Trujillo Alto, Puerto Rico
Posts:
1,456
Plugin Contributions:
4

Post #15 by IDEASLady

i couldn't see any reference to it inthe link you provided.
What do you mean? :blink:

IDEASLady
IDEAS Creative Studio

Your image... our business!

21 Mar 2010, 5:13 AM
#16
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Post #16 by drbyte

Strictly speaking, Priced by Attribute really wasn't meant for a Product Price and Attribute Prices. It was initially designed that they would be mutually exclusive, not combined; which is likely the reason for the inconsistencies you're saying you're experiencing when combining them.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

21 Mar 2010, 8:53 AM
#17
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Post #17 by drbyte

Here's something you can TRY. I've NOT tested this thoroughly, but at a cursory level it appears to allow you to set a product price AND flag the product as priced-by-attributes AND have it auto-calculate the lowest "starting at" price when negative prices are used for attributes.

/includes/functions/functions_prices.php
somewhere around maybe line 115 you'll have a "zen_get_products_base_price" function definition, which starts with these lines:```
function zen_get_products_base_price($products_id) {
global $db;
$product_check = $db->Execute("select products_price, products_priced_by_attribute from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");

// is there a products_price to add to attributes
$products_price = $product_check->fields['products_price'];

  // do not select display only attributes and attributes_price_base_included is true

[B] $product_att_query = $db->Execute("select options_id, price_prefix, options_values_price, attributes_display_only, attributes_price_base_included from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and attributes_display_only != '1' and attributes_price_base_included='1'". " order by options_id, price_prefix, options_values_price");[/B]

  $the_options_id= 'x';
  $the_base_price= 0;

// add attributes price to price
if ($product_check->fields['products_priced_by_attribute'] == '1' and $product_att_query->RecordCount() >= 1) {
while (!$product_att_query->EOF) {
if ( $the_options_id != $product_att_query->fields['options_id']) {
$the_options_id = $product_att_query->fields['options_id'];
[B] $the_base_price += $product_att_query->fields['options_values_price'];[/B]
}
$product_att_query->MoveNext();
}
.......

Try changing the 2 lines highlighted above with their respective replacements shown below:
2 changes in this line:```
      $product_att_query = $db->Execute("select options_id, price_prefix, options_values_price, attributes_display_only, attributes_price_base_included[B], round(concat(price_prefix, options_values_price), 5) as value[/B] from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and attributes_display_only != '1' and attributes_price_base_included='1'". " order by options_id[B], value[/B]");
```and 1 change in this line:```
            $the_base_price += [B](($product_att_query->fields['price_prefix'] == '-') ? -1 : 1) * [/B]$product_att_query->fields['options_values_price'];

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

21 Mar 2010, 4:57 PM
#18
shaztesting avatar

shaztesting

New Zenner

Join Date:
Jun 2009
Posts:
71
Plugin Contributions:
0

Post #18 by shaztesting

ideasgirl:

What do you mean? :blink:

nevermind that comment i made, i didn't understand how that sandbox example really worked in the backend, i do appreciate your help though!

DrByte:

Here's something you can TRY. I've NOT tested this thoroughly,

Thanks DrByte! I will try this later on in the day and do as much testing on it as i can. I'm so excited, :clap: