Files: 
CommentFileSizeAuthor
#15 771028-decrementing-by-attribute-sku.patch3.89 KBpaul.dambra
PASSED: [[SimpleTest]]: [MySQL] 1,707 pass(es).
[ View ]
#12 771028-decrementing-by-attribute-sku.patch3.83 KBpaul.dambra
FAILED: [[SimpleTest]]: [MySQL] 1,709 pass(es), 0 fail(s), and 1 exception(s).
[ View ]
#10 decrement_stock_attributes.patch4.17 KBpaul.dambra
FAILED: [[SimpleTest]]: [MySQL] 1,707 pass(es), 0 fail(s), and 1 exception(s).
[ View ]
#9 decrement_stock_attributes.patch4.25 KBpaul.dambra
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch decrement_stock_attributes.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Comments

Status:Patch (to be ported)» Active

Can you tell me whether you have stock tracking for the base SKU enabled? If you don't have tracking on the base SKU, I would consider this to be a bug. But if you *do* have tracking on the base SKU, I think this is more a side-effect of how uc_stock works, since there is now an ambiguity as to which SKU should be decremented, the adjusted one or the base one.

The "decrement twice" issue is almost certainly the same as #644538: Duplicate order notification e-mail, and duplicate stock decrement so please participate in the discussion in that thread.

Status:Active» Postponed (maintainer needs more info)

I have the same issue. How to you track your base SKU? All the SKUs are marked active, including the base SKU. I'm using the paypal module and the order status shows complete.

Component:Code» Stock
Status:Postponed (maintainer needs more info)» Closed (won't fix)

Title:Patch for uc_stock incorrectly updating products wiht attributesUc_stock incorrectly updating products with attributes
Status:Closed (won't fix)» Needs review

Hello Tr,

I'm not sure this one should be closed just yet. I'm still seeing this issue in Drupal 6.22, UC Stock 6.x-2.7.

The issue looks fairly straight forward.

In uc_cart.module:uc_cart_get_item(), the code loads the node, and sets the product->model equal to the main sku for the item:

<?php
  $product
= node_load($item->nid);
  if (!
$product) {
    return;
  }
 
$item->vid = $product->vid;
 
$item->title = $product->title;
 
$item->cost = $product->cost;
 
$item->price = $product->sell_price;
 
$item->weight = $product->weight;
 
$item->data = unserialize($item->data);
 
$item->module = $item->data['module'];
 
$item->model = $product->model;
?>

The stock decrement code in uc_stock:uc_stock_adjust_product_stock(), then attempts to decrement the model's stock.

<?php
 
// Product has an active stock?
 
if (!uc_stock_is_active($product->model)) {
    return;
  }
?>

But, that may not be the model or sku that we actually wish to use. If you've turned on an attribute, and setup a separate stock sku for it's options, your sub-skus are the ones with he inventory.

Other modules need the main sku for things, I assume. So it makes sense to provide a sub-sku or just more accurate sku, in the product->data['sku']. It should be as simple as adding the sku to the product data, then using it in the uc_stock_adjust_product_stock function.

Any chance of getting that small piece added to the next version, and a patch we could all use until then?

Version:6.x-2.2» 6.x-2.x-dev
Status:Needs review» Active

Wrong status - "needs review" is only used when there's a patch.

TR, there won't really be a patch until the issue has some clear direction. Need a decision from the maintainers on how you'd like to handle the variation sku.

Other modules need the main sku for things. So it makes sense to provide a sub-sku or just more accurate sku, in the product->data['sku']. It should be as simple as adding the sku to the product data, then using it in the uc_stock_adjust_product_stock function.

If that's what you want, speak up and someone can patch that way.

Status:Active» Needs review
StatusFileSize
new4.25 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch decrement_stock_attributes.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

I've fixed this for my use-case and so I thought I'd submit a patch...

I've left the $product object alone so as not to have to worry about side effects...

At the start of uc_stock:uc_stock_adjust_product_stock() this patch tries to load an sku using the

<?php
$product
->data['attributes']
?>
. Where an attribute / adjustment sku can be found that is used otherwise the $product->model is used.

StatusFileSize
new4.17 KB
FAILED: [[SimpleTest]]: [MySQL] 1,707 pass(es), 0 fail(s), and 1 exception(s).
[ View ]

Oops just realised that was a messy patch.

This is tidier...

P

Status:Needs review» Needs work

The last submitted patch, decrement_stock_attributes.patch, failed testing.

StatusFileSize
new3.83 KB
FAILED: [[SimpleTest]]: [MySQL] 1,709 pass(es), 0 fail(s), and 1 exception(s).
[ View ]

trying again...

is it better to edit the failed ones with new attachments?

Status:Needs work» Needs review

changing status

Status:Needs review» Needs work

The last submitted patch, 771028-decrementing-by-attribute-sku.patch, failed testing.

Status:Needs work» Needs review
StatusFileSize
new3.89 KB
PASSED: [[SimpleTest]]: [MySQL] 1,707 pass(es).
[ View ]

added check for undefined index....

Status:Needs review» Needs work

Please pay attention to Drupal coding standards: http://drupal.org/coding-standards

I'm happy to... I'm new to PHP and Drupal. Could you be more specific?

Thanks for your work.

I've tested patch in #15 and apparently works with an attribute but doesn't when more than one attributes are present in a product