Forums / Setting Up Categories, Products, Attributes / Calculating the price of a product

Calculating the price of a product

Locked

Views: 4,708

Results 1 to 13 of 13
This thread is locked. New replies are disabled.
6 Aug 2007, 11:38 PM
#1
audleman avatar

audleman

New Zenner

Join Date:
Jul 2007
Posts:
69
Plugin Contributions:
0

Calculating the price of a product

I would like to create a custom Product Type to handle donations. The user will have a number of options for inputting the amount, including radio buttons with predefined values, an Other: text field, and a recurring monthly donation text field. The reason I think I need a custom product is that my requirements for entering donation amounts surpass what standard attributes will do (and also I want to heavily modify the product layout).

My question is: where does Zen Cart calculate the total price of the product? I would like to rewrite this code to take into account the array of options I have provided. I've been digging through the code but haven't been able to find this yet.

Any fingers pointing in the right direction much appreciated.

Kevin

7 Aug 2007, 12:32 AM
#2
brandtim avatar

brandtim

Zen Follower

Join Date:
Apr 2006
Posts:
250
Plugin Contributions:
0

Re: Calculating the price of a product

Take a look at the calculate function in the shopping_cart class.

I've thought about doing this myself and debated making a new product type. I would think it would be easier to extend the attributes ... I would think you'd be basically duplicating code there.

BrandTim

7 Aug 2007, 12:44 AM
#3
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Calculating the price of a product

Wouldn't it be easier to make a Product for $1.00 and use this products_id to customize the product_info to hide the price and instead of the Add to Cart box have it read: Donation amount

Sure would be a lot less work than what you appear to be attempting ... :cool:

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

7 Aug 2007, 1:04 AM
#4
audleman avatar

audleman

New Zenner

Join Date:
Jul 2007
Posts:
69
Plugin Contributions:
0

Re: Calculating the price of a product

Ajeh:

Wouldn't it be easier to make a Product for $1.00 and use this products_id to customize the product_info to hide the price and instead of the Add to Cart box have it read: Donation amount

Sure would be a lot less work than what you appear to be attempting ... :cool:

Well...is there a good way to have a set of predefined amounts ($25, $50, $75) using attributes that the user can select, only having them enter a quantity if they want to choose other?

Also, I want to add another Other field for "Donate [XXX] per month". I think I'm getting beyond what I can do with the core code.

However I like the suggestion to extend attributes. I'll have to poke my head around that code for a while.

Thank you both!

Kevin

7 Aug 2007, 2:29 AM
#5
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Calculating the price of a product

There is not a simple way to have both ...

The Attributes are also based on:
Atrribute Price * Quantity = Donation amount

This is why it is easier to just have a single Product for 1.00 and configure the page to display properly in a more donation like look ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

7 Aug 2007, 4:52 PM
#6
audleman avatar

audleman

New Zenner

Join Date:
Jul 2007
Posts:
69
Plugin Contributions:
0

Re: Calculating the price of a product

Ajeh:

There is not a simple way to have both ...

The Attributes are also based on:
Atrribute Price * Quantity = Donation amount

This is why it is easier to just have a single Product for 1.00 and configure the page to display properly in a more donation like look ...

Ok, that really makes a lot of sense and would be much simpler. One more question: if I want to configure the page to display properly in a donation like look, is there a simpler way to do that other than creating a new product type?

Thanks,
Kevin

7 Aug 2007, 4:56 PM
#7
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Calculating the price of a product

Yes ...

One method is to use the Document Product type for the Donation product and customize the files for it so that any product that is Document Product would appear to be a Donation ...

Another method is to add IF statements and turn off the Product Price with the products_id is the Gift Certificate products_id or the products_model first 4 characters are GIFT ... and to change the Add to Cart to read Donation Amount or what have you based on the same conditions ...

Advantage of the first method is it keeps your changes specific to a Product Type and makes it easier for you to customize things ...

Disadvantage is instead of making a new Product Type you are using the Document Product and that will not be available to you for other things ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

7 Aug 2007, 5:18 PM
#8
audleman avatar

audleman

New Zenner

Join Date:
Jul 2007
Posts:
69
Plugin Contributions:
0

Re: Calculating the price of a product

Ajeh:

Yes ...

One method is to use the Document Product type for the Donation product and customize the files for it so that any product that is Document Product would appear to be a Donation ...

Another method is to add IF statements and turn off the Product Price with the products_id is the Gift Certificate products_id or the products_model first 4 characters are GIFT ... and to change the Add to Cart to read Donation Amount or what have you based on the same conditions ...

Advantage of the first method is it keeps your changes specific to a Product Type and makes it easier for you to customize things ...

Disadvantage is instead of making a new Product Type you are using the Document Product and that will not be available to you for other things ...

Oba-chan, no more questions for now, just a big THANK YOU for walking me through the options. I've worked with a number of open source projects and it is rare for someone to be as responsive and helpful as you. I feel, dare I say it, Zenned!

Cheers,
Kevin

7 Aug 2007, 5:21 PM
#9
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Calculating the price of a product

You are most welcome ... we look forward to seeing your shop up and running and soon to be added to the Zen Cart Showcase ... :cool:

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

8 Aug 2007, 10:15 PM
#10
brandtim avatar

brandtim

Zen Follower

Join Date:
Apr 2006
Posts:
250
Plugin Contributions:
0

Re: Calculating the price of a product

You know, if you're going with the $1 product idea, you could just have some javascript buttons that change the qty field to $25, $50, etc.... then the qty. field itself would be the fill-in-the-blank/other...

BrandTim

9 Aug 2007, 1:05 AM
#11
audleman avatar

audleman

New Zenner

Join Date:
Jul 2007
Posts:
69
Plugin Contributions:
0

Re: Calculating the price of a product

brandtim:

You know, if you're going with the $1 product idea, you could just have some javascript buttons that change the qty field to $25, $50, etc.... then the qty. field itself would be the fill-in-the-blank/other...

BrandTim

Great idea! I'm about 80% of the way to implementing this. You can see it here if you like: http://208.106.141.15/ZenCart/index.php?main_page=document_product_info&cPath=5&products_id=12

What I'm stuck on is that my Javascript isn't updating the quantity and I don't know why.

I'm also going to have to figure out how to display the donation in the cart without the quantity box. Is there a template file I can overwrite for that?

Kevin

9 Aug 2007, 3:21 PM
#12
brandtim avatar

brandtim

Zen Follower

Join Date:
Apr 2006
Posts:
250
Plugin Contributions:
0

Re: Calculating the price of a product

With this code:

onclick="document.getElementsByName('cart_quantity')[0].value = 25;"

The [0] element returned is actually this element:

<form name="cart_quantity" action="http://208.106.141.15/ZenCart/index.php?main_page=document_product_info&cPath=5&products_id=12&action=add_product" method="post" enctype="multipart/form-data">

You want to get this element:

<input type="text" name="cart_quantity" value="1" maxlength="6" size="4" />

Which requires this code:

onclick="document.getElementsByName('cart_quantity')[1].value = 25;"

The shopping cart display is in includes/templates/YOUR_TEMPLATE/templates/tpl_shopping_cart_default.php.

I think it would be fairly simple just to add another check in the if statement for the quantities display and not display it if the products_id matches the donations product.

BrandTim

9 Aug 2007, 11:45 PM
#13
audleman avatar

audleman

New Zenner

Join Date:
Jul 2007
Posts:
69
Plugin Contributions:
0

Re: Calculating the price of a product

Thanks again BrandTim. I've got it working pretty darn well now. I appreciate all of the help!

Kevin