Support from Acquia helps fund testing for Drupal Acquia logo

Comments

TR’s picture

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.

TR’s picture

Status: Active » Postponed (maintainer needs more info)
fehin’s picture

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.

TR’s picture

Component: Code » Stock
Status: Postponed (maintainer needs more info) » Closed (won't fix)
lance.gliser’s picture

Title: Patch for uc_stock incorrectly updating products wiht attributes » Uc_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:

  $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.

  // 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?

longwave’s picture

TR’s picture

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.

lance.gliser’s picture

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.

paul.dambra’s picture

Status: Active » Needs review
FileSize
4.25 KB

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

$product->data['attributes']

. Where an attribute / adjustment sku can be found that is used otherwise the $product->model is used.

paul.dambra’s picture

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.

paul.dambra’s picture

trying again...

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

paul.dambra’s picture

Status: Needs work » Needs review

changing status

Status: Needs review » Needs work

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

paul.dambra’s picture

Status: Needs work » Needs review
FileSize
3.89 KB

added check for undefined index....

TR’s picture

Status: Needs review » Needs work

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

paul.dambra’s picture

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

vdupom’s picture

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