<?php

/**
 * Copy Right IJH.CC
 * Each engineer has a duty to keep the code elegant
 * Author @shzhrui<Anhuike@gmail.com>
 * $Id: widget.php 9343 2015-03-24 07:07:00Z youyi $
 */
class Widget_Product extends Model {

    public function index(&$params)
    {
        
    }

    public function cate(&$params)
    {
        $params['tpl'] = 'cate_options.html';
        $data['value'] = $params['value'] ? $params['value'] : 0;
        $from = $params['from'] ? $params['from'] : null;
        $data['tree'] = K::M('product/cate')->items($from);
        return $data;
    }

    public function product(&$params)
    {
        if(!$params['tpl']){
            if(!in_array($params['type'], array('label', 'checkbox', 'radio', 'option'))){
                $params['type'] = 'option';
            }
            $params['tpl'] = 'widget:default/'.$params['type'].'.html';
        }
        $data['value'] = $params['value'] ? $params['value'] : '';
        $data['options'] = K::M('product/product')->options();
        return $data;         
    }

}
