Skip to content

Commit

Permalink
Stockable implementations use stock/backorder getters instead of the …
Browse files Browse the repository at this point in the history
…direct field access
  • Loading branch information
fulopattila122 committed Oct 21, 2024
1 parent 2e33036 commit a8baa63
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
- `Shipment`
- `ShippingMethod`
- `TaxRate`
- Changed the product and variant Stockable logic so that the derived getters use `onStockQuantity()` and `backorderQuantity()`
instead of direct `stock` and `backorder` field access. This makes possible to override stock logic and remain consistent
in extended classes
- Added the following, v5 interface candidate methods to the Checkout implementations:
- `addCoupon()`
- `removeCoupon()`
Expand Down
7 changes: 7 additions & 0 deletions src/MasterProduct/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## 4.x Series

## Unreleased
##### 2024-XX-YY

- Changed the variant's Stockable logic so that the derived getters use `onStockQuantity()` and `backorderQuantity()`
instead of direct `stock` and `backorder` field access. This makes possible to override stock logic and remain consistent
in extended classes

## 4.1.0
##### 2024-07-11

Expand Down
6 changes: 3 additions & 3 deletions src/MasterProduct/Models/MasterProductVariant.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function masterProduct(): BelongsTo

public function isOnStock(): bool
{
return $this->stock > 0;
return $this->onStockQuantity() > 0;
}

public function isOutOfStock(): bool
Expand All @@ -87,7 +87,7 @@ public function onStockQuantity(): float

public function isBackorderUnrestricted(): bool
{
return null === $this->backorder;
return null === $this->backorderQuantity();
}

public function backorderQuantity(): ?float
Expand All @@ -97,7 +97,7 @@ public function backorderQuantity(): ?float

public function totalAvailableQuantity(): float
{
return $this->stock + (float) $this->backorder;
return $this->onStockQuantity() + (float) $this->backorderQuantity();
}

public function hasDimensions(): bool
Expand Down
8 changes: 8 additions & 0 deletions src/Product/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## 4.x Series

## Unreleased
##### 2024-XX-YY

- Changed the product's Stockable logic so that the derived getters use `onStockQuantity()` and `backorderQuantity()`
instead of direct `stock` and `backorder` field access. This makes possible to override stock logic and remain consistent
in extended classes


## 4.1.0
##### 2024-07-11

Expand Down
6 changes: 3 additions & 3 deletions src/Product/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function getIsActiveAttribute(): bool

public function isOnStock(): bool
{
return $this->stock > 0;
return $this->onStockQuantity() > 0;
}

public function isOutOfStock(): bool
Expand All @@ -116,7 +116,7 @@ public function onStockQuantity(): float

public function isBackorderUnrestricted(): bool
{
return null === $this->backorder;
return null === $this->backorderQuantity();
}

public function backorderQuantity(): ?float
Expand All @@ -126,7 +126,7 @@ public function backorderQuantity(): ?float

public function totalAvailableQuantity(): float
{
return $this->stock + (float) $this->backorder;
return $this->onStockQuantity() + (float) $this->backorderQuantity();
}

public function title(): string
Expand Down

0 comments on commit a8baa63

Please sign in to comment.