Changeset 2964024
- Timestamp:
- 09/07/2023 09:13:31 AM (2 years ago)
- Location:
- drivefx-woocommerce/trunk
- Files:
-
- 3 edited
-
PHCLibrary/utils.php (modified) (3 diffs)
-
class.DriveFxWoocommerce.php (modified) (23 diffs)
-
settings/backend.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
drivefx-woocommerce/trunk/PHCLibrary/utils.php
r2946752 r2964024 982 982 "offset": 0, 983 983 "orderByItems":[], 984 "SelectItems": ["st.ref","st.design","st.familia","s t.stock","'.$priceColumn.'","st.usrdata","st.qttcli"],984 "SelectItems": ["st.ref","st.design","st.familia","sa.stock","'.$priceColumn.'","st.usrdata","st.qttcli"], 985 985 "entityName":"St", 986 986 "filterItems":['.$filterItems.'], … … 1006 1006 //Build Http query using params 1007 1007 //$this->logs->writeFileLog('params:', $this->params); 1008 $this->query = http_build_query ($this->params); 1008 $this->query = http_build_query ($this->params); 1009 1009 1010 //Called webservice that make a request 1010 1011 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); … … 1093 1094 return $response; 1094 1095 } 1096 1097 /******************************************************************* 1098 * --- Query Complex 1 --- * 1099 ********************************************************************/ 1100 /** Header to create Query of webservice called **/ 1101 public function queryComplex1($ch, $credentials, $entityName, $filterItems, $comparison, $filterItem = null, $valueItem = null){ 1102 $this->url = $credentials->backendUrl."/REST/SearchWS/QueryAsEntities"; 1103 // Create map with request parameters 1104 $this->params = array ('itemQuery' => '{"groupByItems":[], 1105 "lazyLoaded":false, 1106 "joinEntities":[], 1107 "orderByItems":[], 1108 "SelectItems":[], 1109 "entityName":"'.$entityName.'", 1110 "filterItems":['.$filterItems.' 1111 { 1112 "comparison":"'.$comparison.'", 1113 "filterItem":"'.$filterItem.'", 1114 "valueItem":"'.$valueItem.'", 1115 "groupItem":1, 1116 "checkNull":false, 1117 "skipCheckType":false, 1118 "type":"Number" 1119 } 1120 ]}' 1121 ); 1122 // Build Http query using params 1123 $this->query = http_build_query ($this->params); 1124 $this->logs->writeFileLog('$this->params', $this->params); 1125 //Called webservice that make a request 1126 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 1127 1128 return $response; 1129 } 1130 1131 /******************************************************************* 1132 * --- Query Complex 2 --- * 1133 ********************************************************************/ 1134 /** Header to create Query of webservice called (ex. paramsQuery2) **/ 1135 public function queryComplex2($ch, $credentials, $entityName, $filterItems){ 1136 $this->url = $credentials->backendUrl."/REST/SearchWS/QueryAsEntities"; 1137 //Create map with request parameters 1138 $this->params = array ('itemQuery' => '{"groupByItems":[], 1139 "lazyLoaded":false, 1140 "joinEntities":[], 1141 "orderByItems":[], 1142 "SelectItems":[], 1143 "entityName":"'.$entityName.'", 1144 "filterItems":['.$filterItems.'] 1145 }' 1146 ); 1147 //Build Http query using params 1148 $this->query = http_build_query($this->params); 1149 1150 //Called webservice that make a request 1151 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 1152 1153 return $response; 1154 } 1155 1156 /******************************************************************* 1157 * --- Query single item + list of filters --- * 1158 ********************************************************************/ 1159 public function queryFiltersList($ch, $credentials, $entityName, $selectItems, $filterItems){ 1160 $this->url = $credentials->backendUrl."/REST/SearchWS/QueryAsEntities"; 1161 //Create map with request parameters 1162 $this->params = array ('itemQuery' => '{"groupByItems":[], 1163 "lazyLoaded":false, 1164 "joinEntities":[], 1165 "orderByItems":[], 1166 "SelectItems":["'.$selectItems.'"] 1167 "entityName":"'.$entityName.'", 1168 "filterItems":['.$filterItems.'] 1169 }' 1170 ); 1171 //Build Http query using params 1172 $this->query = http_build_query($this->params); 1173 1174 //Called webservice that make a request 1175 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 1176 1177 return $response; 1178 } 1179 1180 /******************************************************************* 1181 * --- Query single item + list of filters --- * 1182 ********************************************************************/ 1183 public function queryFStJoinSa($ch, $credentials, $salesPrice, $filterItems, $armazem){ 1184 $this->url = $credentials->backendUrl."/REST/SearchWS/QueryAsEntities"; 1185 //Create map with request parameters 1186 $this->params = array ('itemQuery' => '{"distinct": true, 1187 "groupByItems": [], 1188 "lazyLoaded": false, 1189 "offset": 0, 1190 "orderByItems":[], 1191 "SelectItems": [ 1192 "st.ref", 1193 "st.design", 1194 "st.familia", 1195 "sa.stock", 1196 "st.desctec", 1197 "st.qttcli", 1198 "'.$salesPrice.'" 1199 ], 1200 "entityName": "st", 1201 "filterItems":['.$filterItems.'] 1202 "joinEntities": [{ 1203 "tableName": "sa", 1204 "joinType": 1, 1205 "joinExp": [{ 1206 "filterItem": "sa.ref", 1207 "comparison": 0, 1208 "valueItem": "<#var>st.ref", 1209 "groupItem": 1 1210 }, 1211 { 1212 "filterItem": "sa.armazem", 1213 "comparison": 0, 1214 "valueItem": "'.$armazem.'", 1215 "groupItem": 0 1216 }] 1217 }] 1218 }' 1219 ); 1220 //Build Http query using params 1221 $this->query = http_build_query ($this->params); 1222 //Called webservice that make a request 1223 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 1224 1225 return $response; 1226 } 1227 1095 1228 } 1096 1229 ?> -
drivefx-woocommerce/trunk/class.DriveFxWoocommerce.php
r2946752 r2964024 66 66 'lastUpdateFrom' => array('label' => 'Last update from:', 'type' => 'text', 'required' => false, 'descr' => 'Enter the date since the products were updated in the PHC GO register.<br><i>(Ex: 2022-01-01)</i>', 'notice' => ''), 67 67 'lastUpdateTo' => array('label' => 'Last update to:', 'type' => 'text', 'required' => false, 'descr' => 'Enter the date until the products were updated in the PHC GO register.<br><i>(Ex: 2022-01-31)</i>', 'notice' => ''), 68 'startingTo' => array('label' => 'Starting with:', 'type' => 'text', 'required' => false, 'descr' => 'Filter by the first characters with which the reference begins.<br><i>(ex. Abc)</i>', 'notice' => '') 68 69 ) 69 70 ); … … 717 718 // send response as JSON 718 719 $response = json_decode($response, true); 719 // get the new token and insert in credentials object720 $credentials->token = $response['result'][0]['token'];721 722 720 //$this->logs->writeFileLog('Login response_1:', $response); 723 721 … … 734 732 unset($_SESSION['username']); 735 733 } else { 734 // get the new token and insert in credentials object 735 $credentials->token = $response['result'][0]['token']; 736 736 737 //Save data of login to show in backend.php the other fields (type of invoice and type of order) 737 738 $_SESSION['username'] = $response['result'][0]['username']; … … 2132 2133 //built filters for products query 2133 2134 $filterItems = ""; 2134 if (isset($settings['backend'])){ 2135 $filterItems .= '{ 2136 "comparison":0, 2137 "filterItem":"'.$columnIva.'", 2138 "valueItem":'.$taxIncluded.', 2139 "groupItem":1, 2140 "checkNull":false, 2141 "skipCheckType":false, 2142 "type":"number" 2143 }'; 2144 if (isset($settings['backend']['lastUpdateFrom']) && $settings['backend']['lastUpdateFrom'] != ""){ 2145 $filterItems .= '{ 2146 "comparison":3, 2147 "filterItem":"st.usrdata", 2148 "valueItem":"'.$settings['backend']['lastUpdateFrom'].'", 2149 "groupItem":1, 2150 "checkNull":false, 2151 "skipCheckType":false, 2152 "type":"date" 2153 }'; 2135 if (isset($settings['backend'])) 2136 { 2137 $filterItems .= '{"comparison":0, "filterItem":"'.$columnIva.'", "valueItem":'.$taxIncluded.', "groupItem":1, "checkNull":false, "skipCheckType":false, "type":"number"},'; 2138 2139 if (isset($settings['backend']['lastUpdateFrom']) && $settings['backend']['lastUpdateFrom'] != "") { 2140 $filterItems .= '{"comparison":3, "filterItem":"st.usrdata", "valueItem":"'.$settings['backend']['lastUpdateFrom'].'", "groupItem":1, "checkNull":false, "skipCheckType":false, "type":"date"},'; 2154 2141 } 2155 if (isset($settings['backend']['lastUpdateTo']) && $settings['backend']['lastUpdateTo'] != ""){ 2156 $filterItems .= '{ 2157 "comparison":5, 2158 "filterItem":"st.usrdata", 2159 "valueItem":"'.$settings['backend']['lastUpdateTo'].'", 2160 "groupItem":1, 2161 "checkNull":false, 2162 "skipCheckType":false, 2163 "type":"date" 2164 }'; 2142 if (isset($settings['backend']['lastUpdateTo']) && $settings['backend']['lastUpdateTo'] != "") { 2143 $filterItems .= '{"comparison":5, "filterItem":"st.usrdata", "valueItem":"'.$settings['backend']['lastUpdateTo'].'", "groupItem":1, "checkNull":false, "skipCheckType":false, "type":"date"},'; 2144 } 2145 if (isset($settings['backend']['startingTo']) && $settings['backend']['startingTo'] != "") { 2146 $filterItems .= '{"comparison":6, "filterItem":"st.ref", "valueItem":"'.$settings['backend']['startingTo'].'", "groupItem":1, "checkNull":false, "skipCheckType":false, "type":"date"},'; 2165 2147 } 2166 if (isset($settings['backend']['positiveStock']) && $settings['backend']['positiveStock'] == 'on'){ 2167 $filterItems .= '{ 2168 "comparison":2, 2169 "filterItem":"st.stock", 2170 "valueItem":0, 2171 "groupItem":1, 2172 "checkNull":false, 2173 "skipCheckType":false, 2174 "type":"date" 2175 }'; 2148 if (isset($settings['backend']['positiveStock']) && $settings['backend']['positiveStock'] == 'on') { 2149 $filterItems .= '{"comparison":2, "filterItem":"st.stock", "valueItem":0, "groupItem":1, "checkNull":false, "skipCheckType":false, "type":"date"}'; 2176 2150 } 2177 2151 } 2178 //$this->logs->writeFileLog('Sts filterItems:', $filterItems); 2179 2152 2180 2153 if($_SESSION['gamaDRIVEFX'] < 9 || $settings['backend']['warehouse'] == -1 || $settings['backend']['warehouse'] == ''){ 2181 2154 $response = $this->utils_services->productQuery($ch, $credentials, "st.".$settings['backend']['productPriceColumn'], $filterItems); … … 2195 2168 } else if(count($response['result']) > 0){ 2196 2169 $refArray = ""; 2197 2170 2198 2171 foreach ($response['result'] as $key => $value){ 2199 if($key > 0){2200 $refArray .= ",";2201 }2202 2203 2172 // filter stock - uninvoiced order 2204 2173 if (isset($settings['backend']['filterStock']) && $settings['backend']['filterStock'] == 'on'){ 2205 2174 // Get all the stock (entries) 2206 2175 $responseFilter = $this->utils_services->doubleFilter($ch, $credentials, 'Sl', 'ref', $value['ref'], 'entrada', '1'); 2207 //$this->logs->writeFileLog('listProducts2', $responseFilter); 2208 /* $totalStock = array_reduce( 2209 $responseFilter['result'], 2210 function( $currentTotal, $sl ) { 2211 return $currentTotal += intval($sl["qtt"]); 2212 }, 2213 0 2214 ); */ 2215 2176 2216 2177 if (isset($settings['backend']['positiveStock']) && $settings['backend']['positiveStock'] == 'on'){ 2217 2178 //Extract the customer ordrers from total stock (just if is not negative) 2218 2179 if ($value['stock'] - $value['qttcli'] > 0){ 2219 //if ($totalStock - $value['qttcli'] > 0){2220 //$arrayRef[$value['ref']] = $totalStock - $value['qttcli'];2221 2180 $arrayRef[$value['ref']] = $value['stock'] - $value['qttcli']; 2222 2181 } else { … … 2225 2184 } else { 2226 2185 //Extract the customer ordrers from total stock 2227 //$arrayRef[$value['ref']] = $totalStock - $value['qttcli'];2228 2186 $arrayRef[$value['ref']] = $value['stock'] - $value['qttcli']; 2229 2187 } 2230 2188 } else{ 2231 2189 $arrayRef[$value['ref']] = $value['stock']; 2232 } 2233 $refArray .= '{ 2234 "comparison":0, 2235 "filterItem":"ref", 2236 "valueItem":"'.$value['ref'].'", 2237 "groupItem":9, 2238 "checkNull":false, 2239 "skipCheckType":false, 2240 "type":"Number" 2241 }'; 2242 } 2243 2244 $response = $this->utils_services->paramsQuery3($ch, $credentials, 'St', $refArray); 2245 //$this->logs->writeFileLog('StList response:', $response); 2246 2247 if (curl_error($ch)) { 2248 $this->logs->writeFileLog('listProducts3', $ch); 2249 } else if(empty($response)){ 2250 $this->logs->writeFileLog('listProducts3', 'EMPTY RESPONSE'); 2251 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 2252 $this->logs->writeFileLog('listProducts3', $response['messages'][0]['messageCodeLocale']); 2190 } 2191 } 2192 2193 //Create rows with information of products 2194 $tableProducts = ''; 2195 $tableProducts .= "<thead><tr><th style='text-align: left;'><input type='checkbox' onClick='toggle(this)'/> Select all</th><th style='text-align: left;'>Ref</th><th style='text-align: left;'>Product Name</th><th style='text-align: left;'>Family</th><th style='text-align: left;'>Sale Price</th>"; 2196 2197 if($_SESSION['manageStockParameter'] === 'S' && $_SESSION['gamaDRIVEFX'] >= 9){ 2198 $tableProducts .= "<th style='text-align: right;'>Stock</th></tr></thead>"; 2253 2199 } else { 2254 2255 //Create rows with information of products 2256 $tableProducts = ''; 2257 $tableProducts .= "<thead><tr><th style='text-align: left;'><input type='checkbox' onClick='toggle(this)'/> Select all</th><th style='text-align: left;'>Ref</th><th style='text-align: left;'>Product Name</th><th style='text-align: left;'>Family</th>"; 2258 2259 if($_SESSION['manageStockParameter'] === 'S' && $_SESSION['gamaDRIVEFX'] >= 9){ 2260 $tableProducts .= "<th style='text-align: right;'>Stock</th></tr></thead>"; 2261 } else { 2262 $tableProducts .= "</tr></thead>"; 2263 } 2264 2265 if(is_array($response['result'])){ 2266 if(!empty($settings['backend']['productPriceColumn']) && $settings['backend']['productPriceColumn'] != 'epv0'){ 2267 foreach ($response['result'] as $key => $value) { 2268 2269 # get the list of products by sku, from "wp_postmeta" table (already imported) 2270 global $wpdb; 2271 $product_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value='%s' LIMIT 1", $response['result'][$key]['ref'] ) ); 2272 //$this->logs->writeFileLog('product_id:', $product_id); 2273 2274 //Create Table 2275 $tableProducts .= "<tr>"; 2276 //if(wc_get_product_id_by_sku($response['result'][$key]['ref'])== ""){ // -- temporary deprecated !!! 2277 if($product_id == ""){ 2278 if($arrayRef[$response['result'][$key]['ref']] < 0){ 2279 2280 $tableProducts .= "<td style='text-align: left;'><input type='checkbox' disabled name='checkboxes' value='".$response['result'][$key]['ref']."'></td>"; 2281 } else { 2282 $tableProducts .= "<td style='text-align: left;'><input type='checkbox' name='checkboxes' value='".$response['result'][$key]['ref']."'></td>"; 2283 } 2200 $tableProducts .= "</tr></thead>"; 2201 } 2202 2203 if(is_array($response['result'])){ 2204 if(!empty($settings['backend']['productPriceColumn']) && $settings['backend']['productPriceColumn'] != 'epv0'){ 2205 foreach ($response['result'] as $key => $value) { 2206 2207 # get the list of products by sku, from "wp_postmeta" table (already imported) 2208 global $wpdb; 2209 $product_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value='%s' LIMIT 1", $response['result'][$key]['ref'] ) ); 2210 //$this->logs->writeFileLog('product_id:', $product_id); 2211 2212 //Create Table 2213 $tableProducts .= "<tr>"; 2214 if($product_id == ""){ 2215 if($arrayRef[$response['result'][$key]['ref']] < 0){ 2216 2217 $tableProducts .= "<td style='text-align: left;'><input type='checkbox' disabled name='checkboxes' value='".$response['result'][$key]['ref']."'></td>"; 2284 2218 } else { 2285 $tableProducts .= "<td style='text-align: left;'>< div class='updateStockShop' id='".$response['result'][$key]['ref']."'><img src='".plugins_url('/images/right.png', __FILE__)."' alt='' width='16' height='16'></div></td>";2219 $tableProducts .= "<td style='text-align: left;'><input type='checkbox' name='checkboxes' value='".$response['result'][$key]['ref']."'></td>"; 2286 2220 } 2287 2288 $tableProducts .= "<td style='text-align: left;'>". $response['result'][$key]['ref']. 2289 "</td><td style='text-align: left;'>". $response['result'][$key]['design']. 2290 "</td><td style='text-align: left;'>". $response['result'][$key]['familia']."</td>"; 2291 2292 //Only exists stocks after Star GAMA 2293 if($_SESSION['manageStockParameter'] === 'S' && $_SESSION['gamaDRIVEFX'] >= 9){ 2294 if($response['result'][$key]['stock'] < 0){ 2295 $tableProducts .= "<td style='text-align: right; color: red;'>".$arrayRef[$response['result'][$key]['ref']]."</td></tr>"; 2296 } else { 2297 $tableProducts .= "<td style='text-align: right;'>".$arrayRef[$response['result'][$key]['ref']]."</td></tr>"; 2298 } 2221 } else { 2222 $tableProducts .= "<td style='text-align: left;'><div class='updateStockShop' id='".$response['result'][$key]['ref']."'><img src='".plugins_url('/images/right.png', __FILE__)."' alt='' width='16' height='16'></div></td>"; 2223 } 2224 2225 $tableProducts .= "<td style='text-align: left;'>". $response['result'][$key]['ref']. 2226 "</td><td style='text-align: left;'>". $response['result'][$key]['design']. 2227 "</td><td style='text-align: left;'>". $response['result'][$key]['familia']. 2228 "</td><td style='text-align: left;'>". $response['result'][$key][$settings['backend']['productPriceColumn']]."</td>"; 2229 2230 //Only exists stocks after Star GAMA 2231 if($_SESSION['manageStockParameter'] === 'S' && $_SESSION['gamaDRIVEFX'] >= 9){ 2232 if($response['result'][$key]['stock'] < 0){ 2233 $tableProducts .= "<td style='text-align: right; color: red;'>".$arrayRef[$response['result'][$key]['ref']]."</td></tr>"; 2234 } else { 2235 $tableProducts .= "<td style='text-align: right;'>".$arrayRef[$response['result'][$key]['ref']]."</td></tr>"; 2299 2236 } 2300 2237 } 2301 echo $tableProducts;2302 } else {2303 $this->logs->writeFileLog('listProducts4', 'Products: Empty productPriceColumn');2304 }2305 } 2306 } 2238 } 2239 echo $tableProducts; 2240 } else { 2241 $this->logs->writeFileLog('listProducts4', 'Products: Empty productPriceColumn'); 2242 } 2243 } 2307 2244 } 2308 2245 } … … 2328 2265 // get the temporary token and insert in credentials object 2329 2266 $credentials->token = $response['result'][0]['token']; 2330 2331 2267 //$this->logs->writeFileLog('SaveProducts Login:', $response); 2332 2268 … … 2341 2277 unset($_SESSION['username']); 2342 2278 } else { 2343 2344 2279 //Obtain gama of PHC 2345 2280 $response = $this->utils_services->paramsGetBackEndInfo($ch, $credentials); 2346 2347 2281 //$this->logs->writeFileLog('SaveProducts BackEnd:', $response); 2348 2282 … … 2357 2291 } 2358 2292 2293 // Build the query filters for get the products data 2294 $refList = ""; 2295 foreach ($refs as $ref){ 2296 $refList .= '{"comparison":0, "filterItem":"ref", "valueItem":"'.$ref.'", "groupItem":9, "checkNull":false, "skipCheckType":false, "type":"Number"},'; 2297 } 2298 2299 // current sales price 2300 $salesPrice = "st.".$settings['backend']['productPriceColumn']; 2301 // Build the list of column to obtain from products data 2302 $selectItems = "st.ref, st.design, $salesPrice, st.familia, st.stock, st.desctec, st.qttcli"; 2303 2359 2304 //Verify GAMA or value choose in warehouse dropdown 2360 2305 if($_SESSION['gamaDRIVEFX'] < 9 || $settings['backend']['warehouse'] == -1 || $settings['backend']['warehouse'] == ''){ 2361 if ($settings['backend']['positiveStock'] == 'on'){ 2362 $response = $this->utils_services->filterItem_compare($ch, $credentials, 'St', '2', 'stock', '0'); 2363 } else { 2364 $response = $this->utils_services->entityName_Query($ch, $credentials, 'St'); 2365 } 2306 $response = $this->utils_services->queryFiltersList($ch, $credentials,'St', $selectItems, $refList); 2307 //$this->logs->writeFileLog('list.st:', $response); 2366 2308 } else { 2367 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'Sa', 'armazem', $settings['backend']['warehouse']); 2368 } 2369 2370 //$this->logs->writeFileLog('SaveProducts St ou Sa:', $response); 2309 $response = $this->utils_services->queryFStJoinSa($ch, $credentials, $salesPrice, $refList, $settings['backend']['warehouse']); 2310 //$this->logs->writeFileLog('list.sa:', $response); 2311 } 2371 2312 2372 2313 if (curl_error($ch)) { … … 2376 2317 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 2377 2318 $this->logs->writeFileLog('saveProducts2', $response['messages'][0]['messageCodeLocale']); 2378 } else { 2319 } else { 2320 //If exists products, import 2379 2321 $i = 0; 2380 2322 $count = count($response['result']); 2381 $refArray = ''; 2382 //Create query of products to insert 2323 2383 2324 while ($i < $count) { 2384 foreach ($response['result'][$i] as $key => $value){ 2385 if(is_array($refs)){ 2386 foreach ($refs as $arrayOfRef){ 2387 if($key == "ref" && $arrayOfRef == $value){ 2388 if($i > 0){ 2389 $refArray .= ","; 2390 } 2391 $arrayRef[$value] = $response['result'][$i]['stock']; 2392 2393 $refArray .= '{ 2394 "comparison":0, 2395 "filterItem":"ref", 2396 "valueItem":"'.$value.'", 2397 "groupItem":9, 2398 "checkNull":false, 2399 "skipCheckType":false, 2400 "type":"Number" 2401 }'; 2402 } 2403 } 2325 foreach ($refs as $key => $value) { 2326 if ($value == $response['result'][$i]['ref']) { 2327 //Obtain url of image to save in shop 2328 $settings['backend']['url'] = rtrim($settings['backend']['url'], '/html/'); 2329 $settings['backend']['url'] = rtrim($settings['backend']['url'], '/html'); 2330 $settings['backend']['url'] = rtrim($settings['backend']['url'], '/'); 2331 2332 $thumb_url = ''; 2333 2334 2335 //Add Product 2336 $this->addProduct($response['result'][$i]['design'], 2337 $response['result'][$i]['design'], 2338 $response['result'][$i]['desctec'], 2339 $response['result'][$i]['design'], 2340 $response['result'][$i]['stock'], 2341 $response['result'][$i][$settings['backend']['productPriceColumn']], 2342 $response['result'][$i]['ref'], 2343 'yes', 2344 'visible', 2345 $thumb_url); 2404 2346 } 2405 2347 } 2406 2348 ++$i; 2407 } 2408 2409 //Obtain products from st 2410 $response = $this->utils_services->paramsQuery3($ch, $credentials, 'St', $refArray); 2411 2412 //$this->logs->writeFileLog('SaveList St:', $response); 2413 2414 if (curl_error($ch)) { 2415 $this->logs->writeFileLog('saveProducts3', $ch); 2416 } else if(empty($response)){ 2417 $this->logs->writeFileLog('saveProducts3', 'EMPTY RESPONSE'); 2418 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 2419 $this->logs->writeFileLog('saveProducts3', $response['messages'][0]['messageCodeLocale']); 2420 } else { 2421 //If exists selected products 2422 if(is_array($refs)){ 2423 $i = 0; 2424 $count = count($response['result']); 2425 2426 while ($i < $count) { 2427 foreach ($refs as $key => $value) { 2428 if ($value == $response['result'][$i]['ref']) { 2429 //Obtain url of image to save in shop 2430 $settings['backend']['url'] = rtrim($settings['backend']['url'], '/html/'); 2431 $settings['backend']['url'] = rtrim($settings['backend']['url'], '/html'); 2432 $settings['backend']['url'] = rtrim($settings['backend']['url'], '/'); 2433 2434 $thumb_url = ''; 2435 2436 2437 //Add Product 2438 $this->addProduct($response['result'][$i]['design'], 2439 $response['result'][$i]['design'], 2440 $response['result'][$i]['desctec'], 2441 $response['result'][$i]['design'], 2442 $arrayRef[$response['result'][$i]['ref']], 2443 $response['result'][$i][$settings['backend']['productPriceColumn']], 2444 $response['result'][$i]['ref'], 2445 'yes', 2446 'visible', 2447 $thumb_url); 2448 } 2449 } 2450 ++$i; 2451 } 2452 } 2453 } 2349 } 2454 2350 } 2455 2351 } … … 2476 2372 // get the temporary token and insert in credentials object 2477 2373 $credentials->token = $response['result'][0]['token']; 2478 2479 2374 //$this->logs->writeFileLog('Login response:', $response); 2480 2375 … … 2489 2384 unset($_SESSION['username']); 2490 2385 } else { 2491 2492 //Obtain gama of PHC 2493 $response = $this->utils_services->paramsGetBackEndInfo($ch, $credentials); 2494 //$this->logs->writeFileLog('Get Gama:', $response); 2386 //Obtain gama of PHC 2387 $response = $this->utils_services->paramsGetBackEndInfo($ch, $credentials); 2388 //$this->logs->writeFileLog('Get Gama:', $response); 2495 2389 2496 2390 if (curl_error($ch)) { … … 2503 2397 $_SESSION['gamaDRIVEFX'] = $response['result'][0]["gama"]; 2504 2398 } 2505 2399 // Build the query filters for get the products data 2400 $refList = ""; 2401 foreach ($refs as $ref){ 2402 $refList .= '{"comparison":0, "filterItem":"ref", "valueItem":"'.$ref.'", "groupItem":9, "checkNull":false, "skipCheckType":false, "type":"Number"},'; 2403 } 2404 // current sales price 2405 $salesPrice = "st.".$settings['backend']['productPriceColumn']; 2406 // Build the list of column to obtain from products data 2407 $selectItems = 'st.ref, st.stock, st.qttcli'; 2408 2506 2409 //Verify GAMA or value choose in warehouse dropdown 2507 2410 if($_SESSION['gamaDRIVEFX'] < 9 || $settings['backend']['warehouse'] == -1 || $settings['backend']['warehouse'] == ''){ 2508 $response = $this->utils_services->entityName_Query($ch, $credentials, 'St');2509 2411 2412 $response = $this->utils_services->queryFiltersList($ch, $credentials,'St', $selectItems, $refList); 2510 2413 //$this->logs->writeFileLog('st:', $response); 2511 2414 } else { 2512 //$response = $this->utils_services->filterItem_Query($ch, $credentials, 'Sa', 'armazem', $settings['backend']['warehouse']);2513 $response = $this->utils_services->entityName_Query1($ch, $credentials, $settings['backend']['warehouse']);2415 $response = $this->utils_services->queryFStJoinSa($ch, $credentials, $salesPrice, $refList, $settings['backend']['warehouse']); 2416 //$this->logs->writeFileLog('sa:', $response); 2514 2417 } 2515 2418 … … 2529 2432 $refArray[$i]=array(); 2530 2433 // filter stock - uninvoiced order 2531 if ($settings['backend']['filterStock'] == 'on'){ 2434 if ($settings['backend']['filterStock'] == 'on'){ 2532 2435 // Get all the stock (entries) 2533 2436 $responseFilter = $this->utils_services->doubleFilter($ch, $credentials, 'Sl', 'ref', $response['result'][$i]['ref'], 'entrada', '1'); … … 2540 2443 0 2541 2444 ); 2542 //Extract the customer ord rers from total stock2445 //Extract the customer orders from total stock 2543 2446 $arrayRef[$value] = $totalStock - $response['result'][$i]['qttcli']; 2544 2447 … … 2552 2455 //If exists selected products 2553 2456 foreach ($refArray as $prod) { 2457 2554 2458 //Obtain post_id of postmeta table 2555 2459 //$productID = wc_get_product_id_by_sku($prod['sku']); -- temporary deprecated !!! … … 2598 2502 // get the temporary token and insert in credentials object 2599 2503 $credentials->token = $response['result'][0]['token']; 2600 2601 2504 //$this->logs->writeFileLog('Login response:', $response); 2602 2505 … … 2649 2552 //Update all prices in Woocommerce 2650 2553 foreach($values_touse as $key => $values){ 2651 //$productID = wc_get_product_id_by_sku($key); - temporary deprecated2652 2653 2554 # get the product ID by sku (ref) directly from wp_postmeta table 2654 2555 global $wpdb; … … 2682 2583 // get the temporary token and insert in credentials object 2683 2584 $credentials->token = $response['result'][0]['token']; 2684 2685 2585 //$this->logs->writeFileLog('Login response:', $response); 2686 2586 … … 2695 2595 unset($_SESSION['username']); 2696 2596 } else { 2697 2698 2597 //Obtain gama of PHC 2699 2598 $response = $this->utils_services->paramsGetBackEndInfo($ch, $credentials); … … 2745 2644 } 2746 2645 2747 2748 2646 if( $settings['backend']['warehouse'] != -1 && $settings['backend']['warehouse'] != ''){ 2749 2647 … … 2799 2697 }else{ 2800 2698 for($i=0;$i<sizeof($response['result']);$i++){ 2801 2802 $values_touse[$response['result'][$i]['ref']]['stock']=$response['result'][$i]['stock']; 2803 2699 $values_touse[$response['result'][$i]['ref']]['stock']=$response['result'][$i]['stock']; 2804 2700 } 2805 2701 } … … 2807 2703 2808 2704 foreach($values_touse as $key => $values){ 2809 //$productID = wc_get_product_id_by_sku($key); -- temporary deprecated !!! 2810 2811 # get the product ID by sku (ref) directly from wp_postmeta table 2812 global $wpdb; 2813 $productID = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value='%s' LIMIT 1", $key)); 2814 2815 update_post_meta($productID,'_stock',$values['stock']); 2816 2817 $my_post = array('ID' => $productID, 2818 'post_title' => $values['design'] 2819 ); 2820 2821 wp_update_post( $my_post ); 2822 update_post_meta( $productID, '_price', $values[$settings['backend']['productPriceColumn']] ); 2823 update_post_meta( $productID, '_regular_price', $values[$settings['backend']['productPriceColumn']]); 2824 2825 } 2826 2827 2705 # get the product ID by sku (ref) directly from wp_postmeta table 2706 global $wpdb; 2707 $productID = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value='%s' LIMIT 1", $key)); 2708 2709 update_post_meta($productID,'_stock',$values['stock']); 2710 2711 if($values['stock'] > 0){ 2712 update_post_meta( $productID, '_stock_status', 'instock'); 2713 } else { 2714 update_post_meta( $productID, '_stock_status', 'outofstock'); 2715 } 2716 2717 $my_post = array('ID' => $productID, 'post_title' => $values['design']); 2718 2719 wp_update_post( $my_post ); 2720 update_post_meta( $productID, '_price', $values[$settings['backend']['productPriceColumn']] ); 2721 update_post_meta( $productID, '_regular_price', $values[$settings['backend']['productPriceColumn']]); 2722 } 2828 2723 } 2829 2724 } -
drivefx-woocommerce/trunk/settings/backend.php
r2946752 r2964024 754 754 </tr> 755 755 <?php } break; 756 case 'lastUpdateTo': 756 case 'lastUpdateTo': 757 if((isset($_SESSION['username']) && $_SESSION['username'] != '') && (isset($settings['backend']['createInvoice']) && $settings['backend']['createInvoice'] != '')){ ?> 758 <tr> 759 <th scope="row"> 760 <label for="<?php echo $id ?>"><?php echo $opts['label'] ?></label> 761 </th> 762 <td> 763 <input class="regular-text" id="<?php echo $id ?>" type="<?php echo $opts['type'] ?>" name="<?php echo $name ?>" value="<?php echo $value ?>"> 764 <p class="description"><?php if (isset($opts['descr'])) echo $opts['descr'] ?></p> 765 </td> 766 </tr> 767 <?php } break; 768 case 'startingTo': 757 769 if((isset($_SESSION['username']) && $_SESSION['username'] != '') && (isset($settings['backend']['createInvoice']) && $settings['backend']['createInvoice'] != '')){ ?> 758 770 <tr>
Note: See TracChangeset
for help on using the changeset viewer.