Ejemplo n.º 1
0
function fn_delete_company($company_id)
{
    if (empty($company_id)) {
        return false;
    }
    //TODO log_event
    // Log user deletion
    /*fn_log_event('companies', 'delete', array (
    		'company_id' => $company_id
    	));*/
    $condition = fn_get_company_condition('company_id');
    $company_id = db_get_field("SELECT company_id FROM ?:companies WHERE 1 {$condition} AND company_id = ?i", $company_id);
    if (empty($company_id)) {
        return false;
    }
    db_query("DELETE FROM ?:companies WHERE company_id = ?i", $company_id);
    // deleting products
    $product_ids = db_get_fields("SELECT product_id FROM ?:products WHERE company_id = ?i", $company_id);
    foreach ($product_ids as $product_id) {
        fn_delete_product($product_id);
    }
    // deleting shipping
    $shipping_ids = db_get_fields("SELECT shipping_id FROM ?:shippings WHERE company_id = ?i", $company_id);
    foreach ($shipping_ids as $shipping_id) {
        fn_delete_shipping($shipping_id);
    }
    if (PRODUCT_TYPE == 'MULTIVENDOR') {
        db_query("DELETE FROM ?:company_descriptions WHERE company_id = ?i", $company_id);
        // deleting product_options
        $option_ids = db_get_fields("SELECT option_id FROM ?:product_options WHERE company_id = ?i", $company_id);
        foreach ($option_ids as $option_id) {
            fn_delete_product_option($option_id);
        }
        // deleting orders
        $order_ids = db_get_fields("SELECT order_id FROM ?:orders WHERE company_id = ?i", $company_id);
        foreach ($order_ids as $order_id) {
            fn_delete_order($order_id);
        }
        // deleting users
        $user_ids = db_get_fields("SELECT user_id FROM ?:users WHERE company_id = ?i", $company_id);
        foreach ($user_ids as $user_id) {
            fn_delete_user($user_id);
        }
        // deleting pages
        $page_ids = db_get_fields("SELECT page_id FROM ?:pages WHERE company_id = ?i", $company_id);
        foreach ($page_ids as $page_id) {
            fn_delete_page($page_id);
        }
        // deleting promotions
        $promotion_ids = db_get_fields("SELECT promotion_id FROM ?:promotions WHERE company_id = ?i", $company_id);
        fn_delete_promotions($promotion_ids);
    }
    //db_query("UPDATE ?:orders SET user_id = 0 WHERE company_id = ?i", $company_id);
    fn_set_hook('delete_company', $company_id);
    return true;
}
Ejemplo n.º 2
0
function fn_delete_company($company_id)
{
    if (empty($company_id)) {
        return false;
    }
    if (fn_allowed_for('MULTIVENDOR')) {
        // Do not delete vendor if there're any orders associated with this company
        if (db_get_field("SELECT COUNT(*) FROM ?:orders WHERE company_id = ?i", $company_id)) {
            fn_set_notification('W', __('warning'), __('unable_delete_vendor_orders_exists'), '', 'company_has_orders');
            return false;
        }
    }
    fn_set_hook('delete_company_pre', $company_id);
    $result = db_query("DELETE FROM ?:companies WHERE company_id = ?i", $company_id);
    // deleting categories
    $cat_ids = db_get_fields("SELECT category_id FROM ?:categories WHERE company_id = ?i", $company_id);
    foreach ($cat_ids as $cat_id) {
        fn_delete_category($cat_id, false);
    }
    // deleting products
    $product_ids = db_get_fields("SELECT product_id FROM ?:products WHERE company_id = ?i", $company_id);
    foreach ($product_ids as $product_id) {
        fn_delete_product($product_id);
    }
    // deleting shipping
    $shipping_ids = db_get_fields("SELECT shipping_id FROM ?:shippings WHERE company_id = ?i", $company_id);
    foreach ($shipping_ids as $shipping_id) {
        fn_delete_shipping($shipping_id);
    }
    if (fn_allowed_for('ULTIMATE')) {
        // deleting layouts
        $layouts = Layout::instance($company_id)->getList();
        foreach ($layouts as $layout_id => $layout) {
            Layout::instance($company_id)->delete($layout_id);
        }
    }
    $blocks = Block::instance($company_id)->getAllUnique();
    foreach ($blocks as $block) {
        Block::instance($company_id)->remove($block['block_id']);
    }
    $product_tabs = ProductTabs::instance($company_id)->getList();
    foreach ($product_tabs as $product_tab) {
        ProductTabs::instance($company_id)->delete($product_tab['tab_id'], true);
    }
    $_menus = Menu::getList(db_quote(" AND company_id = ?i", $company_id));
    foreach ($_menus as $menu) {
        Menu::delete($menu['menu_id']);
    }
    db_query("DELETE FROM ?:company_descriptions WHERE company_id = ?i", $company_id);
    // deleting product_options
    $option_ids = db_get_fields("SELECT option_id FROM ?:product_options WHERE company_id = ?i", $company_id);
    foreach ($option_ids as $option_id) {
        fn_delete_product_option($option_id);
    }
    // deleting company admins and users
    if (Registry::get('settings.Stores.share_users') != 'Y') {
        $users_condition = db_quote(' OR company_id = ?i', $company_id);
    } else {
        $users_condition = '';
        // Unassign users from deleted company
        db_query('UPDATE ?:users SET company_id = 0 WHERE company_id = ?i', $company_id);
    }
    $user_ids = db_get_fields("SELECT user_id FROM ?:users WHERE company_id = ?i AND user_type = ?s ?p", $company_id, 'V', $users_condition);
    foreach ($user_ids as $user_id) {
        fn_delete_user($user_id);
    }
    // deleting pages
    $page_ids = db_get_fields("SELECT page_id FROM ?:pages WHERE company_id = ?i", $company_id);
    foreach ($page_ids as $page_id) {
        fn_delete_page($page_id);
    }
    // deleting promotions
    $promotion_ids = db_get_fields("SELECT promotion_id FROM ?:promotions WHERE company_id = ?i", $company_id);
    fn_delete_promotions($promotion_ids);
    // deleting features
    $feature_ids = db_get_fields("SELECT feature_id FROM ?:product_features WHERE company_id = ?i", $company_id);
    foreach ($feature_ids as $feature_id) {
        fn_delete_feature($feature_id);
    }
    // deleting logos
    $types = fn_get_logo_types();
    foreach ($types as $type => $data) {
        fn_delete_logo($type, $company_id);
    }
    $payment_ids = db_get_fields('SELECT payment_id FROM ?:payments WHERE company_id = ?i', $company_id);
    foreach ($payment_ids as $payment_id) {
        fn_delete_payment($payment_id);
    }
    // Delete sitemap sections and links
    $params = array('company_id' => $company_id);
    $section_ids = fn_get_sitemap_sections($params);
    fn_delete_sitemap_sections(array_keys($section_ids));
    fn_set_hook('delete_company', $company_id, $result);
    return $result;
}
Ejemplo n.º 3
0
        Registry::get('view')->assign('condition_data', array('condition' => $_REQUEST['condition']));
    } elseif (!empty($_REQUEST['bonus'])) {
        Registry::get('view')->assign('bonus_data', array('bonus' => $_REQUEST['bonus']));
    }
    if (fn_allowed_for('ULTIMATE') && !Registry::get('runtime.company_id')) {
        Registry::get('view')->assign('picker_selected_companies', fn_ult_get_controller_shared_companies($_REQUEST['promotion_id'], 'promotions', 'update'));
    }
    // promotions list
} elseif ($mode == 'manage') {
    list($promotions, $search) = fn_get_promotions($_REQUEST, Registry::get('settings.Appearance.admin_elements_per_page'), DESCR_SL);
    Registry::get('view')->assign('search', $search);
    Registry::get('view')->assign('promotions', $promotions);
    // Delete selected promotions
} elseif ($mode == 'delete') {
    if (!empty($_REQUEST['promotion_id'])) {
        fn_delete_promotions($_REQUEST['promotion_id']);
    }
    return array(CONTROLLER_STATUS_REDIRECT, "promotions.manage");
}
function fn_update_promotion($data, $promotion_id, $lang_code = DESCR_SL)
{
    if (!empty($data['conditions']['conditions'])) {
        $data['conditions_hash'] = fn_promotion_serialize($data['conditions']['conditions']);
        $data['users_conditions_hash'] = fn_promotion_serialize_users_conditions($data['conditions']['conditions']);
    } else {
        $data['conditions_hash'] = $data['users_conditions_hash'] = '';
    }
    $data['conditions'] = empty($data['conditions']) ? array() : $data['conditions'];
    $data['bonuses'] = empty($data['bonuses']) ? array() : $data['bonuses'];
    fn_promotions_check_group_conditions($data['conditions']);
    if ($data['bonuses']) {