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;
 }
 public function profile_url()
 {
     $url = new CC_Cloud_URL();
     return $url->profile();
 }
Exemplo n.º 3
0
 public function __construct()
 {
     if (!isset(self::$cloud)) {
         self::$cloud = new CC_Cloud_API_V1();
     }
 }
Exemplo n.º 4
0
 public static function ajax_add_to_cart()
 {
     $response = self::add_to_cart($_POST);
     if (is_wp_error($response)) {
         $response_code = $response->get_error_code();
     } else {
         $response_code = $response['response']['code'];
     }
     // CC_Log::write('Ajax response code: ' . print_r($response_code, TRUE));
     if ($response_code == '500') {
         header('HTTP/1.1 500: SERVER ERROR', true, 500);
     } elseif ($response_code != '201') {
         header('HTTP/1.1 422: UNPROCESSABLE ENTITY', true, 422);
         echo $response['body'];
     } else {
         $redirect_type = CC_Admin_Setting::get_option('cart66_main_settings', 'add_to_cart_redirect_type');
         $out = array('task' => 'redirect');
         $url = new CC_Cloud_URL();
         if ('view_cart' == $redirect_type) {
             $out['url'] = $url->view_cart();
         } elseif ('checkout' == $redirect_type) {
             $out['url'] = $url->checkout();
         } else {
             $product_info = json_decode($response['body'], true);
             $product_name = $product_info['product_name'];
             $message = $product_name . ' added to cart';
             $view_cart = '<a href="' . $url->view_cart() . '" class="btn btn-small pull-right ajax_view_cart_button" rel="nofollow">View Cart <i class="icon-arrow-right" /></a>';
             $out = array('task' => 'stay', 'response' => $message . $view_cart);
         }
         CC_Log::write('Ajax created :: response code 201 :: output: ' . print_r($out, TRUE));
         header('HTTP/1.1 201 Created', true, 201);
         header('Content-Type: application/json');
         echo json_encode($out);
         do_action('cc_after_add_to_cart');
     }
     die;
 }
Exemplo n.º 5
0
/**
 * Handle public actions for cart66
 */
function cc_route_handler()
{
    global $wp;
    // If the cc-action is not available forget about doing anything else here
    if (!isset($wp->query_vars['cc-action'])) {
        return;
    }
    $action = $wp->query_vars['cc-action'];
    CC_Log::write("Route handler found action: {$action}");
    if ($action) {
        unset($wp->query_vars['cc-action']);
        $url = new CC_Cloud_URL();
        if (isset($_SERVER['PHP_AUTH_USER'])) {
            // Authenticated requests
            if (cc_auth_verify_secret_key($_SERVER['PHP_AUTH_USER'])) {
                switch ($action) {
                    case 'product-update':
                        cc_auth_product_update();
                        break;
                    case 'product-create':
                        CC_Log::write('About to create a product');
                        cc_auth_product_create();
                        break;
                    case 'settings-create':
                        cc_auth_settings_create();
                        break;
                }
            } else {
                CC_Log::write("Protected request failed authentication: {$action}");
                status_header('401');
                exit;
            }
        } else {
            // Open requests
            switch ($action) {
                case 'sign-in':
                    wp_redirect($url->sign_in());
                    exit;
                    break;
                case 'sign-out':
                    if (class_exists('CM_Visitor')) {
                        $visitor = new CM_Visitor();
                        $visitor->sign_out();
                    }
                    wp_redirect($url->sign_out());
                    exit;
                    break;
                case 'view-cart':
                    wp_redirect($url->view_cart(true));
                    exit;
                    break;
                case 'checkout':
                    wp_redirect($url->checkout(true));
                    exit;
                    break;
                case 'order-history':
                    wp_redirect($url->order_history());
                    exit;
                    break;
                case 'profile':
                    wp_redirect($url->profile());
                    exit;
                    break;
                case 'receipts':
                    $order_id = $wp->query_vars['cc-order-number'];
                    CC_Log::write("Getting receipt for order number: {$order_id}");
                    $_GET['cc_page_title'] = 'Receipt';
                    $_GET['cc_page_name'] = 'Receipt';
                    $_GET['cc_order_id'] = $order_id;
                    add_action('pre_get_posts', 'CC_Page_Slurp::set_query_to_slurp');
                    add_filter('wp_title', 'CC_Page_Slurp::set_page_title');
                    add_filter('the_title', 'CC_Page_Slurp::set_page_heading');
                    CC_Page_Slurp::check_receipt();
                    break;
                case 'plugin-info':
                    $data = cc_plugin_info();
                    header('Content-Type: application/json');
                    echo json_encode($data);
                    exit;
                    break;
                case 'save-secret-key':
                    if ('POST' == $_SERVER['REQUEST_METHOD']) {
                        $post_body = file_get_contents('php://input');
                        if ($settings = json_decode($post_body)) {
                            $main_settings = CC_Admin_Setting::get_options('cart66_main_settings');
                            if (!isset($main_settings['secret_key']) || empty($main_settings['secret_key'])) {
                                $main_settings['secret_key'] = $settings->secret_key;
                                CC_Admin_Setting::update_options('cart66_main_settings', $main_settings);
                                status_header('201');
                            } else {
                                CC_Log::write('Not overwriting existing secret key');
                                status_header('412');
                            }
                        }
                        exit;
                    }
                    break;
                default:
                    CC_Log::write("Unknown open request: {$action}");
                    status_header('404');
                    exit;
            }
            // end switch $action
        }
        // end open requests
    }
    // end if $action
}
/**
 * Handle public actions for cart66
 */
function cc_route_handler()
{
    global $wp;
    CC_Log::write('cc_route_handler: starting');
    // If the cc-action is not available forget about doing anything else here
    if (!isset($wp->query_vars['cc-action'])) {
        CC_Log::write('cc-action not set in WP query vars so bailing out of route handler.');
        return;
    }
    $action = $wp->query_vars['cc-action'];
    CC_Log::write("Route handler found action: {$action}");
    if ($action) {
        unset($wp->query_vars['cc-action']);
        $url = new CC_Cloud_URL();
        // Check for PHP_AUTH_USER when Apache is run in CGI mode
        CC_Log::write('Display SERVER: ' . print_r($_SERVER, true));
        if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) {
            CC_Log::write('Checking for basic auth headers: ' . $_SERVER['REDIRECT_HTTP_AUTHORIZATION']);
            if (preg_match('/Basic\\s+(.*)$/i', $_SERVER['REDIRECT_HTTP_AUTHORIZATION'], $matches)) {
                list($name, $password) = explode(':', base64_decode($matches[1]));
                $_SERVER['PHP_AUTH_USER'] = strip_tags($name);
                $_SERVER['PHP_AUTH_PW'] = strip_tags($password);
                CC_Log::write("Found basic auth :: {$name} :: {$password}");
            }
        }
        if (isset($_SERVER['PHP_AUTH_USER'])) {
            // Authenticated requests
            if (cc_auth_verify_secret_key($_SERVER['PHP_AUTH_USER'])) {
                switch ($action) {
                    case 'product-update':
                        cc_auth_product_update();
                        break;
                    case 'product-create':
                        CC_Log::write('About to create a product');
                        cc_auth_product_create();
                        break;
                    case 'settings-create':
                        cc_auth_settings_create();
                        break;
                }
            } else {
                CC_Log::write("Protected request failed authentication: {$action}");
                status_header('401');
                exit;
            }
        } else {
            CC_Log::write("PHP_AUTH_USER not set - assuming unauthenticated request: {$action}");
            // Open requests
            switch ($action) {
                case 'sign-in':
                    wp_redirect($url->sign_in());
                    exit;
                    break;
                case 'sign-out':
                    if (class_exists('CM_Visitor')) {
                        $visitor = CM_Visitor::get_instance();
                        $visitor->sign_out();
                    }
                    wp_redirect($url->sign_out());
                    exit;
                    break;
                case 'view-cart':
                    wp_redirect($url->view_cart(true));
                    exit;
                    break;
                case 'checkout':
                    wp_redirect($url->checkout(true));
                    exit;
                    break;
                case 'order-history':
                    wp_redirect($url->order_history());
                    exit;
                    break;
                case 'profile':
                    wp_redirect($url->profile());
                    exit;
                    break;
                case 'receipts':
                    $order_id = $wp->query_vars['cc-order-number'];
                    CC_Log::write("CC API Call: Getting receipt for order number: {$order_id}");
                    $_GET['cc_page_title'] = 'Receipt';
                    $_GET['cc_page_name'] = 'Receipt';
                    $_GET['cc_order_id'] = $order_id;
                    add_action('pre_get_posts', 'CC_Page_Slurp::set_query_to_slurp');
                    add_filter('document_title_parts', 'CC_Page_Slurp::set_page_title');
                    add_filter('the_title', 'CC_Page_Slurp::set_page_heading');
                    CC_Page_Slurp::check_receipt();
                    break;
                case 'plugin-info':
                    $data = cc_plugin_info();
                    header('Content-Type: application/json');
                    echo json_encode($data);
                    exit;
                    break;
                case 'save-secret-key':
                    if ('POST' == $_SERVER['REQUEST_METHOD']) {
                        $post_body = file_get_contents('php://input');
                        if ($settings = json_decode($post_body)) {
                            $main_settings = CC_Admin_Setting::get_options('cart66_main_settings');
                            if (!isset($main_settings['secret_key']) || empty($main_settings['secret_key'])) {
                                $main_settings['secret_key'] = $settings->secret_key;
                                CC_Admin_Setting::update_options('cart66_main_settings', $main_settings);
                                status_header('201');
                            } else {
                                CC_Log::write('Not overwriting existing secret key');
                                status_header('412');
                            }
                        }
                        exit;
                    }
                    break;
                default:
                    CC_Log::write("Unknown open request: {$action}");
                    status_header('404');
                    exit;
            }
            // end switch $action
        }
        // end open requests
    }
    // end if $action
}