Update CartItem.php

This commit is contained in:
Patrick
2022-02-03 00:00:30 +01:00
committed by GitHub
parent 79fd28851a
commit 06a828208b

View File

@@ -114,162 +114,6 @@ class CartItem implements Arrayable, Jsonable
$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.
*
@@ -493,33 +337,6 @@ class CartItem implements Arrayable, Jsonable
{
ksort($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);
return md5($id . serialize($options));
}
}