EShoppingCart::getCost PHP Method

getCost() public method

Returns total price for all items in the shopping cart.
public getCost ( boolean $withDiscount = true ) : float
$withDiscount boolean
return float
    public function getCost($withDiscount = true)
    {
        $price = 0.0;
        foreach ($this as $position) {
            $price += $position->getSumPrice($withDiscount);
        }
        if ($withDiscount) {
            $price -= $this->discountPrice;
        }
        return $price;
    }

Usage Example

Esempio n. 1
0
 function testDiscount()
 {
     $this->setUp();
     $cart = new EShoppingCart();
     $cart->discounts = array(array('class' => 'ext.yiiext.components.shoppingCart.discounts.TestDiscount', 'rate' => 40));
     $book = Book::model()->findByPk(1);
     $cart->put($book, 2);
     $this->assertEquals(159.84, $cart->getCost());
 }