I sell custom-made and ready-made items and have a slight problemette with stock control, and was hoping someone may be able to help.
Say I was selling T-shirts. I have a base stock of 20 red, 20 blue and 20 black t-shirts, and each listing corresponds to a t-shirt design. Now, currently, if someone buys a black t-shirt with an elephant design, the t-shirt stock on the elephant will go down to 19, but the other listings stay at 20. I would like all the custom t-shirts stock to go down to 19, while not affecting the ready-made stuff.
I've had a fiddle with catalog/model/checkout/order.php and am able to reduce stock across all options that have the same option_value_id, but this also affects the stock levels of ready-made stuff. I'd like to narrow it down to just custom bits, either by category_id or option_value_id=whatever, is this even possible?
Any help would be most gratefully received.
Kinda worked out how to do it whilst half-asleep at 4 in the morning and it appears to work on my test shop. am worried about the code, though, as I am a noob, will it be alright on the live shop?
Have changed a bit of catalog/model/checkout/order.php from:
to this:
It's not going to be mean to the server, is it? Thanks.

Have changed a bit of catalog/model/checkout/order.php from:
Code: Select all
foreach ($order_product_query->rows as $order_product) {
$this->db->query("UPDATE " . DB_PREFIX . "product SET quantity = (quantity - " . (int)$order_product['quantity'] . ") WHERE product_id = '" . (int)$order_product['product_id'] . "' AND subtract = '1'");
$order_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "' AND order_product_id = '" . (int)$order_product['order_product_id'] . "'");
foreach ($order_option_query->rows as $option) {
$this->db->query("UPDATE " . DB_PREFIX . "product_option_value SET quantity = (quantity - " . (int)$order_product['quantity'] . ") WHERE product_option_value_id = '" . (int)$option['product_option_value_id'] . "' AND subtract = '1'");
}
}
Code: Select all
foreach ($order_product_query->rows as $order_product) {
$this->db->query("UPDATE " . DB_PREFIX . "product SET quantity = (quantity - " . (int)$order_product['quantity'] . ") WHERE product_id = '" . (int)$order_product['product_id'] . "' AND subtract = '1'");
$order_option_query = $this->db->query("SELECT * FROM ". DB_PREFIX . "order_option JOIN product_option_value ON order_option.product_option_value_id = product_option_value.product_option_value_id WHERE order_id = '" . (int)$order_id . "' AND order_product_id = '". (int)$order_product['order_product_id'] . "'");
$ovidarray = array("132", "133", "whatever", "put option_value_id here");
foreach ($order_option_query->rows as $option) {
$ovidyay = $option['option_value_id'];
if (in_array($ovidyay, $ovidarray)) {
$this->db->query("UPDATE " . DB_PREFIX . "product_option_value SET quantity = (quantity - " . (int)$order_product['quantity'] . ") WHERE option_value_id = '" . (int)$option['option_value_id'] . "' AND subtract = '1'");
} else {
$this->db->query("UPDATE " . DB_PREFIX . "product_option_value SET quantity = (quantity - " . (int)$order_product['quantity'] . ") WHERE product_option_value_id = '" . (int)$option['product_option_value_id'] . "' AND subtract = '1'");
}
}
}
Did you get this working?
Professional Robotics Repair Center
Specializing in Roomba, Scooba, and Neato Robot Parts and Repair
http://www.iFixRobot.com
@ defenestrator - Thank you for posting your code, I have used this and it has worked great in OC 1.5.5.1.
However this only solves 1/2 my issue, what I am trying to do now is get OC to check through the options when adding to cart. Similar to what you have done, but for it to check the options (stock quantity) when adding to cart on a global scale rather than on a per product basis. As I have many custom t-shirts designs that are available on different colour t-shirts and sizes.
Example Physical stock = 2x Black t-shirts
Product A:
option_value = Black T-shirt (stock 2)
Product B:
option_value = Black T-shirt (stock 2)
Current OC set-up will allow 2x product A with option_value 'Black T-shirt' to be added to cart, and not greater that x2 - all good so far.
But when I add 2x Product B with option_value 'Black T-Shirt' to the cart it will be allowed as the product option stock is also 2 (this is oc default) - here is what I would like to change and get the code to look at what is already in the cart and not allow this to be added as an item x2 (product A) with option_value 'Black T-shirt' is already in the cart and a greater quantity of 2 (in this example) should not be allowed as the physical 'Black T-shirt' stock is 2.
Hopefully I have made sense here, any help would be gratefully received, Thanks.

However this only solves 1/2 my issue, what I am trying to do now is get OC to check through the options when adding to cart. Similar to what you have done, but for it to check the options (stock quantity) when adding to cart on a global scale rather than on a per product basis. As I have many custom t-shirts designs that are available on different colour t-shirts and sizes.
Example Physical stock = 2x Black t-shirts
Product A:
option_value = Black T-shirt (stock 2)
Product B:
option_value = Black T-shirt (stock 2)
Current OC set-up will allow 2x product A with option_value 'Black T-shirt' to be added to cart, and not greater that x2 - all good so far.
But when I add 2x Product B with option_value 'Black T-Shirt' to the cart it will be allowed as the product option stock is also 2 (this is oc default) - here is what I would like to change and get the code to look at what is already in the cart and not allow this to be added as an item x2 (product A) with option_value 'Black T-shirt' is already in the cart and a greater quantity of 2 (in this example) should not be allowed as the physical 'Black T-shirt' stock is 2.
Hopefully I have made sense here, any help would be gratefully received, Thanks.
Who is online
Users browsing this forum: No registered users and 4 guests