Would be a nice feature to have it ported.

I'm off of time with other projects, as soon as I'm able I'm gonna help on that.

Hope somebody decides to begin patching.

P.S: Please, whoever has permissions change the version to 7.x 1.x-dev. Thanks.

Comments

ParisLiakos’s picture

StatusFileSize
new7.58 KB

this is what i have done so far,against 6.x-2.x-dev
There some warnings left , i think it needs a bit more work

raulmuroc’s picture

Status: Active » Needs review
StatusFileSize
new7.58 KB

Nice job @rootatwc :-)!!

As soon as I can I'll review it (or whoever).

raulmuroc’s picture

Status: Needs review » Active

Ok tested it. It failed to me. Found errors:

It is looking for *.install, but this module doesn't have that file. :S So it looks like doesn't have sense.
At line 84 of uc_restrict_qty.module it brokes.

Hope the feedback helps to repair. As soon as I can I will contribute to repairing patch but I am full of work and other modules patches and cannot more. Sorry for that and thanks for your effort.

ParisLiakos’s picture

Status: Active » Needs review

@RaulMuroc, like i stated above,this patch is against 6.x-2.x-dev, not 6.x-1.1

Freakachoo’s picture

I found errors in patch.

Code:
$models = uc_product_get_models($node);

shouldSbe
$models = uc_product_get_models($node->nid);

Because in ubercart module this function get as argument $nid, not $node
function uc_product_get_models($nid, $add_blank = TRUE) {

Also code:
$key = NULL;
if ($product_qty['rqpid']) {
$key = 'rqpid';
}

Should be:
$key = array();
if ($product_qty['rqpid']) {
$key[] = 'rqpid';
}

Code:
function uc_restrict_qty_cart_item($op, &$item) {

Should be:
function uc_restrict_qty_uc_cart_item($op, &$item) {

Code:
function uc_restrict_qty_add_to_cart_data($form_values) {

Should be:
function uc_restrict_qty_uc_add_to_cart_data($form_values) {

Code:
function uc_restrict_qty_theme() {
return array(
'restrict_qty_field' => array(
'arguments' => arra('form' => null),
),
);
}

Should be:
/**
* Implementation of hook_theme().
*/
function uc_restrict_qty_theme() {
return array(
'restrict_qty_field' => array(
'render element' => 'form',
),
);
}

AND

Code:
// Themes cart Qty. boxes so they can't be changed. (currently not in use)
function theme_restrict_qty_field($element) {
return check_plain($element['#value']);
}

Should be:
// Themes cart Qty. boxes so they can't be changed. (currently not in use)
function theme_restrict_qty_field($variables) {
return check_plain($variables['form']['#value']);
}

Sorry i don't know how to make patch file. :)

Freakachoo’s picture

StatusFileSize
new13.7 KB

Ok here is working ported d7 module.

ParisLiakos’s picture

here,this will help you with patching:
http://drupal.org/project/uc_restrict_qty/git-instructions

Hendry Lee’s picture

@Freakachoo

Thanks for the ported version. Unfortunately, it doesn't work with UC 3.0. A quick troubleshooting reveals that uc3 no longer uses hook_cart_item or hook_uc_cart_item, so the function uc_restrict_qty_uc_add_to_cart() is never called.

raulmuroc’s picture

Priority: Normal » Major
jhrizz’s picture

I too am interested in this. When I try to use rules, it tells me that the Item QTY field is not writable.. Going to see if there is another way to force a qty for a product.

denisr’s picture

I had a go too, same thing. :(

raulmuroc’s picture

Priority: Major » Normal
Status: Needs review » Active

Thins would become easier to port & test to D7 with a nex 7.x-1.x-dev branch.

Thanks in advance.

a.knutson’s picture

Does anyone have any plans to port this to D7 UC3? I'm compiling a list of Ubercart related modules and trying to get an idea of what still needs to get ported over.

Thanks in advance!!

raulmuroc’s picture

Category: task » bug
Priority: Normal » Major

I have just contacted the module maintainer to discover if he is considering that way...

Jeffrey C.’s picture

Category: bug » task

Changing the issue to the correct category.

raulmuroc’s picture

Issue tags: +Ubercart, +restrict, +limit, +quantity, +qty, +UC Restrict QTY
StatusFileSize
new32.21 KB

I made a petition (again) of a new 7.x-1.x-dev branch and to be co-maintainer if possible.

after that we should spend our energy on make it working.

Until now we have the filre in #6 (thanks @Freakachoo) which just implements the Interface part (see attached image) but it does not do anything at all whaever which option you choose.

Does somebody else want to help? Let me know please.

thank you.

anjjriit’s picture

I've tested this version, but still found this error
"Notice: Undefined index: restrict_qty in uc_restrict_qty_form_alter() (line 281 of ../sites/all/modules/uc_restrict_qty/uc_restrict_qty.module)."....

my be the order already in chart form before this module installed.

raulmuroc’s picture

First of all we need a new maintainer (and co-maintainer if possible :P).

The current one is so busy that even do not answer mail contact :(

Could you please send some message to him as well?

We also need to open a new branch: 7.x-1.x-dev to commit the ported version and future bug fixes.

raulmuroc’s picture

Status: Active » Needs review
StatusFileSize
new8.88 KB

This patch:

- Ports to D7 coming from 6.x-2.x-dev branch.
- Fixes previous bugs.

raulmuroc’s picture

Status: Needs review » Closed (fixed)

The above patch has been committed through the creation of a new Branch for Drupal 7:

7.x-1.x-dev.

Since now we should work on solving bugs, adding new reliable features, etc.

Thank you.

ParisLiakos’s picture

+++ b/uc_restrict_qty.moduleundefined
@@ -11,17 +11,17 @@
+	return array(
+		'restrict_qty_field' => array(
+			'render element' => 'form',
+		),
+	);

@@ -171,22 +176,25 @@ function uc_restrict_qty_feature_form_submit($form, &$form_state) {
+	$key = array();
+	if ($product_qty['rqpid']) {
+		$key[] = 'rqpid';
+	}

@@ -283,17 +291,17 @@ function uc_restrict_qty_form_alter(&$form, &$form_state, $form_id) {
+	return check_plain($variables['form']['#value']);

you should use spaces, not tabs. see http://drupal.org/coding-standards#indenting

teddymik’s picture

Will the 7.x-1.x-dev version be uploaded shortly?

raulmuroc’s picture

Priority: Major » Normal

It is currently uploaded as development version.

Feel free to point any bug issue or patch.

diego.paroni’s picture

One solution for me is the module "UC Add to Cart Tweaks":
empty the shopping cart when the add to cart form is submitted and alter the add to cart redirect URL to checkout page.

rimu’s picture

In UC 3, hook_uc_cart_item has become several functions hook_uc_cart_item_OPERATION where OPERATION is insert, update, delete and presave. See ubercart/uc_cart/uc_cart.api.php for details.

Rather than patch this module, as a fix to @Hendry Lee #8 (getting this module working with UC 3.0), I put this code in a custom module


function MODULENAME_uc_cart_item_insert($entity) {
  // If this item has a quantity restriction on it...
  if ($entity->data['restrict_qty']['qty'] > 0) {
    $is_lifetime = isset($entity->data['restrict_qty']['lifetime']) && $entity->data['restrict_qty']['lifetime'];
    $restrict_qty = $is_lifetime ? $entity->data['restrict_qty']['rest'] : $entity->data['restrict_qty']['qty'];
    if ($entity->qty > $restrict_qty) {
      // Reduce the quantity to 1 if necessary.
      $entity->qty = $restrict_qty;
      db_query("UPDATE {uc_cart_products} SET qty = :qty, changed = :changed WHERE cart_id = :cart_id AND nid = :nid AND data = :data", 
      array(':qty' => $restrict_qty, ':changed' => time(), ':cart_id' => uc_cart_get_id(), ':nid' => $entity->nid, ':data' => serialize($entity->data)));
      drupal_set_message(format_plural($restrict_qty, 'You may only add 1 !item to your cart. Quantity has been restricted.', 'You may only add @count !item to your cart. Quantity has been restricted.', array('!item' => $entity->title)), 'warning');
    }
  }
}

function MODULENAME_uc_cart_item_update($entity) {
  // If this item has a quantity restriction on it...
  if ($entity->data['restrict_qty']['qty'] > 0) {
    $is_lifetime = isset($entity->data['restrict_qty']['lifetime']) && $entity->data['restrict_qty']['lifetime'];
    $restrict_qty = $is_lifetime ? $entity->data['restrict_qty']['rest'] : $entity->data['restrict_qty']['qty'];
    if ($entity->qty > $restrict_qty) {
      // Reduce the quantity to 1 if necessary.
      $entity->qty = $restrict_qty;
      db_query("UPDATE {uc_cart_products} SET qty = :qty, changed = :changed WHERE cart_id = :cart_id AND nid = :nid AND data = :data", 
      array(':qty' => $restrict_qty, ':changed' => time(), ':cart_id' => uc_cart_get_id(), ':nid' => $entity->nid, ':data' => serialize($entity->data)));
      drupal_set_message(format_plural($restrict_qty, 'You may only add 1 !item to your cart. Quantity has been restricted.', 'You may only add @count !item to your cart. Quantity has been restricted.', array('!item' => $entity->title)), 'warning');
    }
  }
}