| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace FluentCart\App\Http\Controllers; |
| 4 | 4 | |
| 5 | +use FluentCart\Api\ModuleSettings; | |
| 5 | 6 | use FluentCart\Api\Resource\ProductDetailResource; |
| 6 | 7 | use FluentCart\Api\Resource\ProductResource; |
| 7 | 8 | use FluentCart\Api\Resource\ProductVariationResource; |
| 8 | 9 | use FluentCart\App\Events\StockChanged; |
| @@ -1539,8 +1540,13 @@ | ||
| 1539 | 1540 | } |
| 1540 | 1541 | |
| 1541 | 1542 | public function updateInventory(Request $request, $postId, $variantId) |
| 1542 | 1543 | { |
| 1544 | + if (!ModuleSettings::isActive('stock_management')) { | |
| 1545 | + return $this->response->sendError([ | |
| 1546 | + 'message' => __('Stock Management module is disabled. Enable it from Settings to manage inventory.', 'fluent-cart') | |
| 1547 | + ], 422); | |
| 1548 | + } | |
| 1543 | 1549 | |
| 1544 | 1550 | $variant = ProductVariation::query()->find($variantId); |
| 1545 | 1551 | |
| 1546 | 1552 | if (!$variant) { |
| @@ -1605,8 +1611,17 @@ | ||
| 1605 | 1611 | |
| 1606 | 1612 | public function updateManageStock(Request $request, $postId) |
| 1607 | 1613 | { |
| 1608 | 1614 | $manageStock = sanitize_text_field($request->get('manage_stock')); |
| 1615 | + | |
| 1616 | + // Turning inventory ON requires the Stock Management module to be active. | |
| 1617 | + // Turning it OFF stays allowed so a store that disables the module can | |
| 1618 | + // still clean up products that were left with manage_stock = 1. | |
| 1619 | + if ($manageStock == 1 && !ModuleSettings::isActive('stock_management')) { | |
| 1620 | + return $this->response->sendError([ | |
| 1621 | + 'message' => __('Stock Management module is disabled. Enable it from Settings to manage inventory.', 'fluent-cart') | |
| 1622 | + ], 422); | |
| 1623 | + } | |
| 1609 | 1624 | |
| 1610 | 1625 | $detail = ProductDetail::query()->where('post_id', $postId)->first(); |
| 1611 | 1626 | |
| 1612 | 1627 | $updateData = [ |