Skip to content

Commit

Permalink
Bugfix Addresstypes has no collection
Browse files Browse the repository at this point in the history
  • Loading branch information
sweikert committed Mar 31, 2022
1 parent 3542977 commit 94ac51f
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 166 deletions.
20 changes: 0 additions & 20 deletions examples/addresstypes/page_addresstypes.php

This file was deleted.

48 changes: 1 addition & 47 deletions src/Endpoints/AddresstypeEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,22 @@

use Digitalprint\Oro\Api\Exceptions\ApiException;
use Digitalprint\Oro\Api\Resources\Addresstype;
use Digitalprint\Oro\Api\Resources\AddresstypeCollection;
use Digitalprint\Oro\Api\Resources\ResourceFactory;
use stdClass;

/**
*
*/
class AddresstypeEndpoint extends CollectionEndpointAbstract
class AddresstypeEndpoint extends EndpointAbstract
{
/**
* @var string
*/
protected string $resourcePath = "api/addresstypes";

/**
* Get the object that is used by this API. Every API uses one type of object.
*
* @return Addresstype
*/
protected function getResourceObject(): Addresstype
{
return new Addresstype($this->client);
}

/**
* Get the collection object that is used by this API. Every API uses one type of collection object.
*
* @param stdClass|null $links
*
* @return AddresstypeCollection
*/
protected function getResourceCollectionObject(stdClass $links = null): AddresstypeCollection
{
return new AddresstypeCollection($this->client, $links);
}

/**
* @param string $addresstypeId
* @param array $filter
Expand All @@ -51,30 +31,4 @@ public function get(string $addresstypeId, array $filter = []): Addresstype
return $this->rest_read($addresstypeId, $filter);
}

/**
* @param string|null $number
* @param string|null $size
* @param array $filter
*
* @return AddresstypeCollection
* @throws ApiException
*/
public function page(string $number = null, string $size = null, array $filter = []): AddresstypeCollection
{
$filter = array_merge(["number" => $number, "size" => $size], $filter);
$filter = $this->buildFilters($filter);

$result = $this->client->performHttpCall(
self::REST_LIST,
$this->getResourcePath() . $this->buildQueryString($filter)
);

$collection = $this->getResourceCollectionObject();

foreach ($result->data as $dataResult) {
$collection[] = ResourceFactory::createFromApiResult($dataResult, $this->getResourceObject());
}

return $collection;
}
}
20 changes: 0 additions & 20 deletions src/Resources/Addresstype.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,6 @@

namespace Digitalprint\Oro\Api\Resources;

use Digitalprint\Oro\Api\Exceptions\ApiException;
use Digitalprint\Oro\Api\OroApiClient;

class Addresstype extends BaseResource
{
/**
* @return BaseResource
* @throws ApiException
*/
public function get(): BaseResource
{
$result = $this->client->performHttpCallToFullUrl(
OroApiClient::HTTP_GET,
$this->links->self
);

return ResourceFactory::createFromApiResult(
$result->data,
new Productprice($this->client)
);
}

}
22 changes: 0 additions & 22 deletions src/Resources/AddresstypeCollection.php

This file was deleted.

57 changes: 0 additions & 57 deletions tests/Digitalprint/Oro/API/Endpoints/AddresstypeEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,39 +40,6 @@ public function testGetAddresstype(): void
$this->assertAddresstype($addresstype);
}

/**
* @return void
* @throws ApiException
* @throws IncompatiblePlatform
* @throws UnrecognizedClientException
*/
public function testListAdresstypes(): void
{
$this->mockApiCall(
new Request(
"GET",
"/admin/api/addresstypes",
[],
''
),
new Response(
200,
[],
$this->getAddresstypeCollectionResponse()
)
);

$addresses = $this->apiClient->addresstypes->page();

$this->assertInstanceOf(AddresstypeCollection::class, $addresses);

foreach ($addresses as $address) {
$this->assertInstanceOf(Addresstype::class, $address);
$this->assertEquals("addresstypes", $address->type);
$this->assertNotEmpty($address->attributes);
}
}

/**
* @param $addresstype
* @return void
Expand Down Expand Up @@ -115,28 +82,4 @@ protected function getAddresstypeResponse(): string
}';
}

/**
* @return string
*/
protected function getAddresstypeCollectionResponse(): string
{
return '{
"data": [
{
"type": "addresstypes",
"id": "billing",
"attributes": {
"label": "Billing"
}
},
{
"type": "addresstypes",
"id": "shipping",
"attributes": {
"label": "Shipping"
}
}
]
}';
}
}

0 comments on commit 94ac51f

Please sign in to comment.