/** * Return stdClass summary of cart state * * If the cart is empty, the subtotal and item count will both be null. * * $summary->subtotal = '$125.00'; * $summary->item_count = 3; * * @return stdClass */ protected static function load_summary() { $summary = new stdClass(); $summary->subtotal = null; $summary->item_count = null; $summary->api_ok = true; $cloud_cart = new CC_Cloud_Cart(); if ($cart_key = $cloud_cart->get_cart_key(false)) { try { $summary = $cloud_cart->summary($cart_key); if (is_object($summary)) { $summary->api_ok = true; self::$cart_summary = $summary; } } catch (CC_Exception_API_CartNotFound $e) { CC_Log::write("The cart key could not be found. Dropping the cart cookie: {$cart_key}"); $summary->api_ok = false; self::drop_cart(); } catch (CC_Exception_API $e) { CC_Log::write("Unable to retrieve cart from Cart66 Cloud due to API failure: {$cart_key}"); $summary->api_ok = false; } } return $summary; }
public static function check_receipt() { // Drop the cart key cookie if the receipt page is requested if (isset($_GET['cc_order_id']) && isset($_GET['cc_page_name']) && strtolower($_GET['cc_page_name']) == 'receipt') { CC_Log::write("Receipt page requested - preparing to drop the cart"); CC_Cart::drop_cart(); add_filter('the_content', array('CC_Page_Slurp', 'load_receipt')); } }
/** * Return the total price of the cart for the current visitor formatted as currency * * @return string */ public static function cart_subtotal() { $subtotal = ''; $cart_key = CC_Cart::get_cart_key(false); $cart = new CC_Cloud_Cart(); if ($cart_key) { $summary = $cart->summary($cart_key); $subtotal = $summary->subtotal; } return $subtotal; }
public static function ajax_render_content() { $item_count = 0; $subtotal = 0; $api_ok = false; $cart_summary = CC_Cart::get_summary(); if (is_object($cart_summary)) { $item_count = $cart_summary->item_count; $subtotal = $cart_summary->subtotal; $api_ok = $cart_summary->api_ok; } $url = new CC_Cloud_URL(); $data = array('view_cart_url' => $url->view_cart(), 'checkout_url' => $url->checkout(), 'item_count' => $item_count, 'subtotal' => $subtotal, 'api_ok' => $api_ok); $view = CC_View::get(CC_PATH . 'views/widget/cart-sidebar-content.php', $data); echo $view; die; }
/** * /products/<id>/add_to_cart_form * Returns HTML */ public function get_order_form($display_quantity = 'true', $display_price = 'true', $display_mode = null) { $html = 'Product not available'; // Figure out about the product id vs sku $product_id = $this->id; if (strlen($this->sku) > 0) { $product_id = $this->sku; } CC_Log::write("Get order form for product id: {$product_id}"); if (strlen($product_id) > 0) { try { $redirect_url = CC_Cart::get_redirect_url(); $html = CC_Cart::get_order_form($product_id, $redirect_url, $display_quantity, $display_price, $display_mode); } catch (CC_Exception_API $e) { $html = "Unable to retrieve product order form"; } } else { throw new CC_Exception_Product('Unable to get add to cart form because the product id is not available'); } return $html; }
public function create_cart($force = true) { return CC_Cart::get_cart_key($force); }