Post by JIMSLITA » Sat Apr 06, 2013 11:09 pm

Would anyone be able to tell me whether it is possible to have 2 products sharing the same stock level at database level?

We sell Product A which has 4 options.

We would like to also offer, in another category, the product B which is, in reality, Product A option 4 but with a different price/discount structure than we have for Product A (because the discounts we can offer for option 4 are very different than those for options 1, 2 & 3)

Any insight into this concept would be greatly appreciated!

Thanks
Last edited by JIMSLITA on Tue Apr 16, 2013 10:40 pm, edited 1 time in total.

OC v 1.5.4 with alot of tweaks,exts & mods.


User avatar
New member

Posts

Joined
Fri Feb 08, 2013 3:49 pm

Post by butte » Sun Apr 07, 2013 10:01 am

That would be an interestingly different approach to discounts. I would guess that if they share the same id in the appropriate table(s), then either shared stock will increment or decrement in unison, or else instead the code will throw errors. Accordingly, after backing up your database, try setting their two id values to be the same, force Maintenance mode (to keep customers out for a little while), and try it. Either their stock will drop and rise together, or code will throw an error. With question answered, then either go forth smiling or reinstate database as it was. Remember to release Maintenance mode.

On a production box error reporting (not logging) should be turned off, in both php.ini and your admin panel. If you turn it on just for the test, it may help. A reasonably expected error would relate to a shared column in tables.

Guru Member

Posts

Joined
Wed Mar 20, 2013 6:58 am

Post by JIMSLITA » Mon Apr 08, 2013 2:08 am

Hi butte

I don't really understand how they can share the same ids - you can't set 2 products to have the same product id in the database - it'll just throw an Mysql error when you try and set a duplicate value for the primary key.

Is this what you were suggesting or am I misunderstanding your suggestion?

OC v 1.5.4 with alot of tweaks,exts & mods.


User avatar
New member

Posts

Joined
Fri Feb 08, 2013 3:49 pm

Post by rph » Mon Apr 08, 2013 2:41 am

Stock is kept on the product level so you'd have to do some custom coding to subtract from both products on checkout (dependent on option).

-Ryan


rph
Expert Member

Posts

Joined
Fri Jan 08, 2010 5:05 am
Location - Lincoln, Nebraska

Post by JIMSLITA » Mon Apr 08, 2013 2:53 am

Hi Ryan

Yes that's what I have discovered - its impossible to force in the DB because you are always trying to change the primary key and it obviously will not allow the duplicate to be saved.

How do you imagine this could be tackled? Might you be interested in it from a commercial point of view? I am keen to try and do it as it replicates the way customers have bought from us in the past, but it makes stock control much more painless if the option stock level is same for both products.

Regards

Jim

OC v 1.5.4 with alot of tweaks,exts & mods.


User avatar
New member

Posts

Joined
Fri Feb 08, 2013 3:49 pm

Post by butte » Mon Apr 08, 2013 7:11 am

What I ventured as the first alternative outcome depends, as came as no real surprise, upon whether a primary or other field "id" is used (you had meant it as key sensu stricto), and what I ventured as the second alternative outcome pans out, obviously because the id used (as key sensu stricto) is a primary table index key, and sharing it throws errors. In this instance the possibility of shared stock wasn't anticipated in a way to prevent throwing the error, and consequently referring to stock in a different way arises as a way out.

You could try keeping, of course, the nominal and primary product id as it was and wants to be (key), and adding a secondary one (not as an "id" key but as "name" in an ordinary field, separately positioned from the index field) to identify identically the two products' stocks in order that they can decrement and increment together. In effect, timing of change in one stock value for one product could trigger change in stock value of the other product.

Another or additional means (respectively without or with a second field for stock) might be to add an arithmetic step which will update stock of one dependently upon changes in stock of the other one, cued by timing.

The foregoing could also be approached by adding a new stock table, cued by product id with manipulable stock field values.

It's entirely possible that what I called "an interestingly different approach" is not doable without altering more of the core than will likely happen soon. Interim modifications might approach or reach what you need. And since you won't have been the only one with this problem (or with this solution to another one), the folks given to wring code should start noticing and thinking about it within a few days.

Guru Member

Posts

Joined
Wed Mar 20, 2013 6:58 am

Post by rph » Mon Apr 08, 2013 3:02 pm

JIMSLITA wrote:Hi Ryan

Yes that's what I have discovered - its impossible to force in the DB because you are always trying to change the primary key and it obviously will not allow the duplicate to be saved.

How do you imagine this could be tackled? Might you be interested in it from a commercial point of view? I am keen to try and do it as it replicates the way customers have bought from us in the past, but it makes stock control much more painless if the option stock level is same for both products.

Regards

Jim
I'm available for commercial work. You can find my rates at http://development.opencarthelp.com.

If it's just about hard-coding the values (e.g. it's just a product or two and the values won't need to be changed in the future once set up) it's a fairly fast change. If you want to try a go at it yourself you'd edit /catalog/model/checkout/order.php and in the confirm() function have OpenCart look for specific product_ids and product_option_value_ids and update the corresponding value accordingly.

If you want a robust system that can be edited through Admin things get more complicated. There would need to be a new database table and Admin would require a lot of controller and template changes.

-Ryan


rph
Expert Member

Posts

Joined
Fri Jan 08, 2010 5:05 am
Location - Lincoln, Nebraska

Post by JIMSLITA » Tue Apr 16, 2013 10:47 pm

Just to give credit where credit's due:

Ryan created a custom extension for us which did exactly what we wanted - in in the end a bit more! - quickly, efficiently and at a reasonable and pre-agreed price. His communication was prompt and clear and we managed to achieve a great solution which allows us not only to have 2 products, both with options, sharing the same stock (at an option stock level) but also it also allows us to now attribute an option to a product which is, in its self, a separate product on the website - at any price we choose and have stock decrement in tandem: much reducing stock control issues and improving upselling possibilities.

A credit to the developer community and a pleasure to do business with.

Thanks Ryan.

OC v 1.5.4 with alot of tweaks,exts & mods.


User avatar
New member

Posts

Joined
Fri Feb 08, 2013 3:49 pm

Post by Charlie-- » Tue Jun 04, 2013 4:21 am

@Ryan - The custom mod you coded, I would be interested in something similar.

I have several products that share the same options and I need the options stock quantity to be shared globally rather than per-product as it is currently. To stop customers ordering out of stock options.

Would this be possible? - I don't mind if it hard-coded and not that admin friendly.

Thanks

User avatar
Newbie

Posts

Joined
Mon Feb 27, 2012 7:03 am

Post by rph » Tue Jun 04, 2013 11:46 am

I've actually had several inquiries about this so I'm developing it into a mod. This is essentially a complete rewrite to work with an admin user interface. I'm at about the two-thirds point now but I don't have an ETA as it's getting worked on between other projects. I'm figuring at least two more weeks.

-Ryan


rph
Expert Member

Posts

Joined
Fri Jan 08, 2010 5:05 am
Location - Lincoln, Nebraska

Post by Charlie-- » Tue Jun 04, 2013 6:42 pm

Ok thanks, I will keep an eye out for it, cheers :)

User avatar
Newbie

Posts

Joined
Mon Feb 27, 2012 7:03 am

Post by stevieboy1101 » Tue Feb 10, 2015 7:10 pm

Is this mod avaiable for 1.5.6.4. Where can i download it?

Newbie

Posts

Joined
Tue Feb 10, 2015 7:07 pm

Post by llermaly » Fri Feb 19, 2016 11:04 am

BUMP

Newbie

Posts

Joined
Mon Sep 01, 2014 2:11 pm

Post by mattenderle » Sun Jan 27, 2019 11:45 am

rph wrote:
Tue Jun 04, 2013 11:46 am
I've actually had several inquiries about this so I'm developing it into a mod. This is essentially a complete rewrite to work with an admin user interface. I'm at about the two-thirds point now but I don't have an ETA as it's getting worked on between other projects. I'm figuring at least two more weeks.
I understand that this post is six years old, but were you ever able to finish this?

Newbie

Posts

Joined
Sat Apr 07, 2018 10:24 pm
Who is online

Users browsing this forum: Amazon [Bot] and 92 guests