<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Ajax extends AJAX_Controller  {

    public function __construct()
    {
        parent::__construct();


    }

    public function re_order_list(){

        $result = $this->mProduct_variants->re_order_list(array(
            'product_id'=> RequestInput::post('product_id'),
            'user_id'=> SessionManager::getData('id_user'),
            'list'=> RequestInput::post('list'),
        ));

        echo json_encode($result);return;

    }


    public function removeVariant(){

        $result = $this->mProduct_variants->removeVariant(array(
            'variant_id'=> RequestInput::post('variant_id'),
            'user_id'=> SessionManager::getData('id_user'),
        ));

        echo json_encode($result);return;

    }

    public function createGroup(){

        $result = $this->mProduct_variants->createGrp(array(
            'user_id'=> SessionManager::getData('id_user'),
            'product_id'=> RequestInput::post('product_id'),
            'label'=> RequestInput::post('label'),
            'option_type'=> RequestInput::post('option_type'),
            'value_type'=> RequestInput::post('value_type')
        ));

        if($result[Tags::SUCCESS]==1){
            $data['grp'] = $result[Tags::RESULT];
            echo json_encode(array(
                Tags::SUCCESS=>1,
                Tags::RESULT=> $this->load->view('product_variants/plug/options/group_row',$data,TRUE)
            ));
        }else
            echo json_encode($result);


    }

    public function updateGroup(){

        $result = $this->mProduct_variants->updateGroup(array(
            'user_id'=> SessionManager::getData('id_user'),
            'store_id'=> RequestInput::post('store_id'),
            'variant_id'=> RequestInput::post('variant_id'),
            'product_id'=> RequestInput::post('product_id'),
            'label'=> RequestInput::post('label'),
            'option_type'=> RequestInput::post('option_type'),
            'value_type'=> RequestInput::post('value_type')
        ));

        if($result[Tags::SUCCESS]==1){
            $data['grp'] = $result[Tags::RESULT];
            echo json_encode(array(
                Tags::SUCCESS=>1,
                Tags::RESULT=> $this->load->view('product_variants/plug/options/group_row',$data,TRUE)
            ));
        }else
            echo json_encode($result);


    }


    public function createOption(){

        $result = $this->mProduct_variants->createOption(array(
            'user_id'=> SessionManager::getData('id_user'),
            'product_id'=> RequestInput::post('product_id'),
            'variant_id'=> RequestInput::post('variant_id'),
            'option_price'=> RequestInput::post('option_price'),
            'option_name'=> RequestInput::post('option_name'),
        ));

        if($result[Tags::SUCCESS]==1){
            $data['opt'] = $result[Tags::RESULT];
            echo json_encode(array(
                Tags::SUCCESS=>1,
                Tags::RESULT=> $this->load->view('product_variants/plug/options/option_row',$data,TRUE)
            ));
        }else
            echo json_encode($result);


    }


    public function updateOption(){

        $params = array(
            'user_id'=> SessionManager::getData('id_user'),

            'store_id'=> RequestInput::post('store_id'),
            'product_id'=> RequestInput::post('product_id'),
            'option_name'=> RequestInput::post('option_name'),
            'variant_id'=> RequestInput::post('variant_id'),
            'option_price'=> RequestInput::post('option_price'),
        );


        $result = $this->mProduct_variants->updateOption($params);

        if($result[Tags::SUCCESS]==1){
            $data['opt'] = $result[Tags::RESULT];
            echo json_encode(array(
                Tags::SUCCESS=>1,
                Tags::RESULT=> $this->load->view('product_variants/plug/options/option_row',$data,TRUE)
            ));
        }else
            echo json_encode($result);

    }





}