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

时间:2015-04-20 08:14:42

标签: php 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';
}

`

hook模板: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>

1 个答案:

答案 0 :(得分:0)

我会考虑将你的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/

希望有所帮助!