Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit afced87

Browse files
authored
Merge pull request #33 from grayloon/product-category-assignment
Add API endpoint to get products that belong to categories
2 parents 126e7cf + 496545f commit afced87

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/Api/Categories.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,18 @@ public function all($pageSize = 50, $currentPage = 1)
1919
'searchCriteria[currentPage]' => $currentPage,
2020
]);
2121
}
22+
23+
/**
24+
* Get products assigned to category.
25+
*
26+
* @param int $categoryId
27+
*
28+
* @return array
29+
*/
30+
public function products($categoryId)
31+
{
32+
$this->validateSingleStoreCode();
33+
34+
return $this->get('/categories/'.$categoryId.'/products');
35+
}
2236
}

tests/Api/CategoriesTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,27 @@ public function test_can_call_magento_api_products_all()
2525

2626
$this->assertTrue($api->ok());
2727
}
28+
29+
public function test_can_call_magento_api_categories_products()
30+
{
31+
Http::fake([
32+
'*rest/default/V1/categories/1/products' => Http::response([], 200),
33+
]);
34+
35+
$magento = new Magento();
36+
$magento->storeCode = 'default';
37+
38+
$api = $magento->api('categories')->products(1);
39+
40+
$this->assertTrue($api->ok());
41+
}
42+
43+
public function test_magento_api_categories_products_requires_store_code()
44+
{
45+
$this->expectException('exception');
46+
47+
$magento = new Magento();
48+
49+
$api = $magento->api('categories')->products(1);
50+
}
2851
}

0 commit comments

Comments
 (0)