Skip to content

Commit

Permalink
Merge pull request #38 from klingac/feature/fair_price_and_promotions
Browse files Browse the repository at this point in the history
Feature/fair price and promotions
  • Loading branch information
michalkelcik authored Oct 4, 2022
2 parents a5f5841 + 3689c45 commit 504d2a2
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 5 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 4.4.0 - 2022-10-03

### Changed

- `promotions` attribute is deprecated

## 4.3.0 - 2022-10-03

### Added

- `fairPrice` attribute to `Article entity`

## 4.2.0 - 2022-08-04

### Added
Expand Down
4 changes: 4 additions & 0 deletions example/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
echo 'In stock: ' . $product->getInStock() . PHP_EOL;
echo 'Rrp: ' . $product->getRrp() . PHP_EOL;
echo 'Price: ' . $product->getPrice() . PHP_EOL;
echo 'Fair price: ' . $product->getFairPrice() . PHP_EOL;
echo 'Purchase price: ' . $product->getPurchasePrice() . PHP_EOL;
echo 'Variants count: ' . $product->getVariantsCount() . PHP_EOL;
echo PHP_EOL;
Expand Down Expand Up @@ -218,6 +219,7 @@
echo 'Rrp: ' . $productPricing->getRrp() . PHP_EOL;
echo 'Price: ' . $productPricing->getPrice() . PHP_EOL;
echo 'Purchase price: ' . $productPricing->getPurchasePrice() . PHP_EOL;
echo 'Fair price: ' . $productPricing->getFairPrice() . PHP_EOL;
echo PHP_EOL;
} catch (MpApiException $e) {
echo 'Unexpected error occurred while loading product pricing: ' . $e->getMessage();
Expand Down Expand Up @@ -259,6 +261,7 @@
echo 'In stock: ' . $variant->getInStock() . PHP_EOL;
echo 'Rrp: ' . $variant->getRrp() . PHP_EOL;
echo 'Price: ' . $variant->getPrice() . PHP_EOL;
echo 'Fair price: ' . $variant->getFairPrice() . PHP_EOL;
echo 'Purchase price: ' . $variant->getPurchasePrice() . PHP_EOL;
echo PHP_EOL;
}
Expand Down Expand Up @@ -417,6 +420,7 @@
echo 'Rrp: ' . $variantPricing->getRrp() . PHP_EOL;
echo 'Price: ' . $variantPricing->getPrice() . PHP_EOL;
echo 'Purchase price: ' . $variantPricing->getPurchasePrice() . PHP_EOL;
echo 'Fair price: ' . $variantPricing->getFairPrice() . PHP_EOL;
echo PHP_EOL;
} catch (MpApiException $e) {
echo 'Unexpected error occurred while loading variant pricing: ' . $e->getMessage();
Expand Down
16 changes: 16 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,20 @@
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<DeprecatedClass>
<errorLevel type="suppress">
<file name="src/Article/Entity/Common/PromotionIterator.php"/>
<file name="src/Article/Entity/Common/AbstractArticle.php"/>
<file name="src/Article/DTO/AbstractArticleRequest.php"/>
</errorLevel>
</DeprecatedClass>
<DeprecatedProperty>
<errorLevel type="suppress">
<file name="src/Article/Entity/Common/AbstractArticle.php"/>
<file name="src/Article/DTO/AbstractArticleRequest.php"/>
</errorLevel>
</DeprecatedProperty>
</issueHandlers>
</psalm>
7 changes: 7 additions & 0 deletions src/Article/DTO/AbstractArticleRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ abstract class AbstractArticleRequest implements JsonSerializable
protected ?float $purchasePrice = null;
protected ?float $rrp = null;
protected MediaIterator $media;
/** @deprecated */
protected PromotionIterator $promotions;
protected ParameterIterator $parameters;
protected LabelIterator $labels;
Expand Down Expand Up @@ -146,11 +147,17 @@ public function setMedia(MediaIterator $media): void
$this->media = $media;
}

/**
* @deprecated
*/
public function getPromotions(): PromotionIterator
{
return $this->promotions;
}

/**
* @deprecated
*/
public function setPromotions(PromotionIterator $promotions): void
{
$this->promotions = $promotions;
Expand Down
2 changes: 2 additions & 0 deletions src/Article/DTO/ProductRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public static function createFromProduct(Product $product): self
$self->setPurchasePrice($product->getPurchasePrice());
$self->setRrp($product->getRrp());
$self->setMedia($product->getMedia());
/** @psalm-suppress DeprecatedMethod */
$self->setPromotions($product->getPromotions());
$self->setParameters($product->getParameters());
$self->setDimensions($product->getDimensions());
Expand Down Expand Up @@ -78,6 +79,7 @@ public static function createFromProduct(Product $product): self
*/
public function getArrayForApi(): array
{
/** @psalm-suppress DeprecatedMethod */
$mandatory = [
'id' => $this->getId(),
'title' => $this->getTitle(),
Expand Down
2 changes: 2 additions & 0 deletions src/Article/DTO/VariantRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static function createFromVariant(Variant $variant): self
$self->setBarcode($variant->getBarcode());
$self->setPurchasePrice($variant->getPurchasePrice());
$self->setRrp($variant->getRrp());
/** @psalm-suppress DeprecatedMethod */
$self->setPromotions($variant->getPromotions());
$self->setDimensions($variant->getDimensions());
$self->setAvailability($variant->getAvailability());
Expand All @@ -61,6 +62,7 @@ public static function createFromVariant(Variant $variant): self
*/
public function getArrayForApi(): array
{
/** @psalm-suppress DeprecatedMethod */
$mandatory = [
'id' => $this->getId(),
'title' => $this->getTitle(),
Expand Down
9 changes: 9 additions & 0 deletions src/Article/Entity/BasicProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ final class BasicProduct implements JsonSerializable
private int $inStock;
private string $categoryId;
private float $price;
private ?float $fairPrice;
private float $purchasePrice;
private float $rrp;
private int $variantsCount;
Expand All @@ -34,6 +35,7 @@ private function __construct(
int $inStock,
string $categoryId,
float $price,
?float $fairPrice,
float $purchasePrice,
float $rrp,
int $variantsCount,
Expand All @@ -47,6 +49,7 @@ private function __construct(
$this->inStock = $inStock;
$this->categoryId = $categoryId;
$this->price = $price;
$this->fairPrice = $fairPrice;
$this->purchasePrice = $purchasePrice;
$this->rrp = $rrp;
$this->variantsCount = $variantsCount;
Expand All @@ -70,6 +73,7 @@ public static function createFromApi(array $data): self
(int) $data['in_stock'],
(string) $data['category_id'],
(float) $data['price'],
isset($data['fair_price']) ? (float) $data['fair_price'] : null,
(float) $data['purchase_price'],
(float) $data['rrp'],
(int) $data['variants_count'],
Expand Down Expand Up @@ -117,6 +121,11 @@ public function getPrice(): float
return $this->price;
}

public function getFairPrice(): ?float
{
return $this->fairPrice;
}

public function getPurchasePrice(): float
{
return $this->purchasePrice;
Expand Down
9 changes: 9 additions & 0 deletions src/Article/Entity/BasicVariant.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ final class BasicVariant implements JsonSerializable
private StatusEnum $status;
private int $inStock;
private float $price;
private ?float $fairPrice;
private float $purchasePrice;
private float $rrp;

Expand All @@ -30,6 +31,7 @@ private function __construct(
StatusEnum $status,
int $inStock,
float $price,
?float $fairPrice,
float $purchasePrice,
float $rrp
) {
Expand All @@ -40,6 +42,7 @@ private function __construct(
$this->status = $status;
$this->inStock = $inStock;
$this->price = $price;
$this->fairPrice = $fairPrice;
$this->purchasePrice = $purchasePrice;
$this->rrp = $rrp;
}
Expand All @@ -60,6 +63,7 @@ public static function createFromApi(array $data): self
new StatusEnum((string) $data[StatusEnum::KEY_NAME]),
(int) $data['in_stock'],
(float) $data['price'],
isset($data['fair_price']) ? (float) $data['fair_price'] : null,
(float) $data['purchase_price'],
(float) $data['rrp'],
);
Expand Down Expand Up @@ -100,6 +104,11 @@ public function getPrice(): float
return $this->price;
}

public function getFairPrice(): ?float
{
return $this->fairPrice;
}

public function getPurchasePrice(): float
{
return $this->purchasePrice;
Expand Down
15 changes: 15 additions & 0 deletions src/Article/Entity/Common/AbstractArticle.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ abstract class AbstractArticle implements JsonSerializable
protected int $priority;
protected ?string $barcode;
protected float $price;
protected ?float $fairPrice;
protected float $purchasePrice;
protected float $rrp;
protected MediaIterator $media;
/**
* @deprecated
*/
protected PromotionIterator $promotions;
protected ParameterIterator $parameters;
protected Dimensions $dimensions;
Expand All @@ -47,6 +51,7 @@ abstract class AbstractArticle implements JsonSerializable
* @param int $priority
* @param string|null $barcode
* @param float $price
* @param ?float $fairPrice
* @param float $purchasePrice
* @param float $rrp
* @param MediaIterator $media
Expand All @@ -72,6 +77,7 @@ protected function __construct(
int $priority,
?string $barcode,
float $price,
?float $fairPrice,
float $purchasePrice,
float $rrp,
MediaIterator $media,
Expand All @@ -96,6 +102,7 @@ protected function __construct(
$this->priority = $priority;
$this->barcode = $barcode;
$this->price = $price;
$this->fairPrice = $fairPrice;
$this->purchasePrice = $purchasePrice;
$this->rrp = $rrp;
$this->media = $media;
Expand Down Expand Up @@ -164,6 +171,11 @@ public function getPrice(): float
return $this->price;
}

public function getFairPrice(): ?float
{
return $this->fairPrice;
}

public function getPurchasePrice(): float
{
return $this->purchasePrice;
Expand All @@ -179,6 +191,9 @@ public function getMedia(): MediaIterator
return $this->media;
}

/**
* @deprecated
*/
public function getPromotions(): PromotionIterator
{
return $this->promotions;
Expand Down
11 changes: 10 additions & 1 deletion src/Article/Entity/Common/Pricing.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ final class Pricing implements JsonSerializable
private float $price;
private float $rrp;
private float $purchasePrice;
private ?float $fairPrice;

public function __construct(float $price, float $rrp, float $purchasePrice)
public function __construct(float $price, float $rrp, float $purchasePrice, ?float $fairPrice = null)
{
$this->price = $price;
$this->rrp = $rrp;
$this->purchasePrice = $purchasePrice;
$this->fairPrice = $fairPrice;
}

/**
Expand All @@ -32,6 +34,7 @@ public static function createFromApi(array $data): self
(float) $data['price'],
(float) $data['rrp'],
(float) $data['purchase_price'],
isset($data['fair_price']) ? (float) $data['fair_price'] : null
);
}

Expand All @@ -44,6 +47,7 @@ public function getArrayForApi(): array
'price' => $this->getPrice(),
'rrp' => $this->getRrp(),
'purchase_price' => $this->getPurchasePrice(),
'fair_price' => $this->getFairPrice(),
];
}

Expand All @@ -62,4 +66,9 @@ public function getPurchasePrice(): float
return $this->purchasePrice;
}

public function getFairPrice(): ?float
{
return $this->fairPrice;
}

}
1 change: 1 addition & 0 deletions src/Article/Entity/Common/Promotion.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use MpApiClient\Common\Util\InputDataUtil;
use MpApiClient\Common\Util\JsonSerializeEntityTrait;

/** @deprecated */
final class Promotion implements JsonSerializable
{

Expand Down
1 change: 1 addition & 0 deletions src/Article/Entity/Common/PromotionIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/**
* @extends AbstractIntKeyIterator<Promotion>
* @property Promotion[] $data
* @deprecated
*/
final class PromotionIterator extends AbstractIntKeyIterator
{
Expand Down
6 changes: 6 additions & 0 deletions src/Article/Entity/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ final class Product extends AbstractArticle
protected ?float $weeeFee;

/**
* @psalm-suppress DeprecatedClass
* @param string $id
* @param int $articleId
* @param ProductStageEnum $stage
Expand All @@ -41,6 +42,7 @@ final class Product extends AbstractArticle
* @param int $priority
* @param string|null $barcode
* @param float $price
* @param ?float $fairPrice
* @param float $purchasePrice
* @param int $vat
* @param float $rrp
Expand Down Expand Up @@ -74,6 +76,7 @@ private function __construct(
int $priority,
?string $barcode,
float $price,
?float $fairPrice,
float $purchasePrice,
int $vat,
float $rrp,
Expand Down Expand Up @@ -105,6 +108,7 @@ private function __construct(
$priority,
$barcode,
$price,
$fairPrice,
$purchasePrice,
$rrp,
$media,
Expand Down Expand Up @@ -138,6 +142,7 @@ private function __construct(
*/
public static function createFromApi(array $data): self
{
/** @psalm-suppress DeprecatedClass */
return new self(
(string) $data['id'],
(int) $data['article_id'],
Expand All @@ -150,6 +155,7 @@ public static function createFromApi(array $data): self
(int) $data['priority'],
InputDataUtil::getNullableString($data, 'barcode'),
(float) $data['price'],
isset($data['fair_price']) ? (float)$data['fair_price'] : null,
(float) $data['purchase_price'],
(int) $data['vat'],
(float) $data['rrp'],
Expand Down
2 changes: 2 additions & 0 deletions src/Article/Entity/Variant.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ final class Variant extends AbstractArticle
*/
public static function createFromApi(array $data): self
{
/** @psalm-suppress DeprecatedClass */
return new self(
(string) $data['id'],
(int) $data['article_id'],
Expand All @@ -35,6 +36,7 @@ public static function createFromApi(array $data): self
(int) $data['priority'],
InputDataUtil::getNullableString($data, 'barcode'),
(float) $data['price'],
isset($data['fair_price']) ? (float) $data['fair_price'] : null,
(float) $data['purchase_price'],
(float) $data['rrp'],
MediaIterator::createFromApi($data['media']),
Expand Down
Loading

0 comments on commit 504d2a2

Please sign in to comment.