mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-24 07:55:35 +00:00
Update CartItem.php
This commit is contained in:
185
src/CartItem.php
185
src/CartItem.php
@@ -114,162 +114,6 @@ class CartItem implements Arrayable, Jsonable
|
|||||||
$this->rowId = $this->generateRowId($id, $options);
|
$this->rowId = $this->generateRowId($id, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the formatted weight.
|
|
||||||
*
|
|
||||||
* @param int $decimals
|
|
||||||
* @param string $decimalPoint
|
|
||||||
* @param string $thousandSeperator
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function weight(int $decimals = null, ?string $decimalPoint = null, ?string $thousandSeperator = null)
|
|
||||||
{
|
|
||||||
return $this->numberFormat($this->weight, $decimals, $decimalPoint, $thousandSeperator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the formatted price without TAX.
|
|
||||||
*
|
|
||||||
* @param int $decimals
|
|
||||||
* @param string $decimalPoint
|
|
||||||
* @param string $thousandSeperator
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function price(?int $decimals = null, ?string $decimalPoint = null, ?string $thousandSeperator = null)
|
|
||||||
{
|
|
||||||
return $this->numberFormat($this->price, $decimals, $decimalPoint, $thousandSeperator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the formatted price with discount applied.
|
|
||||||
*
|
|
||||||
* @param int $decimals
|
|
||||||
* @param string $decimalPoint
|
|
||||||
* @param string $thousandSeperator
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function priceTarget(?int $decimals = null, ?string $decimalPoint = null, ?string $thousandSeperator = null)
|
|
||||||
{
|
|
||||||
return $this->numberFormat($this->priceTarget, $decimals, $decimalPoint, $thousandSeperator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the formatted price with TAX.
|
|
||||||
*
|
|
||||||
* @param int $decimals
|
|
||||||
* @param string $decimalPoint
|
|
||||||
* @param string $thousandSeperator
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function priceTax(?int $decimals = null, ?string $decimalPoint = null, ?string $thousandSeperator = null)
|
|
||||||
{
|
|
||||||
return $this->numberFormat($this->priceTax, $decimals, $decimalPoint, $thousandSeperator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the formatted subtotal.
|
|
||||||
* Subtotal is price for whole CartItem without TAX.
|
|
||||||
*
|
|
||||||
* @param int $decimals
|
|
||||||
* @param string $decimalPoint
|
|
||||||
* @param string $thousandSeperator
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function subtotal(?int $decimals = null, ?string $decimalPoint = null, ?string $thousandSeperator = null)
|
|
||||||
{
|
|
||||||
return $this->numberFormat($this->subtotal, $decimals, $decimalPoint, $thousandSeperator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the formatted total.
|
|
||||||
* Total is price for whole CartItem with TAX.
|
|
||||||
*
|
|
||||||
* @param int $decimals
|
|
||||||
* @param string $decimalPoint
|
|
||||||
* @param string $thousandSeperator
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function total(?int $decimals = null, ?string $decimalPoint = null, ?string $thousandSeperator = null)
|
|
||||||
{
|
|
||||||
return $this->numberFormat($this->total, $decimals, $decimalPoint, $thousandSeperator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the formatted tax.
|
|
||||||
*
|
|
||||||
* @param int $decimals
|
|
||||||
* @param string $decimalPoint
|
|
||||||
* @param string $thousandSeperator
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function tax(?int $decimals = null, ?string $decimalPoint = null, ?string $thousandSeperator = null)
|
|
||||||
{
|
|
||||||
return $this->numberFormat($this->tax, $decimals, $decimalPoint, $thousandSeperator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the formatted tax.
|
|
||||||
*
|
|
||||||
* @param int $decimals
|
|
||||||
* @param string $decimalPoint
|
|
||||||
* @param string $thousandSeperator
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function taxTotal(?int $decimals = null, ?string $decimalPoint = null, ?string $thousandSeperator = null)
|
|
||||||
{
|
|
||||||
return $this->numberFormat($this->taxTotal, $decimals, $decimalPoint, $thousandSeperator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the formatted discount.
|
|
||||||
*
|
|
||||||
* @param int $decimals
|
|
||||||
* @param string $decimalPoint
|
|
||||||
* @param string $thousandSeperator
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function discount(?int $decimals = null, ?string $decimalPoint = null, ?string $thousandSeperator = null)
|
|
||||||
{
|
|
||||||
return $this->numberFormat($this->discount, $decimals, $decimalPoint, $thousandSeperator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the formatted total discount for this cart item.
|
|
||||||
*
|
|
||||||
* @param int $decimals
|
|
||||||
* @param string $decimalPoint
|
|
||||||
* @param string $thousandSeperator
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function discountTotal(?int $decimals = null, ?string $decimalPoint = null, ?string $thousandSeperator = null)
|
|
||||||
{
|
|
||||||
return $this->numberFormat($this->discountTotal, $decimals, $decimalPoint, $thousandSeperator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the formatted total price for this cart item.
|
|
||||||
*
|
|
||||||
* @param int $decimals
|
|
||||||
* @param string $decimalPoint
|
|
||||||
* @param string $thousandSeperator
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function priceTotal(?int $decimals = null, ?string $decimalPoint = null, ?string $thousandSeperator = null)
|
|
||||||
{
|
|
||||||
return $this->numberFormat($this->priceTotal, $decimals, $decimalPoint, $thousandSeperator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the quantity for this cart item.
|
* Set the quantity for this cart item.
|
||||||
*
|
*
|
||||||
@@ -493,33 +337,6 @@ class CartItem implements Arrayable, Jsonable
|
|||||||
{
|
{
|
||||||
ksort($options);
|
ksort($options);
|
||||||
|
|
||||||
return md5($id.serialize($options));
|
return md5($id . serialize($options));
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the formatted number.
|
|
||||||
*
|
|
||||||
* @param float $value
|
|
||||||
* @param int $decimals
|
|
||||||
* @param string $decimalPoint
|
|
||||||
* @param string $thousandSeperator
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function numberFormat($value, ?int $decimals, ?string $decimalPoint, ?string $thousandSeperator) : string
|
|
||||||
{
|
|
||||||
if (is_null($decimals)) {
|
|
||||||
$decimals = config('cart.format.decimals', 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_null($decimalPoint)) {
|
|
||||||
$decimalPoint = config('cart.format.decimal_point', '.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_null($thousandSeperator)) {
|
|
||||||
$thousandSeperator = config('cart.format.thousand_separator', ',');
|
|
||||||
}
|
|
||||||
|
|
||||||
return number_format($value, $decimals, $decimalPoint, $thousandSeperator);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user