Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Product Quantity Field increments


skaterguy

Recommended Posts

Hi Folks

 

Trying to setup a fabric store with osCommerce. Some of the products will be fabric and may be ordered in 10 cm increments with .3 being the minimum cut or as a fat quarter [(50 cm X 55 cm), which is (20 " X 22")] . Note we use the metric system meters versus yards.

 

Choices - Any .10 cm increments

- Fat Quarter (50 cm X 55 cm)

- A whole bolt of fabric ( 10 meters)

 

As a newbie, I would appreciate any suggestion on how to do this effectively. Please be as specific as possible.

 

Thanks

 

Danny

Link to comment
Share on other sites

  • 4 months later...
  • 4 months later...

I guess this is unlikely to get answered but I'd like to know as well as I need to do this for a store.

 

I have seen a contibution that adds support for text box attributes which would be ideal to use for ordering lengths but I saw no way of specifying constraints on what values would be accepted. It also didn't appear to change the cost of the product based on what was entered. I don't know enough about osCommerce (or PHP) to hack this in myself.

Link to comment
Share on other sites

For the store I set up, we instruct the visitors to enter the length of fabric required as a quantity.

 

I have not yet figured out how to allow quantities less than 1 (ie 0.5 for half a metre).

 

Its not ideal but it works (kind of)!

Link to comment
Share on other sites

For the store I set up, we instruct the visitors to enter the length of fabric required as a quantity.

 

I have not yet figured out how to allow quantities less than 1 (ie 0.5 for half a metre).

 

Its not ideal but it works (kind of)!

 

Hi folks

 

I reported this bug on the 4th July 2005 and it has never been assigned to anyone or fix. For more details look at http://www.oscommerce.com/community/bugs,2...search,quantity ...

 

I was able to get some fractional data as a quantity - as mentioned in the bug discription. I'm still interested in using osCommerce - but I would need this bug to be fixed. One possible work-around is to use a product attribute contribution and define different quantifier such as fat quarter, 1/2 meter, etc... Not ideal but does work.

 

If anyone has a better solution - feel free to share.

 

Danny

Link to comment
Share on other sites

Currently testing and appears to work...

 

Changed customers_basket_quantity in the customers_basket table to DECIMAL 15,4 format.

Changed products_quantity in the orders_products table to DECIMAL 15,4 format.

Changed products_quantity in the products table to DECIMAL 15,4 format.

Changed products_ordered in the products table to DECIMAL 15,4 format.

 

 

In catalog/includes/classes/shopping_cart.php change the < 1 number to whatever is the smallest decimal/fractional which you allow clients to purchase. In my case, you can purchase .1 of a meter and up.... so if it's less than .1 it's reset...

 

EXISTING CODE in function cleanup() around line 161

reset($this->contents);

while (list($key,) = each($this->contents)) {

if ($this->contents[$key]['qty'] < 1) {

unset($this->contents[$key]);

 

MODIFIED CODE

reset($this->contents);

while (list($key,) = each($this->contents)) {

if ($this->contents[$key]['qty'] < .1) {

unset($this->contents[$key]);

 

I'm justing testing this - so use at your own risk... Don't recommend using it in a production environment until the developers have a chance to review and comment.

 

Remember I'am a newbie and welcome any comments/suggestion to make this better or if you encounter problems. Would appreciate comments from the developers on this work-around.

 

Dan

Link to comment
Share on other sites

  • 2 months later...

I'm doing fabric as well, and found the place I had to change to allow 0.5 yards of fabric.

 

To allow less than 1 item, change:

catalog:includes:classes:shopping_cart.php"; Line 146:

from:

if ($this->contents[$key]['qty'] < 1) {

to:

if ($this->contents[$key]['qty'] <= 0) {

 

I thought I was all set until today when I hit the database thing when selecting the shopping cart button, and all my quantities rounded to the nearest integer.

 

Argh. Store opens in four days, I need to figure out how to modify the database.

Link to comment
Share on other sites

About my last post, I just realized that you already found that, sorry.

 

Did you find the place to quantize the quantities to your cutting limitations? I'd like to quantize to quarter yards, .25, .5, .75, and of course .0.

 

There should be a place where the user's number is entered where I could just to an int(q*4+0.5)/4.

Link to comment
Share on other sites

Okay, I found the place for quantizing the quantities to the nearest quarter yard.

 

In includes/classes/shopping_cart.php, around line 125, and a line to quantize $quantity to the increment you want. For me, it was fourths, so I used the formula floor( $quantity * 4 + 0.5) / 4. This rounds to the nearest valid value. If 10cm is your quanta, you could use floor( $quantity * 10 + 0.5) / 10.

 

if (is_numeric($products_id) && isset($this->contents[$products_id_string]) && is_numeric($quantity)) {

New line of code here---> $quantity = floor( $quantity * 4 + 0.5) / 4;

$this->contents[$products_id_string] = array('qty' => $quantity);

Link to comment
Share on other sites

Even with the database changes, if I log out the customer, and log back in again, my quantities are truncated down to the lower integer.

 

I found two more places in /includes/classes/shopping_cart.php where the quantity is explicitly truncated.

 

One is around line 99, the other around 138. Search for "(int)$Q" and remove the "(int)".

 

(One of them is (int)$qty, the other (int)$quantity.)

 

Now my only problem is that when I read it in, the trailing zeros are there, so "2.25" comes back as "2.2500". I'm looking for a place where it reads it in, and hasn't turned it into a number yet. I'm open to ideas for where to fix that.

Link to comment
Share on other sites

  • 5 weeks later...

I found one more problem for fabric shops. The customer must have a minimum of 1.0 items in the cart before an order will be accepted, preventing an order for a single half-yard or quarter-yard. (You could order four .25 yard cuts, but not just one.)

 

The fix is in catalog/checkout_shipping.php, around line 23, change:

 

// if there is nothing in the customers cart, redirect them to the shopping cart page

if ($cart->count_contents() < 1) {

tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));

}

 

to read

 

// if there is nothing in the customers cart, redirect them to the shopping cart page

if ($cart->count_contents() < 0.25) {

tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));

}

 

which will allow a minimum order of 1/4 yard.

 

- Jeff

Link to comment
Share on other sites

  • 7 months later...

I found TWO more places that need to be changed, in order to handle an order whose total quantity is less than 1.0.

 

In catalog/checkout_payment.php, fix line 22:

From:

// if there is nothing in the customers cart, redirect them to the shopping cart page

if ($cart->count_contents() < 1) {

tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));

}

 

To:

// if there is nothing in the customers cart, redirect them to the shopping cart page

if ($cart->count_contents() <= 0) {

tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));

}

 

and the exact same change is needed in catalog/checkout_confirmation.php:

Same line number, same change, as in checkout_payment.php.

Link to comment
Share on other sites

  • 11 months later...
Okay, I found the place for quantizing the quantities to the nearest quarter yard.

 

if (is_numeric($products_id) && isset($this->contents[$products_id_string]) && is_numeric($quantity)) {

New line of code here---> $quantity = floor( $quantity * 4 + 0.5) / 4;

$this->contents[$products_id_string] = array('qty' => $quantity);

 

Thanks again so much for posting this, JAL. This solution works perfectly if your product_info page uses an "add to cart" button only and then the customer updates the quantity in the shopping cart. But, if you have a quantity text input box on your product page, there's one more step necessary in the form, but I can't quite figure it out.

 

Anyone know how to round to particular fractions quantities entered in the quantity text input box?

 

Don't know if I'm on the right track, but I've been playing with this function

 

function RoundTo(X) {	if (document.getElementById('amount').value == parseFloat(document.getElementById('amount').value)) {	amount = .25 *
   Math.round(document.getElementById('amount').value / .25);		  if (amount == 0) {	  amount = .25;			  }		 } else {			  amount = .25;		}		document.getElementById('quantity').value = quantity;
}

 

and calling it in the relevant form field in product_info.php

 

<input type="text" name="quantity" value="1" maxlength="5" size="5" text-align="right" onBlur="RoundTo(this.form)">

 

but I can't make it work.

 

Ideas anyone?

Link to comment
Share on other sites

Ok, I've re-thought and re-written that function as

 

function RoundTo(X) {
amount = .25 * Math.round(document.getElementById("quantity").value / .25);  
	document.getElementById("quantity").value = amount;
	}

 

but still no go.

Link to comment
Share on other sites

Nothing like freshly caffeinated eyes to make one's mistakes clear.

 

Here's the working function and its call, just in case anyone ever wants to use it.

 

This function rounds the customer's quantity input to the nearest .25. It also rounds any entry of less than 1 to 1. Put this wherever you store your functions:

function RoundTo(X) {
	var amount = .25 * Math.round(document.getElementById('quantity').value / .25);  
	if (amount < .9) {	amount = 1;  }
			 return document.getElementById('quantity').value=amount;
	}

 

And for your product info page, here's your quantity box. This recalculates the quantity before the customers eyes so it's obvious they can't order in increments other than .25.

 

<input type="text" name="quantity" value="1" maxlength="5" size="5" text-align="right" onBlur="RoundTo(this.value)" >

 

It's worth noting that because the store I'm building doesn't sell all its products in .25 increments, I have added a binary field to the products table and set up a conditional statement dependent on its value that presents an integer-filled drop-down quantity box under one condition, and this rounded text input quantity box based on the other.

 

Hope that helps someone!

Link to comment
Share on other sites

  • 1 year later...

I think I finally found my last bug in fractional quantities. I've been having a problem where an order reduces my in-stock quantity to below 1.0, and it gets marked as out of stock even if there is .75 or .5 left. I found it in catalog/checkout_process.php, at line 151, change:

 

if ( ($stock_left < 1) && (STOCK_ALLOW_CHECKOUT == 'false') ) {

 

to read

 

if ( ($stock_left <= 0) && (STOCK_ALLOW_CHECKOUT == 'false') ) {

 

Here is a bit more of the context, in case your line numbers are different:

 

tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");

if ( ($stock_left <= 0) && (STOCK_ALLOW_CHECKOUT == 'false') ) {

tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '0' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...