' ; }
//escapte against hijack
$id_param = mysqli_real_escape_string($con, isset($_GET['id']) ? $_GET['id'] : '');
//code for forbidden skus as take from array in domains.php file
if (in_array(strtolower($id_param), $forbidden_skus )) {
exit;
}
// re scramble the sku
if (strpos(strtolower($id_param), 'sku') === false)
{$id_param = str_rot13($id_param);}
//code to analyze and filter the id parameter - we will only accept certain type - if not then we will reject the request.
//echo strtolower($id_param); echo strpos(strtolower($id_param), 'skuwmt'); echo strlen($id_param);
if (substr(strtolower($id_param), 0, 3) !== 'sku' || strpos(strtolower($id_param), 'sku') === false || strlen($id_param) > 18 || strlen($id_param) < 8)
{
// hey hacker, get out !!!!!
echo 'invalid request - check your url parameter';
exit;
}
// check if we have bot or human - we will use it in actual pages code to eliminate bot traffic as much as possible
$visitor_type = "human"; $bot_type = "";
if (preg_match('/Linguee|bot|crawl|slurp|trident|spider|bing|google|pinterest|duckduckgo|qwant|github|knowledge|bdbrandprotect|LinkWalker|brandprotect|Baiduspider|facebook|tiktok|YandexBot/i', strtolower($agent)) == true ) { $visitor_type = "bot"; }
if ( $visitor_type == "bot" ) {
// try to catch all bad bots that are not google bing pinterest tiktok facebook
if (preg_match('/bing|google|pinterest|duckduckgo|facebook|tiktok/i', strtolower($agent)) == true ) { $bot_type = "good"; } else { $bot_type = "bad";}
}
// without google :
//if (preg_match('/Linguee|bot|crawl|slurp|trident|spider|bing|qwant|github|knowledge|bdbrandprotect|LinkWalker|brandprotect|Baiduspider|YandexBot/i', strtolower($agent)) == true ) { $visitor_type = "bot"; }
// without google and bing :
//if (preg_match('/Linguee|bot|crawl|slurp|trident|spider|qwant|github|knowledge|bdbrandprotect|LinkWalker|brandprotect|Baiduspider|YandexBot/i', strtolower($agent)) == true ) { $visitor_type = "bot"; }
// ad more bots ..
//if (preg_match('/Baiduspider|YandexBot/i', strtolower($agent)) == true ) { $visitor_type = "bot"; }
//include 'crawler_detect.php';
//if (smart_ip_detect_crawler($agent) == true) { $visitor_type = "bot"; }
//if (preg_match('/bot|crawl|spider/i', $agent) == true ) { $visitor_type = "bot"; }
/*
require_once 'bot_check_function.php';
if(smart_ip_detect_crawler($agent)==true){ $visitor_type = "bot"; }
*/
// see if we can get it from url - used for testing behaviour of bot / human
//if (isset($_GET['visitor_type'])) {$visitor_type = $_GET['visitor_type'];};
// disable %80 of bots from processing this page due to performance issues
$hour = (int) date('G');
if ($hour >= 6 && $hour <=22) {$site_working_hours = 1;} else {$site_working_hours = 0;}
// this can be added to the if statemnt below should we need to later ... but for now we have removed many bad bots ...
// ((($visitor_type == "bot" && $site_working_hours == 1) || ($visitor_type == "bot" && $site_working_hours == 0 && rand(0,100) > 30 )) && (1 == 0)) ||
// this condition we set all the sites we actually advertise so we know which bots to kick out and which to stay ...
$advertised_site = 0 ;
if (strpos($domain_1 , 'webcortex') !== false || strpos($domain_1 , 'bta-mall') !== false || strpos($domain_1 , 'alumigogo') !== false ) { $advertised_site = 1 ;}
if ( (in_array($ip, $forbidden_ips_like_human) && isset($_GET['iamhuman']) == false) || ($visitor_type == "bot" && $advertised_site == 0 ) || $bot_type == "bad" ) {
?>
';
exit; }
// if store currency is UK dollar and item is NOT then we do not allow to display it !
if ($currency_code == "GBP" && $warehouse_item != 'amznuk') {
echo 'Sorry this item can not be displayed in UK store... ';
exit; }
//amznca is a warehouse where prices are in AU currency
// if store currency is AU dollar and item is NOT then we do not allow to display it !
if ($currency_code == "AUD" && $warehouse_item != 'amznau') {
echo 'Sorry this item can not be displayed in AUSTRALIAN store... ';
exit; }
// if store currency is US dollar and item is not in USA then we do not allow to display it !
if ($currency_code == "USD" && $warehouse_item !== 'amzn') {
echo 'Sorry this item can not be displayed in USA store... ';
exit; }
$email_err='';
$cookie_is_set = 1; // do not show email box for now...
$valid_asin = 1;
//open new connection with db user
//$con_db=mysqli_connect($server_db,"fankeyco_user1","99-99shay","fankeyco_1cd") or die("Error Connecting To Database" . mysqli_error($con_db));
$con_db=mysqli_connect($server_db,$server_db_user,$server_db_psw,$server_db_name) or die("Error Connecting To Database " . mysqli_error($con_db));
if (isset($_GET['test1test'])) { echo 'server_db : ' . $server_db . ' ' ; }
if (isset($_GET['test1test'])) { echo 'server_db_user : ' . $server_db_user . ' ' ; }
if (isset($_GET['test1test'])) { echo 'server_db_psw : ' . $server_db_psw . ' ' ; }
if (isset($_GET['test1test'])) { echo 'server_db_name : ' . $server_db_name . ' ' ; }
if (isset($_GET['test1test'])) { echo "domain 1 " . $domain_1.' '; }
if (isset($_GET['test1test'])) { echo "product_sku_prefix " . $product_sku_prefix.' '; }
if (isset($_GET['test1test'])) { echo "hour " . $hour.' '; }
if (isset($_GET['test1test'])) { echo "api_enabled " . $api_enabled.' '; }
//record into visitor table only if it's not a bot
// check if in any case we have a bing click then enter inside to record it !
// $_GET['click_src'] - coming from bing feed
//$_GET['clicksrc-act'] - coming from bing admin campaign
$click_src = $_GET['click_src'] . 'X' . $_GET['clicksrc-act'] . 'X' . $mobile_str;
//if (!isset($_SESSION['click_src'])) {
$_SESSION['click_src'] = $click_src;
//}
if (isset($_GET['test1test'])) { echo 'click_src : ' . $click_src . ' ';}
// code to skip amazon api or not
// restrict it to 2daydeliver.com domain and from USA only clients as we suffer extremem bot and other traffic to other domains...
// fix - try to enalbe api call to all except for bots
$api_use = 0 ;
/*
if ( strpos($domain_1 , '2daydeliver.com') !== false) {$api_use = 1;}
if ( strpos($domain_1 , 'bta-mall.com') !== false) {$api_use = 1;}
if ( strpos($domain_1 , 'alumigogo.com') !== false) {$api_use = 1;}
if ( strpos($domain_1 , 'singularart.shop') !== false) {$api_use = 1;}
*/
// if ref is not empty it means this user comes from good place so allow him to run the api
//if ( trim($ref) !== '') {$api_use = 1;}
// if ( $visitor_type == "human" && $click_src <> 'XX' && $click_src <> 'XXmobile' ) {$api_use = 1;}
//if ( $visitor_type == "human" && $click_src <> 'XX' && $click_src <> 'XXmobile' && $click_src <> 'insideXX' ) {$api_use = 1;}
// if ( $visitor_type == "human" && strpos($domain_1 , '2daydeliver.com') !== false ) {$api_use = 1;}
//if ( $visitor_type == "human" ) {$api_use = 1;}
//if ( $visitor_type == "human" && strpos($domain_1 , 'alumigogo.com') === false ) {$api_use = 1;}
//if ( $visitor_type == "human" ) {$api_use = 1;}
//if ( $click_src <> 'XX' && $click_src <> 'XXmobile' ) {$api_use = 1; $visitor_type = "human";}
//if (isset($_GET['clicksrc-act'])) {$api_use = 1; $visitor_type = "human";}
//if ( trim($ref) !== '') {$api_use = 1; $visitor_type = "human";}
//if ( trim($ref) !== '' && strpos($domain_1 , 'alumigogo.com') !== false && $visitor_type == "human") {$api_use = 1; }
//if (isset($_GET['test1test'])) {$api_use = 1;}
//in case agent is empty / missing / etc
if ( trim($ref) !== '') {$api_use = 1;}
//if ( strpos($ref , $domain_1) !== false) {$api_use = 0;}
/*
if ( strpos($ref , 'bing') !== false) {$api_use = 1;}
if ( strpos($ref , 'google') !== false) {$api_use = 1;}
if ( strpos($ref , 'pinterest') !== false) {$api_use = 1;}
if ( strpos($ref , 'yahoo') !== false) {$api_use = 1;}
if ( strpos($ref , 'tiktok') !== false) {$api_use = 1;}
if ( strpos($ref , 'aol') !== false) {$api_use = 1;}
if ( strpos($ref , 'toloka') !== false) {$api_use = 1;}
if (preg_match('/bing|google|pinterest|yahoo|tiktok|aol|toloka/i', strtolower($ref)) == true ) { $api_use = 1; }
*/
//if ( $click_src == 'insideXX' ) {$api_use = 0; }
//if ( $_SESSION['click_src'] == 'insideXX' ) {$api_use = 0; }
//if ( $click_src == 'XX' ) {$api_use = 0; }
//if ( $_SESSION['click_src'] == 'XX' ) {$api_use = 0; }
if ( strlen($agent) < 10 || $agent == '' || $agent == '0' || $agent == '1' || is_null($agent) || isset($agent) == false) {$api_use = 0; }
//if ( $click_src == 'XX' || $click_src == 'XXmobile' ) {$api_use = 0;}
if ( $visitor_type == "bot" ) {$api_use = 0;}
//if ( ($click_src == 'XX' || $click_src == 'XXmobile') && trim($ref) == '' ) {$api_use = 0;}
//if ($ip == '54.36.162.160') {$api_use = 0;}
if (in_array($ip, $forbidden_ips )) {$api_use = 0; }
// try to approve clicks accordng to observation
if ( $visitor_type == "human" && strpos($click_src , 'bingads') !== false && strpos($domain_1 , 'alumigogo.com') !== false ) {$api_use = 1;}
if ( $visitor_type == "human" && strpos($click_src , 'googleads') !== false && strpos($domain_1 , 'webcortex.com') !== false ) {$api_use = 1;}
if ( $visitor_type == "human" && strpos($click_src , 'googleads') !== false && strpos($domain_1 , 'bta-mall.com') !== false ) {$api_use = 1;}
//////
//check for fobidden bot ips
// test - just use the ip blocker only ....
// $api_use = 1 ;
/*
$sql_ip = 'select ip from forbidden_ips';
$result_ip = mysqli_query($con,$sql_ip);
while($row = mysqli_fetch_array($result_ip))
{ if ($ip == $row['ip']) {$api_use = 0; } }
*/
/////
//fixes for a bot that attack singularart
//if ( strpos($domain_1 , 'singularart.shop') !== false) {$api_use = 0;}
// if (isset($_GET["last_node"])) {$api_use = 1;}
//debugging ...
//////////////////
//////////////////
// temp add this to block all api calls except when coming from campaign ...
//if ( $click_src == 'XX' || $click_src == 'XXmobile' ) {$api_use = 0;}
//if ($_GET['click_src'] == 'googleads') {$api_use = 0;}
//////////////////
//////////////////
// check in visitors table if we already processed this ASIN in last N minutes to set it to api_use 0
// disalbeld for now - we have good API rate ....
if ($api_enabled == true) {
if ( (strpos($warehouse_item,'amzn') !== false || $warehouse_item == 'wmt') && 1 == 1) {
//$sql_check_asin = "select sku from visitors where sku = '".$id_param."' and date_time > (NOW() - INTERVAL 180 MINUTE);";
//$sql_check_asin = "SELECT * FROM from_bg_small where product_sku = '".$id_param."' and product_price > 0 and qty > 0 and date_mod > (NOW() - INTERVAL 1 HOUR) ; ";
$sql_check_asin = "SELECT * FROM from_bg_small where
product_sku = '".$id_param."' and product_price > 0 and qty > 0
and (( date_mod > (NOW() - INTERVAL 1 HOUR) and is_eligible_for_super_saver_shipping = 1 ) OR ( date_mod > (NOW() - INTERVAL 72 HOUR) and is_eligible_for_super_saver_shipping = 0 and qty_u = 3 )) ; ";
$result_check_asin = mysqli_query($con_db,$sql_check_asin);
$found_prime_in_from_bg_small = false ;
if (mysqli_num_rows($result_check_asin)>0) {
$api_use = 0;
//if (isset($_GET['test1test'])) { echo 'sql_check_asin : ' . $sql_check_asin . ' ' ; }
$row_of_result_check_asi = mysqli_fetch_array($result_check_asin);
if (isset($_GET['test1test']))
{ echo ' we have data in from_bg_small for item - product_price - ' . $row_of_result_check_asi['product_price'] .' '; }
// set $pricemain as if it was coming from api ...
$pricemain = $row_of_result_check_asi['product_price'];
$qty_api = $row_of_result_check_asi['qty'];
$Availability = $row_of_result_check_asi['availability'];
// set the arrive date to availability in this case...
$arrive_date = $row_of_result_check_asi['arrive_date'];
//$price_updated_today = true;
$found_prime_in_from_bg_small = true ;
}
}
}
if (isset($_GET['api_use'])) {$api_use = $_GET['api_use']; $found_prime_in_from_bg_small = false ;}
if ($api_enabled == false) {$api_use = 0; $Availability = 'In Stock.'; $arrive_date = '2-3 Days Delivery'; $found_prime_in_from_bg_small = false ;}
//if (isset($_GET['test1test'])) { echo 'var dump : ' . var_dump($_SERVER) . ' ' ; }
//if (isset($_GET['test1test'])) { echo 'get_server_memory_usage : ' . shell_exec('free') . ' ' ; }
//if (isset($_GET['test1test'])) { echo 'get_server_cpu_usage : ' . sys_getloadavg() . ' ' ; }
//// check the memory on this page //////////////
//if (isset($_GET['test1test'])) { echo 'memory_get_usage : ' . memory_get_usage() . ' ' ; }
if (isset($_GET['test1test'])) { echo 'api_use : ' . $api_use . ' ' ; }
if (isset($_GET['test1test'])) { echo 'visitor_type : ' . $visitor_type . ' ' ; }
if (isset($_GET['test1test'])) { echo 'SESSION[order_total] : ' . $_SESSION['order_total'] . ' ' ; }
//!!! set the country to USA all the time to improve performace
// Disable for now ...
$_SESSION['buyer_country'] = "United States";
//////////////////////////////////////////////
// discover user country
if ((strpos($warehouse_item,'amzn') !== false || $warehouse_item == 'wmt' || $warehouse_item == 'ae') && $visitor_type == "human" && 1 == 0 && $api_use == 1 && isset($_GET['country'])==false && isset($_SESSION['buyer_country']) == false)
{
// discover user country // Get user IP first
$buyer_country = 'United States'; // default
$user_ip=get_client_ip();
$sql_country = ("SELECT country_name FROM ip_country_list WHERE INET_ATON('".$user_ip."') BETWEEN ip_range_start_int AND ip_range_end_int LIMIT 1");
$result_country = mysqli_query($con_db,$sql_country);
$row_country = mysqli_fetch_array($result_country);
if (mysqli_num_rows($result_country)>0) { $buyer_country = $row_country['country_name']; }
$_SESSION['buyer_country'] = $buyer_country;
// try also to get user country from server ...
/*if ($buyer_country == 'NA') {
if( isset($_SERVER['HTTP_CF_IPCOUNTRY']) ){$buyer_country = $_SERVER['HTTP_CF_IPCOUNTRY'];}
}*/
//debugging ...
if (isset($_GET['test1test'])) { echo 'user_ip : ' . $user_ip . ' ' . 'buyer_country : ' . $buyer_country . ' ' . '_SESSION_buyer_country : ' . $_SESSION['buyer_country'] . ' ' ; }
}
//get country from URL
if (isset($_GET['country'])==true) {$_SESSION['buyer_country']=$_GET['country'];}
if (isset($_GET['test1test'])) { echo 'SESSION[buyer_country] : ' . $_SESSION['buyer_country'] . ' ' ; }
$email_from_cookie = '';
// record customers viewed items
if (isset($_COOKIE["email_cookie"])) {
// insert into viewed item table to record all requested sku that users want to see in store
$sql_insert_viewed_items_customer = "insert into viewed_items_customer (item_sku, email) values('".$id_param."', '".$_COOKIE["email_cookie"]."')";
// disable for now - too many records not needed
mysqli_query($con_db,$sql_insert_viewed_items_customer );
$email_from_cookie = $_COOKIE["email_cookie"];
}
$unique_id = uniqid();
//unset($_COOKIE['shopper_cookie']);
// setcookie('shopper_cookie', '', time() - 3600,"/",str_replace('www.','',$domain_1)); // empty value and old timestamp
if ( isset($_COOKIE["shopper_cookie"]) == false ) {
setcookie("shopper_cookie", $unique_id, time()+60*60*24*365*20,"/",str_replace('www.','',$domain_1));
//echo "unique_id 1 -" . $unique_id . " ";
} else if (isset($_COOKIE["shopper_cookie"]) == true) {
$unique_id = $_COOKIE["shopper_cookie"];
//echo "unique_id 2 -" . $unique_id . " ";
}
include 'visitors_insert.php';
// // record in visitors table only the clicks paid so we can analyze them
// //if ( $visitor_type == "human" && $click_src <> 'XX' && $click_src <> 'XXmobile' )
// //if ( $click_src <> 'XX' && $click_src <> 'XXmobile' )
// //if (isset($_GET['clicksrc-act']))
// //if ( ($visitor_type == "human" && $api_use == 1 ) || (1 == 0))
// //if ( ($visitor_type == "human" && $click_src <> 'XX' && $click_src <> 'XXmobile') || (1 == 0))
// //if ( trim($ref) !== '')
// //if ( $api_use == 1 || 1 == 0)
// //if ( ($visitor_type == "human" || $api_use == 1 ) || (1 == 0))
// if ( ($api_use == 1 ) || (1 == 0))
// {
// // record into visitors table
// $sql_insert_visitor = "insert into visitors (session_id,sku,referer,ip,agent,domain, country, click_src,email,cookie_id, source) values('".session_id()."','".$id_param."','".$ref."','".$ip."','".$agent."','".$domain."','".$_SESSION['buyer_country']."','". mysqli_real_escape_string($con_db,$click_src)."','".$email_from_cookie."', '".$unique_id."', '".$visitor_type."')";
// //$sql_insert_visitor = "insert into visitors (session_id,sku,referer,ip,agent,domain) values('".session_id()."','".$id_param."','".$ref."','".$ip."','".$agent."','".$domain."')";
// // disable for now - too many records not needed
// mysqli_query($con_db,$sql_insert_visitor );
// if (isset($_GET['test1test'])) { echo 'sql_insert_visitor : ' . $sql_insert_visitor . ' ' ; }
// }
// initiate some parameters
$shipping_from_country ='USA';
$arrive_date = '2-3 Days Delivery';
////////**** ae code *******///////////
if ($warehouse_item == 'ae') {
$shipping_from_country ='CHINA';
$arrive_date = '10 Days Delivery';
}
////////**** ae code *******///////////
////////**** ae code *******///////////
if ($warehouse_item == 'amznca') {
$shipping_from_country ='CANADA';
$arrive_date = '2-3 Days Delivery';
}
if ($warehouse_item == 'amznau') {
$shipping_from_country ='AUSTRALIA';
$arrive_date = '2-3 Days Delivery';
}
/// uk site ///
if ($base_country == "United Kingdom") {
$shipping_from_country ='USA';
$arrive_date = '7-10 Days Delivery';
}
//////////////////////////////////////////
//real time checking if we have in stock for amazon / wmt item / ae item
if ((strpos($warehouse_item,'amzn') !== false || $warehouse_item == 'wmt' || $warehouse_item == 'ae') && $visitor_type == "human" && 1 == 1 && $api_use == 1)
{
// insert into viewed item table to record all requested sku that users want to see in store
$sql_insert_viewed_items = "replace into viewed_items (item_sku) values('".$id_param."')";
// disable for now - too many records not needed
mysqli_query($con_db,$sql_insert_viewed_items );
//debugging ...
if (isset($_GET['test1test'])) {echo ' line 2 - try amazon / wmt / ae api ' . ' ';}
if (strpos($warehouse_item,'amzn') !== false)
{
// initiate some more parameters for amazon api
$asin = str_replace($product_sku_prefix,"",$id_param) ;
$qty_u = 0;
//////////////////////// Amazon API CALL ////////////////////////
//call the api - we will try using while until we are able to get result ... if not able to get result we will make the item out of stock...
//////// try call amazon API ////////
//we shuffle array each time - hence inside the while loop
//include 'amazon_api/amazonapi/amazon_api_list.php';
if ($amazon_api_country == 'us') {
include 'amazon_api_list.php';
} else if ($amazon_api_country == 'au') {
include 'amazon_au_api_list.php';
} else if ($amazon_api_country == 'ca') {
include 'amazon_ca_api_list.php';
} else if ($amazon_api_country == 'uk') {
include 'amazon_uk_api_list.php';
}
foreach ($amazon_apis as $amazon_api) {
if (isset($_GET['test1test'])) {echo '=> $amazon_api: ' . $amazon_api . ' trying... ';}
$amazon_api_arr = explode(' ', $amazon_api);
$tag = $amazon_api_arr[0]; $AWSAccessKeyId = $amazon_api_arr[1]; $AWSSecretKey = $amazon_api_arr[2];
///API 5.0///
//////// try call amazon API ////////
//echo "tag = " . $tag . " " ;
$config = new Configuration();
$config->setAccessKey($AWSAccessKeyId); $config->setSecretKey($AWSSecretKey); $partnerTag = $tag;
if ($amazon_api_country == 'us') {
$config->setHost('webservices.amazon.com'); $config->setRegion('us-east-1');
} else if ($amazon_api_country == 'au') {
$config->setHost('webservices.amazon.com.au'); $config->setRegion('us-west-2');
} else if ($amazon_api_country == 'ca') {
$config->setHost('webservices.amazon.ca'); $config->setRegion('us-east-1');
} else if ($amazon_api_country == 'uk') {
$config->setHost('webservices.amazon.co.uk'); $config->setRegion('eu-west-1');
}
$apiInstance = new DefaultApi( new GuzzleHttp\Client(), $config );
# Request initialization
$itemIds = array($asin);
$valid_asin = 1;
$VariationPage = 1 ;
/*
Choose resources you want from GetItemsResource enum
For more details, refer: https://webservices.amazon.com/paapi5/documentation/get-items.html#resources-parameter
*/
$resources = array( GetItemsResource::ITEM_INFOTITLE, GetItemsResource::ITEM_INFOPRODUCT_INFO, GetItemsResource::OFFERSLISTINGSPRICE, GetItemsResource::PARENT_ASIN,
GetItemsResource::OFFERSSUMMARIESOFFER_COUNT, GetItemsResource::OFFERSSUMMARIESLOWEST_PRICE, GetItemsResource::OFFERSLISTINGSDELIVERY_INFOIS_FREE_SHIPPING_ELIGIBLE,
GetItemsResource::OFFERSLISTINGSDELIVERY_INFOIS_PRIME_ELIGIBLE, GetItemsResource::OFFERSLISTINGSAVAILABILITYMESSAGE, GetItemsResource::OFFERSLISTINGSAVAILABILITYTYPE,
GetItemsResource::OFFERSLISTINGSMERCHANT_INFO,
GetItemsResource::OFFERSLISTINGSCONDITION,
GetItemsResource::OFFERSLISTINGSCONDITIONSUB_CONDITION,
GetItemsResource::OFFERSLISTINGSAVAILABILITYMAX_ORDER_QUANTITY,
GetItemsResource::OFFERSLISTINGSAVAILABILITYMIN_ORDER_QUANTITY,
GetItemsResource::OFFERSLISTINGSDELIVERY_INFOIS_AMAZON_FULFILLED,
GetItemsResource::BROWSE_NODE_INFOBROWSE_NODES, GetItemsResource::BROWSE_NODE_INFOBROWSE_NODESANCESTOR, GetItemsResource::BROWSE_NODE_INFOBROWSE_NODESSALES_RANK, GetItemsResource::BROWSE_NODE_INFOWEBSITE_SALES_RANK, GetItemsResource::ITEM_INFOFEATURES,
GetItemsResource::ITEM_INFOEXTERNAL_IDS, GetItemsResource::ITEM_INFOCLASSIFICATIONS, GetItemsResource::ITEM_INFOMANUFACTURE_INFO, GetItemsResource::ITEM_INFOBY_LINE_INFO,
GetItemsResource::IMAGESPRIMARYLARGE, GetItemsResource::IMAGESVARIANTSLARGE, GetVariationsResource::ITEM_INFOTITLE,
GetVariationsResource::OFFERSLISTINGSPRICE, GetVariationsResource::IMAGESPRIMARYSMALL );
# Forming the request
$getItemsRequest = new GetItemsRequest();
$getItemsRequest->setItemIds($itemIds); $getItemsRequest->setPartnerTag($partnerTag);
$getItemsRequest->setPartnerType(PartnerType::ASSOCIATES); $getItemsRequest->setResources($resources);
# Sending the request
# Forming the request
$getVariationsRequest = new GetVariationsRequest();
$getVariationsRequest->setASIN($asin);
$getVariationsRequest->setPartnerTag($partnerTag);
$getVariationsRequest->setPartnerType(PartnerType::ASSOCIATES);
$getVariationsRequest->setResources($resources);
$getVariationsRequest->setVariationPage($VariationPage);
try {
$getItemsResponse = $apiInstance->getItems($getItemsRequest);
if ( $getItemsResponse->getItemsResult())
{$item = $getItemsResponse->getItemsResult()->getItems()[0];}
else {$valid_asin = 0; $item = null; $tag = 'failed' ;}
$getVariationsResponse[1] = $apiInstance->getVariations($getVariationsRequest);
if (isset($_GET['test1test'])) {echo '=> api amazon get success ';} break 1;
} catch (Exception $e) {
if (strpos($e,'not a valid value') !== false || strpos($e,'is not accessible') !== false ) { $valid_asin = 0; }
$tag = 'failed' ; if (isset($_GET['test1test'])) {echo $e . '=> failed... ' . ' valid asin ' . $valid_asin . ' ';}
}
///////API 5.0/////
//break in case of non valid asin ... update DB as well ...
/*
if ($valid_asin == 0) {
$sql_delete_first = "delete from from_bg_small where product_sku = '" .$id_param . "'";
mysqli_query($con_db,$sql_delete_first);
$sql_insert = "insert into from_bg_small (product_sku, qty) values ('" .$id_param . "', 0) ";
mysqli_query($con_db,$sql_insert);
break 1;
}
*/
}
if ($valid_asin == 0) {
$sql_delete_first = "delete from from_bg_small where product_sku = '" .$id_param . "'";
mysqli_query($con_db,$sql_delete_first);
$sql_insert = "insert into from_bg_small (product_sku, qty) values ('" .$id_param . "', 0) ";
mysqli_query($con_db,$sql_insert);
}
//////// try call amazon API ////////
//debugging ...
if (isset($_GET['test1test'])) { echo " working tag " . $tag . " " ; }
//////////////////////// Amazon API CALL END ////////////////////////
//exit ;
// added code to block if tag = failed... and send email to admin ...
if ($tag == 'failed') {
$api_use = 0;
// mail('vikoko@gmail.com', 'api-tag failed', '');
// new code 29-08-2023 !!!
// scrap prices if API failed !!!
// if ( $scrap_prices == true ) {
// ob_implicit_flush(1);
// include "scrap_price_amazon.php";
// }
}
if ($tag !== 'failed') {
// mail('vikoko@gmail.com', 'api-tag success', '');
if (isset($_GET['test1test'])) { echo " working tag " . $tag . " " ; }
// Get date from amazon api into local varialbles...
//$Merchant = $response->Items->Item->Offers->Offer->Merchant->Name;
//$TotalVariations = $response->Items->Item->Variations->TotalVariations;
if ($getVariationsResponse[1]->getVariationsResult()) {
$TotalVariations = $getVariationsResponse[1]->getVariationsResult()->getVariationSummary()->getVariationCount();
$TotalVariationsPages = $getVariationsResponse[1]->getVariationsResult()->getVariationSummary()->getPageCount();
} else {$TotalVariations = 0;} ;
if ($TotalVariationsPages > 1) {
// in case we have more then 1 page of variations store them in array ....
for ($i=2; $i<=$TotalVariationsPages; $i++) {
# Forming the request
$VariationPage = $i;
$getVariationsRequest = new GetVariationsRequest();
$getVariationsRequest->setASIN($asin);
$getVariationsRequest->setPartnerTag($partnerTag);
$getVariationsRequest->setPartnerType(PartnerType::ASSOCIATES);
$getVariationsRequest->setResources($resources);
$getVariationsRequest->setVariationPage($VariationPage);
//echo '=> api VariationPage: ' . $VariationPage . ' ';
try {
$getVariationsResponse[$i] = $apiInstance->getVariations($getVariationsRequest);
// if (isset($_GET['test1test'])) {echo '=> api getVariationsResponse amazon get success - Complete Response: ' . $getVariationsResponse[$i] . ' ';} ;
} catch (Exception $e) {
$getVariationsResponse[$i] = null ;
}
}
//exit ;
}
//$parent_asin = $response->Items->Item->ParentASIN;
$parent_asin = $item->getParentASIN();
$parent_asin_api = $parent_asin ;
$parent_sku = $product_sku_prefix.$item->getParentASIN();
if ($parent_sku == $product_sku_prefix) {$parent_sku = "";}
// $LowestNewPrice = $response->Items->Item->OfferSummary->LowestNewPrice->FormattedPrice;
$LowestUsedPrice = null;
$Merchant = null ;
$saleprice = null;
$pricemain = null;
$IsEligibleForSuperSaverShipping = null ;
$IsEligibleForPrime = null ;
$Availability = null ;
$qty_api = null ;
$qty_api_used = null;
$qty_api_refurbished = null;
$savings = null;
if ($item->getOffers()) {
if ($item->getOffers()->getListings()[0]->getPrice()->getSavings()) {
$savings = $item->getOffers()->getListings()[0]->getPrice()->getSavings()->getAmount();
}
// price condition and qty for BUYBOX !!! but we will not use it we will always use usedlikenew as it is mostly same ...
$pricemain = $item->getOffers()->getListings()[0]->getPrice()->getAmount();
$Condition = $item->getOffers()->getListings()[0]->getCondition()->getValue();
$SubCondition = $item->getOffers()->getListings()[0]->getCondition()->getSubCondition()->getValue();
$Merchant = $item->getOffers()->getListings()[0]->getMerchantInfo()->getName();
// $IsEligibleForSuperSaverShipping is our main parameter to know if item is FBA or NOT - $IsEligibleForPrime is also use to determine the value of this parameter - see code below...
$IsEligibleForSuperSaverShipping = $item->getOffers()->getListings()[0]->getdeliveryInfo()->getisFreeShippingEligible();
$IsEligibleForPrime = $item->getOffers()->getListings()[0]->getdeliveryInfo()->getisPrimeEligible();
if ($IsEligibleForSuperSaverShipping==null) {$IsEligibleForSuperSaverShipping=0;}
if ($IsEligibleForPrime==null) {$IsEligibleForPrime=0;}
$Availability = $item->getOffers()->getListings()[0]->getAvailability()->getMessage();
//$MaxOrderQuantity = $item->getOffers()->getListings()[0]->getAvailability()->getMaxOrderQuantity();
//$MinOrderQuantity = $item->getOffers()->getListings()[0]->getAvailability()->getMinOrderQuantity();
$array_Summaries = $item->getOffers()->getSummaries();
foreach ($array_Summaries as $Summaries) {
if ($Summaries->getLowestPrice()) {
$LowestPrice_array_val = $Summaries->getLowestPrice()->getAmount();
$ConditioLowestPrice_array_val = $Summaries->getCondition()->getValue();
$qtyLowestPrice_array_val =$Summaries->getOfferCount();
//echo 'LowestPrice_array_val - ' . $LowestPrice_array_val . ' ';
// echo ' ConditioLowestPrice_array_val - ' . $ConditioLowestPrice_array_val . ' ';
// echo ' qtyLowestPrice_array_val - ' . $qtyLowestPrice_array_val . '';
if ($ConditioLowestPrice_array_val == 'New') {
$LowestNewPrice = $LowestPrice_array_val;
$ConditioLowestNewPrice = $ConditioLowestPrice_array_val;
$qtyLowestNewPrice = $qtyLowestPrice_array_val;
//$qty = $qtyLowestNewPrice;
$qty_api = $qtyLowestNewPrice;
$Condition = $ConditioLowestNewPrice;
//disalbe $pricemain = $LowestNewPrice as too many mistakes happen in amazon api - the result will be that pricemain is taken from buybox
//$pricemain = $LowestNewPrice;
}
if ($ConditioLowestPrice_array_val == 'Used') {
$LowestUsedPrice = $LowestPrice_array_val;
$ConditioLowestUsedPrice = $ConditioLowestPrice_array_val;
$qtyLowestUsedPrice = $qtyLowestPrice_array_val;
//$qty = $qtyLowestNewPrice;
$qty_api_used = $qtyLowestUsedPrice;
$Condition = $ConditioLowestUsedPrice;
//disalbe $pricemain = $LowestNewPrice as too many mistakes happen in amazon api - the result will be that pricemain is taken from buybox
//$pricemain = $LowestNewPrice;
}
}
}
// put some logic to determine best offer
// sometimes "buy box" offer is just first item in offerslist and does not represent - we will check if the subcondition is new - if so then it is good buy box...
//if ($SubCondition == 'New') {}
//// disable this as code above replaces this logic ...
/*
if ($item->getOffers()->getSummaries()[0]->getLowestPrice()) {
$LowestNewPrice = $item->getOffers()->getSummaries()[0]->getLowestPrice()->getAmount(); }
$qty_api = $item->getOffers()->getSummaries()[0]->getOfferCount();
*/
//$pricemain = $item->getOffers()->getListings()[0]->getPrice()->getAmount();
//// //// //// //// //// //// ////
//// disable this as with new API it returns price of used ones ...
/*
if ($item->getOffers()->getListings()[0]->getPrice()) {
$pricemain = $item->getOffers()->getListings()[0]->getPrice()->getAmount();
}
*/
//// //// //// //// //// //// ////
$pricemain_insert = $pricemain;
$saleprice = null;
// $IsEligibleForSuperSaverShipping is our main parameter to know if item is FBA or NOT - $IsEligibleForPrime is also use to determine the value of this parameter - see code below...
}
if ($IsEligibleForSuperSaverShipping==null) {$IsEligibleForSuperSaverShipping=0;}
if ($IsEligibleForPrime==null) {$IsEligibleForPrime=0;}
if ($IsEligibleForPrime==1) {$IsEligibleForSuperSaverShipping=1;}
if ($qty_api==null) {$qty_api=0;}
if ($qty_api_used==null) {$qty_api_used=0;}
if ($qty_api_refurbished==null) {$qty_api_refurbished=0;}
//special case for missing data in api - we set price to LowestNewPrice
if (!isset($pricemain) && isset($LowestNewPrice) && isset($qty_api))
{$pricemain = $LowestNewPrice; }
if (isset($pricemain)) {
$pricemain = preg_replace("/[^0-9\.]/", "", $pricemain);
$pricemain_insert = preg_replace("/[^0-9\.]/", "", $pricemain_insert);
}
// update price in case we have sale price in effect
if (isset($saleprice))
{
$saleprice = preg_replace("/[^0-9\.]/", "", $saleprice);
if ( $saleprice > 0) { $pricemain = $saleprice ; }
}
if (isset($LowestNewPrice)) {
$LowestNewPrice = preg_replace("/[^0-9\.]/", "", $LowestNewPrice);
}
if (isset($LowestUsedPrice)) {
$LowestUsedPrice = preg_replace("/[^0-9\.]/", "", $LowestUsedPrice);
}
//$product_name = $response->Items->Item->ItemAttributes->Title;
$product_name = $item->getItemInfo()->getTitle()->getDisplayValue();
if (isset($_GET['test1test'])) { echo " product_name tag " . $product_name . " " ; }
$product_name= mysqli_real_escape_string($con,$product_name);
//$customer_reviews = $response->Items->Item->CustomerReviews->IFrameURL;
$customer_reviews = null;
//code for more offers
//$offers_total = $response->Items->Item->Offers->TotalOffers;
$offers_total = null;
//$offers_total_pages = $response->Items->Item->Offers->TotalOfferPages;
$offers_total_pages = null;
//$offers_url = $response->Items->Item->Offers->MoreOffersUrl;
$offers_url = null;
}
}
/////////////////// walmart code start ///////
else if ($warehouse_item == 'wmt')
{
$asin = str_replace("SKUWMT","",$id_param) ;
// get the product data from walmart api
require 'get_wmt_info.php';
}
/////////////////// walmart code end
/////////////////// ae code start ///////
else if ($warehouse_item == 'ae')
{
$asin = str_replace("SKUAE","",$id_param) ;
// get the product data from walmart api
require 'get_ae_info.php';
}
/////////////////// walmart code end
// disable update to table from_bg as it affect performance... we will update the table from_bg_small instead ...
//we will update from this table daily to from_bg
// we will use price and qty_api retrieved from amazon in the product detailed page...
// above method not working well - we will try new method :
// updated are from from_bg_small and insert new proudcts are from from_bg_inserts table then update the new products into the from_bg table.
if (isset($_GET['test1test'])) //debugging ...
{
echo 'TotalVariations : ' . $TotalVariations . ' ';
echo 'TotalVariationsPages : ' . $TotalVariationsPages . ' ';
echo 'Merchant : ' . $Merchant . ' ';
echo 'pricemain : ' . $pricemain . ' ';
echo 'LowestNewPrice : ' . $LowestNewPrice . ' ';
echo 'LowestUsedPrice : ' . $LowestUsedPrice . ' ';
echo 'qty_api : ' . $qty_api . ' ';
echo 'qty_api_used : ' . $qty_api_used . ' ';
echo 'qty_api_refurbished : ' . $qty_api_refurbished . ' ';
echo '$Condition : ' . $Condition . ' ';
echo 'Availability : ' . $Availability . ' ';
echo 'IsEligibleForSuperSaverShipping : ' . $IsEligibleForSuperSaverShipping . '';
echo 'isset pricemain : ' . isset($pricemain) . ' ';
echo 'isset Availability : ' . isset($Availability) . ' ';
echo 'isset qty_api : ' . isset($qty_api) . '';
echo 'empty pricemain : ' . empty($pricemain) . ' ';
echo 'empty LowestNewPrice : ' . empty($LowestNewPrice) . ' ';
echo 'empty qty_api : ' . empty($qty_api) . ' ';
}
//exit ;
// only run code if we have real values for the 3 components : $qty_api - $pricemain - $Availability
if (isset($qty_api) && $visitor_type == "human") {
if (isset($_GET['test1test'])) //just for debug ...
{ echo 'have values for $qty_api - $pricemain - $Availability ' . ' ';}
// if ($qty_api > 0 && $pricemain > 0 && !strpos(strtolower($Availability), 'out of stock') && !strpos(strtolower($Availability), 'weeks') && !strpos(strtolower($Availability), 'months') && !strpos(strtolower($Availability), 'not available'))
// {
if ($qty_api > 0 && $pricemain > 0 && !strpos(strtolower($Availability), 'out of stock') && !strpos(strtolower($Availability), 'not available'))
{
if (isset($_GET['test1test']))
{ echo ' values for $qty_api - $pricemain - $Availability are OK' . ' ';} //just for debug ...
// update price in case we have sale price in effect
//if (isset($saleprice)) { if ( $saleprice > 0) { $pricemain = $saleprice ; } }
}
else // values are not good
{ if (isset($_GET['test1test'])) { echo 'bad values ' . ' ';}
// set $qty_api to zero - out of stock...
$qty_update = 0; $qty_api = 0;
//if (isset($Availability) == false) {$Availability = '';}
if (isset($pricemain) == false) {$pricemain = 0;}
$sql_delete_first = "delete from from_bg_small where product_sku = '" .$id_param . "'";
mysqli_query($con_db,$sql_delete_first);
$sql_insert = "insert into from_bg_small (product_sku, product_name,qty,product_price,availability,is_eligible_for_super_saver_shipping,qty_u) values
('" .$id_param . "', '". $product_name ."', ". $qty_update .", ". $pricemain .", '". $Availability ."', ". $IsEligibleForSuperSaverShipping .", ". $qty_u .") ";
mysqli_query($con_db,$sql_insert);
if (isset($_GET['test1test'])) { echo 'sql_insert from_bg_small ' . $sql_insert . ' ';}
}
}
/* disable no need to update if no value in API
else // the item can not be retrieved using the api so we set it to out of stock
{
// true for amazon api only - on walmart we have limit of 5000 hits per day which is not enought..
if (strpos($warehouse_item,'amzn') !== false && $visitor_type == "human")
{
//echo "error : qty or price or availability can not be retrieved via the api ";
//make the item out of stock by setting the qty to zero...
// 30/04/2016 - api is now working for all items - set this to 10 as emergency fix .... later re change it to zero....
$qty_update = 0;
// disable real time updates - we will update once per day to comply with google shopping
$sql_delete_first = "delete from from_bg_small where product_sku = '" .$id_param . "'";
mysqli_query($con_db,$sql_delete_first);
$sql_insert = "insert into from_bg_small (product_sku, qty) values ('" .$id_param . "', ". $qty_update .") ";
mysqli_query($con_db,$sql_insert);
}
}
*/
}
//end of real time checking if we have in stock for amazon item
//////////////////////////////////////////
// free up the resources
//if(is_resource($con_db)) { mysqli_close($con_db); }
/******taken from header.php******/
$search_param = '';
// email code - contact us with questions ....
$email_q_err='';
// some filtering based on warehouse and store_id - as defined in domains.php
//we have usa client with usa web site to show him only usa warehouse item
// update fix - since we select the item via the product_sku - we don't really need the below code -
$warehouse_sql_text = '';
/* if (isset($warehouse_item)) {
$warehouse_sql_text = " from_bg.warehouse = '" . $warehouse_item . "' and ";
} */
// check if we have different store id then zero then we will only show sub set of items for that store....
$store_id_sql_text = '' ;
if (isset($store_id)) {
$store_id_sql_text = " from_bg.store_id = " . $store_id . " and ";
}
$prime_sql_text ='';
if (isset($show_prime_items_only)) {
if ($show_prime_items_only==1) {
$prime_sql_text = "from_bg.availability = 'Usually ships in 24 hours' and is_eligible_for_super_saver_shipping=1 and ";
}
}
// small fix for dealz17 ...
if ($domain_1 == "www.dealz17.com") {$binding_sql_text =='';}
// check to see if item in DB at all ... if yes then we will check if we can display in store ...
$sql_select_join = "SELECT from_bg.*, from_bg.product_price*".$discount_amount."+".$flat_fee." as 1cd_price, from_bg_product_description.product_description FROM from_bg inner join from_bg_product_description on from_bg.product_sku = from_bg_product_description.product_sku where " . $prime_sql_text . $warehouse_sql_text . $binding_sql_text . $forbidden_items_sql_text . $store_id_sql_text . " from_bg_product_description.product_sku = '" . $id_param . "'";
if ($visitor_type == "bot") {
$sql_select_join = "SELECT from_bg.*, from_bg.product_price*".$discount_amount."+".$flat_fee." as 1cd_price, from_bg.product_name as product_description FROM from_bg where " . $prime_sql_text . $warehouse_sql_text . $binding_sql_text . $forbidden_items_sql_text . $store_id_sql_text . " from_bg.product_sku = '" . $id_param . "'";
};
// check to see if item in DB at all ... if yes then we will check if we can display in store ...
//$sql_select = "SELECT *, product_price*".$discount_amount."+".$flat_fee." as 1cd_price FROM from_bg where " . $prime_sql_text . $warehouse_sql_text . $store_id_sql_text . " product_sku = '" . $id_param . "'";
//we will check the store_id and warehouse in the code below since we want to know if the item in is DB at all since we have a funciton that loads it from amazon to from_bg_inserts ....
$result = mysqli_query($con,$sql_select_join);
if (isset($_GET['test1test'])) { echo '$sql_select_join 0: ' . $sql_select_join. ' ' ; }
if (isset($_GET['test1test'])) { echo '$sql_select- is item in from_bg - mysqli_num_rows - ? 0 : ' . mysqli_num_rows($result). ' ' ; }
// if not in from_bg DB try to get it from_bg_inserts ....
if (mysqli_num_rows($result)==0) {
$result = null;
$sql_select_join = "SELECT from_bg_inserts.*, from_bg_inserts.product_price*".$discount_amount."+".$flat_fee." as 1cd_price, from_bg_inserts.product_description FROM from_bg_inserts where " . str_replace('from_bg','from_bg_inserts',$prime_sql_text . $warehouse_sql_text . $binding_sql_text . $forbidden_items_sql_text . $store_id_sql_text ) . " from_bg_inserts.product_sku = '" . $id_param . "'";
$result = mysqli_query($con,$sql_select_join);
}
// in case of using ai text we will use this sql join statement to get data from from_bg_ai table
if ( $use_ai_product_name == true ) {
//$sql_select_join = "SELECT from_bg_ai.product_name_ai as product_name, from_bg.*, from_bg.product_price*".$discount_amount."+".$flat_fee." as 1cd_price, from_bg_product_description.product_description FROM from_bg inner join from_bg_product_description on from_bg.product_sku = from_bg_product_description.product_sku inner join from_bg_ai on from_bg_product_description.product_sku = from_bg_ai.product_sku where " . $prime_sql_text . $warehouse_sql_text . $binding_sql_text . $forbidden_items_sql_text . $store_id_sql_text . " from_bg_product_description.product_sku = '" . $id_param . "'";
$sql_select_join = "SELECT from_bg_ai.product_name_ai as product_name, from_bg.*, from_bg.product_price*".$discount_amount."+".$flat_fee." as 1cd_price, from_bg_ai.product_name_ai as product_name FROM from_bg inner join from_bg_ai on from_bg.product_sku = from_bg_ai.product_sku where " . $prime_sql_text . $warehouse_sql_text . $binding_sql_text . $forbidden_items_sql_text . $store_id_sql_text . " from_bg.product_sku = '" . $id_param . "'";
$result = mysqli_query($con,$sql_select_join);
}
//debugging ...
if (isset($_GET['test1test'])) { echo '$sql_select_join 1: ' . $sql_select_join. ' ' ; }
if (isset($_GET['test1test'])) { echo '$sql_select- is item in from_bg - mysqli_num_rows - ? 1 : ' . mysqli_num_rows($result) . ' ' ; }
$item_in_db = false;
if (mysqli_num_rows($result)>0)
{
//// check the memory on this page //////////////
//if (isset($_GET['test1test'])) { echo 'memory_get_usage : ' . memory_get_usage() . ' ' ; }
$item_in_db = true;
// item is in DB - fetch it ...
while($row = mysqli_fetch_array($result))
{ $array_item[] = $row; }
$date_mod = $array_item[0]['date_mod'];
if (isset($_GET['test1test'])) { echo ' - server time : ' . date("Y-m-d H:i:s") . ' ' ; }
if (isset($_GET['test1test'])) { echo ' - date_mod : ' . $date_mod . ' ' ; }
if (isset($_GET['test1test'])) { echo ' - diff-between-hours : ' . abs(strtotime(date("Y-m-d H:i:s")) - strtotime($date_mod))/(60*60) . ' ' ; }
$line_id = $array_item[0]['line_id'];
$store_id_value = $array_item[0]['store_id'];
$deleted = $array_item[0]['deleted'];
if (isset($_GET['test1test'])) { echo '$ - deleted : ' . $deleted . ' ' ; }
$price = $array_item[0]['1cd_price'];
$show_in_store_value = $array_item[0]['show_in_store'];
$binding = $array_item[0]['binding'];
$product_group = $array_item[0]['product_group'];
$product_type = $array_item[0]['product_type'];
$label = $array_item[0]['label'];
$qty_in_stock= $array_item[0]['qty'];
//if (isset($_GET['test1test'])) { echo 'qty_in_stock : ' . $qty_in_stock . ' ' ; }
//if ($tag == 'failed') {$qty_in_stock = 0;}
// if not a valid asin we will show as out of stock ...
if ($valid_asin == 0) {$qty_in_stock = 0;}
if (isset($_GET['test1test'])) { echo 'qty_in_stock : ' . $qty_in_stock . ' ' ; }
$item_warehourse = $array_item[0]['warehouse'];
$sold_qty = $array_item[0]['sold_qty'];
$item_sku = $array_item[0]['product_sku'];
$category = $array_item[0]['category'];
$sub_category = $array_item[0]['sub_category'];
$last_node = $array_item[0]['last_node'];
$cat_text = $array_item[0]['cat_text'];
$parent_sku = $array_item[0]['parent_sku'];
if ($parent_sku <> "") {$parent_asin = str_replace($product_sku_prefix,"",$parent_sku); $parent_sku_db = $parent_sku;}
if (!isset($cat_text)) { $cat_text ='';}
$cat_text_array = explode(' > ', $cat_text);
if (isset($_GET['test1test'])) { echo 'cat_text_array : ' . $cat_text_array[0] . $cat_text_array[1] . $cat_text_array[2]. $cat_text_array[3]. $cat_text_array[4]. $cat_text_array[5].' ' ; }
if ($cat_text_array[0] !== '') {$cat_text_0 = $cat_text_array[0] . ' > ' ;}
if ($cat_text_array[1] !== '') {$cat_text_1 = $cat_text_array[1] . ' > ' ;}
if ($cat_text_array[2] !== '') {$cat_text_2 = $cat_text_array[2] . ' > ' ;}
if ($cat_text_array[3] !== '') {$cat_text_3 = $cat_text_array[3] . ' > ' ;}
if ($cat_text_array[4] !== '') {$cat_text_4 = $cat_text_array[4] . ' > ' ;}
if ($cat_text_array[5] !== '') {$cat_text_5 = $cat_text_array[5] ;}
$cat_text_show = $cat_text_0 . $cat_text_1 . $cat_text_2 . $cat_text_3 . $cat_text_4 . $cat_text_5 ;
$cat_text_show =str_replace("Categories >","",$cat_text_show);
$cat_text_show =str_replace("Departments >","",$cat_text_show);
$cat_text_show =str_replace("Products >","",$cat_text_show);
if (isset($_GET['test1test'])) { echo "new show " . $cat_text_show.' '; }
$cat_text_array[5] = trim($cat_text_array[5]);
///// search for handmade products
$hand_made_item = false;
if (in_array('Handmade Products', $cat_text_array)) {$hand_made_item = true;}
if (isset($_GET['test1test'])) { echo 'hand_made_item : ' . $hand_made_item . ' ' ; }
///// /////
if (strlen($array_item[0]['isbn']) == 13) {$gtin =$array_item[0]['isbn'];}
else if (strlen($array_item[0]['upc']) == 12 ) {$gtin =$array_item[0]['upc'];}
else if (strlen($array_item[0]['ean']) == 12 || strlen($array_item[0]['ean']) == 13) {$gtin = $array_item[0]['ean'];}
$mpn = $array_item[0]['mpn'];
$sales_rank = $array_item[0]['sales_rank'];
$item_name = $array_item[0]['product_name'];
$item_desc = $array_item[0]['product_description'];
$sql_get_prodcut_description = "select product_description from from_bg_product_description where product_sku = '" . $id_param . "'";
$result_prodcut_description = mysqli_query($con,$sql_get_prodcut_description);
$row_prodcut_description = mysqli_fetch_assoc($result_prodcut_description);
if (mysqli_num_rows($result_prodcut_description)>0) {
$product_description = $row_prodcut_description['product_description'];
if (isset($_GET['test1test'])) { echo 'sql_get_prodcut_description - 00: ' . $sql_get_prodcut_description . ' ' ; }
if (isset($_GET['test1test'])) { echo 'item_in_db_product_description - 00: ' . $product_description . ' ' ; }
}
$customer_reviews = $array_item[0]['customer_reviews'];
$warranty = $array_item[0]['warranty'];
$manufacturer = $array_item[0]['manufacturer'];
$model = $array_item[0]['model'];
$size = $array_item[0]['size'];
$Weight = $array_item[0]['weight'];
$Height = $array_item[0]['height'];
$Length = $array_item[0]['length'];
$Width = $array_item[0]['width'];
$WeightUnits = $array_item[0]['weight_units'];
$SizeUnits = $array_item[0]['size_units'];
$brand = $array_item[0]['brand'];
$condition = 'NewCondition'; $condition_text = 'New';
if (strpos(strtolower($item_name), 'refurbished') !== false || strpos(strtolower($item_name), 'renewed') !== false ) { $condition = 'RefurbishedCondition'; $condition_text = 'Refurbished';}
if (strpos(strtolower($item_name), 'open box') !== false ) { $condition = 'UsedCondition'; $condition_text = 'Used';}
$color = $array_item[0]['color'];
$clothing_size = $array_item[0]['clothing_size'];
$image_url0 = $array_item[0]['image_url0'];
$local_image_url0 =$array_item[0]['local_image_url0'];
if (isset($_GET['test1test'])) { echo 'image_url0 : ' . $image_url0 . ' ' ; }
$image_url1 =$array_item[0]['image_url1'];
$local_image_url1 =$array_item[0]['local_image_url1'];
$image_url2 =$array_item[0]['image_url2'];
$local_image_url2 =$array_item[0]['local_image_url2'];
$image_url3 =$array_item[0]['image_url3'];
$local_image_url3 =$array_item[0]['local_image_url3'];
$image_url4 =$array_item[0]['image_url4'];
$local_image_url4 =$array_item[0]['local_image_url4'];
$image_url5 =$array_item[0]['image_url5'];
$local_image_url5 =$array_item[0]['local_image_url5'];
$image_url6 =$array_item[0]['image_url6'];
$local_image_url6 =$array_item[0]['local_image_url6'];
$similarproduct0 =$array_item[0]['similarproduct0'];
$similarproduct1 =$array_item[0]['similarproduct1'];
$similarproduct2 =$array_item[0]['similarproduct2'];
$similarproduct3 =$array_item[0]['similarproduct3'];
$similarproduct4 =$array_item[0]['similarproduct4'];
if (isset($_GET['test1test'])) { echo '$show_in_store_value : ' . $show_in_store_value . ' ' ; }
if ( $show_in_store_value==0) { exit; }
// code to ignore deleted in case of some last_node as we checkout via stripe - stripe is only accepted by 2daydliver as only there we have SSL..
$forbidden_last_node_by_paypal = array("Hemp Oil", "Electronic Cigarettes", "Cigarettes", "Tobacco Products", "Ammunition","Tactical Knives");
/**/ if ($domain_1 == "www.2daydeliver.com" && 1 == 0) { // disalbed as stripe is disabled as a gateway ...
if ( $deleted==1 && in_array($last_node, $forbidden_last_node_by_paypal))
{$deleted = 0 ;
$_SESSION['show_only_paypal'] = false; $show_only_paypal = false;
$_SESSION['show_only_stripe'] = true; $show_only_stripe = true;}
}
// code to reflect forbidden stripe brands ...
$forbidden_brands_by_stripe = array("apple", "adidas");
if (in_array(strtolower($brand), $forbidden_brands_by_stripe)) {
$_SESSION['show_only_stripe'] = false; $show_only_stripe = false;
$_SESSION['show_only_paypal'] = true; $show_only_paypal = true;
}
//code for forbidden brands as take from array in domains.php file
if (in_array(strtolower($brand), $forbidden_brands )) {
$deleted=1;
}
//code for forbidden keywords that pp or brand names do not like us to show - we will search the item name for the forbideen keyword
if ($forbidden_keywords) {
foreach ($forbidden_keywords as $value_word) {
if (strpos(strtolower($item_name),strtolower($value_word)) !== false ) { $deleted=1;}
}
}
// if we have both show_only_paypal & show_only_stripe then we will exit since none can be displayed...
//if ($show_only_stripe == true && $show_only_paypal == true) { exit; }
if (isset($_GET['test1test'])) { echo '$deleted : ' . $deleted . ' ' ; }
// in case we have deleted items due to policy violations and such...
if ($deleted==1){ exit; }
//debugging ...
if (isset($_GET['test1test'])) { echo 'deleted : ' . $deleted . ' ' ; }
if (isset($_GET['test1test'])) { echo 'last_node : ' . $last_node . ' ' ; }
if (isset($_GET['test1test'])) { echo 'brand : ' . $brand . ' ' ; }
if (isset($_GET['test1test'])) { echo 'SESSION[show_only_stripe] : ' . $_SESSION['show_only_stripe'] . ' ' ; }
if (isset($_GET['test1test'])) { echo 'SESSION[show_only_paypal] : ' . $_SESSION['show_only_paypal'] . ' ' ; }
if (isset($_GET['test1test'])) { echo 'show_only_stripe : ' . $show_only_stripe . ' ' ; }
if (isset($_GET['test1test'])) { echo 'show_only_paypal : ' . $show_only_paypal . ' ' ; }
//// check the memory on this page //////////////
if (isset($_GET['test1test'])) { echo 'memory_get_usage : ' . memory_get_usage() . ' ' ; }
// adding code to support store id and warehouse parametes
// if store id param exist then we will check if we can show this item in this specific store...
//if (isset($store_id)) { if ($store_id_value <> $store_id) { $item_can_show_in_store = false; } }
//if (isset($warehouse_item)) { if ($item_warehourse <> $warehouse_item) { $item_can_show_in_store = false; } }
if (isset($_GET['test1test'])) { echo 'warehouse_item : ' . $warehouse_item . ' ' ; }
// load reviews and hi res queries here before so we can use the data ...
// first check to see if we have reviews in DB ... if not then load from amazon...
$reviews_total_record_found = false ;
if ($visitor_type == "human" && $show_reviews == true ) {
$sql_customer_reviews_total = " SELECT * from customer_reviews_total WHERE product_sku = '".$id_param."' LIMIT 1 ";
$result_customer_reviews_total = mysqli_query($con,$sql_customer_reviews_total);
if( mysqli_num_rows($result_customer_reviews_total) <= 0 ){ $reviews_total_record_found = false ;}
else { $reviews_total_record_found = true ;
$row_of_result_customer_reviews_total = mysqli_fetch_array($result_customer_reviews_total);
$review_total = $row_of_result_customer_reviews_total['review_total'];
$star_rating_total = $row_of_result_customer_reviews_total['star_rating_total'];
}
}
}
//echo $use_ai_product_name; echo ' ';
//echo $item_in_db; echo ' ';
// if item not in db and this item has ai text - it means we had an issue and hence we will just exit ...
// usually all items in from_bg_ai table are already added to DB and hence this will be very rate case
if ($use_ai_product_name == true && $item_in_db == false) { exit; }
//// check the memory on this page //////////////
if (isset($_GET['test1test'])) { echo 'memory_get_usage : ' . memory_get_usage() . ' ' ; }
if (isset($qty_api) && $visitor_type == "human" && $api_use == 1) {
///////////////////////////////////
// if sku / adin not in DB we will ADD It - directly to from_bg_inserts table then we will re run query
if ($item_in_db == false && (strpos($warehouse_item,'amzn') !== false || $warehouse_item == 'wmt' || $warehouse_item == 'ae') && $visitor_type == "human")
// load from amazon directly ( since item is not in DB... we will store it in inserts table then add it to DB daily...
{
// not in our DB so add it...
$sku_from_product_details = $id_param;
$category_from_product_details = 'General';
$sub_category_from_product_details = 'General';
$last_node_from_product_details = 'General';
if (isset($_GET["last_node"]))
{ //check if last_node is in google taxonomy
$result_categ = mysqli_query($con,"select category from google_taxonomy where last_node = '" . urldecode($_GET["last_node"]) . "'");
while($row = mysqli_fetch_array($result_categ))
{ //find the main category and main sub_category
$categ_split_two_times = explode('>', $row['category'],2);
$category_from_product_details = str_replace(array("\n", "\r"), '',$categ_split_two_times[0]);
$sub_category_from_product_details = str_replace(array("\n", "\r"), '',$categ_split_two_times[1]); $last_node_from_product_details = urldecode($_GET["last_node"]);
}
}
if (strpos($warehouse_item,'amzn') !== false)
{ //require 'amazon_api/amazonapi/insert_from_product_details.php';
require 'insert_from_product_details.php';
}
else if ($warehouse_item == 'wmt')
{ // require 'walmart_api/walmartapi/insert_from_product_details_wmt.php';
require 'insert_from_product_details_wmt.php';
}
else if ($warehouse_item == 'ae')
{ // require 'walmart_api/walmartapi/insert_from_product_details_wmt.php';
require 'insert_from_product_details_ae.php';
}
///// varialbes are suppose to be loaded here see insert_from_product_details.php - if not then item was not added...
}
// added code in case item is in DB and from amazon to update it via insertion
///////////////////////////////////
// if sku / asin in DB we will ADD It - directly to from_bg_inserts table then we will re run query
// add only if more then 1 day older - cancelled as we now have many used items to add changed 24 to 0
if (isset($_GET['test1test'])) { echo 'item_in_db : ' . $item_in_db . ' ' ; }
if ($item_in_db == true && strpos($warehouse_item,'amzn') !== false && $visitor_type == "human" && 1==1 && (abs(strtotime(date("Y-m-d H:i:s")) - strtotime($date_mod))/(60*60)) > 0)
// load from amazon directly ( since item is not in DB... we will store it in inserts table then add it to DB daily...
{
if (isset($_GET['test1test'])) { echo 'insert_from_product_details : ' . $item_in_db . ' ' ; }
$sku_from_product_details = $id_param; // in our DB
$category_from_product_details = $category;
$sub_category_from_product_details = $sub_category;
$last_node_from_product_details = $last_node;
//require 'amazon_api/amazonapi/insert_from_product_details.php';
require 'insert_from_product_details.php';
///// varialbes are suppose to be loaded here see insert_from_product_details.php - if not then item was not added...
}
}
?>
' ; }
//change item title for SEO
$item_name_m = $item_name;
$value_m = "";
$category_m=str_replace(">"," ",$category);
$category_m=str_replace("&"," ",$category_m);
$category_m=str_replace("-"," ",$category_m);
$category_m = $category_m . " " ;
$sub_category_m=str_replace(">"," ",$sub_category);
$sub_category_m=str_replace("&"," ",$sub_category_m);
$sub_category_m=str_replace("-"," ",$sub_category_m);
$sub_category_m = $sub_category_m . " " ;
$array_category_words=explode(" ", $category_m . $sub_category_m);
// loop through array
foreach ($array_category_words as $value) {
if ($value !== " " && $value !== "")
{
if (strpos($item_name, $value) === false)
{
//echo strpos($item_name, $value);
$value_m = $value_m . " " . $value;
}
}
}
//item name for meta tags for SEO
$item_name_m = $item_name . " " . $value_m;
//item name with added brand / size / color / etc
//first check if we do not have that alrady in the name then add it.
$item_name_extended=$item_name;
//check and possibly add brand into the title...
// structgure of title will be : brand + item_name + department + color + clothing size + size
/*
if (isset( $array_item[0]['brand']))
{ if (!empty( $array_item[0]['brand'])) { if (strpos($item_name, $array_item[0]['brand']) === false) { $item_name_extended = $array_item[0]['brand'] . " " . $item_name;} } }
//check and possibly add department into the title...
if (isset( $array_item[0]['department']))
{ if (!empty( $array_item[0]['department'])) { if (strpos($item_name, $array_item[0]['department']) === false) { $item_name_extended = $item_name_extended . ", " . $array_item[0]['department'];} } }
//check and possibly add color into the title...
if (isset( $array_item[0]['color']))
{ if (!empty( $array_item[0]['color'])) { if (strpos($item_name, $array_item[0]['color']) === false) { $item_name_extended = $item_name_extended . ", " . $array_item[0]['color'];} } }
//check and possibly add clothing_size into the title...
if (isset( $array_item[0]['clothing_size']))
{ if (!empty( $array_item[0]['clothing_size'])) { if (strpos($item_name, $array_item[0]['clothing_size']) === false) { $item_name_extended = $item_name_extended . ", " . $array_item[0]['clothing_size'];} } }
//check and possibly add size into the title...
if (isset( $array_item[0]['size']))
{ if (!empty( $array_item[0]['size'])) { if (strpos($item_name, $array_item[0]['size']) === false) { $item_name_extended = $item_name_extended . ", " . $array_item[0]['size'];} } }
*/
if (isset( $array_item[0]['brand']))
{ if (!empty( $array_item[0]['brand'])) { if (strpos(strtolower(str_replace(' ', '',$item_name)), strtolower(str_replace(' ', '',$array_item[0]['brand']))) === false) {$item_name_extended = $array_item[0]['brand'] . " " . $item_name;} } }
//check and possibly add department into the title...
if (isset( $array_item[0]['department']))
{ if (!empty( $array_item[0]['department'])) { if (strpos(strtolower(str_replace(' ', '',$item_name)), strtolower(str_replace(' ', '',$array_item[0]['department']))) === false) { $item_name_extended = $item_name_extended . ", " . $array_item[0]['department'];} } }
//check and possibly add color into the title...
if (isset( $array_item[0]['color']))
{ if (!empty( $array_item[0]['color'])) { if (strpos(strtolower(str_replace(' ', '',$item_name)), strtolower(str_replace(' ', '',$array_item[0]['color']))) === false) { $item_name_extended = $item_name_extended . ", " . $array_item[0]['color'];} } }
//check and possibly add clothing_size into the title...
if (isset( $array_item[0]['clothing_size']))
//{ if (!empty( $array_item[0]['clothing_size'])) { if (strpos($title, $array_item[0]['clothing_size']) === false) { $item_name_extended = $item_name_extended . ", " . $array_item[0]['clothing_size'];} } }
{ if (!empty( $array_item[0]['clothing_size'])) { if (strpos(strtolower(str_replace(' ', '',$item_name)), strtolower(str_replace(' ', '',$array_item[0]['clothing_size']))) === false) { $item_name_extended = $item_name_extended . ", " . $array_item[0]['clothing_size'];} } }
//check and possibly add size into the title...
else if (isset( $array_item[0]['size']))
{ if (!empty( $array_item[0]['size'])) { if (strpos(strtolower(str_replace(' ', '',$item_name)), strtolower(str_replace(' ', '',$array_item[0]['size']))) === false) { $item_name_extended = $item_name_extended . ", " . $array_item[0]['size'];} } }
//finally replace the \' with ' and \" with "
$item_name_extended = str_replace("\'","'",$item_name_extended);
$item_name_extended = str_replace('\"','"',$item_name_extended);
//replace the word amazon with our store / business name :
//$item_name_extended = str_replace("Amazon",$business_name,$item_name_extended );
// same for item desc :
//finally replace the \' with ' and \" with "
//$item_desc = str_replace("==>","",$item_desc);
// $item_desc = '';
if (isset($_GET['test1test'])) { echo 'item_desc -- 5555 : ' . $item_desc . ' ' ; }
$item_desc = str_replace("\'","'",$item_desc);
$item_desc = str_replace('\"','"',$item_desc);
$item_desc_meta = strip_tags(substr(html_entity_decode($item_desc),0,300)) ;
$item_desc_meta = str_replace('>','',$item_desc_meta);
//replace the word amazon with our store / business name :
//$item_desc = str_replace("Amazon",$business_name,$item_desc );
//finally replace the \' with ' and \" with "
$brand = str_replace("\'","'",$brand);
$brand = str_replace('\"','"',$brand);
include 'header.php';?>
Departments > ','',$cat_text_show); } ?>
3rd Party Supplier - Calculating Delivery Information...
Please wait a few seconds, loading prices and shipping info from suppliers ... ';
ob_implicit_flush(1);
include "scrap_price_amazon.php";}
}
if ($visitor_type == "human" && isset($qty_api) && ($IsEligibleForSuperSaverShipping==0 || $IsEligibleForSuperSaverShipping==1 || isset($LowestUsedPrice) ) && 1 == 1 && $_SESSION['buyer_country'] == "United States") {
// firstly check in from_bg_small table to see if we already called the amazon page today - in such case we shall not call it again but rather take the date from the from_bg_small table
// that table will deleted daily via cron job so each day there should be fresh amazon scrapping...
// $sql_check_if_updated = "select * from from_bg_small where product_sku = '" .$id_param . "' and date_mod > (NOW() - INTERVAL 1 HOUR)";
$sql_check_if_updated = "select * from from_bg_small where product_sku = '" .$id_param . "' and (( date_mod > (NOW() - INTERVAL 1 HOUR) and is_eligible_for_super_saver_shipping = 1 ) OR ( date_mod > (NOW() - INTERVAL 72 HOUR) and is_eligible_for_super_saver_shipping = 0 and qty_u = 3 )) ";
$resut_of_check_if_updated = mysqli_query($con_db,$sql_check_if_updated);
if (mysqli_num_rows($resut_of_check_if_updated)>0)
{
// check if we have something in table ...
$row_of_check_if_updated = mysqli_fetch_array($resut_of_check_if_updated);
$qty_u = $row_of_check_if_updated['qty_u'];
if (isset($_GET['test1test']))
{ echo ' we have data in from_bg_small - qty_u - ' . $row_of_check_if_updated['qty_u'] .
' Availability - ' . $row_of_check_if_updated['availability'] .
' product_price - ' . $row_of_check_if_updated['product_price'] .
' product_name - ' . $row_of_check_if_updated['product_name'] .
' qty_u - ' . $row_of_check_if_updated['qty_u'] .
' arrive_date - ' . $row_of_check_if_updated['arrive_date'] .
' product_price - ' . $row_of_check_if_updated['product_price'] .
' '; }
//just for debug ...
// only if $qty_u==9 means this is from amazon scrap - so we can use this ...
// check if have the words arrives between bla bla...
// if ($row_of_check_if_updated['qty_u']==3 && strpos(strtolower(trim($row_of_check_if_updated['arrive_date'])),'between') == true && $row_of_check_if_updated['product_price']>0) {
if ($row_of_check_if_updated['qty_u']==3 && $row_of_check_if_updated['product_price']>0) {
$price_updated_today = true;
$pricemain = $row_of_check_if_updated['product_price'];
$Availability = $row_of_check_if_updated['availability'];
// set the arrive date to availability in this case...
$arrive_date = $row_of_check_if_updated['arrive_date']; ;
}
else {$price_updated_today = false; }
if (isset($_GET['test1test'])) { echo ' $price_updated_today - ' . $price_updated_today .' '; }
}
// set the price to be for used / warehouse deals / enable_warehouse_deals
// set $IsEligibleForSuperSaverShipping to 1 to support it is shipped from amazon
$processed_used_item = false ;
if ($price_updated_today == false && $visitor_type == "human" ) {
if (strpos($warehouse_item,'amzn') !== false && isset($LowestUsedPrice) && isset($qty_api_used) && $enable_warehouse_deals == true) {
if ( $LowestUsedPrice > 0 && $qty_api_used > 0 && $LowestUsedPrice < $LowestNewPrice )
{
// try to find out if there exit used like new - only if exist we will offer it to CS
// also need to see if it is sold via amazon or seller with shipping ...
//
$processed_used_item = true ;
require 'get_shipping_faster_used.php';
//exit ;
//$IsEligibleForSuperSaverShipping = 1;
if (isset($used_price)) {
if ($used_price > 0 ) {
$pricemain = $used_price;
$qty_api = $qty_api_used;
// update DB so next time we can skip this check ...
////////////////////// //////
if (isset($_GET['test1test'])) { echo ' Availability after scrapping used - ' . $Availability .' '; }
if (isset($_GET['test1test'])) { echo ' arrive_date after scrapping used ' . $arrive_date .' '; }
if (isset($_GET['test1test'])) { echo ' $pricemain after scrapping used' . $pricemain .' '; }
$sql_delete_first = "delete from from_bg_small where product_sku = '" .$id_param . "'";
mysqli_query($con_db,$sql_delete_first);
$sql_insert = "insert into from_bg_small (product_sku, product_name,qty,product_price,availability,is_eligible_for_super_saver_shipping, qty_u, arrive_date, shipping_from_country) values
('" .$id_param . "', '". $product_name ."', ". $qty_api .", ". $pricemain .", '". $Availability ."', ". $IsEligibleForSuperSaverShipping .", ". $qty_u .", '". $arrive_date ."', '". $shipping_from_country ."' ) ";
mysqli_query($con_db,$sql_insert);
// set this value so we don't need to scrap again..
$price_updated_today = true;
if (isset($_GET['test1test'])) { echo 'sql_insert from_bg_small 2 ' . $sql_insert . ' ';}
}
}
}
}
}
if (isset($_GET['test1test'])) { echo ' $price_updated_today - ' . $price_updated_today .' '; }
if ($processed_used_item == false && $found_prime_in_from_bg_small == false && $price_updated_today == false && $visitor_type == "human" ) {
// scrapping will start here if human and not bot ...
if (strpos($warehouse_item,'amzn') !== false && $IsEligibleForSuperSaverShipping==0 && 1 == 1 && $api_use == 1 && $hand_made_item !== true) {
// flash the content before we go to get scrapping which can be slow....
//echo ' Please wait a few seconds, loading prices and shipping info from suppliers ... ';
ob_implicit_flush(1);
if (isset($_GET['test1test'])) { echo ' $pricemain before scrapping - ' . $pricemain .' '; } //just for debug ...
// try with curl and http://proxybonanza.com/
//require 'amazon_api/custom_scrap/get_shipping_faster.php';
// !!!!!!! disabled scrapping and set $shipping_price to $5 or %5 which ever greater and arrive_date to below - to improve performance ...!!!!
// re enbaled as it did not had effect on performance of orders
//require 'get_shipping_faster.php';
//$shipping_price = 0 ;
$shipping_price = max(5,0.05 * $pricemain);
// add shipping price as we received from above included get_shipping.php script
if ($pricemain > 0) {
$arrive_date='Arrives between 2-7 days';
$pricemain = $pricemain + $shipping_price;
}
// availablitly in this case is "arrives between" as taken from amazon scrap
// $qty_u we get from scrapping script - 0 or 9 in case of amazon...
//if (isset($arrive_date)) { $Availability = $arrive_date ; }
if (isset($_GET['test1test'])) { echo ' shipping_price after scrapping - ' . $Availability .' '; } //just for debug ...
if (isset($_GET['test1test'])) { echo ' Availability after scrapping - ' . $Availability .' '; } //just for debug ...
if (isset($_GET['test1test'])) { echo ' arrive_date after scrapping - ' . $arrive_date .' '; } //just for debug ...
if (isset($_GET['test1test'])) { echo ' $pricemain after scrapping - ' . $pricemain .' '; } //just for debug ...
} else if ($warehouse_item == 'wmt') {
// for walmart we include shipping only if price is below $35 ...Orders under $35 ship for $5.99
if ($pricemain < 35.01) { $shipping_price = 5.99;} else { $shipping_price = 0;}
// add shipping price
$pricemain = $pricemain + $shipping_price;
// code for handmade items - add 33% shipping
} else if (strpos($warehouse_item,'amzn') !== false && $hand_made_item == true) {
$shipping_price = 0.33 * $pricemain;
$pricemain = $pricemain + $shipping_price;
$arrive_date = 'Usually takes between 2 and 7 days to create';
if (isset($_GET['test1test'])) { echo ' hand_made_item - $pricemain - ' . $pricemain .' '; } //just for debug ...
}
////////////////////// //////
$sql_delete_first = "delete from from_bg_small where product_sku = '" .$id_param . "'";
mysqli_query($con_db,$sql_delete_first);
$sql_insert = "insert into from_bg_small (product_sku, product_name,qty,product_price,availability,is_eligible_for_super_saver_shipping, qty_u, arrive_date, shipping_from_country) values
('" .$id_param . "', '". $product_name ."', ". $qty_api .", ". $pricemain .", '". $Availability ."', ". $IsEligibleForSuperSaverShipping .", ". $qty_u .", '". $arrive_date ."', '". $shipping_from_country ."' ) ";
mysqli_query($con_db,$sql_insert);
// added code for price history - we will track and analyze using another script to find better product deals and price drops ....
if ($pricemain > 0 && 1==0) {
// calc current avg price
$avg_price = 0 ;
$price_sql = "select product_price from from_bg_history_prices where product_sku = '" .$id_param . "' order by date_mod desc limit 1";
$result_price_sql = mysqli_query($con,$price_sql);
$row_of_price_sql = mysqli_fetch_array($result_price_sql);
$current_price = $row_of_price_sql['product_price'];
echo $current_price ; echo $pricemain ;
if ($current_price == null || $current_price > 1.03*$pricemain || $current_price < 0.97*$pricemain ) {
$sql_insert_history_prices = "insert into from_bg_history_prices (product_sku, product_price) values ('" .$id_param . "', ". $pricemain ." ) ";
mysqli_query($con_db,$sql_insert_history_prices);
}
//echo $sql_insert_history_prices;
}
if (isset($_GET['test1test'])) { echo 'sql_insert from_bg_small 3 ' . $sql_insert . ' ';}
}
}
}
//////////////////////////////////////////////////////////
//// FOR INT BUYERS CACLULATE the price DISABLED - use new simple code below
///////////////////////////// ////
//LOADING INT SHIPPING PRICE HERE - WE CAN FLUSH to browser before we finish to process slow call to amazon scrapping...
// get the shipping price via scrapping directly from amazon product page
// we are doing it using Free CURL and also sometimes PAID rotating proxy which we pay $$ / month
// we will only use this script for non prime items ...
$price_updated_today = false; // only do this for non prime / seller items
$can_ship_to_country = true; // default is true but it can be changed to false below
if (strpos($warehouse_item,'amzn') !== false && $visitor_type == "human" && isset($qty_api) && 1 == 0 && $_SESSION['buyer_country'] !== "United States") {
// firstly check in from_bg_small table to see if we already called the amazon page today - in such case we shall not call it again but rather take the date from the from_bg_small table
// that table will deleted daily via cron job so each day there should be fresh amazon scrapping...
$sql_check_if_updated = "select * from from_bg_sku_country_shipping where product_sku = '" .$id_param . "' and country = '" . $_SESSION['buyer_country'] . "' and date_mod > (NOW() - INTERVAL 240 HOUR)";
$resut_of_check_if_updated = mysqli_query($con_db,$sql_check_if_updated);
if (isset($_GET['test1test'])) { echo $sql_check_if_updated .' '; }
if (mysqli_num_rows($resut_of_check_if_updated)>0)
{
// check if we have something in table ...
$row_of_check_if_updated = mysqli_fetch_array($resut_of_check_if_updated);
if (isset($_GET['test1test']))
{ echo ' we have data in from_bg_sku_country_shipping - shipping_time - ' . $row_of_check_if_updated['shipping_time'] . ' can_ship - ' . $row_of_check_if_updated['can_ship'] . ' shipping_price - ' . $row_of_check_if_updated['shipping_price'] .' '; }
$price_updated_today = true;
$shipping_price = $row_of_check_if_updated['shipping_price'];
$shipping_time = $row_of_check_if_updated['shipping_time'];
// set the arrive date to availability in this case...
$can_ship = $row_of_check_if_updated['can_ship'];
if ($can_ship == 0 || $shipping_price == -1) // can not ship to this country
{$can_ship_to_country = false; }
else if ($can_ship == 1 ) {$can_ship_to_country = true;
$pricemain = $pricemain + $shipping_price;
if ($shipping_time !== 'NA') {$arrive_date = $shipping_time;} else {$arrive_date='Arrives between 3-10 days';}
}
} else {$price_updated_today = false; }
if (isset($_GET['test1test'])) { echo ' $price_updated_today - ' . $price_updated_today .' '; }
if ($price_updated_today == false && $visitor_type == "human" ) {
// scrapping will start here if human and not bot ...
if (strpos($warehouse_item,'amzn') !== false && 1 == 1 && $api_use == 1 && $hand_made_item !== true) {
// flash the content before we go to get scrapping which can be slow....
//echo ' Please wait a few seconds, loading prices and shipping info from suppliers ... ';
ob_implicit_flush(1);
if (isset($_GET['test1test'])) { echo ' $pricemain before scrapping - ' . $pricemain .' '; } //just for debug ...
// try with curl and http://proxybonanza.com/
//require 'amazon_api/custom_scrap/get_shipping_faster.php';
require 'mts_amazon_check_ship_country.php';
if ($can_ship == 0 || $shipping_price == -1) // can not ship to this country
{$can_ship_to_country = false; }
else if ($can_ship == 1 ) {$can_ship_to_country = true;
$pricemain = $pricemain + $shipping_price;
if ($shipping_time !== 'NA') {$arrive_date = $shipping_time;} else {$arrive_date='Arrives between 3-10 days';}
}
// availablitly in this case is "arrives between" as taken from amazon scrap
// $qty_u we get from scrapping script - 0 or 9 in case of amazon...
//if (isset($arrive_date)) { $Availability = $arrive_date ; }
if (isset($_GET['test1test'])) { echo ' can_ship after scrapping - ' . $can_ship .' '; } //just for debug ...
if (isset($_GET['test1test'])) { echo ' shipping_price after scrapping - ' . $shipping_price .' '; } //just for debug ...
if (isset($_GET['test1test'])) { echo ' shipping_time after scrapping - ' . $shipping_time .' '; } //just for debug ...
}
////////////////////// //////
$sql_delete_first = "delete from from_bg_sku_country_shipping where product_sku = '" .$id_param . "' and country = '" . $_SESSION['buyer_country'] . "'";
mysqli_query($con_db,$sql_delete_first);
$sql_insert = "insert into from_bg_sku_country_shipping (product_sku, country,shipping_time,shipping_price,can_ship) values
('" .$id_param . "', '". $_SESSION['buyer_country'] ."', '". $shipping_time ."', ". $shipping_price .", ". $can_ship ." ) ";
if (isset($_GET['test1test'])) {echo $sql_insert .' ';}
mysqli_query($con_db,$sql_insert);
}
}
/// END INT BUYERS ////////////////////////////////
/// NEW CODE FOR INT BUYERS ////////////////////////////////
if (strpos($warehouse_item,'amzn') !== false && $visitor_type == "human" && isset($qty_api) && 1 == 1 && $_SESSION['buyer_country'] !== "United States") {
//for int buyers show only paypal ... disabled for now ..
//if ($_SESSION['show_only_stripe'] == false) {
//$_SESSION['show_only_paypal'] = true; $show_only_paypal = true; }
$can_ship_to_country = true;
$pricemain = 1.33 * $pricemain;
$arrive_date='Arrives between 3-10 days'; }
/// END CODE INT BUYERS ////////////////////////////////
/// code to fix empty Availability - in this case arrive_date will be set to 7-15 days
if (isset($Availability)) {
if (trim($Availability) == '') {$arrive_date='Arrives between 3-10 days';}
}
// code for downloaded software JAN-2023
if ( $binding == "Software Download") { $arrive_date='Immediate Download'; $qty_in_stock=15; }
//// we will use price and qty_api retrieved from amazon / walmart in the product detailed page...
if (isset($_GET['test1test'])) { echo 'qty_api - ' . $qty_api . ' qty_in_stock before isset($qty_api) - ' . $qty_in_stock .' '; }
if (isset($qty_api)) { $qty_in_stock = $qty_api;}
if (isset($_GET['test1test'])) { echo 'qty_api - ' . $qty_api . 'qty_in_stock after isset($qty_api) - ' . $qty_in_stock .' '; }
//check if we have forced qty_api in url then apply it
if (isset($_GET["forced_max_qty"]) && is_numeric($_GET["forced_max_qty"]) )
{$qty_in_stock=$_GET["forced_max_qty"];}
// Temp test : make all items in stock by setting $qty_in_stock to 1 when it is zero
/////////////////////////////////////
$out_of_stock = false;
if ($qty_in_stock == 0 && $sell_out_of_stock_in_store == true) {$out_of_stock = true; $arrive_date='Unknown delivery date'; $qty_in_stock=1;}
/////////////////////////////////////
//temp solution for serious bug on 07-06-2016
//$qty_in_stock = 12;
//temp solution for serious bug on 07-06-2016
// add 10 to each $qty_in_stock
if ($qty_in_stock > 0) { $qty_in_stock = $qty_in_stock + 10; }
//if we have price from amazon api we will use it instead of price from database
if (isset($pricemain) && $pricemain > 0) {
$price = $pricemain * $discount_amount + $flat_fee;
if (isset($_GET['test1test'])) { echo '$pricemain after api - ' . $pricemain .' '; } //just for debug ...
if (isset($_GET['test1test'])) { echo '$price after api - ' . $price .' '; } //just for debug ..
}
// save the item cost for later when we need to buy it from amazon...
$item_cost = ($price - $flat_fee)/$discount_amount;
if (isset($_GET['test1test'])) { echo 'item_cost - ' . $item_cost .' '; } //just for debug ..
// 12-03-2024 added code to check if we have amazon base discount for this item
///// check discount as defined by amazon
$savingspercent = null ;
$sql_check_savings = "SELECT savingspercent FROM from_bg_price_used where product_sku = '".$id_param."' and savingspercent is not null and savingspercent > 2";
$result_check_savings = mysqli_query($con_db,$sql_check_savings);
if (mysqli_num_rows($result_check_savings)>0) {
$row_of_result_check_savings = mysqli_fetch_array($result_check_savings);
$savingspercent = $row_of_result_check_savings['savingspercent']/100;
//$savingspercent = $savingspercent / 100 ;
//$promo_amount = $savingspercent;
if (isset($_GET['test1test']))
{ echo ' we have data in from_bg_price_used for item - savingspercent - ' . $savingspercent .' '; }
}
//// end of code for check discount as defined by amazon
// make the discount_amount which is the profit amount (my mistake in the name) lower as the price goes higher
//only if $discount_amount > 1.8 and $promo_amount > 0.89
if ($qty_discount == 1 )
{
if ($price > 20*$rate_factor && $price <= 40*$rate_factor) {$price = $price*0.9;}
else if ($price > 40*$rate_factor && $price <= 60*$rate_factor) {$price = $price*0.83;}
else if ($price > 60*$rate_factor && $price <= 80*$rate_factor) {$price = $price*0.78;}
else if ($price > 80*$rate_factor ) {$price = $price*0.75;}
}
if (isset($_GET['test1test'])) { echo '$price after qty_discount - ' . $price .' '; } //just for debug ..
//
?>
isMobile() || 1 == 1) { ?>
= 5 ) {?>
Features:","",$item_desc ); //remove features warding
//$item_desc = str_replace("Description:","",$item_desc ); //remove Description warding
/*$item_desc = str_replace("font-size: 12px","font-size:16px",$item_desc ); //fix font size
$item_desc = str_replace("font-size:12px","font-size:16px",$item_desc ); //fix font size
$item_desc = str_replace("Package included","Package includes",$item_desc ); //fix Package included
$item_desc = str_replace("Package Included","Package includes",$item_desc ); //fix Package included //Package Included
$item_desc = str_replace("banggood","1chinadirect",$item_desc ); //fix Package included //Package Included
*/
if ($show_smaller_title == true )
{ echo "Description: " . $item_name_extended_full . ""; }
//find item features
$item_desc = html_entity_decode($item_desc);
$item_desc = str_replace('\"','"',$item_desc);
//$item_desc = str_replace("==>","",$item_desc);
$pos_start = strpos($item_desc,"Features:") ;
$pos_finish = strpos($item_desc,"Description:") ;
$item_features = substr($item_desc,0, $pos_finish); //
// re style it
$item_features = str_replace('list-style: none','',$item_features);
//remove empty elements
$item_features = str_replace('','',$item_features);
//apply quick fix for know
curl hires... ';}
$hires_images = '';
if ($visitor_type == "human" && $show_bottom_images == true ) {
// first check to see if we have hires in DB ... if not then load from amazon...
$sql_select_hires = "select * from from_bg_hires where product_sku = '" . $id_param . "' ";
$resut_of_sql_select_hires = mysqli_query($con,$sql_select_hires);
//echo mysqli_num_rows($resut_of_sql_select_review); exit;
if (mysqli_num_rows($resut_of_sql_select_hires)>0)
{ $row_of_select_hires = mysqli_fetch_array($resut_of_sql_select_hires);
/*$hires_images =
"Hi resolution images
" ;
}
}
// if hi res is empty then load large images here ... then run scraping code...
if ($hires_images == '' && $show_bottom_images == true) {?>
View larger images
This site is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com.