【问题标题】:How to add Buy Now button in cs-cart如何在 cs-cart 中添加“立即购买”按钮
【发布时间】:2015-04-20 08:14:41
【问题描述】:

我正在创建一个立即购买按钮 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>

【问题讨论】:

    标签: php cs-cart


    【解决方案1】:

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

    希望有帮助!

    【讨论】:

    • 它没有打印任何东西。刚刚将产品添加到购物车。
    • 如果你把骰子(print_r($errorMessage, true ));在添加到购物车功能之前,它会打印出什么吗?
    • 还有其他的重定向方法吗?
    • 您能否发布更多您在答案中的代码?如果没有看到更多你尝试过的东西,很难提供任何适合你的实施的东西
    • 请告诉我怎么做?
    猜你喜欢
    • 1970-01-01
    • 2014-06-06
    • 2015-09-22
    • 1970-01-01
    • 1970-01-01
    • 2014-10-05
    • 2013-01-03
    • 2012-08-22
    • 1970-01-01
    相关资源
    最近更新 更多