-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.php
More file actions
88 lines (83 loc) · 3.57 KB
/
Copy pathfunction.php
File metadata and controls
88 lines (83 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
* Order-time and storefront hooks for the flash-sale quota.
*
* gp247/shop calls these by name when they exist (soft dependency, see
* ShopOrder::addOrder / returnStockToInventory / takeStockBack), so the shop never
* has to know this plugin exists. Each helper is also opt-out through
* config('gp247_functions_except') like core's own helpers.
*
* @aidlc-unit plugin-product-flash-sale
* @aidlc-story US-product-flash-sale-quota-integrity
*/
use App\GP247\Plugins\ProductFlashSale\Models\PluginModel;
if (!function_exists('gp247_product_flash_check_over') && !in_array('gp247_product_flash_check_over', config('gp247_functions_except', []))) {
/**
* Whether the flash-sale quota still allows selling this quantity.
*
* Advisory pre-check used before an order is written (and before a cancelled
* order is re-opened). The binding decision is made by
* gp247_product_flash_update_stock(), which is atomic.
*
* @param string $productId
* @param int $quantity
* @return bool True when allowed (including when the product is not on flash sale).
*
* @aidlc-unit plugin-product-flash-sale
* @aidlc-story US-product-flash-sale-quota-integrity
*/
function gp247_product_flash_check_over($productId, $quantity) {
return (new PluginModel)->canConsume($productId, $quantity);
}
}
if (!function_exists('gp247_product_flash_update_stock') && !in_array('gp247_product_flash_update_stock', config('gp247_functions_except', []))) {
/**
* Consume flash-sale quota for a sold line.
*
* @param string $productId
* @param int $quantity
* @return bool True when consumed (or nothing to consume); false when the quota
* ran out between the pre-check and here, so the caller can roll
* the order back instead of overselling the sale.
*
* @aidlc-unit plugin-product-flash-sale
* @aidlc-story US-product-flash-sale-quota-integrity
*/
function gp247_product_flash_update_stock($productId, $quantity) {
return (new PluginModel)->consumeQuota($productId, $quantity);
}
}
if (!function_exists('gp247_product_flash_release_stock') && !in_array('gp247_product_flash_release_stock', config('gp247_functions_except', []))) {
/**
* Return flash-sale quota when an order's goods go back to inventory.
*
* Without this, cancelling an order returned the product stock but kept the
* flash-sale units spent, so a sale could read "sold out" while nothing had
* actually been sold.
*
* @param string $productId
* @param int $quantity
* @return void
*
* @aidlc-unit plugin-product-flash-sale
* @aidlc-story US-product-flash-sale-quota-integrity
*/
function gp247_product_flash_release_stock($productId, $quantity) {
(new PluginModel)->releaseQuota($productId, $quantity);
}
}
if (!function_exists('gp247_product_flash') && !in_array('gp247_product_flash', config('gp247_functions_except', []))) {
/**
* Products currently on flash sale, in admin sort order.
*
* @param int $limit Items to return (page size when paginating).
* @param bool $paginate Return a paginator instead of a plain collection.
* @return \Illuminate\Support\Collection|\Illuminate\Contracts\Pagination\LengthAwarePaginator
*
* @aidlc-unit plugin-product-flash-sale
* @aidlc-story US-product-flash-sale-visibility-parity
*/
function gp247_product_flash($limit = 8, $paginate = false) {
return (new PluginModel)->getProductFlash($limit, $paginate);
}
}