uc_multi_stock (stock manager with attributes)

Contrib type: 
Module
Status: 
Complete and working
Moderation: 
Not ready for moderation

Downloads


Compatibility: 
Ubercart 1.x
Compatibility: 
Ubercart 2.x

A stock level manager working with uc_stock, that takes into account the different sku of a product, according to the attribute selected.
Tests are made in -
* add to cart form
* cart view form
* final checkout

Error messages are themeable.

This module borrows freely (i.e - copies) some code from the Inventory API & Simple Stock Levels - (http://www.ubercart.org/contrib/132), by CpILL (http://www.ubercart.org/user/29), but is meant to be used with the uc_stock module.

according to user experience (http://www.ubercart.org/comment/20036/Re_I_noticed_contribution):
Be sure to disable uc_stockstub and Inventory API (from the modules menu) before installing uc_multi_stock.

see comparison of different stock managers : http://www.ubercart.org/docs/user/5181/out_stock_solutions

Other modules that can be used in addition to this one -

Ubercart Out of stock AJAX Notification
UC Attribute Stock Filter
Stock Notify

Drupal 6.x Notes:
in D6 the Ubercart Out of stock Notification contains the server side as well, so use this module only if you don't plan to use it as the client side component.


Al
Al's picture
Offline
Bug FinderGetting busy with the Ubercode.Internationalizationizer
Joined: 02/14/2008
Juice: 249
few minor issues

Thank you very much for this very much needed contribution, great work! As I will heavily rely on it I tested it intensively and founded few minor issues, sure fast to fix.

In all 3 tests of the stock level you test against the threshold. But the threshold is for informing admin that only few pieces are left, so you should test against 0. See patch.

Second is about your use of the t()-function which is not ok. See the patch how to get variables into the message.

Thanks again for this important contrib,

Al

AttachmentSize
uc_multi_stock.module.patch 2.99 KB
talbone's picture
Offline
Joined: 06/06/2008
Juice: 87
few minor issues

thanks for the comments, Al.

regarding the t() function - i will fix it.
regarding checking vs the threshold and not 0, i am actually not sure which is better. maybe I'll add it as a configuration option.

cheers,
tal

Al
Al's picture
Offline
Bug FinderGetting busy with the Ubercode.Internationalizationizer
Joined: 02/14/2008
Juice: 249
Threshold

Thanks for your answer. Just wanted to PM you. If you read the leading comment in uc_stock.module you find:

Quote:

... Store admins can set
* the stock levels on a product edit page and a threshold for each SKU value
* When that threshold is reached admins can be optionally notified about the
* current stock level...

So I am sure it is meant like this: We sell until stock is zero, but the admin can get a notification at threshold.

talbone's picture
Offline
Joined: 06/06/2008
Juice: 87
Threshold

Wow Al, thanks for the quick reply - and of course the improvements.
i am comparing to the threshold on purpose, not bu chance - it is more convenient if you also take phone orders, and want to set aside a bit of stock, and still use only one stock management.
BUT - i can see that using it the "right" way will be better in most cases, one of them is my current project, so i will add this as an option.

Al
Al's picture
Offline
Bug FinderGetting busy with the Ubercode.Internationalizationizer
Joined: 02/14/2008
Juice: 249
Re: Threshold

Configurable option sounds good. Regarding your "second outlet": I am sure my Multiple stock edit module is exactly what you need. It is running already a week on my customer's site and as they have about 30 stores they love it. If you have ideas to improve usability let me know,

Al

talbone's picture
Offline
Joined: 06/06/2008
Juice: 87
Re: Threshold

i'll be sure to give it a try.

Tal

TimK's picture
Offline
Joined: 08/18/2007
Juice: 147
Re: Re: Threshold

Is the patch now applied to the module? Thanks.

talbone's picture
Offline
Joined: 06/06/2008
Juice: 87
Re: Re: Re: Threshold

i afraid not yet.

talbone's picture
Offline
Joined: 06/06/2008
Juice: 87
Re: Re: Re: Threshold

it is now.

Insurrectus's picture
Offline
Spreading the word - Ubercart for president.
Joined: 08/22/2007
Juice: 364
Hide Out of Stock Options Instead of Message

Is there anyway to setup this module to just hide the product options that are out of stock instead of providing the post selection error message?

Example:
Small - 12
Medium - 10
Large - 0

I choose "Large" and get what appears to be an error message, at least until I read it.

Suggestion/Request:
Small - 12
Medium - 10

Large just doesn't show up in the list.

Insurrectus's picture
Offline
Spreading the word - Ubercart for president.
Joined: 08/22/2007
Juice: 364
Re: Hide Out of Stock Options Instead of Message

Bump.

marqpdx's picture
Offline
Joined: 08/09/2008
Juice: 2
Bump and where to handle hiding out of stock items

Great mod, Thanks!!

I'm bumping b/c i agree that hiding out of stock attributes (or graying out) is preferable to doing it after submit.

Where would that be in the event chain, code-wise. Would be glad to take a look, but a starting point would help.

Thanks again!
m

talbone's picture
Offline
Joined: 06/06/2008
Juice: 87
Re: Hide Out of Stock Options Instead of Message

there is more to it than that - a product can have more than one attribute (size AND color), and only specific combinations can be out of stock.
in that case, disabling one option just does not cover it.
i am not sure that dynamically disabling/enabling the options is the best solution - i tend more to the availability table solution. it is much simpler.

tal

brakk's picture
Offline
Cool profile pic award.
Joined: 08/14/2008
Juice: 20
Where are the settings

I have been looking for something like this module, and just installed it. It seems to be working ok, but I can't find any settings page to configure it. Are there any options to change and if so, where do I look?

Thank you.

graper@drupal.org's picture
Offline
Joined: 08/22/2008
Juice: 16
a feature request

Is it possible to have this module also provide different weight, price and cost for each combination?

I'm working on a website for a jewelery store and being able to price rings based on the combination of size and its metal type would be a great boon, the problem is that no other module makes the combinations that this module makes. So if this module could just add the weight, cost and price adjustments for each combination that would be awesome.

Granville
granville [at] kirkhamsystems [dot] com

hanoii's picture
Offline
Joined: 07/30/2008
Juice: 103
collaborating

I am about to use and test this module. I will probably contribute any modification to it. One question though, I chose to use the one with the applied patch, however, having two attachments confuses me.. are you planning on mainting two different branches or your code, or just one?

Thanks,
a.=

hanoii's picture
Offline
Joined: 07/30/2008
Juice: 103
very small comment

I just noticed after a few tests that the legend:

We're sorry. The @product in your selected size/color combination is out of stock. Please consider another size/color in this style.

Includes the size/color combination as a fix one. Now I know that this is a theme function and can be overriden in the theme, but noticing that the theme function only does a few calls to the t() function which can be easily tweaked using the locate module I am just thinking that it might be a good idea to try to improve that legend a little bit more, by retrieving the combination of attributes selected from the actual product. Thus, if a product have a size/length combination instead of size/color it would display the legend properly.

This is hardy a priority for me now but If I get a chance to do this I'll post the patch. Just thought worth mentioning the idea and leave it here.

Thanks,
a.=

hanoii's picture
Offline
Joined: 07/30/2008
Juice: 103
small bug

When removing out of stock items, the error still occurs and the validation fails not letting me remove the actual out of stock items from the cart.

I looked in the code and I noticed that was looked for, but by just looking at the quantity of the items and not also the remove checkbox.

Here is what I changed:

Line: 167

<?php
       
// dont test the removal of out of stock products
       
if($item['qty']>0){
?>

by

<?php
       
// dont test the removal of out of stock products
       
if(!$item['remove'] && $item['qty']>0){
?>
Insurrectus's picture
Offline
Spreading the word - Ubercart for president.
Joined: 08/22/2007
Juice: 364
Re: uc_multi_stock (stock manager with attributes)

I've been using this module for awhile and overall I'm very happy with it. I've noticed one thing I can seem to figure out. Occasionally I will get a stock value of -1, what does this mean?

wilky24's picture
Offline
Joined: 08/30/2008
Juice: 2
Set error message to show which attribute is out of stock

Is there a way to set the error message to display which attribute is out of stock? I am opening a skateboard shop and when a customer orders a custom deck they will have multiple attributes (wheels, trucks, grip tape, etc) to choose from and if just one is out of stock, I don't want them to have to guess which option is returning the error.

firebus@drupal.org's picture
Offline
Joined: 08/31/2008
Juice: 9
dynamically disabling/enabing the options is the best solution

the current solution *is* much simpler, but it's a huge pain in the ass for customers, many of whom would rather shop elsewhere than try over and over again to add out of stock items to your cart.

it's not okay to consider the current implementation finished. there are no popular ecommerce systems that don't have a method of telling customers what is out of stock before they try to add it to the cart.

yes, the complexity is in multiple attributes, and javascript is required to make things work correctly in this case.

it might be helpful to use workflow to disable attributes when stock reaches zero, but some logic and javascript on the product page will still be necessary to make sure that only valid options are presented to the customer.

Insurrectus's picture
Offline
Spreading the word - Ubercart for president.
Joined: 08/22/2007
Juice: 364
Amen. @firebus I would be

Amen. @firebus

I would be willing to post a $50 bounty to get this functionality added.

talbone's picture
Offline
Joined: 06/06/2008
Juice: 87
Re: Where are the settings

there is only one setting - how to use the thresh hold - only for notification, or for stock management as well.
all the rest is done with the regular stock management.
anyway, the setting page is under your-site-url/admin/store/settings/multi_stock

cheers,
tal

talbone's picture
Offline
Joined: 06/06/2008
Juice: 87
Re: a feature request

this is just a humble stock manager. it does not change the product attributes at all.
i think you will have better luck with the attributes management - mimic the way the system modify the sku for the ther qualities, too. i think that cost is already available.

talbone's picture
Offline
Joined: 06/06/2008
Juice: 87
Re: collaboratingno

sorry for the confusion.
no two branches - use the later one. it is backward compatible.
will make this a drupal project as soon as i manage to login to the cvs.

talbone's picture
Offline
Joined: 06/06/2008
Juice: 87
Re: small bug

you are correct.
i will update the code.
thanks

talbone's picture
Offline
Joined: 06/06/2008
Juice: 87
Re: uc_multi_stock (stock manager with attributes)

it meas a bug.
could you provide some more details of the context of this happening ? what were the stock levels of the products, and such ? anything you think is relevant.

talbone's picture
Offline
Joined: 06/06/2008
Juice: 87
Re: Set error message to show which attribute is out of stock

yes, there is in fact such a way.
the module come with theme-able functions - theme_uc_multi_stock_out_of_stock_error(),theme_uc_multi_stock_too_many_in_order_error().
both receive the attributes as parameters.

so - you can theme your error messages to reflect the actual attribute that is missing.

talbone's picture
Offline
Joined: 06/06/2008
Juice: 87
Re: dynamically disabling/enabing the options is the best soluti

implementation of open source projects is never finished. but it is very democratic - when someone has the need, he will write it. feel free to do so. i will be more than happy to use any improvements.

cheers,
tal

TimK's picture
Offline
Joined: 08/18/2007
Juice: 147
Now Posted On Drupal Org

I noticed that this is now posted on Drupal Org.

http://drupal.org/project/uc_multi_stock

Wondering if any of these features requests have now been implemented?

Also, how does this module compare to http://www.ubercart.org/contrib/4792 which changes the text on the add to cart button to read 'not available' when a customer selects a product attribute that is out of stock.

Is there any way of combining the two modules?

Thanks.

talbone's picture
Offline
Joined: 06/06/2008
Juice: 87
Re: Now Posted On Drupal Org

yep, i am pleased that i have finally managed to post the module to www.drupal.org.
none of the feature requests are implemented.
there is a comparison between the different stock managers - http://www.ubercart.org/docs/user/5181/out_stock_solutions. it also address the issue of combining them together.

greggles's picture
Offline
Joined: 12/12/2007
Juice: 97
great work

Great to see this on drupal.org It does exactly what I need.

I have provided a patch for it http://drupal.org/node/304226 which will help make it more "standardized".

Also, this page lists the status as "Complete and working." If you feel that is the case you should create an official release as 5.x-1.0 on drupal.org

Greggles Drupal Articles

hanoii's picture
Offline
Joined: 07/30/2008
Juice: 103
another module

Hi,

I just want to poing out a new module I just contrib tu drupal.org as well which is related to this one. I am actually using mine and this one together.

I am doing some Jquery and Ajax to fetch from the server if a combination of attributes is currently of stock, and if not, I am replacing the Add To Cart button with a configurable HTML snippet.

It's in a beta state, certainly working on a live site (DEMO available on drupal.org project's page) but I only tested on one ubercart site, other sites are welcome to try it out.

http://drupal.org/project/uc_out_of_stock

Thanks,
a.=

talbone's picture
Offline
Joined: 06/06/2008
Juice: 87
Re: another module

that's great.
a lot of people have been asking for this kind of functionality.
i have added a reference for it in the drupal project page and here.

hedgehog's picture
Offline
Joined: 10/07/2008
Juice: 14
stock won't decrement with this installed

I think I may have found a possible bug.
With this module installed, stock will no longer decrement (via Workflow-ng) whenever a product with attributes is purchased. And I have noticed that when this happens, the model field in the table uc_order_products remains empty.
If I disable multi_stock, then it will decrement properly again.

Products without attributes will decrement properly with multi_stock installed.

I have tried everything i can think of, including deleting all data including products and then reinstalling all of ubercart and Workflow-ng but this error remains.

Hope you can help as apart from this problem, this module is great and is exactly what I need for my site.

talbone's picture
Offline
Joined: 06/06/2008
Juice: 87
stock won't decrement with this installed

Hi hedgehog,
can you provide some extra data - drupal and ubercart versions, and possibly a description of the features/attributes you are using and their respective modification of the sku.
also, if you are using any other stock related modules at all - or any module that interact with the skus.

thanks,
tal

hedgehog's picture
Offline
Joined: 10/07/2008
Juice: 14
attributes problem solved but new Add to Cart problem

Hi tal,

I found the solution in this thread:

10/10/08 this was a bug in multistock, here is the fix
http://www.ubercart.org/issue/6304/sku_modelnumber_not_saved_order_infor...
Hi!
I hunted the bug over tree hours, but sovved this finally.
The bug is in the uc_multi_stock-contribution module in line 92.
This is original line:
$item->model = $sku;
This is fixed line:
if(!empty($sku)) $item->model = $sku;

However, my site is now having another serious problem with the module. It seems that when it does the stock check on Adding to Cart, it looks at the quantity of ALL the different products in my cart instead of just the product with the SKU that I am trying to add.

For example:
I have Product A which has 10 units left in stock. If I have no other products in my cart, multi stock works correctly when I Add to Cart with Product A.

However, if I have 10 or more units of Product B in my cart, and then I try to add 1 unit of Product A, I get an error message saying there are only 10 units of Product A, and it stops me adding 1 to my cart.

Likewise, if I have say 5 units of Product B in my cart and 5 units of Product C, then when I try to add 1 unit of Product A, it gives me the error message stopping me adding Product A to my cart, even though there are 10 units of Product A left.

This problem does not however occur when pressing the Update button once in the Cart - the stock tracking works correctly here. It seems to be just when clicking Add to Cart that is the problem.

I am using Drupal 5.15 and Ubercart 1.7 and version of multi-stock:
uc_multi_stock.module,v 1.1.2.1 2008/09/05 19:59:09 talbone

Would be grateful for any help as my site is live and I have only just noticed the problem as my customers are sometimes prevented from buying stuff that is actually in stock.

Edit: My products all have attributes but the attributes do not have their own SKUs. I think this may be the reason for my Add to Cart problem and also my previous decrementing problem above. I'm not a coder at all but looking at the comments in the module code, it seems like it is built around assuming that every attribute will have its own SKU.

Any chance of updating the module to make provision for where the product has attributes with no SKU of their own?

Or even any advice on how i can do a temporary hack to remove the attribute checking? I'm too scared to experiment with any changes to the code myself!

jibbajabba's picture
Offline
Joined: 09/20/2008
Juice: 133
Also having trouble with stock not decrementing

I have uc_multi_stock installed. I have added multiple SKUs/attributes to a product and the stock isn't reducing after user completes checkout, with status changing to either "Pending" (2checkout), "Payment Received" (PayPal) or "Completed". I tried adding workflows, but that didn't do anything.

I posted my progress researching this issue and all of the things I've tried here.

Any suggestions?

hanoii's picture
Offline
Joined: 07/30/2008
Juice: 103
stock derementing issue probably solved

I just struggled with this same issue and I think I came up with a solution. I have submitted the patch on drupal.org project's page for you to review and test it.

If you have any comment or find any problem with the patch, follow the discussion in the drupal.org issue's queue:

The link to the patch is http://drupal.org/node/427732#comment-1507856

a.=

talbone's picture
Offline
Joined: 06/06/2008
Juice: 87
Re: attributes problem solved but new Add to Cart problem

Hi hedgehog,
thank you for founding and posting the solution here.
as for your problem with the several products having the same sku, i am afraid i dont have plans to add this feature. this module uses the standard ubercart stock management, that is using the sku to determine the stock. to add more elements to the key means to manage the stock separately, and its not my intention for this module to do so.
we usually use a variation on the same parent sku - 12345 , 12345-a , 12345-b for exactly this functionality. i believe there is a module for mass editing of products in one go.
sorry for not coming with the solution you wanted, but only with 'good' advices.

talbone's picture
Offline
Joined: 06/06/2008
Juice: 87
Re: Also having trouble with stock not decrementing

this module does not handle the stock decreasing. that is done by ubercart uc_stock module.
this one only manages the prevention of buying more products than in stock.

kyutums's picture
Offline
Joined: 05/24/2009
Juice: 45
Porting to UC 2? :)

Any plans of porting this to UC 2? Or perhaps you have some tips that could lead me on how to port this to UC 2? Smiling

tracer's picture
Offline
Joined: 12/01/2008
Juice: 57
Print Stock Level Instead of Message

Is there anyway to print stock level anywhere on product page (node-product.tpl.php)
with something like this?

If a Product have 2 attributes with 1-100 SKU's and i chose
one of them than it will show the stock level for chosen SKU.
Is that possible?

<?php
print uc_stock_level($node->model);
?>
navi85sin's picture
Offline
Joined: 02/03/2010
Juice: 2
Print Stock Level Instead of Message alternative

hi,

after adding the product user need to know the quantity of it, when he is on the cart pane. /cart

the multi stock module just add the attribute in the cart pane and does not give any information about the quantity of the product sku that is available.

the code below shows the quantity of the multi stock products when they are added to the cart. it is for ubercart 1.x

need multi stock module, attribute module, product module.

in uc_product module change the function on line 1464 which is
function uc_product_cart_display($item) {
$node = node_load($item->nid);
$element = array();
$element['nid'] = array('#type' => 'value', '#value' => $node->nid);
$element['module'] = array('#type' => 'value', '#value' => 'uc_product');
$element['remove'] = array('#type' => 'checkbox');

$element['options'] = '';
if (module_exists('uc_attribute') && is_array($item->options)) {
foreach ($item->options as $option) {
$op_names[] = t('@attribute: @option', array('@attribute' => $option['attribute'], '@option' => $option['name']));

}
$element['options'] = array('#value' => theme('item_list', $op_names, NULL, 'ul', array('class' => 'cart-options')));
}

$element['title'] = array(
'#value' => node_access('view', $node) ? l($item->title, 'node/'. $node->nid) : check_plain($item->title),
);
$element['#total'] = $item->price * $item->qty;
$element['data'] = array('#type' => 'hidden', '#value' => serialize($item->data));
$element['qty'] = array(
'#type' => 'textfield',
'#default_value' => $item->qty,
'#size' => 5,
'#maxlength' => 6
);
return $element;
}

change this function to this

function uc_product_cart_display($item) {
$node = node_load($item->nid);
$element = array();
$element['nid'] = array('#type' => 'value', '#value' => $node->nid);
$element['module'] = array('#type' => 'value', '#value' => 'uc_product');
$element['remove'] = array('#type' => 'checkbox');

$element['options'] = '';
if (module_exists('uc_attribute') && is_array($item->options)) {
foreach ($item->options as $option) {
$op_names[] = t('@attribute: @option', array('@attribute' => $option['attribute'], '@option' => $option['name']));
$op_names[] = t('@attribute: @option', array('@attribute' => 'Quantity Available', '@option' => $option['qwty']));

}
$element['options'] = array('#value' => theme('item_list', $op_names, NULL, 'ul', array('class' => 'cart-options')));
}

$element['title'] = array(
'#value' => node_access('view', $node) ? l($item->title, 'node/'. $node->nid) : check_plain($item->title),
);
$element['#total'] = $item->price * $item->qty;
$element['data'] = array('#type' => 'hidden', '#value' => serialize($item->data));
$element['qty'] = array(
'#type' => 'textfield',
'#default_value' => $item->qty,
'#size' => 5,
'#maxlength' => 6
);
return $element;
}

now in uc_attribute module change the function
below on line 1484

function _uc_cart_product_get_options($item) {
$options = array();

$data = $item->data;
if (!empty($data['attributes']) && is_array($data['attributes'])) {

foreach ($data['attributes'] as $aid => $oid) {
$attribute = uc_attribute_load($aid, $item->nid, 'product');

// Only discrete options can affect the price of an item.
if ($attribute->display && count($attribute->options)) {
$options[$aid] = (array)$attribute->options[$oid];
$options[$aid]['attribute'] = $attribute->name;
}
else {

$options[$aid] = array('attribute' => $attribute->name,
'oid' => 0,
'name' => $oid,
'cost' => 0,
'price' => 0,
'weight' => 0,
);
}
}
}
else {
$options = array();
}
return $options;
}

to the function below

function _uc_cart_product_get_options($item) {
$options = array();

$data = $item->data;
//print_r($data['model']);
if (!empty($data['attributes']) && is_array($data['attributes'])) {

foreach ($data['attributes'] as $aid => $oid) {
$attribute = uc_attribute_load($aid, $item->nid, 'product');
$qwty=uc_stock_level($data['model']);
// Only discrete options can affect the price of an item.
if ($attribute->display && count($attribute->options)) {
$options[$aid] = (array)$attribute->options[$oid];
$options[$aid]['attribute'] = $attribute->name;
$options[$aid]['qwty'] = $qwty;
}
else {

$options[$aid] = array('attribute' => $attribute->name,
'oid' => 0,
'name' => $oid,
'cost' => 0,
'price' => 0,
'weight' => 0,
);
}
}
}
else {
$options = array();
}
return $options;
}

after doing this u will see an quantity available field in the product field also.

alexd73's picture
Offline
Joined: 08/12/2010
Juice: 33
Re: uc_multi_stock (stock manager with attributes)

My English not very good and I can't find information about settings of this module. How to use attributes and SKU? Give me a link to the manual, please? I understand, what this very simple, but I can't find any solution .
I hope you understand me Smiling

alexd73's picture
Offline
Joined: 08/12/2010
Juice: 33
Re: Re: uc_multi_stock (stock manager with attributes)

sorry for my stupidity. I understand this solution now Smiling

Now I decide other problem. Under the term of the problem, any product can be moved between different stocks, and these movements must be in the reports, such as invoice.
how to resolve this problem?
The best solution would: create this as a Order, but as a Customer input a Stock.
any ideas?

cmwwebfx's picture
Offline
Joined: 10/13/2010
Juice: 26
Auto refill stock

Hi there,

I was wondering if it were possible that thi could help with refilling stock levels automatically at a given period.
Example of use:

Client pays for a hired item from shop, the shop keeper has a 3 day limit then the item is collected from the client.
the system automatically restocks the database after the 3rd day. The stock levels on the site get replenished, and
a hired item is then ready to sell/hire again.

I hope this makes sense?

cmwwebfx's picture
Offline
Joined: 10/13/2010
Juice: 26
Re: Auto refill stock

Giving this a Friday *BUMP*..
Thanks in advance for any assistance.

talbone's picture
Offline
Joined: 06/06/2008
Juice: 87
Re: Auto refill stock

hi cmwwebfx,

i don't think this is in the scope of this module. the uc_multi_stock just prevents your customers from purchasing out of stock products.
check out the project on drupal, and you will see that active development is happening at http://drupal.org/project/uc_out_of_stock for D6.

in any case, i think your request should be implemented in a separate module.

moonleaf's picture
Offline
Joined: 03/12/2011
Juice: 4
Re: very small comment

Could somebody explain to me how to override this out of stock message in the theme? Thanks~~

"We're sorry. The @product in your selected size/color combination is out of stock. Please consider another size/color in this style."