darryldecode / laravelshoppingcart

Shopping Cart Implementation for Laravel Framework
1.32k stars 413 forks source link

getPriceSum() in getSubTotalWithoutConditions() errors when summing #350

Open adsy2010 opened 1 year ago

adsy2010 commented 1 year ago

The sum method in the get sub total without conditions method uses get price sum

/**
 * get cart sub total without conditions
 * @param bool $formatted
 * @return float
 */
public function getSubTotalWithoutConditions($formatted = true)
{
    $cart = $this->getContent();

    $sum = $cart->sum(function ($item) {
        return $item->getPriceSum();
    });

    return Helpers::formatValue(floatval($sum), $formatted, $this->config);
}

I would propose that the getPriceSum method should take a formatted boolean value to turn off formatting on the get price sum. Any values over 1000 add a , which means that the value cannot be summed correctly.

Proposed solution:

Cart.php /**

ItemCollection.php

/**
 * get the sum of price
 *
 * @return mixed|null
 */
public function getPriceSum($formatted = true)
{
    return Helpers::formatValue($this->price * $this->quantity, $formatted, $this->config);
}