Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
adsy2010 opened this issue Dec 22, 2022 · 0 comments
Open

Comments

@adsy2010
Copy link

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
/**
* 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(false);
    });

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

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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant