Zen Cart Logo
Forums / Setting Up Categories, Products, Attributes / User input product dimensions, update price based on inputs

User input product dimensions, update price based on inputs

Locked

Views: 9,052

Results 1 to 18 of 18
This thread is locked. New replies are disabled.
24 Jun 2008, 11:39 PM
#1
thestebes avatar

thestebes

New Zenner

Join Date:
Jun 2008
Posts:
3
Plugin Contributions:
0

User input product dimensions, update price based on inputs

Hi, first let me say I am not currently using ZenCart. I am looking for a solution in order to setup an online store for my local business, and I am trying to figure out if Zencart will fit my needs. Hopefully this is an appropriate forum section to post my question. I have read up, checked the FAQ's, searched and can't find anything. :frusty:

My family runs a bedding and foam store. I would like to sell foam cut-to-size online (cushions, etc). In order to do this, I need the user to be able to input custom dimensions. The product listings would consist of the basic shapes, rectangle, circle, etc. After selecting the specific product, the user would need to input dimensions - length, width, etc.

I would then set things up so that the user selects the foam type and thickness from a drop-down menu... this doesn't seem to be difficult. However, the dimensions dictate the price of the product.

Basically, I need to be able to calculate a price based on volumetric dimensions, which the user inputs. The material selected would determine the price per unit volume or area. This seems easy, but I can't imagine any way of doing this without more advanced custom coding.

Any help would be much appreciated, even if it is just to say it's not possible with ZenCart. Thanks,

Scott

25 Jun 2008, 12:59 AM
#2
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: User input product dimensions, update price based on inputs

One way is to Break this out and price by the sq in or sq ft and/or allow a partial sq ft

Have a drop box for thickness and a price per unit for each thickness

I don't know if you sur charge for circles and odd shapes but you should decide this upfront.

You only then have to custom a bit of code to determine say the sq ft mathematically in your shopping_cart.php file

25 Jun 2008, 1:54 AM
#3
thestebes avatar

thestebes

New Zenner

Join Date:
Jun 2008
Posts:
3
Plugin Contributions:
0

Re: User input product dimensions, update price based on inputs

thanks for the reply. So there is a way to have it calculate the square footage based on the input dimensions and then multiply this number by whatever price per sq. foot is set for the selected thickness? Circles wouldn't be an issue but complex cushion shapes require more than 2 input dimension (length, width), so in some cases it wouldn't be as simple as a length*width calculation for sq footage.

25 Jun 2008, 2:19 AM
#4
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: User input product dimensions, update price based on inputs

So there is a way to have it calculate the square footage based on the input dimensions and then multiply this number by whatever price per sq. foot is set for the selected thickness?
Not a default method - see post where I stated "Custom"

As Zen Cart is open source, one can alter the code to do most anything possible

25 Jun 2008, 4:38 AM
#5
thestebes avatar

thestebes

New Zenner

Join Date:
Jun 2008
Posts:
3
Plugin Contributions:
0

Re: User input product dimensions, update price based on inputs

I think this is going to take some custom javascript programming. While I havn't worked in javascript in awhile, and don't know a whole lot, I might be able to figure it out.

At this point, I'm not quite sure how to combine a shopping cart setup and the javascript price dimension inputs and price calculation scripts.

25 Jun 2008, 5:00 AM
#6
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: User input product dimensions, update price based on inputs

Suggest you start by using the min and unit functions in the product entry areas first and see what you are missing before forging ahead with a full blown coding excercise..

I do not have your specific insight into what you are envisioning but have set a similar thing up for a flooring sales site and did not use any js

29 May 2009, 5:58 PM
#7
zenner27534 avatar

zenner27534

New Zenner

Join Date:
May 2009
Posts:
6
Plugin Contributions:
0

Re: User input product dimensions, update price based on inputs

I also need the same functionality. I want a user to be able to enter width and length, have it multiply the two, then add a $ per square foot.

Has anyone found a solution to this, or created scripting that will do product dimensions? If so, please share. we should add this to the add-on section! It would be so useful.

Thanks,
:lamo:

6 Nov 2009, 7:04 PM
#8
zahid_hussain avatar

zahid_hussain

New Zenner

Join Date:
Sep 2009
Posts:
54
Plugin Contributions:
0

Re: User input product dimensions, update price based on inputs

I want to done some calculation on price, that give me a new price for product, now I want that zencart will accept my this new calculated price and passed to add to cart, but it not working as it every time accept there previous price, so my question is that, did any one give me an idea, that what variable is used for price, that I will assigned my calculated value.

Thanks
Zahid.

6 Nov 2009, 8:34 PM
#9
jackie_taferner avatar

jackie_taferner

Totally Zenned

Join Date:
Jun 2009
Location:
Orange County, California
Posts:
547
Plugin Contributions:
3

Re: User input product dimensions, update price based on inputs

Hello Zahin,

I realize there are many people, including yourself, that could really use this attribute calculator mod... i have not been able to complete it and upload in the add-ons section quite yet.

But since you have the immediate need for it, I'm going to kick it into high gear and just get it done asap.

Can you wait til Monday? I can surely have it ready for you by then.

Thanks!

8 Nov 2009, 9:13 PM
#10
bigsy85 avatar

bigsy85

New Zenner

Join Date:
Aug 2008
Posts:
50
Plugin Contributions:
0

Re: User input product dimensions, update price based on inputs

I believe in you jackie!
attribute calculator mod YES!

9 Nov 2009, 11:37 AM
#11
zahid_hussain avatar

zahid_hussain

New Zenner

Join Date:
Sep 2009
Posts:
54
Plugin Contributions:
0

Re: User input product dimensions, update price based on inputs

Thanks jackie,
I would be varying thankful to you. But it would be vary nice if this would fulfilled my requirement.
Today I would be waiting for your link,
Thanks
Zahid
:clap:

9 Nov 2009, 5:58 PM
#13
jackie_taferner avatar

jackie_taferner

Totally Zenned

Join Date:
Jun 2009
Location:
Orange County, California
Posts:
547
Plugin Contributions:
3

Re: User input product dimensions, update price based on inputs

Hello Zahid,

My mod will work a little different from what you have there on your site - it will actually take the length and width, and calculate the square footage as well as the total cost. the customer will not need to enter the square footage itself :)

It will not calculate it directly on the product page, but when customer clicks "add to cart", it will calculate and add price to the shopping cart.

Hopefully in the future I'll get some more features added (like showing total on product page, etc).

Link to download coming later today!

9 Nov 2009, 7:24 PM
#14
zahid_hussain avatar

zahid_hussain

New Zenner

Join Date:
Sep 2009
Posts:
54
Plugin Contributions:
0

Re: User input product dimensions, update price based on inputs

Hello! Jackie,

Thanks for your response,
My problem is that, I do my all calculation, but now my new price will not to add as final price as I have no idea about final price variable , that I will assigned my final value to that that variable,

Please let me know if you have an idea about this situation.

Thanks:clap:
Zahid.

10 Nov 2009, 4:22 AM
#15
jackie_taferner avatar

jackie_taferner

Totally Zenned

Join Date:
Jun 2009
Location:
Orange County, California
Posts:
547
Plugin Contributions:
3

Re: User input product dimensions, update price based on inputs

Hello Zahid,

Here's what I've got for the mod so far... kind of a beta version, but hopefully it will help solve your situation.

I had this working on a live site, but as I'm trying to make the code scalable for use on any website, I'm running into trouble getting it to work just right. I'll keep at it. If there are any other Zen Cart pros on here that would like to have a look and let me know why this would or wouldn't work, or if there may be vulnerabilities in editing this code, then please feel free to give some feedback ;)

Anyhow, you want to edit this file: includes/classes/shopping_cart.php

Find the following code (should be around line 1180):

        $products_array[] = array('id' => $products_id,
                                  'category' => $products->fields['master_categories_id'],
                                  'name' => $products->fields['products_name'],
                                  'model' => $products->fields['products_model'],
                                  'image' => $products->fields['products_image'],
                                  'price' => ($products->fields['product_is_free'] =='1' ? 0 : $products_price),
        //                                    'quantity' => $this->contents[$products_id]['qty'],
                                  'quantity' => $new_qty,
                                  'weight' => $products->fields['products_weight'] + $this->attributes_weight($products_id),
                                  // fix here
                                  'final_price' => ($products_price + $this->attributes_price($products_id)),
                                  'onetime_charges' => ($this->attributes_price_onetime_charges($products_id, $new_qty)),
                                  'tax_class_id' => $products->fields['products_tax_class_id'],
                                  'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''),
                                  'attributes_values' => (isset($this->contents[$products_id]['attributes_values']) ? $this->contents[$products_id]['attributes_values'] : ''),
                                  'products_priced_by_attribute' => $products->fields['products_priced_by_attribute'],
                                  'product_is_free' => $products->fields['product_is_free'],
                                  'products_discount_type' => $products->fields['products_discount_type'],
                                  'products_discount_type_from' => $products->fields['products_discount_type_from']);
      }
    }
    $this->notify('NOTIFIER_CART_GET_PRODUCTS_END');
    return $products_array;
  }

And REPLACE with this:

		//begin Attribute Calculator 1.0
		//Zen Cart contribution by JT Website Design http://www.jtwebsitedesign.com	
        $description_sql = 'SELECT products_name FROM ' . TABLE_PRODUCTS_DESCRIPTION . ' where products_id = "' . (int) $products_id . '"';

		$pdescription = $db->Execute($description_sql);
		$products_name = $pdescription->fields['products_name'];

		switch($products->fields['products_name'])
			{
		  	case 'Product A':
		  	$priceFactor = 1.00;
		  	break;
		  	case 'Product B':
		  	$priceFactor = 0.50;
		  	break;
		  	case 'Product C':
		  	$priceFactor = 1.25;
		  	break;
		  	default:
			$priceFactor = 0;		
			}
		if($priceFactor != 0)
			{
	        $Length_ID_Query = "select products_options_id from " . TABLE_PRODUCTS_OPTIONS . " where products_options_name = 'Length'";
			$Length_ID = $db->Execute($Length_ID_Query);
			$LengthID = (int)$Length_ID->fields['products_options_id'];
	
			$Width_ID_Query = "select products_options_id from " . TABLE_PRODUCTS_OPTIONS . " where products_options_name = 'Width'";
			$Width_ID = $db->Execute($Width_ID_Query);
			$WidthID = (int)$Width_ID->fields['products_options_id'];
			
			if ($this->contents[$products_id]['attributes_values'][$WidthID] && $this->contents[$products_id]['attributes_values'][$LengthID])
			$areaFactor = $this->contents[$products_id]['attributes_values'][$WidthID]*$this->contents[$products_id]['attributes_values'][$LengthID];
			
			else
			$areaFactor = 0;
			$extraCharge = $areaFactor * $priceFactor;
			}
		else
			$extraCharge = 0;
		//end Attribute Calculator 1.0

        $products_array[] = array('id' => $products_id,
                                  'category' => $products->fields['master_categories_id'],
                                  'name' => $products->fields['products_name'],
                                  'model' => $products->fields['products_model'],
                                  'image' => $products->fields['products_image'],
                                  'price' => ($products->fields['product_is_free'] =='1' ? 0 : $products_price+$extraCharge),
        //                                    'quantity' => $this->contents[$products_id]['qty'],
                                  'quantity' => $new_qty,
                                  'weight' => $products->fields['products_weight'] + $this->attributes_weight($products_id),
                                  // fix here
                                  'final_price' => ($products_price + $this->attributes_price($products_id) + $extraCharge),
                                  'onetime_charges' => ($this->attributes_price_onetime_charges($products_id, $new_qty)),
                                  'tax_class_id' => $products->fields['products_tax_class_id'],
                                  'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''),
                                  'attributes_values' => (isset($this->contents[$products_id]['attributes_values']) ? $this->contents[$products_id]['attributes_values'] : ''),
                                  'products_priced_by_attribute' => $products->fields['products_priced_by_attribute'],
                                  'product_is_free' => $products->fields['product_is_free'],
                                  'products_discount_type' => $products->fields['products_discount_type'],
                                  'products_discount_type_from' => $products->fields['products_discount_type_from']);
      }
    }
    $this->notify('NOTIFIER_CART_GET_PRODUCTS_END');
    return $products_array;
  }

So, what you'll want to do is change "Product A", "Product B", etc to match the names of your product. Then you can put a price per square foot (the variable for this is $PriceFactor), which can be specified for each individual product.

If you want the same price per square foot for all products, the above code can be modified a bit, and you can hard code the PriceFactor to be a specific number, removing the cases per product.

Hope it makes sense and helps out a bit! Let me know if it works for you

11 Nov 2009, 10:53 AM
#16
zahid_hussain avatar

zahid_hussain

New Zenner

Join Date:
Sep 2009
Posts:
54
Plugin Contributions:
0

Re: User input product dimensions, update price based on inputs

<form action="" method="post"> <table width="100%" height="129" border="1" align="center"> <tr> <td height="27" width="50%" bgcolor="#A9A9A9" ><b>Enter Your Square Footage below:</b></td> <td bgcolor="#A9A9A9"><b>Your Material cost</b></td> </tr> <tr> <td width="50%" align="center"><br /><input id="size" size="15" name="boxsize" /></td> <td> <?php

$box=$_POST['boxsize'];
//echo $box;
if($box==0)
{
echo 0;
echo " "."boxes";
}
elseif($box<$products_colour)
{
echo 1;
echo " "."boxes";
}
else
{
//echo "now more than 20";

$noboxes=($box/$products_colour);

$finalbox= ceil($noboxes);
echo $finalbox;
echo " "."boxes";

}
?>
<br /><br />

<?php if($finalbox<1) { echo 1; echo " "."sq.ft"; } else { $sqft=($finalbox*$products_colour); echo $sqft; echo " "."sq.ft"; } ?>

<br /><br />

<?php //echo $pri; $price= $finalbox*$pri; echo " "."$".$price; //$_SESSION['myprice']=$price; //echo $_SESSION['myprice']; ?> </td> <tr><td height="25" colspan="2" align="center"><input type="submit" value="Calculate" /> </td></tr> </tr> </table> </form>

my last calculated price value is "."$".$price;, file name is product_info_display.php :clap:

11 Nov 2009, 5:53 PM
#17
jackie_taferner avatar

jackie_taferner

Totally Zenned

Join Date:
Jun 2009
Location:
Orange County, California
Posts:
547
Plugin Contributions:
3

Re: User input product dimensions, update price based on inputs

Zahid,

So did that work for you in conjunction with my script (or a modification of it)?

You should be able to pass that value to the shopping_cart.php file using a similar method as what i posted.

Note especially this line:
'final_price' => ($products_price + $this->attributes_price($products_id) + $extraCharge),

the $extraCharge variable adds the extra cost

7 Dec 2010, 2:58 PM
#18
3dperuna avatar

3dperuna

New Zenner

Join Date:
Nov 2007
Posts:
33
Plugin Contributions:
0

Re: User input product dimensions, update price based on inputs

Did this module ever get finished? Any updates to it?