From 4ed4111261e5eed83b94e10748c2cae6e410aa08 Mon Sep 17 00:00:00 2001 From: diepxuan Date: Fri, 26 Jul 2024 11:09:36 +0000 Subject: [PATCH] List and show store config --- src/Builders/StoreConfigsBuilder.php | 38 ++++++++++++++++++++++++++++ src/Magento.php | 10 ++++++-- src/Models/StoreConfigs.php | 22 ++++++++++++++++ 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 src/Builders/StoreConfigsBuilder.php create mode 100644 src/Models/StoreConfigs.php diff --git a/src/Builders/StoreConfigsBuilder.php b/src/Builders/StoreConfigsBuilder.php new file mode 100644 index 0000000..45a7054 --- /dev/null +++ b/src/Builders/StoreConfigsBuilder.php @@ -0,0 +1,38 @@ + + * @author Tran Ngoc Duc + * + * @lastupdate 2024-07-26 15:38:19 + */ + +namespace Diepxuan\Magento\Builders; + +use Diepxuan\Magento\Models\StoreConfigs; +use Illuminate\Support\Collection; + +class StoreConfigsBuilder extends Builder +{ + protected $entity = StoreConfigs::ENTITY; + protected $model = StoreConfigs::class; + + protected function parseResponse($response): Collection + { + $fetchedItems = collect($response); + $items = collect([]); + + foreach ($fetchedItems as $index => $item) { + /** @var StoreConfigs $model */ + $model = new $this->model($this->request, $item); + + $items->push($model); + } + + return $items; + } +} diff --git a/src/Magento.php b/src/Magento.php index cf101e5..72c9f52 100644 --- a/src/Magento.php +++ b/src/Magento.php @@ -8,13 +8,14 @@ * @author Tran Ngoc Duc * @author Tran Ngoc Duc * - * @lastupdate 2024-07-25 21:22:21 + * @lastupdate 2024-07-26 15:45:22 */ namespace Diepxuan\Magento; use Diepxuan\Magento\Builders\CategoryBuilder; use Diepxuan\Magento\Builders\ProductBuilder; +use Diepxuan\Magento\Builders\StoreConfigsBuilder; use Diepxuan\Magento\Builders\StoreViewsBuilder; use Diepxuan\Magento\Builders\StoreWebsitesBuilder; use Diepxuan\Magento\Http\Request; @@ -48,6 +49,11 @@ public static function store_views(): StoreViewsBuilder return new StoreViewsBuilder(self::initOAuthRequest()); } + public static function store_configs(): StoreConfigsBuilder + { + return new StoreConfigsBuilder(self::initOAuthRequest()); + } + /** * Initial OAuth Request. * @@ -55,7 +61,7 @@ public static function store_views(): StoreViewsBuilder * @param mixed $options * @param mixed $headers */ - private static function initOAuthRequest($token = [], $options = [], $headers = []) + private static function initOAuthRequest($token = [], $options = [], $headers = []): Request { $base_uri = implode('/', [ config('magento.base_url'), diff --git a/src/Models/StoreConfigs.php b/src/Models/StoreConfigs.php new file mode 100644 index 0000000..6b923b5 --- /dev/null +++ b/src/Models/StoreConfigs.php @@ -0,0 +1,22 @@ + + * @author Tran Ngoc Duc + * + * @lastupdate 2024-07-26 15:28:07 + */ + +namespace Diepxuan\Magento\Models; + +#[\AllowDynamicProperties] +class StoreConfigs extends Model +{ + public const ENTITY = 'store/storeConfigs'; + protected $entity = 'store/storeConfigs'; + protected $primaryKey = 'id'; +}