Shop Stock

Forum
Last Post
Threads / Messages

Kyttias

Super Moderator
Super Mod
Joined
Jan 26, 2014
Messages
849
Points
18
Mysidian Dollar
58,199
Shops with 'stock' that depletes and replenishes... I'm trying to wrap my head around how I might implement this. I'm pretty good with manipulating the framework to my needs but, conceptually, I'm wondering what the best way to do this would be...

I don't want cron jobs. Surely there is another way to fudge some automation?

More database tables will be needed. I'm thinking 'stock' for current stock, a restock threshold, and a timestamp for when the item was last purchased. (In addition to the current restock threshold, its constant restock threshold -the amount it'll always reset to when the stock falls to zero.)

PHP:
if ((($item->stock == 0) && ($item->restockthreshold <= 0)) && (strtotime('+30 minutes', $item->timestamp) < $this->currenttime)){ 
/* 
If the item's stock and the item's current restock threshold are both zero (or less) 
and it has been more than 30 minutes since the item was last bought... 
then bump the stock available up to a positive number! 
*/ 
}

Which isn't pretty, but the jist is that the item's stock will eventually fall to zero. An item will restock when its stock and restock thresholds are both zero.

Each time any item in that shop is bought we'll call a function that'll decrease the restock threshold of every item in that shop whose current stock is equal to zero. Rarer items you want to restock less often should have greater restock thresholds.

In addition, every hour, the item's restock threshold will diminish by 1 every hour - this will be determined on page load of viewing shop, calculated from the last time the item was bought.

Does this sound feasible?
 
Last edited:

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,277
Messages
33,118
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Top