/    Sign up×
Community /Pin to ProfileBookmark

Product List + Inventory

I’m trying to create a simple online shopping system.

Some items are one off items. I could list them in a products table with a integer being set once sold and shouldn’t show online when sold.

Some items have multiple numbers available. Stock that will be replenished.

Any recommendations on table structure to keep track of both scenarios?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@sibertSep 18.2022 — > @kiwis80#1647094 Any recommendations on table structure to keep track of both scenarios?

In many tables I use one column for "status" that is updated if needed. The status column is just an integer that depends on a status table. The status table consists of an index and a name. So status 1 - available, status 2 - out of stock etc.

This way you can create a flexible way of handle future things. Just add an extra status record for example Status 3 - ordered but not delivered. Status 4 - one off etc
Copy linkTweet thisAlerts:
@kiwisauthorSep 18.2022 — Yes but some products should show as sold out while others should disappear when sold (one off unique items).

I'm thinking a column called singleProduct 1 = yes, 0 = no. With a totalAvailable.

Then when singleProduct is set to 0 and totalAvailable is 0 it shows as sold out.

When I add stock I add numbers to totalAvailable. When sold I minus one.

When singleProduct is set to 1 it shows when totalAvailable is 1 and no when 0.
Copy linkTweet thisAlerts:
@sibertSep 19.2022 — > @kiwis80#1647103 I'm thinking a column called singleProduct 1 = yes, 0 = no. With a totalAvailable.

Close to what I use to do, but I call it "type" (integer). Sometimes with a "look up table" and sometimes without. Depending on the number of options. Boolean type makes it harder to expand if needed. Semantic word "type" and "status" makes it more generic and gives more mental flexibility for future types.

It is many times I regret that I hard coded boolean type. I thought it forever would be only one option. I suggest integer type. Same same, but way better.
×

Success!

Help @kiwis spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...