?dispatch=checkout.remote_checkout.product_code.1&c_code=">Your link name ** for a single item checkout with quantity 1 ** For multiple products, use: ** Your link name ** products are aseparated by a '|' and quanity is specified via '@'. **/ // Swap comments for V3 //if ( !defined('AREA') ) die('Access denied'); // End V3 // For V4 if ( !defined('BOOTSTRAP') ) die('Access denied'); use Tygh\Registry; // End V4 if( $mode == 'remote_checkout' || $mode == 'remote_add' ) { // Cart is empty, create it if (empty($_SESSION['cart'])) { if( !isset($_SESSION['cart']) ) $_SESSION['cart'] = array(); fn_clear_cart($_SESSION['cart']); } $cart =& $_SESSION['cart']; // $action holds the product_code (not product_id). $dispatch_extra otpionally holds the quantity. // So need to lookup the code and get product ID $product_str = $action; // Now actually an array of products... $products = explode('|', $product_str); $default_quantity = $dispatch_extra ? $dispatch_extra : 1; // Default quantity if( empty($products) ) { fn_set_notification('E', $mode, "No products", 'K'); return array(CONTROLLER_STATUS_REDIRECT, "index.index"); } $auth =& $_SESSION['auth']; $products_added_ar = array(); foreach($products as $p_str) { $product_code = ''; $amount = 0; @list($product_code, $amount) = explode('@', $p_str); if( empty($amount) ) $amount = $default_quantity; $product_id = db_get_field("SELECT product_id FROM ?:products WHERE product_code=?s LIMIT 1", $product_code); if( empty($product_id) ) // Try option inventory $product_id = db_get_field("SELECT product_id FROM ?:product_options_inventory WHERE product_code=?s", $product_code); if( empty($product_id) ) { fn_set_notification('E', 'Error', "No such product '".$product_code."'", true); fn_redirect(fn_url("/")); } // Add to cart button was pressed for single product on advanced list $product_data = array(); if( $_SERVER['REQUEST_METHOD'] != 'POST' ) { $product_data = fn_get_product_data($product_id, $auth); } $product_data['amount'] = $amount ? $amount : 1; fn_add_product_to_cart(array($product_id=>$product_data), $cart, $auth, true); $products_added_ar[] = $product_code; } // Check for coupon code if( $coupon_code = empty($_REQUEST['c_code']) ? (empty($_REQUEST['cc']) ? '' : $_REQUEST['cc']) : $_REQUEST['c_code'] ) { $cart['pending_coupon'] = $coupon_code; $cart['recalculate'] = true; } fn_save_cart_content($cart, $auth['user_id']); // Note: some change prevents price from showing in cart for 2nd item. // Need to tell it that products have been added (stupid, recalculate should do the same). $cart['change_cart_products'] = true; fn_calculate_cart_content($cart, $auth); $_suffix = ".checkout"; if (defined('AJAX_REQUEST')) { $view->assign('cart_amount', $cart['amount']); $view->assign('cart_subtotal', $cart['display_subtotal']); $view->assign('force_items_deletion', true); // The redirection is made in order to update the page content to see changes made in the cart when adding a product to it from the 'view cart' or 'checkout' pages. if (strpos($_SERVER['HTTP_REFERER'], 'dispatch=checkout.cart') || strpos($_SERVER['HTTP_REFERER'], 'dispatch=checkout.checkout')) { $ajax->assign('force_redirection', $_SERVER['HTTP_REFERER']); } $view->display('views/checkout/components/cart_status.tpl'); $ajax->assign('force_redirection', INDEX_SCRIPT."?dispatch=checkout$_suffix"); exit; } // If not just an add, force to checkout if( $mode == 'remote_add' ) $_suffix = ".cart"; fn_redirect("checkout$_suffix"); } return array(CONTROLLER_STATUS_OK); ?>