Функция перенаправления в аддоне cscart не работает
Функция fn_redirect($url,true,true)
не работает, когда я добавляю его в новый аддон в cscart, который я создал. я добавил use Tygh\Registry;
, Но почему это не работает?
В моем аддоне buy now я вызываю fn_redirect в buy_now.php (контроллер). Он выполняет те же функции, что и addtocart. Но он должен быть перенаправлен на страницу оформления заказа после добавления товара в корзину.
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']);
//header("Location: ". Registry::get('config.https_location') . "/checkout");
fn_redirect(Registry::get('config.https_location') . "/checkout",true);
$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();
foreach ($cart['products'] as $key => $data) {
if (empty($prev_cart_products[$key]) || !empty($prev_cart_products[$key]) && $prev_cart_products[$key]['amount'] != $data['amount']) {
$added_products[$key] = $data;
$added_products[$key]['product_option_data'] = fn_get_selected_product_options_info($data['product_options']);
if (!empty($prev_cart_products[$key])) {
$added_products[$key]['amount'] = $data['amount'] - $prev_cart_products[$key]['amount'];
}
$product_cnt += $added_products[$key]['amount'];
}
}
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']);
}
// $msg = Registry::get('view')->fetch('views/checkout/checkout.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';
if (Registry::get('config.tweaks.disable_dhtml') && Registry::get('config.tweaks.redirect_to_cart') && !defined('AJAX_REQUEST')) {
if (!empty($_REQUEST['redirect_url']) && empty($_REQUEST['appearance']['details_page'])) {
$_SESSION['continue_url'] = fn_url_remove_service_params($_REQUEST['redirect_url']);
}
unset($_REQUEST['redirect_url']);
}
}
return array(CONTROLLER_STATUS_REDIRECT, 'checkout.cart');
}
в add_to_cart.post.tpl
{$id = "buy_now_{$product.product_id}"}
<button id="opener_{$id}" name="dispatch[buy_now.add..{$product.product_id}]" onclick="goto_checkout()" data-ca-target-id="content_{$id}" class=" buynow_btn">BUY NOW</button>
1 ответ
Если вы используете его в php-файл контроллера, что-то вроде
app/addons/MY_ADDON/controllers/frontend/MY_ADDON.php
ты можешь использовать
return array(CONTROLLER_STATUS_REDIRECT, $url);