diff --git a/src/Objects/ArticleInterface.php b/src/Objects/ArticleInterface.php new file mode 100644 index 0000000..e386a78 --- /dev/null +++ b/src/Objects/ArticleInterface.php @@ -0,0 +1,16 @@ +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; + } } \ No newline at end of file diff --git a/src/Objects/OrderLine.php b/src/Objects/OrderLine.php index fd18202..02ba7c0 100644 --- a/src/Objects/OrderLine.php +++ b/src/Objects/OrderLine.php @@ -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']), diff --git a/src/Objects/SingleArticle.php b/src/Objects/SingleArticle.php index 43a758e..8991f4a 100644 --- a/src/Objects/SingleArticle.php +++ b/src/Objects/SingleArticle.php @@ -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; diff --git a/src/Objects/SingleArticleDetails.php b/src/Objects/SingleArticleDetails.php index 2e548c8..1178838 100644 --- a/src/Objects/SingleArticleDetails.php +++ b/src/Objects/SingleArticleDetails.php @@ -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'], ); } diff --git a/src/PicnicClient.php b/src/PicnicClient.php index 3d3b36a..65f2cfc 100644 --- a/src/PicnicClient.php +++ b/src/PicnicClient.php @@ -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. *