/**
  * Returns a calculated subtotal.
  *
  * @param boolean $for_display Just the price itself or with currency symbol + price with optional "(ex. tax)" / "(inc. tax)".
  * @param boolean $apply_discount_and_shipping Subtotal with discount and shipping prices applied.
  * @param boolean $order_exclude_tax Subtotal without taxes no matter settings used by Orders
  * @return mixed|string|void
  */
 public static function get_cart_subtotal($for_display = true, $apply_discount_and_shipping = false, $order_exclude_tax = false)
 {
     do_action('fflcommerce_calculate_totals');
     /* Just some initialization. */
     $discount = self::$discount_total;
     $subtotal = self::$subtotal;
     $tax_label = 0;
     // use with fflcommerce_price. 0 for no label, 1 for ex. tax, 2 for inc. tax
     /**
      * Tax calculation turned ON.
      */
     if (self::get_options()->get('fflcommerce_calc_taxes') == 'yes') {
         // for final Orders in the Admin we always need tax out
         if ($order_exclude_tax) {
             $subtotal = self::get_options()->get('fflcommerce_prices_include_tax') == 'yes' ? self::$subtotal_ex_tax : $subtotal;
             if (self::get_options()->get('fflcommerce_show_prices_with_tax') == 'yes') {
                 $tax_label = 1;
                 //ex. tax
             }
         } else {
             if (self::get_options()->get('fflcommerce_prices_include_tax') == 'yes') {
                 $tax_label = 2;
                 //inc. tax
             } else {
                 $subtotal = self::$subtotal_ex_tax;
                 if (self::get_options()->get('fflcommerce_show_prices_with_tax') == 'yes') {
                     $tax_label = 1;
                     //inc. tax
                 }
             }
         }
     }
     // Don't show the discount bit in the subtotal because discount will be calculated after taxes
     // thus in the grand total (not the subtotal). */
     if (self::get_options()->get('fflcommerce_tax_after_coupon') == 'yes') {
         $discount = 0;
     }
     /* Display totals with discount & shipping applied? */
     // This is only 'true' with the 'Retail Price' displays on Cart, Checkout, View Order
     // Someone should explain why this is used instead of 'Subtotal'
     if ($apply_discount_and_shipping) {
         $subtotal = $subtotal + fflcommerce_cart::get_cart_shipping_total(false);
         $subtotal = $discount > $subtotal ? $subtotal : $subtotal - $discount;
     }
     /* Return a pretty number or just the float. */
     $return = $for_display ? fflcommerce_price($subtotal, array('ex_tax_label' => $tax_label)) : number_format($subtotal, 2, '.', '');
     return $return;
 }
Exemple #2
0
</td>
					</tr>
					<?php 
        if (fflcommerce_cart::get_cart_shipping_total()) {
            ?>
						<tr>
							<th class="cart-row-shipping-title"><?php 
            _e('Shipping', 'fflcommerce');
            ?>
								<small><?php 
            echo _x('To: ', 'shipping destination', 'fflcommerce') . __(fflcommerce_customer::get_shipping_country_or_state(), 'fflcommerce');
            ?>
</small>
							</th>
							<td class="cart-row-shipping"><?php 
            echo fflcommerce_cart::get_cart_shipping_total(true, true);
            ?>
								<small><?php 
            echo fflcommerce_cart::get_cart_shipping_title();
            ?>
</small>
							</td>
						</tr>
					<?php 
        }
        ?>
					<?php 
        if (fflcommerce_cart::show_retail_price() && $options->get('fflcommerce_prices_include_tax') == 'no') {
            ?>
						<tr>
							<th class="cart-row-subtotal-title"><?php 
function fflcommerce_ajax_update_item_quantity()
{
    /** @var fflcommerce_cart $cart */
    $cart = fflcommerce_cart::instance();
    $cart->set_quantity($_POST['item'], (int) $_POST['qty']);
    $items = $cart->get_cart();
    $price = -1;
    if (isset($items[$_POST['item']])) {
        $item = $items[$_POST['item']];
        /** @var fflcommerce_product $product */
        $product = $item['data'];
        $price = apply_filters('fflcommerce_product_subtotal_display_in_cart', fflcommerce_price($product->get_defined_price() * $item['quantity']), $item['product_id'], $item);
    }
    if (fflcommerce_cart::show_retail_price()) {
        $subtotal = fflcommerce_cart::get_cart_subtotal(true, false, true);
    } else {
        if (fflcommerce_cart::show_retail_price() && FFLCommerce_Base::get_options()->get('fflcommerce_prices_include_tax') == 'no') {
            $subtotal = fflcommerce_cart::get_cart_subtotal(true, true);
        } else {
            $subtotal = fflcommerce_cart::$cart_contents_total_ex_tax + fflcommerce_cart::$shipping_total;
            $subtotal = fflcommerce_price($subtotal, array('ex_tax_label' => 1));
        }
    }
    $tax = array();
    foreach (fflcommerce_cart::get_applied_tax_classes() as $tax_class) {
        if (fflcommerce_cart::get_tax_for_display($tax_class)) {
            $tax[$tax_class] = fflcommerce_cart::get_tax_amount($tax_class);
        }
    }
    $shipping = fflcommerce_cart::get_cart_shipping_total(true, true) . '<small>' . fflcommerce_cart::get_cart_shipping_title() . '</small>';
    $discount = '-' . fflcommerce_cart::get_total_discount();
    $total = fflcommerce_cart::get_total();
    echo json_encode(array('success' => true, 'item_price' => $price, 'subtotal' => $subtotal, 'shipping' => $shipping, 'discount' => $discount, 'tax' => $tax, 'total' => $total));
    exit;
}