common/components/CartFunctionality.php
/*
     * This function returns the total amount of cart items
     */
This function returns the total amount of cart items
This function returns the total amount of cart items
public static function total($cart) {
        $subtotal = '0';
        foreach ($cart as $cart_item) {
            if ($cart_item->quantity > 0) {
                $product = Product::find()->where(['id' => $cart_item->product_id, 'status' => '1'])->one();
                if ($product->offer_price == '0' || $product->offer_price == '') {
                    $price = $product->price;
                } else {
                    $price = $product->offer_price;
                }
                $subtotal += ($price * $cart_item->quantity);
            }
        }
        return $subtotal;
    }
public static function total ( $ cart ) { $ subtotal = '0' ; foreach ( $ cart as $ cart_item ) { if ( $ cart_item -> quantity > 0 ) { $ product = Product :: find ( ) -> where ( [ 'id' => $ cart_item -> product_id , 'status' => '1' ] ) -> one ( ) ; if ( $ product -> offer_price == '0' || $ product -> offer_price == '' ) { $ price = $ product -> price ; } else { $ price = $ product -> offer_price ; } $ subtotal += ( $ price * $ cart_item -> quantity ) ; } } return $ subtotal ; }
This function returns the total amount of cart items
This function returns the total amount of cart items