diff --git a/Changelog.md b/Changelog.md index 606f324bb..ceaa79bcf 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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()` diff --git a/src/MasterProduct/Changelog.md b/src/MasterProduct/Changelog.md index f8a310051..c295b75c4 100644 --- a/src/MasterProduct/Changelog.md +++ b/src/MasterProduct/Changelog.md @@ -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 diff --git a/src/MasterProduct/Models/MasterProductVariant.php b/src/MasterProduct/Models/MasterProductVariant.php index b68bd081b..4172c887d 100644 --- a/src/MasterProduct/Models/MasterProductVariant.php +++ b/src/MasterProduct/Models/MasterProductVariant.php @@ -72,7 +72,7 @@ public function masterProduct(): BelongsTo public function isOnStock(): bool { - return $this->stock > 0; + return $this->onStockQuantity() > 0; } public function isOutOfStock(): bool @@ -87,7 +87,7 @@ public function onStockQuantity(): float public function isBackorderUnrestricted(): bool { - return null === $this->backorder; + return null === $this->backorderQuantity(); } public function backorderQuantity(): ?float @@ -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 diff --git a/src/Product/Changelog.md b/src/Product/Changelog.md index aa872b364..146d3ac5d 100644 --- a/src/Product/Changelog.md +++ b/src/Product/Changelog.md @@ -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 diff --git a/src/Product/Models/Product.php b/src/Product/Models/Product.php index 70b5e7e51..b5e0fea1e 100644 --- a/src/Product/Models/Product.php +++ b/src/Product/Models/Product.php @@ -101,7 +101,7 @@ public function getIsActiveAttribute(): bool public function isOnStock(): bool { - return $this->stock > 0; + return $this->onStockQuantity() > 0; } public function isOutOfStock(): bool @@ -116,7 +116,7 @@ public function onStockQuantity(): float public function isBackorderUnrestricted(): bool { - return null === $this->backorder; + return null === $this->backorderQuantity(); } public function backorderQuantity(): ?float @@ -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