Example #1
0
function fn_update_gift_certificate($gift_cert_data, $gift_cert_id = 0, $params = array())
{
    fn_correct_gift_certificate($gift_cert_data);
    $gift_cert_data['products'] = !empty($gift_cert_data['products']) ? serialize($gift_cert_data['products']) : '';
    if (empty($gift_cert_id)) {
        do {
            $code = fn_generate_gift_certificate_code();
        } while (true == fn_check_gift_certificate_code($code));
        $gift_cert_data = fn_array_merge($gift_cert_data, array('gift_cert_code' => $code, 'timestamp' => TIME));
        if (fn_allowed_for('ULTIMATE') && Registry::get('runtime.company_id')) {
            $gift_cert_data['company_id'] = Registry::get('runtime.company_id');
        }
        $gift_cert_id = db_query("INSERT INTO ?:gift_certificates ?e", $gift_cert_data);
    } else {
        // Change certfificate status
        fn_change_gift_certificate_status($gift_cert_id, $gift_cert_data['status'], '', fn_get_notification_rules(array(), false));
        //if difference then add line in log
        $debit_info = db_get_row("SELECT debit AS amount, debit_products AS products FROM ?:gift_certificates_log WHERE gift_cert_id = ?i ORDER BY timestamp DESC", $gift_cert_id);
        if (empty($debit_info)) {
            $debit_info = db_get_row("SELECT amount, products FROM ?:gift_certificates WHERE gift_cert_id = ?i", $gift_cert_id);
        }
        $is_diff = $gift_cert_data['amount'] - $debit_info['amount'] != 0 || md5($gift_cert_data['products']) != md5($debit_info['products']);
        if ($is_diff == true) {
            $_info = array('amount' => $gift_cert_data['amount'], 'products' => $gift_cert_data['products']);
            fn_add_gift_certificate_log_record($gift_cert_id, $debit_info, $_info);
        }
        //Update certificate data
        $_data = $gift_cert_data;
        db_query("UPDATE ?:gift_certificates SET ?u WHERE gift_cert_id = ?i", $gift_cert_data, $gift_cert_id);
    }
    $gc_data = fn_get_gift_certificate_info($gift_cert_id);
    fn_gift_certificate_notification($gc_data, fn_get_notification_rules($params));
    return $gift_cert_id;
}
if ($mode == 'add') {
    fn_add_breadcrumb(fn_get_lang_var('gift_certificates'), "gift_certificates.manage");
    if (!empty($_REQUEST['user_id'])) {
        $user_data = fn_get_user_info($_REQUEST['user_id']);
        $gift_cert_data = array('send_via' => 'E', 'recipient' => "{$user_data['firstname']} {$user_data['lastname']}", 'sender' => Registry::get('settings.Company.company_name'), 'email' => $user_data['email'], 'address' => $user_data['s_address'], 'address_2' => $user_data['s_address_2'], 'city' => $user_data['s_city'], 'country' => $user_data['s_country'], 'state' => $user_data['s_state'], 'zipcode' => $user_data['s_zipcode'], 'phone' => $user_data['phone']);
        $view->assign('gift_cert_data', $gift_cert_data);
    }
    $view->assign('templates', fn_get_gift_certificate_templates());
    $view->assign('states', fn_get_all_states());
    $view->assign('countries', fn_get_countries(CART_LANGUAGE, true));
    $view->assign('amount_variants', fn_get_gift_certificate_amount_variants());
} elseif ($mode == 'update') {
    fn_add_breadcrumb(fn_get_lang_var('gift_certificates'), "gift_certificates.manage.reset_view");
    fn_add_breadcrumb(fn_get_lang_var('search_results'), "gift_certificates.manage.last_view");
    $gift_cert_id = intval($_REQUEST['gift_cert_id']);
    $gift_cert_data = fn_get_gift_certificate_info($gift_cert_id);
    if (empty($gift_cert_data)) {
        return array(CONTROLLER_STATUS_NO_PAGE);
    }
    // [Page sections]
    Registry::set('navigation.tabs', array('detailed' => array('title' => fn_get_lang_var('detailed_info'), 'js' => true), 'log' => array('title' => fn_get_lang_var('history'), 'js' => true)));
    // [/Page sections]
    list($log, $sort_order, $sort_by) = fn_get_gift_certificate_log($gift_cert_id, $_REQUEST);
    $view->assign('log', $log);
    $view->assign('sort_order', $sort_order);
    $view->assign('sort_by', $sort_by);
    if (false != ($last_item = reset($log))) {
        $gift_cert_data['amount'] = $last_item['debit'];
        $gift_cert_data['products'] = $last_item['debit_products'];
    }
    $view->assign('templates', fn_get_gift_certificate_templates());
Example #3
0
        }
        Tygh::$app['view']->assign('verify_data', $verify_data);
    } else {
        fn_set_notification('W', __('warning'), __('error_gift_cert_code'));
        if (defined('AJAX_REQUEST')) {
            exit;
        }
    }
} elseif ($mode == 'add') {
    fn_add_breadcrumb(__('gift_certificates'));
    Tygh::$app['view']->assign('templates', fn_get_gift_certificate_templates());
    Tygh::$app['view']->assign('states', fn_get_all_states());
    Tygh::$app['view']->assign('countries', fn_get_simple_countries(true, CART_LANGUAGE));
} elseif ($mode == 'update') {
    if (!empty($_REQUEST['gift_cert_id']) && !isset($_SESSION['cart']['gift_certificates'][$_REQUEST['gift_cert_id']])) {
        return array(CONTROLLER_STATUS_REDIRECT, 'gift_certificates.add');
    }
    fn_add_breadcrumb(__('gift_certificates'));
    if (!empty($_REQUEST['gift_cert_id'])) {
        $gift_cert_data = fn_get_gift_certificate_info($_REQUEST['gift_cert_id'], 'C');
        if (!empty($gift_cert_data['extra']['exclude_from_calculate'])) {
            return array(CONTROLLER_STATUS_NO_PAGE);
        }
        Tygh::$app['view']->assign('gift_cert_data', $gift_cert_data);
        Tygh::$app['view']->assign('gift_cert_id', $_REQUEST['gift_cert_id']);
    }
    Tygh::$app['view']->assign('templates', fn_get_gift_certificate_templates());
    Tygh::$app['view']->assign('states', fn_get_all_states());
    Tygh::$app['view']->assign('countries', fn_get_simple_countries(true, CART_LANGUAGE));
    Tygh::$app['view']->assign('type', 'C');
}
Example #4
0
function fn_gift_certificates_order_notification(&$order_info, &$order_statuses, &$force_notification)
{
    if (isset($order_info['gift_certificates'])) {
        foreach ($order_info['gift_certificates'] as $k => $v) {
            if (!empty($order_statuses[$order_info['status']]['params']['gift_cert_status'])) {
                $gift_cert_data = fn_get_gift_certificate_info($v['gift_cert_id'], 'B');
                fn_gift_certificate_notification($gift_cert_data, $force_notification);
            }
        }
    }
}
        return array(CONTROLLER_STATUS_REDIRECT, 'wishlist.view');
    }
    if ($mode == 'update') {
        if (!empty($_REQUEST['gift_cert_data']) && !empty($_REQUEST['gift_cert_id']) && $_REQUEST['type'] == 'W') {
            fn_delete_wishlist_gift_certificate($wishlist, $_REQUEST['gift_cert_id']);
            list($gift_cert_id, $gift_cert) = fn_add_gift_certificate_to_wishlist($wishlist, $_REQUEST['gift_cert_data']);
            if (!empty($gift_cert_id)) {
                $wishlist['gift_certificates'][$gift_cert_id] = $gift_cert;
            }
            fn_save_cart_content($wishlist, $auth['user_id'], $_REQUEST['type']);
            return array(CONTROLLER_STATUS_REDIRECT, 'wishlist.view');
        }
    }
    if ($mode == 'wishlist_delete') {
        if (isset($_REQUEST['gift_cert_wishlist_id'])) {
            fn_delete_cart_gift_certificate($_SESSION['wishlist'], $_REQUEST['gift_cert_wishlist_id']);
        }
        return array(CONTROLLER_STATUS_REDIRECT, 'wishlist.view');
    }
}
if ($mode == 'update') {
    if (!empty($_REQUEST['gift_cert_wishlist_id'])) {
        $gift_cert_data = fn_get_gift_certificate_info($_REQUEST['gift_cert_wishlist_id'], 'W');
        if (!empty($gift_cert_data['extra']['exclude_from_calculate'])) {
            return array(CONTROLLER_STATUS_NO_PAGE);
        }
        Registry::get('view')->assign('gift_cert_data', $gift_cert_data);
        Registry::get('view')->assign('gift_cert_id', $_REQUEST['gift_cert_wishlist_id']);
        Registry::get('view')->assign('type', 'W');
    }
}