diff --git a/app/DotsAPI/API/v2/CategoryItemAPI.php b/app/DotsAPI/API/v2/CategoryItemAPI.php new file mode 100644 index 0000000..4343bb2 --- /dev/null +++ b/app/DotsAPI/API/v2/CategoryItemAPI.php @@ -0,0 +1,40 @@ +fetcher->get($endpoint); + + return $categotiesItemsMap; + } + + public function saveMap($categotiesItems, $company = null) { + foreach ($categotiesItems as $category) { + $uuid = $category['id']; + $name = $category['name']; + $url = $category['url']; + + $category = Category::firstOrCreate([ + 'uuid' => $uuid, + 'name' => $name, + 'url' => $url, + 'company_id' => $company->id + ]); + + $item = new ItemAPI($this->fetcher); + + $item->saveMap($category['items']); + } + } +} + diff --git a/app/DotsAPI/API/v2/ItemAPI.php b/app/DotsAPI/API/v2/ItemAPI.php new file mode 100644 index 0000000..8d4e189 --- /dev/null +++ b/app/DotsAPI/API/v2/ItemAPI.php @@ -0,0 +1,34 @@ + $uuid, + 'name' => $name, + 'url' => $url, + 'description' => $description, + 'price' => $price, + 'image' => $image, + 'category_id' => $category->id, + ]); + } + } +}