Skip to content

Commit

Permalink
Added the search engine and inventory feature configuration wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
fulopattila122 committed Oct 18, 2024
1 parent e45d3d4 commit 50c0029
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
- Added `domain` field to the orders table
- Added then automatic completion of `$order->domain` from the current request to the OrderFactory
- Added the `promotions_total` attribute getter to the Foundation `Order` model
- Added the search engine and inventory feature configuration wrappers
- Fixed an error when attempting to remove a product from the cart which is not in the by [xujiongze](https://github.com/xujiongze) in [#188](https://github.com/vanilophp/framework/pull/188)
- Fixed the `Channel::getCurrency()` method returning the wrong attribute by [Ouail](https://github.com/ouail) in [#189](https://github.com/vanilophp/framework/pull/189)

Expand Down
1 change: 1 addition & 0 deletions src/Support/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
##### 2024-XX-YY

- Changed the `ConfigurableModel::hasConfiguration()` trait to return false on empty arrays as well (until now, only `null` was considered as no config)
- Added the search engine and inventory feature configuration wrappers

## 4.1.0
##### 2024-07-11
Expand Down
42 changes: 40 additions & 2 deletions src/Support/Features.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,50 @@
namespace Vanilo\Support;

use Vanilo\Contracts\Feature;
use Vanilo\Support\Features\Inventory;
use Vanilo\Support\Features\MultiChannel;
use Vanilo\Support\Features\Pricing;
use Vanilo\Support\Features\SearchEngine;

class Features
{
private static ?MultiChannel $multiChannel = null;

private static ?Pricing $pricing = null;

private static ?SearchEngine $searchEngine = null;

private static ?Inventory $inventory = null;

public static function findByName(string $name): ?Feature
{
return match ($name) {
'pricing' => self::pricing(),
'multichannel' => self::multichannel(),
'search_engine' => self::searchEngine(),
'inventory' => self::inventory(),
default => null,
};
}

public static function multichannel(): MultiChannel
{
return self::$multiChannel ?: (self::$multiChannel = new MultiChannel());
return self::$multiChannel ??= new MultiChannel();
}

public static function pricing(): Pricing
{
return self::$pricing ?: (self::$pricing = new Pricing());
return self::$pricing ??= new Pricing();
}

private static function searchEngine(): SearchEngine
{
return self::$searchEngine ??= new SearchEngine();
}

public static function inventory(): Inventory
{
return self::$inventory ??= new Inventory();
}

public static function isMultiChannelEnabled(): bool
Expand All @@ -62,4 +80,24 @@ public static function isPricingDisabled(): bool
{
return self::pricing()->isDisabled();
}

public static function isSearchEngineEnabled(): bool
{
return self::searchEngine()->isEnabled();
}

public static function isSearchEngineDisabled(): bool
{
return self::searchEngine()->isDisabled();
}

public static function isInventoryEnabled(): bool
{
return self::inventory()->isEnabled();
}

public static function isInventoryDisabled(): bool
{
return self::inventory()->isDisabled();
}
}
36 changes: 36 additions & 0 deletions src/Support/Features/Inventory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

/**
* Contains the Inventory class.
*
* @copyright Copyright (c) 2024 Vanilo UG
* @author Attila Fulop
* @license MIT
* @since 2024-10-18
*
*/

namespace Vanilo\Support\Features;

use Vanilo\Contracts\Feature;

class Inventory implements Feature
{
public function isEnabled(): bool
{
return config('vanilo.features.pricing.inventory', false)
&& null !== concord()->module('inventory');
}

public function isDisabled(): bool
{
return !$this->isEnabled();
}

public function configuration(): array
{
return config('vanilo.features.inventory', []);
}
}
36 changes: 36 additions & 0 deletions src/Support/Features/SearchEngine.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

/**
* Contains the SearchEngine class.
*
* @copyright Copyright (c) 2024 Vanilo UG
* @author Attila Fulop
* @license MIT
* @since 2024-10-18
*
*/

namespace Vanilo\Support\Features;

use Vanilo\Contracts\Feature;

class SearchEngine implements Feature
{
public function isEnabled(): bool
{
return config('vanilo.features.pricing.search_engine', false)
&& null !== concord()->module('search');
}

public function isDisabled(): bool
{
return !$this->isEnabled();
}

public function configuration(): array
{
return config('vanilo.features.search_engine', []);
}
}

0 comments on commit 50c0029

Please sign in to comment.