Plugin Directory

Changeset 2964024


Ignore:
Timestamp:
09/07/2023 09:13:31 AM (2 years ago)
Author:
phcwordpress
Message:

UPD 20230907

Location:
drivefx-woocommerce/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • drivefx-woocommerce/trunk/PHCLibrary/utils.php

    r2946752 r2964024  
    982982                                                "offset": 0,
    983983                                                "orderByItems":[],
    984                                                 "SelectItems": ["st.ref","st.design","st.familia","st.stock","'.$priceColumn.'","st.usrdata","st.qttcli"],
     984                                                "SelectItems": ["st.ref","st.design","st.familia","sa.stock","'.$priceColumn.'","st.usrdata","st.qttcli"],
    985985                                                "entityName":"St",
    986986                                                "filterItems":['.$filterItems.'],
     
    10061006        //Build Http query using params
    10071007        //$this->logs->writeFileLog('params:', $this->params);
    1008         $this->query = http_build_query ($this->params);     
     1008        $this->query = http_build_query ($this->params); 
     1009
    10091010        //Called webservice that make a request
    10101011        $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials);
     
    10931094        return $response;
    10941095    }
     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
    10951228}
    10961229?>
  • drivefx-woocommerce/trunk/class.DriveFxWoocommerce.php

    r2946752 r2964024  
    6666                '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' => ''),
    6767                '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' => '')
    6869            )
    6970        );
     
    717718            // send response as JSON
    718719            $response = json_decode($response, true);
    719             // get the new token and insert in credentials object
    720             $credentials->token = $response['result'][0]['token'];
    721 
    722720            //$this->logs->writeFileLog('Login response_1:', $response);
    723721
     
    734732                unset($_SESSION['username']);
    735733            } else {
     734                 // get the new token and insert in credentials object
     735                $credentials->token = $response['result'][0]['token'];
     736
    736737                //Save data of login to show in backend.php the other fields (type of invoice and type of order)
    737738                $_SESSION['username'] = $response['result'][0]['username'];
     
    21322133                //built filters for products query
    21332134                $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"},';
    21542141                    } 
    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"},';
    21652147                    }                   
    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"}';
    21762150                    }                   
    21772151                }
    2178                 //$this->logs->writeFileLog('Sts filterItems:', $filterItems);
    2179 
     2152               
    21802153                if($_SESSION['gamaDRIVEFX'] < 9 || $settings['backend']['warehouse'] == -1 || $settings['backend']['warehouse'] == ''){             
    21812154                    $response = $this->utils_services->productQuery($ch, $credentials, "st.".$settings['backend']['productPriceColumn'], $filterItems);
     
    21952168                } else if(count($response['result']) > 0){
    21962169                    $refArray = "";
    2197                    
     2170
    21982171                    foreach ($response['result'] as $key => $value){
    2199                         if($key > 0){
    2200                             $refArray .= ",";
    2201                         }
    2202 
    22032172                        // filter stock - uninvoiced order
    22042173                        if (isset($settings['backend']['filterStock']) && $settings['backend']['filterStock'] == 'on'){
    22052174                            // Get all the stock (entries)
    22062175                            $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                                   
    22162177                            if (isset($settings['backend']['positiveStock']) && $settings['backend']['positiveStock'] == 'on'){
    22172178                                //Extract the customer ordrers from total stock (just if is not negative)
    22182179                                if ($value['stock'] - $value['qttcli'] > 0){
    2219                                     //if ($totalStock - $value['qttcli'] > 0){
    2220                                     //$arrayRef[$value['ref']] = $totalStock - $value['qttcli'];
    22212180                                    $arrayRef[$value['ref']] = $value['stock'] - $value['qttcli'];
    22222181                                } else {
     
    22252184                            } else {
    22262185                                //Extract the customer ordrers from total stock                     
    2227                                 //$arrayRef[$value['ref']] = $totalStock - $value['qttcli'];
    22282186                                $arrayRef[$value['ref']] = $value['stock'] - $value['qttcli'];
    22292187                            }
    22302188                        } else{
    22312189                            $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>";
    22532199                    } 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>";
    22842218                                    } 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>";
    22862220                                    }
    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>";
    22992236                                    }
    23002237                                }
    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                    }               
    23072244                }
    23082245            }
     
    23282265                // get the temporary token and insert in credentials object
    23292266                $credentials->token = $response['result'][0]['token'];
    2330 
    23312267                //$this->logs->writeFileLog('SaveProducts Login:', $response);
    23322268
     
    23412277                    unset($_SESSION['username']);
    23422278                } else {
    2343 
    23442279                    //Obtain gama of PHC
    23452280                    $response = $this->utils_services->paramsGetBackEndInfo($ch, $credentials);
    2346 
    23472281                    //$this->logs->writeFileLog('SaveProducts BackEnd:', $response);
    23482282
     
    23572291                    }
    23582292
     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           
    23592304                    //Verify GAMA or value choose in warehouse dropdown
    23602305                    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);
    23662308                    } 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                    }
    23712312
    23722313                    if (curl_error($ch)) {
     
    23762317                    } else if(isset($response['messages'][0]['messageCodeLocale'])){
    23772318                        $this->logs->writeFileLog('saveProducts2', $response['messages'][0]['messageCodeLocale']);
    2378                     } else {
     2319                    } else {                       
     2320                        //If exists products, import                   
    23792321                        $i = 0;
    23802322                        $count = count($response['result']);
    2381                         $refArray = '';
    2382                         //Create query of products to insert
     2323
    23832324                        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);
    24042346                                }
    24052347                            }
    24062348                            ++$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                        }                   
    24542350                    }
    24552351                }
     
    24762372                // get the temporary token and insert in credentials object
    24772373                $credentials->token = $response['result'][0]['token'];
    2478 
    24792374                //$this->logs->writeFileLog('Login response:', $response);
    24802375
     
    24892384                    unset($_SESSION['username']);
    24902385                } 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);
    24952389
    24962390                    if (curl_error($ch)) {
     
    25032397                        $_SESSION['gamaDRIVEFX'] = $response['result'][0]["gama"];
    25042398                    }
    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           
    25062409                    //Verify GAMA or value choose in warehouse dropdown
    25072410                    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);
    25102413                        //$this->logs->writeFileLog('st:', $response);
    25112414                    } 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);                 
    25142417                    }
    25152418
     
    25292432                                $refArray[$i]=array();
    25302433                                // filter stock - uninvoiced order
    2531                                 if ($settings['backend']['filterStock'] == 'on'){
     2434                                if ($settings['backend']['filterStock'] == 'on'){ 
    25322435                                    // Get all the stock (entries)
    25332436                                    $responseFilter = $this->utils_services->doubleFilter($ch, $credentials, 'Sl', 'ref', $response['result'][$i]['ref'], 'entrada', '1');
     
    25402443                                        0
    25412444                                    );
    2542                                     //Extract the customer ordrers from total stock
     2445                                    //Extract the customer orders from total stock
    25432446                                    $arrayRef[$value] = $totalStock - $response['result'][$i]['qttcli'];
    25442447
     
    25522455                        //If exists selected products
    25532456                        foreach ($refArray as $prod) {
     2457
    25542458                            //Obtain post_id of postmeta table
    25552459                            //$productID = wc_get_product_id_by_sku($prod['sku']); -- temporary deprecated !!!
     
    25982502                // get the temporary token and insert in credentials object
    25992503                $credentials->token = $response['result'][0]['token'];
    2600 
    26012504                //$this->logs->writeFileLog('Login response:', $response);
    26022505
     
    26492552                        //Update all prices in Woocommerce
    26502553                        foreach($values_touse as $key => $values){
    2651                             //$productID = wc_get_product_id_by_sku($key);  - temporary deprecated
    2652 
    26532554                            # get the product ID by sku (ref) directly from wp_postmeta table
    26542555                            global $wpdb;
     
    26822583                // get the temporary token and insert in credentials object
    26832584                $credentials->token = $response['result'][0]['token'];
    2684 
    26852585                //$this->logs->writeFileLog('Login response:', $response);
    26862586
     
    26952595                    unset($_SESSION['username']);
    26962596                } else {
    2697 
    26982597                     //Obtain gama of PHC
    26992598                     $response = $this->utils_services->paramsGetBackEndInfo($ch, $credentials);
     
    27452644                            }
    27462645
    2747 
    27482646                            if( $settings['backend']['warehouse'] != -1 && $settings['backend']['warehouse'] != ''){
    27492647
     
    27992697                                }else{
    28002698                                    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'];
    28042700                                    }
    28052701                                }
     
    28072703
    28082704                        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                        }
    28282723                    }
    28292724                }
  • drivefx-woocommerce/trunk/settings/backend.php

    r2946752 r2964024  
    754754          </tr>
    755755            <?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':
    757769          if((isset($_SESSION['username']) && $_SESSION['username'] != '') && (isset($settings['backend']['createInvoice']) && $settings['backend']['createInvoice'] != '')){ ?>
    758770          <tr>
Note: See TracChangeset for help on using the changeset viewer.