mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-15 12:24:51 +00:00
57 lines
1.2 KiB
PHP
57 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Gloudemans\Shoppingcart;
|
|
|
|
use Money\Money;
|
|
|
|
trait CanBeBought
|
|
{
|
|
/**
|
|
* Get the identifier of the Buyable item.
|
|
*
|
|
* @return int|string
|
|
*/
|
|
public function getBuyableIdentifier()
|
|
{
|
|
return method_exists($this, 'getKey') ? $this->getKey() : $this->id;
|
|
}
|
|
|
|
/**
|
|
* Get the name, title or description of the Buyable item.
|
|
*/
|
|
public function getBuyableDescription(): ?string
|
|
{
|
|
if (($name = $this->getAttribute('name'))) {
|
|
return $name;
|
|
} else if (($title = $this->getAttribute('title'))) {
|
|
return $title;
|
|
} else if (($description = $this->getAttribute('description'))) {
|
|
return $description;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get the price of the Buyable item.
|
|
*/
|
|
public function getBuyablePrice(): Money
|
|
{
|
|
if (($price = $this->getAttribute('price'))) {
|
|
return $price;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get the weight of the Buyable item.
|
|
*/
|
|
public function getBuyableWeight(): float
|
|
{
|
|
if (($weight = $this->getAttribute('weight'))) {
|
|
return $weight;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
}
|