Implement interface for articles
Implement adding product to card
This commit is contained in:
parent
16c30ad036
commit
181879a529
16
src/Objects/ArticleInterface.php
Normal file
16
src/Objects/ArticleInterface.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Ardent\PicnicApi\Objects;
|
||||
|
||||
interface ArticleInterface
|
||||
{
|
||||
public function getId(): string;
|
||||
public function getName(): string;
|
||||
public function getImageId(): string;
|
||||
public function getImageUrl(string $size): string;
|
||||
public function getUnitQuantity(): string;
|
||||
public function getUnitQuantitySub(): string;
|
||||
public function getPrice(): float;
|
||||
public function getMaxCount(): int;
|
||||
public function getDecorators(): array;
|
||||
}
|
@ -6,7 +6,7 @@ namespace Ardent\PicnicApi\Objects;
|
||||
|
||||
use Ardent\PicnicApi\Client;
|
||||
|
||||
class OrderArticle extends AbstractApiObject
|
||||
class OrderArticle extends AbstractApiObject implements ArticleInterface
|
||||
{
|
||||
/**
|
||||
* OrderArticle constructor.
|
||||
@ -14,10 +14,12 @@ class OrderArticle extends AbstractApiObject
|
||||
public function __construct(
|
||||
private string $id,
|
||||
private string $name,
|
||||
private array $imageIds,
|
||||
private array $imageIds,
|
||||
private string $unitQuantity,
|
||||
private int $price,
|
||||
private int $maxCount,
|
||||
private string $unitQuantitySub,
|
||||
private int $price,
|
||||
private int $maxCount,
|
||||
private array $decorators,
|
||||
)
|
||||
{
|
||||
}
|
||||
@ -34,22 +36,18 @@ class OrderArticle extends AbstractApiObject
|
||||
$apiObject['name'],
|
||||
$apiObject['image_ids'],
|
||||
$apiObject['unit_quantity'],
|
||||
$apiObject['unit_quantity_sub'] ?? 'n/a',
|
||||
$apiObject['price'],
|
||||
$apiObject['max_count'],
|
||||
$apiObject['decorators'],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getId(): string
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
@ -67,27 +65,38 @@ class OrderArticle extends AbstractApiObject
|
||||
}, $this->imageIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getImageId(): string
|
||||
{
|
||||
return $this->imageIds[0];
|
||||
}
|
||||
|
||||
public function getImageUrl(string $size = 'medium'): string
|
||||
{
|
||||
return Client::getImageUri($this->getImageId(), $size);
|
||||
}
|
||||
|
||||
public function getUnitQuantity(): string
|
||||
{
|
||||
return $this->unitQuantity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getPrice(): int
|
||||
public function getUnitQuantitySub(): string
|
||||
{
|
||||
return $this->price;
|
||||
return $this->unitQuantitySub;
|
||||
}
|
||||
|
||||
public function getPrice(): float
|
||||
{
|
||||
return $this->price / 100.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getMaxCount(): int
|
||||
{
|
||||
return $this->maxCount;
|
||||
}
|
||||
|
||||
public function getDecorators(): array
|
||||
{
|
||||
return $this->decorators;
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ class OrderLine extends AbstractApiObject
|
||||
|
||||
static public function fromApi(array $apiObject): AbstractApiObject
|
||||
{
|
||||
dump($apiObject);
|
||||
// dump($apiObject);
|
||||
return new self(
|
||||
$apiObject['id'],
|
||||
ApiListTransformer::getObjects($apiObject['items']),
|
||||
|
@ -6,7 +6,7 @@ namespace Ardent\PicnicApi\Objects;
|
||||
|
||||
use Ardent\PicnicApi\Client;
|
||||
|
||||
class SingleArticle extends AbstractApiObject
|
||||
class SingleArticle extends AbstractApiObject implements ArticleInterface
|
||||
{
|
||||
static public function getType(): string
|
||||
{
|
||||
@ -45,41 +45,26 @@ class SingleArticle extends AbstractApiObject
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getId(): string
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getPrice(): float
|
||||
{
|
||||
return $this->price / 100.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getDisplayPrice(): float
|
||||
{
|
||||
return $this->displayPrice / 100.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getImageId(): string
|
||||
{
|
||||
return $this->imageId;
|
||||
@ -90,33 +75,21 @@ class SingleArticle extends AbstractApiObject
|
||||
return Client::getImageUri($this->imageId, $size);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getMaxCount(): int
|
||||
{
|
||||
return $this->maxCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUnitQuantity(): string
|
||||
{
|
||||
return $this->unitQuantity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUnitQuantitySub(): string
|
||||
{
|
||||
return $this->unitQuantitySub;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getDecorators(): array
|
||||
{
|
||||
return $this->decorators;
|
||||
|
@ -6,7 +6,7 @@ namespace Ardent\PicnicApi\Objects;
|
||||
|
||||
use Ardent\PicnicApi\Client;
|
||||
|
||||
class SingleArticleDetails extends AbstractApiObject
|
||||
class SingleArticleDetails extends AbstractApiObject implements ArticleInterface
|
||||
{
|
||||
static public function getType(): string
|
||||
{
|
||||
@ -47,7 +47,7 @@ class SingleArticleDetails extends AbstractApiObject
|
||||
$apiObject['unit_quantity_sub'] ?? 'n/a',
|
||||
$apiObject['decorators'],
|
||||
$apiObject['nutritional_values'],
|
||||
$apiObject['ingredients_blob'],
|
||||
$apiObject['ingredients_blob'] ?? '',
|
||||
$apiObject['additional_info'],
|
||||
);
|
||||
}
|
||||
|
@ -35,6 +35,14 @@ class PicnicClient
|
||||
return ApiListTransformer::getObject($this->client->get(sprintf('product/%s', $productId))['product_details']);
|
||||
}
|
||||
|
||||
public function addProduct(string $productId, int $amount): Order
|
||||
{
|
||||
return ApiListTransformer::getObject($this->client->post('cart/add_product', [
|
||||
'product_id' => $productId,
|
||||
'count' => $amount,
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all past and current deliveries of the user.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user