Στη γέφυρα της EMDI για OpenCart προσθέτουμε το κώδικα
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
// ΥΠΟΛΟΓΙΣΜΟΣ ΕΚΠΤΩΣΕΩΝ if ($action == 'calc_discounts') { $debug=0; //ΕΥΡΕΣΗ ΠΕΛΑΤΩΝ ΜΕ ΕΙΔΙΚΕΣ ΣΥΝΘΗΚΕΣ ΕΚΠΤΩΣΕΩΝ $query=" select cust.customer_id, cust.customer_group_id, ( SELECT (select GROUP_CONCAT( concat( manuf.manufacturer_id,'|',manuf.name) ) from " . $dbprefix . "manufacturer manuf where hist.comment like concat('%,',manuf.name,'%') ) FROM " . $dbprefix . "customer_group_description descr," . $dbprefix . "customer_history hist where descr.language_id=$lang_id and descr.name like '%\%' and hist.comment like descr.name and hist.customer_id=cust.customer_id order by hist.date_added desc limit 1 ) manufacturers_ids , ( SELECT hist.comment FROM " . $dbprefix . "customer_group_description descr," . $dbprefix . "customer_history hist where descr.language_id=$lang_id and descr.name like '%\%' and hist.comment like descr.name and hist.customer_id=cust.customer_id order by hist.date_added desc limit 1 ) hist_comment , ( SELECT descr.customer_group_id FROM " . $dbprefix . "customer_group_description descr," . $dbprefix . "customer_history hist where descr.language_id=$lang_id and descr.name like '%\%' and hist.comment like descr.name and hist.customer_id=cust.customer_id order by hist.date_added desc limit 1 ) new_customer_group from " . $dbprefix . "customer cust where cust.customer_group_id>$min_customer_group and ( SELECT hist.comment FROM " . $dbprefix . "customer_group_description descr," . $dbprefix . "customer_history hist where descr.language_id=$lang_id and descr.name like '%\%' and hist.comment like descr.name and hist.customer_id=cust.customer_id order by hist.date_added desc limit 1 ) is not null "; $data = mysqli_query($link, $query) or die(mysqli_error($link)); //ΛΙΣΤΑ ΕΙΔΩΝ while ($alldata = mysqli_fetch_array($data)) { $typedata = explode(',', $alldata['hist_comment']); $manuf_ids = explode(',', $alldata['manufacturers_ids']); $new_customer_group_name=$alldata[customer_id].'_'.$typedata[0]; //ΔΗΜΙΟΥΡΓΙΑ ΣΥΝΔΥΑΣΜΩΝ $newtype=''; foreach ($manuf_ids as $manuf_id){ $exmanu = explode('|', $manuf_id); //echo $exmanu[0].'@@@@@@'.$exmanu[1].'##<br>'; foreach ($typedata as $typed){ $groupdata = explode(' ', $typed); $percent = str_ireplace('%', '', $groupdata[count($groupdata) - 1]); $newname =trim(str_ireplace($percent.'%', '', $typed)); //echo '#######'.$newname.'@@@@@@'; if ($newname==$exmanu[1]) { $newtype=$newtype.trim($exmanu[0]).'|'.trim($percent).','; break; } } } //ΕΛΕΓΧΟΣ ΓΙΑ ΤΟ ΑΝ ΥΠΑΡΧΕΙ Η ΟΜΑΔΑ ΠΕΛΑΤΩΝ $result = mysqli_query($link, "SELECT customer_group_id FROM " . $dbprefix . "customer_group_description where name='$new_customer_group_name' and language_id=$lang_id" ) or die(mysqli_error($link)); $count = mysqli_fetch_assoc($result) ['customer_group_id']; if (!$count) { //ΔΗΜΙΟΥΡΓΙΑ ΝΕΑΣ ΟΜΑΔΑΣ ΠΕΛΑΤΩΝ $result = mysqli_query($link,"INSERT INTO " . $dbprefix . "customer_group ( approval, sort_order) VALUES (1, 0)") or die(mysqli_error($link)); $last_id = $link->insert_id; $result = mysqli_query($link,"INSERT INTO " . $dbprefix . "customer_group_description (customer_group_id, language_id, name, description) VALUES ($last_id, $lang_id, '$new_customer_group_name', '$newtype')") or die(mysqli_error($link)); // ΕΝΗΜΕΡΩΣΗ ΟΜΑΔΑΣ ΣΕ ΠΕΛΑΤΗ $result = mysqli_query($link,"update " . $dbprefix . "customer set customer_group_id=$last_id where customer_id=$alldata[customer_id]") or die(mysqli_error($link)); // ΕΝΕΡΓΟΠΟΙΗΣΗ ΦΠΑ $data2 = mysqli_query($link, "SELECT tax_rate_id FROM " . $dbprefix . "tax_rate") or die(mysqli_error($link)); while ($alldata2 = mysqli_fetch_array($data2)) { $result = mysqli_query($link," INSERT INTO " . $dbprefix . "tax_rate_to_customer_group (tax_rate_id, customer_group_id) VALUES (".$alldata2['tax_rate_id'].", $last_id) ") or die(mysqli_error($link)); } } else { $result = mysqli_query($link,"update " . $dbprefix . "customer_group_description set description='$newtype' where customer_group_id=$count") or die(mysqli_error($link)); // ΕΝΗΜΕΡΩΣΗ ΟΜΑΔΑΣ ΣΕ ΠΕΛΑΤΗ $result = mysqli_query($link,"update " . $dbprefix . "customer set customer_group_id=$count where customer_id=$alldata[customer_id]") or die(mysqli_error($link)); } if ($debug) { echo $alldata[customer_id].'#'.$alldata[customer_group_id].'#'.$alldata[manufacturers_ids].'#'.$alldata[manufacturers_names].'#'.$alldata[hist_comment].'#'.$alldata[new_customer_group].' >> '.$newtype.'#<br>'; } } ////////////////////////////// ////////////////////////////// ////////////////////////////// ////////////////////////////// ////////////////////////////// $newspecial=0; $modifiedspecial=0; $deletedspecial=0; $data = mysqli_query($link, " SELECT tra.rate as rate_value, pro.product_id, pro.price, pro.upc, pro.manufacturer_id FROM " . $dbprefix . "product pro left join " . $dbprefix . "tax_rule as tru on tru.tax_class_id=pro.tax_class_id left join " . $dbprefix . "tax_rate as tra on tra.tax_rate_id=tru.tax_rate_id ") or die(mysqli_error($link)); //ΛΙΣΤΑ ΕΙΔΩΝ while ($alldata = mysqli_fetch_array($data)) { $productid = $alldata['product_id']; $price = $alldata['price']; $purchaseprice = $alldata['upc']; $manufacturer_id = $alldata['manufacturer_id']; $taxrate = $alldata['rate_value']; $data2 = mysqli_query($link, " SELECT * FROM " . $dbprefix . "customer_group_description where language_id=$lang_id and name like '%\%' ") or die(mysqli_error($link)); //ΛΙΣΤΑ ΚΑΤΗΓΟΡΙΩΝ ΠΕΛΑΤΩΝ while ($alldata2 = mysqli_fetch_array($data2)) { $groupdata = explode(' ', $alldata2['name']); $percent = str_ireplace('%', '', $groupdata[count($groupdata) - 1]); $groupname = $alldata2['name']; $groupid = $alldata2['customer_group_id']; $description = $alldata2['description']; //ΕΥΡΕΣΗ ΠΟΣΟΣΤΟΥ ΒΑΣΕΙ ΚΑΤΑΣΚΕΥΑΣΤΗ if ($description) { $perclines = explode(',', $description); foreach ($perclines as $percline){ $selline = explode('|', $percline); if ($selline[0]==$manufacturer_id) { $percent=$selline[1]; if ($debug) {echo '********';} break; } } } // if ($debug) { echo $productid . '#' . $price . '#' . $purchaseprice . '#' . $groupname . '# ' . $percent . '% #' . $groupid . '#'.$manufacturer_id.' >> '.$description.'<br>'; } //************************************* //ΟΡΣΙΜΟΣ ΤΙΜΩΝ ΚΑΤΗΓΟΡΙΩΝ ΠΕΛΑΤΩΝ //************************************* // //file_put_contents($logfile,'P>'.$proid.' C>'.$catex, FILE_APPEND | LOCK_EX); if ($purchaseprice > 0) { $result = mysqli_query($link, " SELECT COUNT(*) FROM " . $dbprefix . "product_special WHERE product_id=$productid and customer_group_id=$groupid "); $count = mysqli_fetch_assoc($result) ['COUNT(*)']; $price = $purchaseprice + (($percent * $purchaseprice) / 100); //$price= $price + (($taxrate * $price) / 100); if ($count > 0) { $data3 = mysqli_query($link, " UPDATE " . $dbprefix . "product_special SET price=$price WHERE product_id=$productid and customer_group_id=$groupid ") or die(mysqli_error($link)); // echo "UPDATE ".$dbprefix."product_special SET price=$price WHERE product_id=$productid and customer_group_id=$groupid<br>"; //echo mysqli_affected_rows($link).'<br>'; if (mysqli_affected_rows($link) > 0) { $modifiedspecial++; } } else { $data3 = mysqli_query($link, " INSERT INTO " . $dbprefix . "product_special (product_id, customer_group_id, price,date_start,date_end) VALUES ($productid, $groupid, $price,'2000-1-1','2100-1-1') ") or die(mysqli_error($link)); // echo "INSERT INTO ".$dbprefix."product_special (product_id, customer_group_id, price,date_start,date_end) VALUES ($productid, $groupid, $price,'2000-1-1','2100-1-1')<br>"; //echo mysqli_affected_rows($link).'<br>'; if (mysqli_affected_rows($link) > 0) { $newspecial++; } } } else { //ΔΙΑΓΡΑΦΗ $data3 = mysqli_query($link, " delete from " . $dbprefix . "product_special WHERE product_id=$productid and customer_group_id=$groupid ") or die(mysqli_error($link)); //echo mysqli_affected_rows($link).'<br>'; if (mysqli_affected_rows($link) > 0) { $deletedspecial++; } } // //************************************* //************************************* } //$prodopvid = $alldata['product_option_value_id']; } //file_put_contents($logfile,"upload ok\n", FILE_APPEND | LOCK_EX); mysqli_close($link); echo 'New: '.$newspecial.'<br>'; echo 'Modified: '.$modifiedspecial.'<br>'; echo 'Deleted: '.$deletedspecial.'<br>'; } |
Ρυθμίζουμε στο server ώστε να εκτελείται κάθε 10 λεπτά
1 |
wget -qO /dev/null https://mysite.com/emdi_open2_bridge.php?action=calc_discounts >/dev/null 2>&1 |
Στην ομάδα πελατών που επιθυμούμε στη περιγραφή γράφουμε το ID του κατασκευαστή | το ποσοστό έκπτωσης.
Στο πελάτη που θέλουμε να εφαρμόζεται, στο ιστορικό προσθέτουμε ένα σχόλιο, τίτλος ομάδας πελατών κενό ποσοστό έκπτωσης. Να σημειωθεί ότι χρησιμοποιείται μόνο η νεότερη γραμμή σχολίου.