Stock level for certain sizes

Posts: 8
Joined: 08/20/2007

I feel this is tricky, I hope I can find help with the workaround:

I'm using Ubercart to set up the store for my client who sells clothes. Each of the design of his clothes comes in different sizes, e.g. S, M, L, XL. Now, he wants to be able to set stock level for each size. For example: Denim Jacket is only available in M and L sizes, therefore customers should not be allowed to buy S size.

Can this be done?

Posts: 924
Joined: 11/05/2007
Bug FinderFAQ ModeratorGetting busy with the Ubercode.

Yes. Create a "Size" Attribute with S, M, L, XL Options. Edit the product (node/#/edit) and add that Attribute and those Options to the product (see the tabs at the top of the page). Then go to the Adjustments tab and associate a different SKU with each size. You can also set a different price for the different sizes.

--

<tr>.

Posts: 8
Joined: 08/20/2007

Thanks to TR for the tip, I did what you told and I got the following error instead. And the stock level was not saved. Can you try and let me know if you get similar error?

* warning: in_array(): Wrong datatype for first argument in /home/xxx/public_html/sites/all/modules/ubercart/uc_stock/uc_stock.module on line 361.
* warning: in_array(): Wrong datatype for first argument in /home/xxx/public_html/sites/all/modules/ubercart/uc_stock/uc_stock.module on line 361.
* warning: in_array(): Wrong datatype for first argument in /home/xxx/public_html/sites/all/modules/ubercart/uc_stock/uc_stock.module on line 361.

Posts: 332
Joined: 08/07/2007
Administrator

From uc_stock_skus in uc_stock.module:

<?php
   
...
    if (
module_exists('uc_attribute')) {
     
$models = db_query("SELECT model FROM {uc_product_adjustments} WHERE nid = %d", $node->nid);
      while (
$model = db_fetch_object($models)) {
        if (!
in_array($model,$skus)) { //error occurs here
         
$skus[] = $model->model;
        }
      }
    }
    ...
?>

It looks like I had a typo in the in_array's 1st argument; it should be $model->model not $model. I guess my PHP setup is fine with using objects as the argument with in_array function. I've committed a patch to bazaar so that $model->model is used.

--

-Shawn Conn: If the Name Don't Rhyme It Ain't Mine

Posts: 8
Joined: 08/20/2007

Hello Shawn, thank you for responding to this post and your suggestion. I corrected the code and got it working without error. However while I was testing it, I set a particular option to zero stock and tried add it to the cart, I didn't get any warning that prompts me on zero stock, i.e. I was still able to proceed to check out to complete the purchase. Isn't the function of stock to prevent order being made for items that have zero stock? Or is it merely for the purpose of managing stock re-ordering?

Posts: 332
Joined: 08/07/2007
Administrator

The later, right now the uc_stock module just sends out a message to admins notifying the user of a stock level that has dropped below its threshold. An additional step has to be set in place to disable the purchase of a product that has dropped below its threshold.

--

-Shawn Conn: If the Name Don't Rhyme It Ain't Mine

Posts: 25
Joined: 02/26/2008

the best behavior would be upgrading uc_attributes also.

IN the product page should be draw the dropdown attributes with stock qty for each option. Then for options with 0 stock level, should be added a disabled="disabled" code.

Posts: 332
Joined: 08/07/2007
Administrator

The design decision was to make the stock module to just keep track of a stock value and warn admins of it falling below a threshold. No further restrictions were put in place because depending on your business model this might not be needed. More restrictions using the stock module will need to be implemented further down the road, possibly making use of Workflow-NG.

--

-Shawn Conn: If the Name Don't Rhyme It Ain't Mine

Posts: 7
Joined: 03/10/2008

Hi Shawn

i hope this makes sense

Is there any idea if and when this functionality (items with a stock level of 0 are disabled and can not be added to the cart) will be available?

Is this something that would be difficult to configure?

i have no experience in PHP but if this wont be too difficult i will give it a go, it's something that is quite important for the site i am building.

At present as far as i can work out the only options are to either disable the whole item or remove the attribute that is no longer available. As im sure you know When you disable or enable an attribute you lose all the SKU's setup and have to reconfigure.

Have i missed something (it has been known Smiling) and there is an alternative way to achieve this?

cheers

Ap

Posts: 25
Joined: 02/26/2008

I've managed to hack uc_attribute.module to get stock counts based by SKU. But it shown in product page only if you have stock admin privs... -_-

The only thing I can do in the future is automatically avoid to display stocks below thresold by IF statement.

But before this i must manage stock qty also for all kind of users. I seem it's another different query.

I think at least as on/off option in admin pages, check stock qty should improve UC and outdate inventory api contrib that isn't no more developed. And duplicate of stock.