Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Limit cart quantity by catagory (Not just minimum quantity)


Funtime

Recommended Posts

Hi Guys,

 

I am pretty new to osCommerce. I have the shop setup using STS.

 

 

Some products are sold individually (Which are in one catagory), but some are only sold in quantaties of 12 (in a seperate catagory).

 

We sell products in quantities of 12, but the customers are able to choose which of the 14 products they wish to order.

 

For example:

 

We have 2 catagories. Systems and Refills. Systems can be bought on their own, but refills must be bought as a pack of 12 (But people can choose which flavours they want to by in the pack of 12) So the system needs to limited them to buy what ever refills they want but the total quantity of refills must add up to a multiple of 12

 

We have 14 Refills. Each refill flavour is sold in quantities of 1. But an order must make a complete case of 12.

So you could order 3 x Refill A, 4 x Refill B and 5 x Refill C. The cart total must equal a quantiy of these products of 12.

 

Please can also order multiple cases so the total in the cart must be a multiple of 12 (eg 12,24,36,48,60 etc)

 

 

Hope that makes sense, I am not good at explaining really.

 

 

 

Very grateful for any help or guidance.

 

James

Link to comment
Share on other sites

I did something like that here, but that wasn't for "quantity per category" just "total cart quantity" so it wouldn't work for what you are attempting to accomplish.

 

My problem is that if I figured out the code to make it work for specific categories I couldn't tell you what files to change as I know practically ZERO about STS.

 

The only thing I do know is that the whole site works different and to see code changes reflected in the site you have to edit different files than a normal install.

:blush:

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Link to comment
Share on other sites

Thanks for your response. That is exactly what i need to do. Only difference is that i need to limit it to only apply to one catagory.

 

I dont think that the STS part would be a problem linking it into. I know it is a big ask, but if you were able to work out how to make it only apply to certain catagories, i would be very grateful and atleast one stage closer to working out how to impliment it into our shop.... Even if you were able to tell me what files needed changing in the standard RC2 i may be able to work out what files for STS.

 

I would be grateful for any help on this at all.

 

Many thanks

 

 

James

Edited by Funtime
Link to comment
Share on other sites

I'll look into it when I get home tonight.

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Link to comment
Share on other sites

I got the "nuts and bolts" of the code done and debugged (until proven otherwise).

 

Just a little consolidation left to do.

 

I'll be posting the finished code and instructions Tuesday evening.

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Link to comment
Share on other sites

Thank you sooo much.

 

You dont know how much better that is going to make my store. Will save alot of phone calls to people advising them that they have ordered the wronge quantaty..

 

Thanks again

 

 

James

Link to comment
Share on other sites

Step 1: Backup all files involved.

 

Step 2: At the end of /catalog/includes/functions/general.php just before the closing php tag add this code:

 

//// Return categories name
// TABLES: categories_description 
// I didn't write this function, I found it here on the forum
 function tep_get_categories_name( $who_am_i ) { 
   global $languages_id; 

   $the_categories_name_query= tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id= '" . $who_am_i . "' and language_id= '" . $languages_id . "'"); 

   $the_categories_name = tep_db_fetch_array($the_categories_name_query); 

   return $the_categories_name['categories_name']; 

 }

 function tep_prod_in_cart( $target_category ) {
   global $cart;
   if ($cart->count_contents() > 0) {
     $products = $cart->get_products();
     $count = 0;
     for ($i=0, $n=sizeof($products); $i<$n; $i++) {
       $path = tep_get_product_path( $products[$i]['id'] );
       $pieces = explode("_", $path);
       if ( ( count($pieces) ) && ( $target_category == $pieces[0] ) )
         $count += $products[$i]['quantity'];
     }
     return $count;
   } else
     return 0;
 }

 function cart_qty_check( ) {
   global $cart;
   if ($cart->count_contents() > 0) {
     $message = "";
     $qty_restricted_cats = array();
     $qty_restricted_cats = explode( "/", QUANTITY_RESTRICTED_CATEGORIES ); 
     for ($j=0, $n=sizeof($qty_restricted_cats); $j<$n; $j++) {
       $k = tep_prod_in_cart( $qty_restricted_cats[$j] );
       if ( $k % ORDER_QUANTITY_MULTIPLE ) {
         $message .= tep_get_categories_name( $qty_restricted_cats[$j] ) . ',';
       }
     }
     if ( strlen( $message ) ) {
       $message = substr ( $message , 0 , strlen($message) - 1 );
     }
     return $message;
   } else {
     return "";
   }
 }

 

Step 3: In this file:

 

/catalog/includes/configure.php

 

Add these lines:

 

  define('ORDER_QUANTITY_MULTIPLE','12');    // order quantity multilpe
 define('QUANTITY_RESTRICTED_CATEGORIES','21/32');  /// categories to apply it to, separated by a /

Just above this line:

 

// define our database connection

 

The number 12 is for this individual requirement. It can be modified to whatever order quantity multiple is desired.

 

The category ID's you want to apply this to go on this line, separated by a /

 

  define('QUANTITY_RESTRICTED_CATEGORIES','21/32');  /// categories to apply it to, separated by a /

 

Step 4: Add to /catalog/shopping_cart.php

 

/////BELOW///

    } else {
?>
   <tr>
     <td class="stockWarning" align="center"><br><?php echo OUT_OF_STOCK_CANT_CHECKOUT; ?></td>
   </tr>
<?php
   }
 }

////////////

 

/////ADD////

//bof check total order multiple 
   $tellme = cart_qty_check();
   if ( $tellme ) {
?>
   <tr>
     <td class="stockWarning" align="center"><br>The products in the following categorie(s) must be ordered in quantities of <?php echo ORDER_QUANTITY_MULTIPLE; ?>: <br>
<?php
 echo $tellme;
?>
     </td>
   </tr>
<?php
   }
//eof

////////////

 

 

Step 5: Add to these files:

 

/catalog/checkout_shipping.php

/catalog/checkout_process.php

/catalog/checkout_payment.php

/catalog/checkout_confirmation.php

 

/////BELOW///

  require(DIR_WS_CLASSES . 'order.php');
 $order = new order;

////////////

 

/////ADD////

//bof check minimum total order multiple 
 if ( cart_qty_check() ) {
   tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
 }
//eof

 

These instructions are for a standard install.

 

Not sure exactly what files you'll need to edit to get it to work with STS.

:blush:

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Link to comment
Share on other sites

Great!

:)

 

Something else you need to know:

 

Visit the link below:

 

How to Secure Your Site

 

Pay close attention to "SECURING THE ADMIN" - Yours is vulnerable.

 

It's easier to do a few security fixes now than to clean up a hacked store later.

 

And if you don't secure the admin your shop will be hacked.

 

It's just a question of when...

:o

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Link to comment
Share on other sites

  • 5 months later...

okay so I'm trying to follow this. and i think I'm about to look like a complete and utter idiot.. but when you get to the bit that is;

 

define('ORDER_QUANTITY_MULTIPLE','12'); // order quantity multilpe

define('QUANTITY_RESTRICTED_CATEGORIES','21/32'); /// categories to apply it to, separated by a /

 

 

how do you know what the category code is? sorry if this is really thick? is it just the name?

 

thanks

Link to comment
Share on other sites

Look at the URL when you view it.

 

hxxp://www.yoursite.com/catalog/index.php?cPath=xx

 

xx = category code.

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...