繁体   English   中英

如何在cs-cart中添加立即购买按钮

[英]How to add Buy Now button in cs-cart

我正在创建一个立即购买按钮cs-cart附加组件。 我创建了一个加载项,并使添加购物车功能正常工作。 但是无法将其重定向到结帐页面。 我已经使用“ fn_redirect(“ checkout”)“函数进行重定向。 并在下面使用了此功能:

"fn_add_product_to_cart($_REQUEST['product_data'], $cart, $auth);"

我应该怎么做重定向?

编辑:我的控制器(buy_now.php)

if ($mode == 'add') {

    if (empty($auth['user_id']) && Registry::get('settings.General.allow_anonymous_shopping') != 'allow_shopping')
     {
        return array(CONTROLLER_STATUS_REDIRECT, "auth.login_form?return_url=" . urlencode($_REQUEST['return_url']));
    }



    // Add to cart button was pressed for single product on advanced list
    if (!empty($dispatch_extra)) {
        if (empty($_REQUEST['product_data'][$dispatch_extra]['amount'])) {
            $_REQUEST['product_data'][$dispatch_extra]['amount'] = 1;
        }
        foreach ($_REQUEST['product_data'] as $key => $data) {
            if ($key != $dispatch_extra && $key != 'custom_files') {
                unset($_REQUEST['product_data'][$key]);
            }
        }
    }



    $prev_cart_products = empty($cart['products']) ? array() : $cart['products'];

    fn_add_product_to_cart($_REQUEST['product_data'], $cart, $auth);

    fn_save_cart_content($cart, $auth['user_id']);


   $previous_state = md5(serialize($cart['products']));
    $cart['change_cart_products'] = true;
    fn_calculate_cart_content($cart, $auth, 'S', true, 'F', true);



    if (md5(serialize($cart['products'])) != $previous_state && empty($cart['skip_notification'])) {
        $product_cnt = 0;
        $added_products = array();


        if (!empty($added_products)) {
            Registry::get('view')->assign('added_products', $added_products);

            if (Registry::get('config.tweaks.disable_dhtml') && Registry::get('config.tweaks.redirect_to_cart')) {
                Registry::get('view')->assign('continue_url', (!empty($_REQUEST['redirect_url']) && empty($_REQUEST['appearance']['details_page'])) ? $_REQUEST['redirect_url'] : $_SESSION['continue_url']);

               }


             fn_redirect(Registry::get('config.https_location') . "/checkout");
          // $msg = Registry::get('view')->fetch('views/checkout/components/product_notification.tpl');

           //fn_set_notification('I', __($product_cnt > 1 ? 'products_added_to_cart' : 'product_added_to_cart'), $msg, 'I');
            $cart['recalculate'] = true;
        } else {
            fn_set_notification('N', __('notice'), __('product_in_cart'));
        }
    }

    unset($cart['skip_notification']);

    $_suffix = '.checkout';
}

`

挂钩模板:add_to_cart.post.tpl

{$id = "buy_now_{$product.product_id}"}
<button id="opener_{$id}" name="dispatch[buy_now.add..{$product.product_id}]"  class=" vs-button buynow_btn_">Buy Now</button>

我考虑将您的fn_redirect(“ checkout”)代码放入if / else语句中,以查看发生了什么。

如果您有此代码:

    fn_add_product_to_cart($_REQUEST['product_data'], $cart, $auth);

那么,您确定可以将重定向重定向到其下方的结帐页面吗?

    $redirect_url = "http://testcheckout.com?test=test"; //change this!
    $errorMessage = "I should have redirected already....";
    if (!empty($redirect_url)) {
        //if it's not empty then it should redirect.
        fn_redirect($redirect_url);

       //Then put a die statement in here just to check it's not executing
       //anything else and you can see if the redirect has a problem: 
       die(print_r($errorMessage, true ));
    } 
    else {
        //otherwise there is a problem with the supplied redirect url (empty)
        die(print_r($redirect_url, true ));
    }

我还将查看此页面,这可能会有所帮助:

http://forum.cs-cart.com/topic/6873-direct-buy-button/

希望有帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM