| 10582 |
lgm |
1 |
<?php
|
|
|
2 |
if (!defined('BASEPATH'))
|
|
|
3 |
exit('No direct script access allowed');
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
/*
|
|
|
7 |
* Model for home
|
|
|
8 |
*/
|
|
|
9 |
|
|
|
10 |
Class Product_model extends CI_Model {
|
|
|
11 |
|
|
|
12 |
var $url = '';
|
|
|
13 |
var $parser_model;
|
|
|
14 |
var $parser;
|
|
|
15 |
|
|
|
16 |
function __construct() {
|
|
|
17 |
|
|
|
18 |
// Call the Model constructor
|
|
|
19 |
parent::__construct();
|
|
|
20 |
//load appropriate parser
|
|
|
21 |
$current_client =$this -> config -> item('current_client');
|
|
|
22 |
$model = $current_client.'_model';
|
|
|
23 |
$this->load->model($model);
|
|
|
24 |
$this->parser = $this-> $model;
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
function index($get=array(),$post=array(),$module=array())
|
|
|
30 |
{
|
| 16269 |
amit.gupta |
31 |
log_message('error', "in index ".print_r($get));
|
| 10582 |
lgm |
32 |
//add_call( KEY, METHOD, URL, array of PARAMS, array of CURL_OPTS )
|
|
|
33 |
$this->curlURL('products','get',$get);
|
|
|
34 |
$responses = $this->mcurl->execute();
|
|
|
35 |
$responses = $this->parser->parse_response($responses);
|
|
|
36 |
return $responses;
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
function getProducts($get=array(),$post=array(),$module=array(), $itemcode ,$query)
|
|
|
40 |
{
|
|
|
41 |
$output =array();
|
|
|
42 |
if(isset($module) and !empty($module))
|
|
|
43 |
{
|
|
|
44 |
if(isset($module['header']) and !empty($module['header']))
|
|
|
45 |
{
|
|
|
46 |
foreach($module['header'] as $header)
|
|
|
47 |
{
|
|
|
48 |
|
|
|
49 |
$this->curlURL($header,'get');
|
|
|
50 |
}
|
|
|
51 |
}
|
|
|
52 |
if(isset($module['footer']) and !empty($module['footer']))
|
|
|
53 |
{
|
|
|
54 |
foreach($module['footer'] as $footer)
|
|
|
55 |
{
|
|
|
56 |
$this->curlURL($footer,'get');
|
|
|
57 |
}
|
|
|
58 |
}
|
|
|
59 |
if(isset($module['response']) and !empty($module['response']))
|
|
|
60 |
{
|
|
|
61 |
foreach($module['response'] as $response)
|
|
|
62 |
{
|
|
|
63 |
|
|
|
64 |
if(isset($post) and !empty($post))
|
|
|
65 |
{
|
|
|
66 |
if($this->current_client=='magento' )
|
|
|
67 |
$this->curlURL($response,'get',$post);
|
|
|
68 |
else
|
|
|
69 |
$this->curlURL($response,'get',$post);
|
|
|
70 |
|
|
|
71 |
}
|
|
|
72 |
else
|
|
|
73 |
{
|
| 16269 |
amit.gupta |
74 |
log_message('error',"Befor CurlUrl ".print_r($get,1));
|
|
|
75 |
log_message('error',"Befor CurlUrl ".print_r($itemcode,1));
|
|
|
76 |
log_message('error',"Befor CurlUrl ".print_r($response,1));
|
|
|
77 |
log_message('error',"Befor CurlUrl ".print_r($get,1));
|
| 10582 |
lgm |
78 |
$this->curlURL($response,'get',$get,$itemcode,$query);
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
//add_call( KEY, METHOD, URL, array of PARAMS, array of CURL_OPTS )
|
|
|
87 |
//$this->curlURL('products','get',$get);
|
|
|
88 |
$responses = $this->mcurl->execute();
|
|
|
89 |
if(isset($responses) and !empty($responses))
|
|
|
90 |
$responses = $this->parser->parse_response($responses,$module);
|
|
|
91 |
|
|
|
92 |
|
|
|
93 |
return $responses;
|
|
|
94 |
}
|
| 16269 |
amit.gupta |
95 |
function curlURL($configurl=null,$methodtype='get',$parameter=array(),$itemcode=null,$query=null) {
|
| 10582 |
lgm |
96 |
$params ='';
|
|
|
97 |
$display='';
|
|
|
98 |
$url = $this->config->item('curl_base_url');
|
|
|
99 |
$productsurl =$this->config->item($configurl);
|
| 16269 |
amit.gupta |
100 |
if(isset($productsurl['url']) and !empty($productsurl['url'])) {
|
|
|
101 |
$url .=$productsurl['url'];
|
|
|
102 |
if($productsurl['display']) {
|
|
|
103 |
$display=$productsurl['display'];
|
|
|
104 |
}
|
|
|
105 |
if(empty($parameter)){
|
|
|
106 |
$parameter=$productsurl['params'];
|
|
|
107 |
}
|
|
|
108 |
if(isset($parameter) and !empty($parameter) and $methodtype=='get'){
|
|
|
109 |
$params = $this->parser->prepareParams($parameter,$display);
|
|
|
110 |
log_message('error',"Params befor add_call".print_r($params,1));
|
|
|
111 |
}
|
|
|
112 |
if(isset($parameter) and !empty($parameter) and $methodtype=='post'){
|
|
|
113 |
$params = $this->parser->prepareParams($parameter,$display);
|
|
|
114 |
$methodtype ='post';
|
|
|
115 |
}
|
|
|
116 |
if(!isset($parameter) || empty($parameter)){
|
|
|
117 |
$params =$this->parser->prepareParams('',$display);
|
|
|
118 |
}
|
|
|
119 |
if(isset($itemcode) && $itemcode != null){
|
|
|
120 |
$url .= '/'.$itemcode;
|
|
|
121 |
}
|
|
|
122 |
if(isset($query) && $query != null){
|
|
|
123 |
$params = $query;
|
|
|
124 |
}
|
|
|
125 |
log_message('error',"Params befor add_call".print_r($parameter,1));
|
|
|
126 |
log_message('error',"Params befor add_call".print_r($params,1));
|
|
|
127 |
return $this->mcurl->add_call($configurl,$methodtype,$url,$params);
|
| 10582 |
lgm |
128 |
}
|
| 16269 |
amit.gupta |
129 |
else {
|
|
|
130 |
return '';
|
| 10582 |
lgm |
131 |
}
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
|
|
|
135 |
function nextProducts($get=array(),$post=array(),$module=array())
|
|
|
136 |
{
|
|
|
137 |
|
|
|
138 |
$output =array();
|
|
|
139 |
if(isset($module) and !empty($module))
|
|
|
140 |
{
|
|
|
141 |
if(isset($module['header']) and !empty($module['header']))
|
|
|
142 |
{
|
|
|
143 |
foreach($module['header'] as $header)
|
|
|
144 |
{
|
|
|
145 |
|
|
|
146 |
$this->curlURL($header,'get');
|
|
|
147 |
}
|
|
|
148 |
}
|
|
|
149 |
if(isset($module['footer']) and !empty($module['footer']))
|
|
|
150 |
{
|
|
|
151 |
foreach($module['footer'] as $footer)
|
|
|
152 |
{
|
|
|
153 |
$this->curlURL($footer,'get');
|
|
|
154 |
}
|
|
|
155 |
}
|
|
|
156 |
if(isset($module['response']) and !empty($module['response']))
|
|
|
157 |
{
|
|
|
158 |
foreach($module['response'] as $response)
|
|
|
159 |
{
|
|
|
160 |
if(isset($get) and !empty($get))
|
|
|
161 |
$this->curlURL($response,'get',$get);
|
|
|
162 |
|
|
|
163 |
}
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
//add_call( KEY, METHOD, URL, array of PARAMS, array of CURL_OPTS )
|
|
|
170 |
//$this->curlURL('products','get',$get);
|
|
|
171 |
$responses = $this->mcurl->execute();
|
|
|
172 |
//print_r($responses);
|
|
|
173 |
if(isset($responses) and !empty($responses))
|
|
|
174 |
$responses = $this->parser->parse_response($responses,$module);
|
|
|
175 |
|
|
|
176 |
|
|
|
177 |
return $responses;
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
}
|