Skip to content

Commit

Permalink
Added getDefaultPriceType method
Browse files Browse the repository at this point in the history
  • Loading branch information
voidgraphics committed Jan 18, 2022
1 parent bdc3f09 commit f92a96a
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/HasPrices.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function prices()
*/
public function price()
{
return $this->morphOne(Price::class, 'priceable')->where('type', 'selling')->current();
return $this->morphOne(Price::class, 'priceable')->where('type', $this->getDefaultPriceType())->current();
}

/**
Expand Down Expand Up @@ -73,4 +73,30 @@ public function setPrice(

return $this;
}

/**
* Get the price, as a model or as a whitecube/php-prices instance
*
* @param boolean $asModel
* @return void
*/
public function getPrice(bool $asModel = false)
{
if (! $asModel) {
return $this->price;
}

return $this->price()->first();
}

/**
* Get the default price type
*
* @return string
*/
protected function getDefaultPriceType(): string
{
return 'selling';
}

}

0 comments on commit f92a96a

Please sign in to comment.