mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-24 07:55:35 +00:00
Merge pull request #209 from xpundel/master
Add options to buyable methods
This commit is contained in:
@@ -10,7 +10,7 @@ trait CanBeBought
|
|||||||
*
|
*
|
||||||
* @return int|string
|
* @return int|string
|
||||||
*/
|
*/
|
||||||
public function getBuyableIdentifier()
|
public function getBuyableIdentifier($options = null)
|
||||||
{
|
{
|
||||||
return method_exists($this, 'getKey') ? $this->getKey() : $this->id;
|
return method_exists($this, 'getKey') ? $this->getKey() : $this->id;
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,7 @@ trait CanBeBought
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getBuyableDescription()
|
public function getBuyableDescription($options = null)
|
||||||
{
|
{
|
||||||
if(property_exists($this, 'name')) return $this->name;
|
if(property_exists($this, 'name')) return $this->name;
|
||||||
if(property_exists($this, 'title')) return $this->title;
|
if(property_exists($this, 'title')) return $this->title;
|
||||||
@@ -34,7 +34,7 @@ trait CanBeBought
|
|||||||
*
|
*
|
||||||
* @return float
|
* @return float
|
||||||
*/
|
*/
|
||||||
public function getBuyablePrice()
|
public function getBuyablePrice($options = null)
|
||||||
{
|
{
|
||||||
if(property_exists($this, 'price')) return $this->price;
|
if(property_exists($this, 'price')) return $this->price;
|
||||||
|
|
||||||
|
|||||||
@@ -192,9 +192,9 @@ class CartItem implements Arrayable
|
|||||||
*/
|
*/
|
||||||
public function updateFromBuyable(Buyable $item)
|
public function updateFromBuyable(Buyable $item)
|
||||||
{
|
{
|
||||||
$this->id = $item->getBuyableIdentifier();
|
$this->id = $item->getBuyableIdentifier($this->options);
|
||||||
$this->name = $item->getBuyableDescription();
|
$this->name = $item->getBuyableDescription($this->options);
|
||||||
$this->price = $item->getBuyablePrice();
|
$this->price = $item->getBuyablePrice($this->options);
|
||||||
$this->priceTax = $this->price + $this->tax;
|
$this->priceTax = $this->price + $this->tax;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,7 +286,7 @@ class CartItem implements Arrayable
|
|||||||
*/
|
*/
|
||||||
public static function fromBuyable(Buyable $item, array $options = [])
|
public static function fromBuyable(Buyable $item, array $options = [])
|
||||||
{
|
{
|
||||||
return new self($item->getBuyableIdentifier(), $item->getBuyableDescription(), $item->getBuyablePrice(), $options);
|
return new self($item->getBuyableIdentifier($options), $item->getBuyableDescription($options), $item->getBuyablePrice($options), $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -9,19 +9,19 @@ interface Buyable
|
|||||||
*
|
*
|
||||||
* @return int|string
|
* @return int|string
|
||||||
*/
|
*/
|
||||||
public function getBuyableIdentifier();
|
public function getBuyableIdentifier($options = null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the description or title of the Buyable item.
|
* Get the description or title of the Buyable item.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getBuyableDescription();
|
public function getBuyableDescription($options = null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the price of the Buyable item.
|
* Get the price of the Buyable item.
|
||||||
*
|
*
|
||||||
* @return float
|
* @return float
|
||||||
*/
|
*/
|
||||||
public function getBuyablePrice();
|
public function getBuyablePrice($options = null);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user