Post by jtsroberts » Sun May 01, 2011 1:14 pm

I'm using v1.4.9 and am selling products that vary by size only. I've setup each product and the size option with values and quantities per option.

How do you display to the user that it's only certain options that are in stock? ie. if I only have 1 pair of size 10, it somehow shows that size 10 is the only size in stock?

New member

Posts

Joined
Wed Nov 11, 2009 4:24 pm

Post by ocpro » Sun May 01, 2011 6:28 pm

You'll need to make a change to the catalog/model/catalog/product.php firstly.
Find this line

Code: Select all

'price'                   => $product_option_value['price'], 
After it put

Code: Select all

'quantity'                => $product_option_value['quantity'], 
That should load up the quantity value for each option ready to be used in the template. Next you need to put the code into your product template, and use $option_value['quantity'] for the value of the quantity. I'm not actually sure if you want to do it the way you suggested however as if all quantities are 0, then you'll end up with no option values, and that could be an issue

New member

Posts

Joined
Tue Apr 26, 2011 7:57 am

Post by jtsroberts » Mon May 02, 2011 12:43 pm

Thanks ocpro. I added the code and then opted to simply hide the normal Availability line in the product listing and add a stock level to each option in the dropdown:

'name' => $option_value['name'] . ' (' . $option_value['quantity'] . ' in stock)'

Thanks!

New member

Posts

Joined
Wed Nov 11, 2009 4:24 pm

Post by ocpro » Mon May 02, 2011 7:47 pm

Ah right OK. My main concern was that you were going to hide any option that didn't have higher than 0, and leave you with a product with no options

New member

Posts

Joined
Tue Apr 26, 2011 7:57 am

Post by mystifier » Sat May 07, 2011 4:39 am

I think you would also have to add to catalog/controller/product/product.php:

Code: Select all

'quantity' => $option_value['quantity'],
The other consideration is that product and option quantities are allowed to go negative so in
catalog/model/checkout/order.php

Change:

Code: Select all

foreach ($order_option_query->rows as $option) {
  $this->db->query("UPDATE " . DB_PREFIX . "product_option_value SET quantity = (quantity - " . (int)$product['quantity'] . ") WHERE product_option_value_id = '" . (int)$option['product_option_value_id'] . "' AND subtract = '1'");
}
To:

Code: Select all

foreach ($order_option_query->rows as $option) {
  $this->db->query("UPDATE " . DB_PREFIX . "product_option_value SET quantity = greatest(0,(quantity - " . (int)$product['quantity'] . ")) WHERE product_option_value_id = '" . (int)$option['product_option_value_id'] . "' AND subtract = '1'");
}
Which will prevent it from going below zero which would look odd.

+ + +

Personally, I think preventing negative product/option stock should be core behaviour
Example:
- Product has Options A,B,C with quantities 1,1,1 (overall product quantity 3)
- Someone buys 4 of Option C (after 4-5 days message)
- This leaves Options A,B,C with quantities 1,1,-3 (overall product quantity -1)
- Someone wants to buy Options A,B but product confusingly shows out-of-stock despite being available

But, I guess a $this->config->get('Allow_Negative_Stock') would be the best option.

Free v1.4.9 Extensions: Default Specials | Improved Search | Customer Activity Report | Customer Groups | Royal Mail With Handling | Improved Product Page | Random Products | Stock Report | All Products


User avatar
Active Member

Posts

Joined
Tue May 18, 2010 5:15 pm

Post by redg8r » Tue May 17, 2011 12:45 am

Thanks for info, I understand the premise but have a couple questions you guys might clear up for me:

Using the above method, will purchases deduct stock from the options upon purchase? (if setup to deduct normally in ACP)

and

is there a way to prevent negative stock? I assumed if the setting was enabled in the ACP to prevent checkout with items marked "out of stock"

Thank you

Newbie

Posts

Joined
Tue May 17, 2011 12:38 am

Post by elmerrfudd » Sun Jun 05, 2011 5:42 pm

jtsroberts wrote:Thanks ocpro. I added the code and then opted to simply hide the normal Availability line in the product listing and add a stock level to each option in the dropdown:

'name' => $option_value['name'] . ' (' . $option_value['quantity'] . ' in stock)'

Thanks!
Hi, I am trying to do exactly what you did.
Would you please let me know the location of the file where you made the changes in order to display the stock status next to each option and also the file where you removed the normal Availability

Thank you

Newbie

Posts

Joined
Sun Jun 05, 2011 5:38 pm

Post by jtsroberts » Mon Jun 06, 2011 6:29 am

elmerrfudd wrote: Hi, I am trying to do exactly what you did.
Would you please let me know the location of the file where you made the changes in order to display the stock status next to each option and also the file where you removed the normal Availability

Thank you
catalog/model/catalog/product.php

New member

Posts

Joined
Wed Nov 11, 2009 4:24 pm

Post by hoyle.a » Sat Nov 19, 2011 5:32 am

Just edit catalog/model/catalog/product.php

FIND:
$product_option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value WHERE product_option_id = '" . (int)$product_option['product_option_id'] . "' ORDER BY sort_order");

REPLACE:

$product_option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value WHERE product_option_id = '" . (int)$product_option['product_option_id'] . "' AND quantity > 0 ORDER BY sort_order");

This will not allow options with 0 quantity or less to display.... enjoy

User avatar
Newbie

Posts

Joined
Mon Jul 18, 2011 4:15 am
Location - Seattle, WA

Post by hexenium » Wed Oct 10, 2012 5:21 pm

Hi guys!

How can you do the same thing in 1.5.3? (store has 2 languages)

I want the store to display "In Stock" or "Not in stock" after the option name. If i would get the quantity, I would just do an simple if/else there. But I have trouble getting the $option_value['quantity'] value in product.tpl.

I have added

Code: Select all

'quantity'          => $product_option_value['quantity']
on line 345 in "catalog/model/catalog/product.php"

but when I try to

Code: Select all

echo $option_value['name']. " - " .$option_value['quantity'];
on line 72 in "catalog/view/theme/my_theme/template/product/product.tpl"
only the name and the " - " is printed out.

i also tryed echoing $option_value['option_id'] and other array elements there but it seems I can only access $option_value['name']

I'll investigate and post solution, if I find one.

Newbie

Posts

Joined
Fri Jan 27, 2012 6:48 am

Post by BOBKIM7080 » Fri Mar 22, 2013 11:24 am

I have other problem 1.4.9.3
T-shirts Some how quantity 100
Red color 0
Blue color 0
some how customer "add to cart" T-SHIRTS then this order through without option.
How do I have to change if option is 0 then make unable to order.

User avatar
New member

Posts

Joined
Fri Aug 26, 2011 12:53 am


Post by parisarms » Fri Feb 23, 2018 2:30 pm

Is there a way to do this with Version 3.0.2.0 ?

Newbie

Posts

Joined
Mon Dec 11, 2017 2:35 pm
Who is online

Users browsing this forum: No registered users and 73 guests