Skip to content

Commit

Permalink
Foundation's CartItem, Product and MasterProductVariant became Taxable
Browse files Browse the repository at this point in the history
  • Loading branch information
fulopattila122 committed Feb 26, 2024
1 parent f04a105 commit 4a29ff5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
- Added the `backorder` field to products and product variants
- Added the `type` field to the TaxCategory model
- Added the `Taxable` interface
- Added the `Taxable` implementation to Foundation's CartItem, Product and MasterProductVariant classes
- Added the extendable `TaxEngine` (facade) that can resolve tax rates from taxables, billing/shipping addresses (a place for various country-specific taxation drivers)
- Added the `Merchant` interface
- BC: Added the `?CheckoutSubject` return type to the `getCart()` method of the `Checkout` interface
Expand Down
14 changes: 13 additions & 1 deletion src/Foundation/Models/CartItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,24 @@
use Vanilo\Adjustments\Support\HasAdjustmentsViaRelation;
use Vanilo\Adjustments\Support\RecalculatesAdjustments;
use Vanilo\Cart\Models\CartItem as BaseCartItem;
use Vanilo\Taxes\Contracts\Taxable;
use Vanilo\Taxes\Contracts\TaxCategory;

class CartItem extends BaseCartItem implements Adjustable
class CartItem extends BaseCartItem implements Adjustable, Taxable
{
use HasAdjustmentsViaRelation;
use RecalculatesAdjustments;

public function getTaxCategory(): ?TaxCategory
{
$buyable = $this->getBuyable();
if ($buyable instanceof Taxable) {
return $buyable->getTaxCategory();
}

return null;
}

/** @todo rename this in v4 along with the renaming of this method in the Adjustable interface */
public function itemsTotal(): float
{
Expand Down
3 changes: 2 additions & 1 deletion src/Foundation/Models/MasterProductVariant.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
use Vanilo\Properties\Traits\HasPropertyValues;
use Vanilo\Support\Traits\BuyableModel;
use Vanilo\Support\Traits\HasImagesFromMediaLibrary;
use Vanilo\Taxes\Contracts\Taxable;
use Vanilo\Taxes\Traits\BelongsToTaxCategory;

class MasterProductVariant extends BaseMasterProductVariant implements Buyable, HasMedia
class MasterProductVariant extends BaseMasterProductVariant implements Buyable, HasMedia, Taxable
{
use BelongsToTaxCategory;
use BuyableModel;
Expand Down
3 changes: 2 additions & 1 deletion src/Foundation/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
use Vanilo\Properties\Traits\HasPropertyValues;
use Vanilo\Support\Traits\BuyableModel;
use Vanilo\Support\Traits\HasImagesFromMediaLibrary;
use Vanilo\Taxes\Contracts\Taxable;
use Vanilo\Taxes\Traits\BelongsToTaxCategory;

class Product extends BaseProduct implements Buyable, HasMedia
class Product extends BaseProduct implements Buyable, HasMedia, Taxable
{
use BelongsToTaxCategory;
use BuyableModel;
Expand Down

0 comments on commit 4a29ff5

Please sign in to comment.