function lhg_scan_update_ajax() { $pid = $_REQUEST['postid']; $id = $_REQUEST['id']; $session = $_REQUEST['session']; $asinURL = $_REQUEST['asinURL']; $comment = $_REQUEST['comment']; // get image URL $pos = strpos($asinURL, "/B0"); $asin = substr($asinURL, $pos + 1, 10); if (strpos($asinURL, ".com/") > 1) { $amz_region = "com"; } if (strpos($asinURL, ".fr/") > 1) { $amz_region = "fr"; } if (strpos($asinURL, ".de/") > 1) { $amz_region = "de"; } if (strpos($asinURL, ".co.uk/") > 1) { $amz_region = "co.uk"; } $output = lhg_aws_get_price($asin, $amz_region); list($image_url_com, $product_url_com, $price_com, $product_title) = split(";;", $output); $image_url_com = str_replace("Image: ", "", $image_url_com); # update article data by ASIN data $mode = lhg_get_autocreate_mode($pid); lhg_update_tags_by_string($pid, $product_title, $mode); lhg_update_categories_by_string($pid, $product_title, $mode); lhg_update_title_by_string($pid, $product_title, $mode); if ($mode == "drive") { lhg_correct_drive_name($pid, $session); } # extract new Properties and new title coming from ASIN data $newtitle = get_the_title($pid); $posttags = get_the_tags($pid); $properties_array = array(); if ($posttags) { foreach ($posttags as $tag) { array_push($properties_array, $tag->name); #error_log("TAG: ".$tag->name); } } $properties = join(", ", $properties_array); #error_log("PID: $pid - Title: $newtitle - Prop: $properties"); // Write extracted data to DB global $lhg_price_db; $myquery = $lhg_price_db->prepare("UPDATE `lhghwscans` SET usercomment = %s WHERE id = %s ", $comment, $id); $result = $lhg_price_db->query($myquery); $myquery = $lhg_price_db->prepare("UPDATE `lhghwscans` SET url = %s WHERE id = %s ", $asinURL, $id); $result = $lhg_price_db->query($myquery); $myquery = $lhg_price_db->prepare("UPDATE `lhghwscans` SET imgurl = %s WHERE id = %s ", $image_url_com, $id); $result = $lhg_price_db->query($myquery); # And Store asin in WPDB $key = "amazon-product-single-asin"; $value = $asin; if (get_post_meta($pid, $key, FALSE)) { //if the custom field already has a value update_post_meta($pid, $key, $value); } else { //if the custom field doesn't have a value add_post_meta($pid, $key, $value); } $response = new WP_Ajax_Response(); $response->add(array('data' => 'success', 'supplemental' => array('text' => "Debug: {$pid} - {$id} - {$asin} - {$comment} - SID: {$session} -- END", 'imgurl' => "{$image_url_com}", 'properties' => "{$properties}", 'newtitle' => "{$newtitle}"))); $myquery = $lhg_price_db->prepare("UPDATE `lhghwscans` SET usercomment = %s WHERE id = %s ", $comment, $id); #$sql = "SELECT id FROM `lhgshops` WHERE region <> \"de\""; $result = $lhg_price_db->query($myquery); $response->send(); //var_dump($response); exit; //die(); }
function lhg_update_article_by_amazon_search() { $search_region = "com"; #which AMAZON server to ask $pid = absint($_REQUEST['pid']); $id = absint($_REQUEST['id']); $session = $_REQUEST['session']; $mode = lhg_get_autocreate_mode($pid); # first implementation for CPU only $asin[1] = $_REQUEST['asin1']; $asin[2] = $_REQUEST['asin2']; $asin[3] = $_REQUEST['asin3']; $title[1] = $_REQUEST['title1']; $title[2] = $_REQUEST['title2']; $title[3] = $_REQUEST['title3']; $produrl[1] = $_REQUEST['produrl1']; $produrl[2] = $_REQUEST['produrl2']; $produrl[3] = $_REQUEST['produrl3']; $imgurl[1] = $_REQUEST['imgurl1']; $imgurl[2] = $_REQUEST['imgurl2']; $imgurl[3] = $_REQUEST['imgurl3']; #$asin1 = $_REQUEST['asin1'] ; #$asin2 = $_REQUEST['asin2'] ; #$asin3 = $_REQUEST['asin3'] ; $option = $_REQUEST['option']; $type = $_REQUEST['type']; # i.e. "cpu", "mainboard",... #print "Title: ".$title[$option]."<br>IURL: ".$imgurl[$option]." #<br>PURL: ".$produrl[$option]."<br> ASIN: ".$asin[$option]."<br>"; #error_log("DEB: ".$title[$option]); # Update tags by Amazon title lhg_update_tags_by_string($pid, $title[$option], $mode); lhg_update_categories_by_string($pid, $title[$option], $mode); lhg_update_title_by_string($pid, $title[$option], $mode); if ($mode == "drive") { lhg_correct_drive_name($pid, $session); } die; }