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;
|
use Ardent\PicnicApi\Client;
|
||||||
|
|
||||||
class OrderArticle extends AbstractApiObject
|
class OrderArticle extends AbstractApiObject implements ArticleInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* OrderArticle constructor.
|
* OrderArticle constructor.
|
||||||
@ -16,8 +16,10 @@ class OrderArticle extends AbstractApiObject
|
|||||||
private string $name,
|
private string $name,
|
||||||
private array $imageIds,
|
private array $imageIds,
|
||||||
private string $unitQuantity,
|
private string $unitQuantity,
|
||||||
|
private string $unitQuantitySub,
|
||||||
private int $price,
|
private int $price,
|
||||||
private int $maxCount,
|
private int $maxCount,
|
||||||
|
private array $decorators,
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -34,22 +36,18 @@ class OrderArticle extends AbstractApiObject
|
|||||||
$apiObject['name'],
|
$apiObject['name'],
|
||||||
$apiObject['image_ids'],
|
$apiObject['image_ids'],
|
||||||
$apiObject['unit_quantity'],
|
$apiObject['unit_quantity'],
|
||||||
|
$apiObject['unit_quantity_sub'] ?? 'n/a',
|
||||||
$apiObject['price'],
|
$apiObject['price'],
|
||||||
$apiObject['max_count'],
|
$apiObject['max_count'],
|
||||||
|
$apiObject['decorators'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getId(): string
|
public function getId(): string
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getName(): string
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return $this->name;
|
return $this->name;
|
||||||
@ -67,27 +65,38 @@ class OrderArticle extends AbstractApiObject
|
|||||||
}, $this->imageIds);
|
}, $this->imageIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getImageId(): string
|
||||||
* @return string
|
{
|
||||||
*/
|
return $this->imageIds[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getImageUrl(string $size = 'medium'): string
|
||||||
|
{
|
||||||
|
return Client::getImageUri($this->getImageId(), $size);
|
||||||
|
}
|
||||||
|
|
||||||
public function getUnitQuantity(): string
|
public function getUnitQuantity(): string
|
||||||
{
|
{
|
||||||
return $this->unitQuantity;
|
return $this->unitQuantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getUnitQuantitySub(): string
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getPrice(): int
|
|
||||||
{
|
{
|
||||||
return $this->price;
|
return $this->unitQuantitySub;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPrice(): float
|
||||||
|
{
|
||||||
|
return $this->price / 100.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getMaxCount(): int
|
public function getMaxCount(): int
|
||||||
{
|
{
|
||||||
return $this->maxCount;
|
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
|
static public function fromApi(array $apiObject): AbstractApiObject
|
||||||
{
|
{
|
||||||
dump($apiObject);
|
// dump($apiObject);
|
||||||
return new self(
|
return new self(
|
||||||
$apiObject['id'],
|
$apiObject['id'],
|
||||||
ApiListTransformer::getObjects($apiObject['items']),
|
ApiListTransformer::getObjects($apiObject['items']),
|
||||||
|
@ -6,7 +6,7 @@ namespace Ardent\PicnicApi\Objects;
|
|||||||
|
|
||||||
use Ardent\PicnicApi\Client;
|
use Ardent\PicnicApi\Client;
|
||||||
|
|
||||||
class SingleArticle extends AbstractApiObject
|
class SingleArticle extends AbstractApiObject implements ArticleInterface
|
||||||
{
|
{
|
||||||
static public function getType(): string
|
static public function getType(): string
|
||||||
{
|
{
|
||||||
@ -45,41 +45,26 @@ class SingleArticle extends AbstractApiObject
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getId(): string
|
public function getId(): string
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getName(): string
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getPrice(): float
|
public function getPrice(): float
|
||||||
{
|
{
|
||||||
return $this->price / 100.0;
|
return $this->price / 100.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getDisplayPrice(): float
|
public function getDisplayPrice(): float
|
||||||
{
|
{
|
||||||
return $this->displayPrice / 100.0;
|
return $this->displayPrice / 100.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getImageId(): string
|
public function getImageId(): string
|
||||||
{
|
{
|
||||||
return $this->imageId;
|
return $this->imageId;
|
||||||
@ -90,33 +75,21 @@ class SingleArticle extends AbstractApiObject
|
|||||||
return Client::getImageUri($this->imageId, $size);
|
return Client::getImageUri($this->imageId, $size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getMaxCount(): int
|
public function getMaxCount(): int
|
||||||
{
|
{
|
||||||
return $this->maxCount;
|
return $this->maxCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getUnitQuantity(): string
|
public function getUnitQuantity(): string
|
||||||
{
|
{
|
||||||
return $this->unitQuantity;
|
return $this->unitQuantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getUnitQuantitySub(): string
|
public function getUnitQuantitySub(): string
|
||||||
{
|
{
|
||||||
return $this->unitQuantitySub;
|
return $this->unitQuantitySub;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getDecorators(): array
|
public function getDecorators(): array
|
||||||
{
|
{
|
||||||
return $this->decorators;
|
return $this->decorators;
|
||||||
|
@ -6,7 +6,7 @@ namespace Ardent\PicnicApi\Objects;
|
|||||||
|
|
||||||
use Ardent\PicnicApi\Client;
|
use Ardent\PicnicApi\Client;
|
||||||
|
|
||||||
class SingleArticleDetails extends AbstractApiObject
|
class SingleArticleDetails extends AbstractApiObject implements ArticleInterface
|
||||||
{
|
{
|
||||||
static public function getType(): string
|
static public function getType(): string
|
||||||
{
|
{
|
||||||
@ -47,7 +47,7 @@ class SingleArticleDetails extends AbstractApiObject
|
|||||||
$apiObject['unit_quantity_sub'] ?? 'n/a',
|
$apiObject['unit_quantity_sub'] ?? 'n/a',
|
||||||
$apiObject['decorators'],
|
$apiObject['decorators'],
|
||||||
$apiObject['nutritional_values'],
|
$apiObject['nutritional_values'],
|
||||||
$apiObject['ingredients_blob'],
|
$apiObject['ingredients_blob'] ?? '',
|
||||||
$apiObject['additional_info'],
|
$apiObject['additional_info'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,14 @@ class PicnicClient
|
|||||||
return ApiListTransformer::getObject($this->client->get(sprintf('product/%s', $productId))['product_details']);
|
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.
|
* Returns all past and current deliveries of the user.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user