?dispatch=checkout.remote_checkout.1&cc=">Your link name ** or ** Your link name ** to just add one item ** Note: if you require login for checkout, their cart may be lost after logging in. **/ if ( !defined('BOOTSTRAP') ) die('Access denied'); use Tygh\Registry; if( $mode == 'remote_checkout' || $mode == 'remote_add' ) { // Cart is empty, create it if (empty($_SESSION['cart'])) { fn_clear_cart($_SESSION['cart']); } else { $cart =& $_SESSION['cart']; } if( !isset($auth) ) $auth =& $_SESSION['aught']; // $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_code = $action; $amount = $dispatch_extra; if( !$product_code ) { return array(CONTROLLER_STATUS_REDIRECT, "/"); } $product_id = db_get_field("SELECT product_id FROM ?:products WHERE product_code=?s LIMIT 1", $product_code); if( empty($product_id) ) { fn_set_notification('E', 'Error', "No such product '".$product_code."'", true); return array(CONTROLLER_STATUS_REDIRECT, "/"); } // Add to cart button was pressed for single product on advanced list if( empty($_REQUEST['product_data']) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { $_REQUEST['product_data'][$product_id] = fn_get_product_data($product_id, $auth); } $_REQUEST['product_data'][$product_id]['amount'] = $amount ? $amount : 1; // Check for coupon code if( $coupon_code = empty($_REQUEST['ccode']) ? '' : $_REQUEST['ccode'] ) { $cart['pending_coupon'] = $coupon_code; $cart['recalculate'] = true; } fn_add_product_to_cart($_REQUEST['product_data'], $cart, $auth); fn_save_cart_content($cart, $auth['user_id']); $previous_state = md5(serialize($cart['products'])); fn_calculate_cart_content($cart, $auth, 'S', true, 'F', true); $_SESSION['cart'] = $cart; if (md5(serialize($cart['products'])) != $previous_state) { $msg = __('text_product_added_to'); $msg = str_replace('[target]', strtolower(__('cart')), $msg); // fn_set_notification('N', __('notice'), $msg); $cart['recalculate'] = true; } $_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', "?dispatch=checkout$_suffix"); exit; } // If not just an add, force to cart if( $mode == 'remote_add' ) $_suffix = ".cart"; return array(CONTROLLER_STATUS_OK, "checkout$_suffix"); } return array(CONTROLLER_STATUS_OK); ?>