Skip to content

Commit

Permalink
feat(shops): add Shop Features extension (#1172)
Browse files Browse the repository at this point in the history
* adding admin only shops

* stashing for tomorrow -> backend for limited by items missing

* limits backend

* shop limit complete and small aesthetic changes

* adding view for limited shops

* start of coupons

* coupons tag complete, need purchase backend

* coupons finished i hope there's no bugs lol

* hotfix

* adding protection to free items

* adding infinite tags and settings option

* hotfix

* hotfix

* adding FTO only shops & stock

* changing order of abort 404 (thanks uri)

* adding some error reporting

* choose if you can use coupons on limited stock items

* changing the description

* adding modified shops

* fix purchase limit & eager loading

* add credit & more detailed stock info

* add count

* no message

* fix log

* fix logs

* add visibility to shop items

* fix wording

* fix(shops): staff shops visible in ext item info

* add collapsible shops

* fix log cost

* add restocking to shops

* fix kernal schedule

* fix: purchase limites not being recognised due to cost changes

* add disallow transfer option

* feat: Add coupon allowance selection

* Update extension_tracker.php

Minor change, fixes potential mishaps with the extension tracker. (I did not change version number.)

* Purchase Limit Timeframe

* Fix naming on the dropdown

* Show timeframe on main shop page

* Fixes

* no message

* no message

* no message

* no message

* no message

* no message

* add stock/shops that can cycle in/out even with no specific end/start

* fix(shop): Fixed 500 error if guests try to enter a shop with a restriction

* upd(exttracker): forgot version number

* refactor alt shop stock types

* add is visible pivot to shop stock relation

* make shops more compatible

* pull & run before dev to make merge conflicts more manageable

* update format.sh to recurse properly

* format on shop views

* refactor: fix blade formatting

* feat: creation of basic limits, todo dynamic limits and evaluation

* refactor: wording

* refactor: fix blade formatting

* stash

* refactor: fix blade formatting

* refactor: fix PHP styling

* stash

* hotfix: Fix monthly limit on shop stocks

* refactor: fix PHP styling

* feat(limits): default limits done, debitting, shops, submissions

* refactor: fix blade formatting

* refactor: fix PHP styling

* feat(dynamic limits): complete dynamic limits

* refactor: fix blade formatting

* refactor: fix PHP styling

* feat(nit): view cleanupp

* refactor: fix blade formatting

* fix(nit): spelling

* feat(shops): add to stock modal too just in case

* fix(shops): restore disallow transfer

* fix: disallow transfers

* refactor: fix PHP styling

* fix: ordering of debits sometimes throwing undefined array

* refactor: fix blade formatting

* fix: fix limits additions and checkboxes

* fix: disallow transfer

* refactor: fix blade formatting

* refactor: fix PHP styling

* feat(userowned)

* display Cancel button if claim

* feat: make costs variable

* refactor: fix blade formatting

* refactor: fix PHP styling

* fix: stock items having no image

* feat: add hidden shops

* fix: save file

* refactor: fix blade formatting

* refactor: fix PHP styling

* fix: timed stock

* fix: remove biweekly

* feat: random restocks and repeatable timed shops / stock

* refactor: fix PHP styling

* refactor: fix blade formatting

* fix: add currency model trace

* refactor: fix PHP styling

* fix: item held count

* Fix quantity not appearing on admin stock editing modal

* Capitalize Auth

* Add hash to Shop model

* Fix Extension Tracker

* fix(shops index): Capitalized more Auth

* fix: free items not having limits

* refactor: fix PHP styling

* fix: update tab to match

* fix: totalcost if assets dont have indexing, make indexing default on migration

* refactor: fix PHP styling

* fix: displayCosts using indexing

* fix: deleting currency stock checks

* fix: shops not charging correct quantity when multiple units purchased

* fix: logs

* fix: display stocktype in shop logs

* refactor: fix blade formatting

* refactor: fix PHP styling

* fix: deleted costs

* refactor: fix PHP styling

* fix: purchase limits not respected for multiple quantities

* refactor: fix PHP styling

* feat: add coupons to logs

* fix: restore .env.example

* feat: add credits

* refactor: fix PHP styling

* refactor: fix PHP styling

* fix: item->shop relations

* refactor: fix PHP styling

* fix(items): add get to shop query

---------

Co-authored-by: itinerare <[email protected]>
Co-authored-by: Newt <[email protected]>
Co-authored-by: Speedy <[email protected]>
Co-authored-by: ‘AW0005’ <‘[email protected]’>
Co-authored-by: JAM\mallo <[email protected]>
Co-authored-by: Ne-wt <[email protected]>
Co-authored-by: ScuffedNewt <[email protected]>
Co-authored-by: Uri <[email protected]>
Co-authored-by: preimpression <[email protected]>
Co-authored-by: rattusquo <[email protected]>
  • Loading branch information
11 people authored Jan 16, 2025
1 parent fb2e7d5 commit ca359d6
Show file tree
Hide file tree
Showing 89 changed files with 4,341 additions and 320 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
6 changes: 6 additions & 0 deletions app/Console/Commands/AddSiteSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ public function handle() {

$this->addSiteSetting('comment_dislikes_enabled', 0, '0: Dislikes disabled, 1: Dislikes enabled.');

$this->addSiteSetting('shop_type', 0, '0: Default, 1: Collapsible.');

$this->addSiteSetting('coupon_settings', 0, '0: Percentage is taken from total (e.g 20% from 2 items costing a total of 100 = 80), 1: Percentage is taken from item (e.g 20% from 2 items costing a total of 100 = 90)');

$this->addSiteSetting('limited_stock_coupon_settings', 0, '0: Does not allow coupons to be used on limited stock items, 1: Allows coupons to be used on limited stock items');

$this->addSiteSetting('can_transfer_currency_directly', 1, 'Whether or not users can directly transfer currency to other users without trading. 0: Users cannot directly transfer currency. 1: Direct currency transfers are allowed.');

$this->addSiteSetting('can_transfer_items_directly', 1, 'Whether or not users can directly transfer items to other users without trading. 0: Users cannot directly transfer items. 1: Direct item transfers are allowed.');
Expand Down
58 changes: 58 additions & 0 deletions app/Console/Commands/ConvertShopLimits.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace App\Console\Commands;

use App\Models\Limit\Limit;
use DB;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Schema;

class ConvertShopLimits extends Command {
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'convert-shop-limits';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Converts existing shop limits to the new system.';

/**
* Execute the console command.
*/
public function handle() {
if (!Schema::hasTable('shop_limits')) {
$this->info('No shop limits to convert.');

return;
}

$shopLimits = DB::table('shop_limits')->get();
$bar = $this->output->createProgressBar(count($shopLimits));
$bar->start();
foreach ($shopLimits as $shopLimit) {
Limit::create([
'object_model' => 'App\Models\Shop\Shop',
'object_id' => $shopLimit->shop_id,
'limit_type' => 'item',
'limit_id' => $shopLimit->item_id,
'quantity' => 1,
]);

$bar->advance();
}
$bar->finish();

// drop the is_restricted column from the shops table
Schema::table('shops', function ($table) {
$table->dropColumn('is_restricted');
});

Schema::dropIfExists('shop_limits');
}
}
81 changes: 81 additions & 0 deletions app/Console/Commands/RestockShops.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace App\Console\Commands;

use App\Models\Shop\ShopStock;
use Carbon\Carbon;
use Illuminate\Console\Command;

class RestockShops extends Command {
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'restock-shops';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Restocks shops.';

/**
* Create a new command instance.
*/
public function __construct() {
parent::__construct();
}

/**
* Execute the console command.
*
* @return int
*/
public function handle() {
$stocks = ShopStock::where('is_limited_stock', 1)->where('restock', 1)->get();
foreach ($stocks as $stock) {
if ($stock->restock_interval == 2) {
// check if it's start of week
$now = Carbon::now();
$day = $now->dayOfWeek;
if ($day != 1) {
continue;
}
} elseif ($stock->restock_interval == 3) {
// check if it's start of month
$now = Carbon::now();
$day = $now->day;
if ($day != 1) {
continue;
}
}

// if the stock is random, restock from the stock type
if ($stock->isRandom) {
$type = $stock->stock_type;
$model = getAssetModelString(strtolower($type));
if (method_exists($model, 'visible')) {
$itemId = $stock->categoryId ?
$model::visible()->where(strtolower($type).'_category_id', $stock->categoryId)->inRandomOrder()->first()->id :
$model::visible()->inRandomOrder()->first()->id;
} elseif (method_exists($model, 'released')) {
$itemId = $stock->categoryId ?
$model::released()->where(strtolower($type).'_category_id', $stock->categoryId)->inRandomOrder()->first()->id :
$model::released()->inRandomOrder()->first()->id;
} else {
$itemId = $stock->categoryId ?
$model::where(strtolower($type).'_category_id', $stock->categoryId)->inRandomOrder()->first()->id :
$model::inRandomOrder()->first()->id;
}

$stock->item_id = $itemId;
$stock->save();
}

$stock->quantity = $stock->range ? mt_rand(1, $stock->restock_quantity) : $stock->restock_quantity;
$stock->save();
}
}
}
74 changes: 74 additions & 0 deletions app/Console/Commands/UpdateTimedStock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace App\Console\Commands;

use App\Models\Shop\Shop;
use App\Models\Shop\ShopStock;
use Illuminate\Console\Command;

class UpdateTimedStock extends Command {
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'update-timed-stock';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Hides timed stock or shops when expired, or sets it active if ready.';

/**
* Create a new command instance.
*/
public function __construct() {
parent::__construct();
}

/**
* Execute the console command.
*
* @return int
*/
public function handle() {
$hidestock = ShopStock::where('is_timed_stock', 1)->where('is_visible', 1)->get()->filter(function ($stock) {
return !$stock->isActive;
});
$showstock = ShopStock::where('is_timed_stock', 1)->where('is_visible', 0)->get()->filter(function ($stock) {
return $stock->isActive;
});

// set stock that should be active to active
foreach ($showstock as $showstock) {
$showstock->is_visible = 1;
$showstock->save();
}
// hide stock that should be hidden now
foreach ($hidestock as $hidestock) {
$hidestock->is_visible = 0;
$hidestock->save();
}

// also activate or deactivate the shops
$hideshop = Shop::where('is_timed_shop', 1)->where('is_active', 1)->get()->filter(function ($shop) {
return !$shop->isActive;
});
$showshop = Shop::where('is_timed_shop', 1)->where('is_active', 0)->get()->filter(function ($shop) {
return $shop->isActive;
});

// set shop that should be active to active
foreach ($showshop as $showshop) {
$showshop->is_active = 1;
$showshop->save();
}
// hide shop that should be hidden now
foreach ($hideshop as $hideshop) {
$hideshop->is_active = 0;
$hideshop->save();
}
}
}
4 changes: 4 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ protected function schedule(Schedule $schedule) {
->daily();
$schedule->command('update-staff-reward-actions')
->daily();
$schedule->command('restock-shops')
->daily();
$schedule->command('update-timed-stock')
->everyMinute();
}

/**
Expand Down
Loading

0 comments on commit ca359d6

Please sign in to comment.