I'd like to see the qty restriction configurable for product classes so that you can set a class to have a default qty restriction. I am using this for "course registration" and it never makes sense (in our business case) to allow a user to buy more than one (at a time, or ever, though that is a different story for a different feature).

What I am suggesting is that when you create a new product class you would be able to set a default restrict qty value for all products of that product class, though you could override it on a per product basis.

One other thing is that it would be great to have the option to "hide qty if qty restriction is 1" in order to hide the qty from the cart and confirmation screens.

CommentFileSizeAuthor
#23 416422-default-for-product-classes.patch12.37 KBhanoii

Comments

greenbeans’s picture

I'd be interested in this too. Going to check out the code and see if I can make heads or tails of how to implement it.

EDIT: Looks like this might be easier to implement entirely separately than to graft onto this module.

mrfelton’s picture

@greenbeans: Why do you say that? This module is specifically for restricting quantity. New features (including this one) should be added to this module, not created separately, elsewhere. I will try to look into adding this over the next week.

mrfelton’s picture

greenbeans’s picture

Sorry, I meant more that I didn't see a way to do it by reusing the functionality already in the module, not that it should be in a separate one. Let me know if I can help you at all with the implementation.

mrfelton’s picture

Please see notes at #348049: Configurable Qty for initial development of this. IT doesn't yet provide class defaults, but does let you configure the quantity at the product level. Please test and report any problems over at the other thread.

timani’s picture

Potential solution for this while something more comprehensive comes about.

I'd like to see the qty restriction configurable for product classes so that you can set a class to have a default qty restriction. I am using this for "course registration" and it never makes sense (in our business case) to allow a user to buy more than one (at a time, or ever, though that is a different story for a different feature).

With this module you can go the "Product/Plan" and go to the features, and click the checkbox to empty the cart.
http://drupal.org/project/uc_atctweaks

I have a custom template for the content type i wish only to be purchased. I guess you could hide the add to cart or a redirect based on content type or have that taken care of inside the template

Hope that helps

GregoryHeller’s picture

I don't think that the patch or notes in http://drupal.org/node/348049 Configurable Qty really address the issue raised in this ticket, which is to allow for default qty restrictions on products and specifically by product class, which is not to say a total cart restriction, rather a specific product restriction.

Currently the act of adding a restrict qty feature to a product requires that the product creator go to a completely different tab and add this feature thing. I understand for extensibility purposes, perhaps, why restrict qty is a product feature, but it would be far more user friendly if the qty restriction was included in the main product information field set for every product as opposed to obscured on some separate tab.

jamesialford’s picture

I would like this feature ass well. Is there any updates on this?

James

kostajh’s picture

subscribing

mautumn’s picture

Subscribing. It would be more useful if the qty can be specified - not fixed at 1, on a per product basis. Keep up the good work!

tiuman’s picture

PLEASE I NEED IT!!! Add Default Qty Restrictions to all default products!!! tiuman@mail.ru send me please !!!

Anonymous’s picture

For my needs, which is every product has a lifetime quantity restriction of 4, I've created a custom action which I set to trigger whenever a node is added. I thought I'd post the code here as it may be useful to some.

You'll need to create your own custom module and add these functions to it - I've commented where you need to change stuff:

/**
* Implementation of hook_action_info().
* Change my_module to the name of your custom module
*/
function my_module_action_info() {
  return array(
    'my_module_configure_showing_action' => array(
      'description' => t('Add restrict quantity feature'),
      'type' => 'node',
      'configurable' => FALSE,
      'hooks' => array(
        'nodeapi' => array('insert')
        ),
      ),
  );
}

/**
* Implementation of a Drupal action.
* When my_node_type is added, this action automatically adds restrict qty
* Change my_node_type to the name of your product content type
*/
function my_module_configure_showing_action(&$object, $context = array()) {
if ($object->type == 'my_node_type') {
				
		// Set product feature description
		$description = '<strong>'. t('SKU') .':</strong> '. t('Any') .'<br/>';
		$description .= '<strong>'. t('Quantity restriction') .':</strong> '. $product_qty .'<br/>';
		$description .= '<strong>'. t('Type') .':</strong> '. t('Lifetime') .'<br/>'; // Set correct for lifetime, change if not lifetime
		
		// Build the data array
		$data = array(
		  'nid' => $object->nid,
		  'fid' => 'restrict_qty',
		  'description' => $description,
		);				
		
		// Save the feature into the product features table
		db_query("INSERT INTO {uc_product_features} (nid, fid, description) VALUES (%d, '%s', '%s')",
		         $data['nid'], $data['fid'], $data['description']);
		
		// Build the restrict product qty data array ready for saving         
		$product_qty = array(
		  'rqpid'       => NULL,
		  'pfid'        => db_last_insert_id('uc_product_features', 'pfid'),
		  'nid'         => $object->nid,
		  'model'       => NULL,
		  'qty'         => 4, // Change the max qty to your needs
		  'lifetime'    => 1, // Set as lifetime restriction, change if necessary
		);
  	
  	// Save the feature
		drupal_write_record('uc_restrict_qty_products', $product_qty, NULL);
		
	}
}
Anonymous’s picture

Let me try that again - I left in my content type of 'showing' in the code, here's amended version:

/**
* Implementation of hook_action_info().
* Change my_module to the name of your custom module
*/
function my_module_action_info() {
  return array(
    'my_module_configure_my_node_type_action' => array(
      'description' => t('Add restrict quantity feature'),
      'type' => 'node',
      'configurable' => FALSE,
      'hooks' => array(
        'nodeapi' => array('insert')
        ),
      ),
  );
}

/**
* Implementation of a Drupal action.
* When my_node_type is added, this action automatically adds restrict qty
* Change my_node_type to the name of your product content type
*/
function my_module_configure_my_node_type_action(&$object, $context = array()) {
if ($object->type == 'my_node_type') {

// Set product feature description
$description = '<strong>'. t('SKU') .':</strong> '. t('Any') .'<br/>';
$description .= '<strong>'. t('Quantity restriction') .':</strong> '. $product_qty .'<br/>';
$description .= '<strong>'. t('Type') .':</strong> '. t('Lifetime') .'<br/>'; // Set correct for lifetime, change if not lifetime

// Build the data array
$data = array(
  'nid' => $object->nid,
  'fid' => 'restrict_qty',
  'description' => $description,
);

// Save the feature into the product features table
db_query("INSERT INTO {uc_product_features} (nid, fid, description) VALUES (%d, '%s', '%s')",
         $data['nid'], $data['fid'], $data['description']);

// Build the restrict product qty data array ready for saving        
$product_qty = array(
  'rqpid'       => NULL,
  'pfid'        => db_last_insert_id('uc_product_features', 'pfid'),
  'nid'         => $object->nid,
  'model'       => NULL,
  'qty'         => 4, // Change the max qty to your needs
  'lifetime'    => 1, // Set as lifetime restriction, change if necessary
);
 
  // Save the feature
drupal_write_record('uc_restrict_qty_products', $product_qty, NULL);

}
}
Anonymous’s picture

Oh man I need sleep, noticed another error (not critical, only textual!):

$description .= '<strong>'. t('Quantity restriction') .':</strong> '. $product_qty .'<br/>';

Should be;

$description .= '<strong>'. t('Quantity restriction') .':</strong> 4 <br/>';

...or whatever your quantity restriction is.

Right, bed....

carsonw’s picture

stevepurkiss, I created a custom module and implemented your code but I can't get it to work, for the life of me. Would it be possible for you to simply share your module as an attachment (zip) and I could go in and simply edit the node type and quantity?

carsonw’s picture

Or, I wonder what the php code would be to run to simply add the "Restrict Qty" feature to a product using the "Rules" module... this may be a simpler alternative.

alexkb’s picture

I couldn't get stevepurkiss's code to work either.

As a work around, I deleted all the rows in uc_product_features that mentioned 'restrict_qty', and then batch inserted all those that I wanted, i.e.:

DELETE FROM uc_product_features WHERE 'fid' = 'restrict_qty';

INSERT INTO uc_product_features(nid, fid, description) SELECT nid, 'restrict_qty', 'Users may only purchase one of this product at a time.' FROM NODE WHERE `type` = '<node_type>';

(where is the name of the node type you want).

For products added into the future, I just used the following code:


function my_module_name_nodeapi(&$node, $op, $a3, $a4){
	
  if ($node->type == "<node_type>") {
    switch($op) {
      case 'insert':
        $data = array(
          'nid' => $node->nid,
          'fid' => 'restrict_qty',
          'description' => t('Users may only purchase one of this product at a time.'),
        );
        uc_product_feature_save($data);
        break;
      default:
        break;
      }
  }
}

Hope that can help someone! Seems to work fine.

EvanDonovan’s picture

Am I correct in my reading of this issue that no one has submitted a patch for the module yet? stevepurkiss' code, while potentially useful, seems to be more of a workaround than a fix for the underlying issue. alexkb's code is much cleaner, and closer to the correct fix.

I think that the actual fix would do the following:

  • hook_form_alter the product class configuration page to add a variable that would allow you to define whether the given product class was restricted to a specific quantity
  • implement the "insert" $op of hook_nodeapi directly, rather than using an action
  • in the hook_nodeapi implementation, there would be a condition to check $node->type against the types defined in the variable of product classes for which quantity is restricted (this would be quite similar to the code in the second half of #17)

I don't have the time to code this right now, though I would review if it were available. I will just use a modified version of #17 for the time being.

As for doing it using Rules, that would make the node types customizable, and the PHP code would be, I think, what is inside case 'insert': in #17.

EvanDonovan’s picture

By the way, I tested the code in #17 with the following condition:

if ($node->type == 'registration' || $node->type == 'product') {

Works great!

Now someone just needs to write up a patch, and add the variable setting logic as I described in #18.

summit’s picture

Subscribing, greetings, Martijn

Anonymous’s picture

Also subscribing...

hanoii’s picture

Category: bug » feature

I created a patch for this feature, I did it so on 2.x though.

This patch follows the ideas of #18 plus a few more stuff:

- It lets you define defaults on product classes
- It insert the feature for the specific nodes on creation
- It has a batch process allowing you to add the feature to all the nodes that doesn't have it or overwrite everything.
- It fixes a function that should be removing the internal information from the db on node deletion for the proper nodeapi hook.
- it adds fields to the uc_product_classes table using using the proper schema/install/uninstall hooks.

Any help reviewing this is appreciated.

While going through this I got a pretty good picture on how the module works so I will request to owner of this project to become a co-maintainer, I can commit fully to this but one more hand might help a little.

EDIT: NOTE: You need to run update.php after patching the module

hanoii’s picture

Version: 6.x-1.1 » 6.x-2.x-dev
Component: User interface » Code
Status: Active » Needs review
StatusFileSize
new12.37 KB

Forgot to attach the patch.

EvanDonovan’s picture

Thanks, hanoii! We went live with my version of #17, so I don't have time to review at the moment.

We might be developing another site with the same use case, though, so I may have a chance to review at that time.

deadcataudio’s picture

Category: feature » bug

I applied the patch to 6.x-2.x-dev but I get an error while trying to apply QTY 1 in my Product Class:

user warning: Unknown column 'uc_restrict_qty_default_qty' in 'field list' query: uc_restrict_qty_uc_product_class_form_submit /* sfxadmin : uc_restrict_qty_uc_product_class_form_submit */ UPDATE uc_product_classes SET uc_restrict_qty_default_qty = 1, uc_restrict_qty_default_lifetime = 1 WHERE pcid = 'MYPRODUCT' in /home/www/site/html/MYSITE_com_root/sites/all/modules/uc_restrict_qty/uc_restrict_qty.module on line 401.

Did somebody else tried the patch?

hanoii’s picture

I was about to look into this, you need to run update.php file after patching the module, because it adds fields to the product_classes table, that's probably why your query is failing.

deadcataudio’s picture

Category: feature » bug

Thanks, that was the problem - I had a php memory problem thats why the update got stuck in the frist place - disabled some modules, ran update again and - voila :)

Thanks for the quick help and the great time saving patch!

jdmyron’s picture

So, are the default quantity restrictions in the dev version now or no? Still only available via a patch?

strr’s picture

So, are the default quantity restrictions in the dev version now or no? Still only available via a patch?

strr’s picture

So, are the default quantity restrictions in the dev version now or no? Still only available via a patch?

strr’s picture

"It has a batch process allowing you to add the feature to all the nodes that doesn't have it or overwrite everything."

Where and when is a batch done to update all products of a contet type to have restrcition of e.g. 1 item

Thank you.

strr’s picture

Hello,
i applyed the patch successfully and run update.php
I enabled and restricted to "1" at admin/store/settings/products/edit/features
But nothing is restricted when i add a product to the cart.
Are there any other settings i need to do - what have i missed.
I cannot restrict anything even without the patch?

Thank you

hanoii’s picture

It's been a while since I used this module and submitted the patch. By looking at it, there's an option in the product class form in which you set the default, to batch add the restrictions to the products, that should work. Otherwise I am not sure I'll be able to look into this unless the maintainer is willing to accept this patch, in which case I might try to push it a little bit forward, but It was working for me.

raulmuroc’s picture

Status: Needs review » Closed (fixed)

That's currently included in the stable version.

Search for:

" Default maximum limit for a product " in the Ubercart Restrict Qty UI.

NamesBuying.com’s picture

#22 & #23 works for me, thank you hanoii .

After I search the internet and drupal for 3 days , this patch only works for me properly!!

vmtrinka’s picture

Voila !! There is a module for that !!
https://www.drupal.org/project/uc_restrict_qty

joe huggans’s picture

Issue summary: View changes

@vmtrinka - this module doesn't allow restriction per product class. I'm looking for a D7 solution if anyone knows of one