/home/hdwebsolution/public_html/sareen-1/application/helpers/custom_helper.php
<?php
/*
 * Custom Helpers
 *
 */

if (strpos($_SERVER['REQUEST_URI'], '/index.php') !== false) {
    $ci = &get_instance();
    $ci->load->helper('url');
    redirect(current_url());
    exit();
}

//post method
if (!function_exists('post_method')) {
    function post_method()
    {
        $ci = &get_instance();
        if ($ci->input->method(FALSE) != 'post') {
            exit();
        }
    }
}

//get method
if (!function_exists('get_method')) {
    function get_method()
    {
        $ci = &get_instance();
        if ($ci->input->method(FALSE) != 'get') {
            exit();
        }
    }
}

if (!function_exists('get_active_categories')) {
    function get_active_categories()
    {
        $ci = &get_instance();
        return $ci->general_model->get_all_where('categories', 'category_is_active', '1');
    }
}

if (!function_exists('get_active_featured_categories')) {
    function get_active_featured_categories()
    {
        $ci = &get_instance();
        return $ci->general_model->get_all_where('categories', 'category_is_active', '1', 'category_is_featured', '1');
    }
}

if (!function_exists('get_active_best_selling_products')) {
    function get_active_best_selling_products()
    {
        $ci = &get_instance();
        return $ci->general_model->get_all_where('products', 'product_is_active', '1', 'product_is_best_selling', '1');
    }
}

if (!function_exists('get_active_best_selling_limited_products')) {
    function get_active_best_selling_limited_products($limit)
    {
        $ci = &get_instance();
        return $ci->product_model->get_active_best_selling_limited_products($limit);
    }
}

if (!function_exists('get_active_on_sale_products')) {
    function get_active_on_sale_products()
    {
        $ci = &get_instance();
        return $ci->general_model->get_all_where('products', 'product_is_active', '1', 'product_is_on_sale', '1');
    }
}

if (!function_exists('get_active_new_products')) {
    function get_active_new_products()
    {
        $ci = &get_instance();
        return $ci->general_model->get_all_where('products', 'product_is_active', '1', 'product_is_new', '1');
    }
}

if (!function_exists('get_all_products')) {
    function get_all_products()
    {
        $ci = &get_instance();
        return $ci->general_model->get_all('products');
    }
}

if (!function_exists('get_product_variant_parent')) {
    function get_product_variant_parent($product_id)
    {
        $ci = &get_instance();
        return $ci->product_model->get_product_variant_parent($product_id);
    }
}

if (!function_exists('get_product_variants')) {
    function get_product_variants($product_id, $parent_id)
    {
        $ci = &get_instance();
        return $ci->product_model->get_product_variants($product_id, $parent_id);
    }
}

if (!function_exists('get_all_category_products_novariants')) {
    function get_all_category_products_novariants($category_id)
    {
        $ci = &get_instance();
        $data = $ci->product_model->get_all_category_products_novariants($category_id);

        foreach ($data as $key => $p) {
            if ($p['product_has_variants'] == '1') {
                if ($p['id'] == $p['product_parent_id'] && $p['product_id'] == $p['id']) {
                    //keep
                } else {
                    // remove
                    unset($data[$key]);
                }
            }
        }
        return $data;
    }
}