| @@ -22,8 +22,14 @@ | ||
| 22 | 22 | 'title' => __('Stock Management', 'fluent-cart'), |
| 23 | 23 | 'description' => __('Manage stock of your products easier than ever!', 'fluent-cart'), |
| 24 | 24 | 'type' => 'component', |
| 25 | 25 | 'component' => 'ModuleSettings', |
| 26 | + 'settings' => [ | |
| 27 | + 'enable_advanced_inventory' => [ | |
| 28 | + 'label' => __('Enable Advanced Inventory', 'fluent-cart'), | |
| 29 | + 'default' => 'no' | |
| 30 | + ] | |
| 31 | + ] | |
| 26 | 32 | ]; |
| 27 | 33 | return $fields; |
| 28 | 34 | }, 10, 2); |
| 29 | 35 | |
| @@ -31,8 +37,13 @@ | ||
| 31 | 37 | $app->addFilter('fluent_cart/module_setting/default_values', function ($values, $args) { |
| 32 | 38 | if (empty($values['stock_management']['active'])) { |
| 33 | 39 | $values['stock_management']['active'] = 'no'; |
| 34 | 40 | } |
| 41 | + | |
| 42 | + if (empty($values['stock_management']['enable_advanced_inventory'])) { | |
| 43 | + $values['stock_management']['enable_advanced_inventory'] = 'no'; | |
| 44 | + } | |
| 45 | + | |
| 35 | 46 | return $values; |
| 36 | 47 | }, 10, 2); |
| 37 | 48 | |
| 38 | 49 | add_filter('fluent_cart/shop_query', [$this, 'filterShopQuery'], 10, 2); |
| @@ -207,9 +218,9 @@ | ||
| 207 | 218 | |
| 208 | 219 | // get product details by $productId and get only id from it |
| 209 | 220 | $detail = ProductDetail::query()->where('post_id', $productId)->select('id')->first(); |
| 210 | 221 | |
| 211 | - if (!$detail->id) { | |
| 222 | + if (!$detail || !$detail->id) { | |
| 212 | 223 | continue; |
| 213 | 224 | } |
| 214 | 225 | $updatedProducts[] = [ |
| 215 | 226 | 'id' => $detail->id, |
| @@ -486,11 +497,8 @@ | ||
| 486 | 497 | $removedOnHold = $remove; |
| 487 | 498 | $remainingRefund -= $remove; |
| 488 | 499 | |
| 489 | 500 | $stockMovement[$orderItemId]['on_hold'] = $oldOnHold - $remove; |
| 490 | - if ($stockMovement[$orderItemId]['on_hold'] <= 0) { | |
| 491 | -// unset($stockMovement[$orderItemId]['on_hold']); | |
| 492 | - } | |
| 493 | 501 | } |
| 494 | 502 | |
| 495 | 503 | if ($place === 'committed' && $oldCommitted > 0) { |
| 496 | 504 | $remove = min($oldCommitted, $remainingRefund); |
| @@ -497,11 +505,8 @@ | ||
| 497 | 505 | $removedCommitted = $remove; |
| 498 | 506 | $remainingRefund -= $remove; |
| 499 | 507 | |
| 500 | 508 | $stockMovement[$orderItemId]['committed'] = $oldCommitted - $remove; |
| 501 | - if ($stockMovement[$orderItemId]['committed'] <= 0) { | |
| 502 | -// unset($stockMovement[$orderItemId]['committed']); | |
| 503 | - } | |
| 504 | 509 | } |
| 505 | 510 | } |
| 506 | 511 | |
| 507 | 512 | // Update stock back |
| @@ -545,12 +550,14 @@ | ||
| 545 | 550 | |
| 546 | 551 | // get product details by $productId and get only id from it |
| 547 | 552 | $detail = ProductDetail::query()->where('post_id', $productId)->select('id')->first(); |
| 548 | 553 | |
| 549 | - $updatedProducts[] = [ | |
| 550 | - 'id' => $detail->id, | |
| 551 | - 'stock_availability' => $hasInStock ? 'in-stock' : 'out-of-stock' | |
| 552 | - ]; | |
| 554 | + if ($detail) { | |
| 555 | + $updatedProducts[] = [ | |
| 556 | + 'id' => $detail->id, | |
| 557 | + 'stock_availability' => $hasInStock ? 'in-stock' : 'out-of-stock' | |
| 558 | + ]; | |
| 559 | + } | |
| 553 | 560 | } |
| 554 | 561 | |
| 555 | 562 | if (!empty($updatedProducts)) { |
| 556 | 563 | ProductDetail::query()->batchUpdate($updatedProducts); |
| @@ -800,12 +807,14 @@ | ||
| 800 | 807 | |
| 801 | 808 | // get product details by $productId and get only id from it |
| 802 | 809 | $detail = ProductDetail::query()->where('post_id', $productId)->select('id')->first(); |
| 803 | 810 | |
| 804 | - $updatedProducts[] = [ | |
| 805 | - 'id' => $detail->id, | |
| 806 | - 'stock_availability' => $hasInStock ? 'in-stock' : 'out-of-stock' | |
| 807 | - ]; | |
| 811 | + if ($detail) { | |
| 812 | + $updatedProducts[] = [ | |
| 813 | + 'id' => $detail->id, | |
| 814 | + 'stock_availability' => $hasInStock ? 'in-stock' : 'out-of-stock' | |
| 815 | + ]; | |
| 816 | + } | |
| 808 | 817 | } |
| 809 | 818 | |
| 810 | 819 | if (!empty($updatedProducts)) { |
| 811 | 820 | ProductDetail::query()->batchUpdate($updatedProducts); |