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

Commit a54764e

Browse files
authored
Merge pull request #44 from matt-gribben/develop
Magento Inventory Sources and Stocks
2 parents 3552255 + 800ec44 commit a54764e

File tree

4 files changed

+124
-0
lines changed

4 files changed

+124
-0
lines changed

src/Api/Sources.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Grayloon\Magento\Api;
4+
5+
class Sources extends AbstractApi
6+
{
7+
/**
8+
* inventoryApiSourcesRepositoryV1
9+
* All of paginated sources.
10+
*
11+
* @param int $pageSize
12+
* @param int $currentPage
13+
* @param array $filters
14+
*
15+
* @return array
16+
*/
17+
public function all($pageSize = 50, $currentPage = 1, $filters = [])
18+
{
19+
return $this->get('/inventory/sources', array_merge($filters, [
20+
'searchCriteria[pageSize]' => $pageSize,
21+
'searchCriteria[currentPage]' => $currentPage,
22+
]));
23+
}
24+
25+
/**
26+
* inventoryApiSourcesRepositoryV1
27+
* Return Specific Source by name.
28+
*
29+
* @param string $name
30+
*
31+
* @return array
32+
*/
33+
public function bySourceName($name = 'default')
34+
{
35+
return $this->get('/inventory/sources/'.$name);
36+
}
37+
}

src/Api/Stocks.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Grayloon\Magento\Api;
4+
5+
class Stocks extends AbstractApi
6+
{
7+
/**
8+
* inventoryApiStocksRepositoryV1
9+
* All of paginated stock items.
10+
*
11+
* @param int $pageSize
12+
* @param int $currentPage
13+
* @param array $filters
14+
*
15+
* @return array
16+
*/
17+
public function all($pageSize = 50, $currentPage = 1, $filters = [])
18+
{
19+
return $this->get('/inventory/stocks', array_merge($filters, [
20+
'searchCriteria[pageSize]' => $pageSize,
21+
'searchCriteria[currentPage]' => $currentPage,
22+
]));
23+
}
24+
}

tests/Api/SourcesTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Grayloon\Magento\Tests;
4+
5+
use Grayloon\Magento\Api\Sources;
6+
use Grayloon\Magento\MagentoFacade;
7+
use Illuminate\Support\Facades\Http;
8+
9+
class SourcesTest extends TestCase
10+
{
11+
public function test_can_instantiate_sources()
12+
{
13+
$this->assertInstanceOf(Sources::class, MagentoFacade::api('sources'));
14+
}
15+
16+
public function test_can_call_sources_all()
17+
{
18+
Http::fake([
19+
'*rest/all/V1/inventory/sources*' => Http::response([], 200),
20+
]);
21+
22+
$api = MagentoFacade::api('sources')->all();
23+
24+
$this->assertTrue($api->ok());
25+
}
26+
27+
public function test_can_call_sources_by_source_name()
28+
{
29+
Http::fake([
30+
'*rest/all/V1/inventory/sources/default*' => Http::response([], 200),
31+
]);
32+
33+
$api = MagentoFacade::api('sources')->bySourceName();
34+
35+
$this->assertTrue($api->ok());
36+
}
37+
}

tests/Api/StocksTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Grayloon\Magento\Tests;
4+
5+
use Grayloon\Magento\Api\Stocks;
6+
use Grayloon\Magento\MagentoFacade;
7+
use Illuminate\Support\Facades\Http;
8+
9+
class StocksTest extends TestCase
10+
{
11+
public function test_can_instantiate_stocks()
12+
{
13+
$this->assertInstanceOf(Stocks::class, MagentoFacade::api('stocks'));
14+
}
15+
16+
public function test_can_call_stocks_all()
17+
{
18+
Http::fake([
19+
'*rest/all/V1/inventory/stocks*' => Http::response([], 200),
20+
]);
21+
22+
$api = MagentoFacade::api('stocks')->all();
23+
24+
$this->assertTrue($api->ok());
25+
}
26+
}

0 commit comments

Comments
 (0)