หัวข้อ: ช่วยด้วยครับ AWS ครับ ดูcode ให้หน่อยผิดตรงไหนเนี่ย เริ่มหัวข้อโดย: krite2010 ที่ 04 มีนาคม 2010, 20:51:56 include('config.php');
function priceCheck($id,$sku,$price,$type){ $request = "http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=".KEYID."&AssociateTag=".AssocTag."&Version=2009-08-15&Operation=ItemLookup&ResponseGroup=ItemAttributes&ItemId=$sku&ResponseGroup=Medium,Offers"; $session = curl_init($request); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); $response = file_get_contents($request); $parsed_xml = simplexml_load_string($response); $awsListPrice=$parsed_xml->Items->Item->ItemAttributes->ListPrice->FormattedPrice; $awsListPriceDB=substr_replace($parsed_xml->Items->Item->ItemAttributes->ListPrice->Amount, '.', -2, 0); $awsOfferListPrice=$parsed_xml->Items->Item->Offers->Offer->OfferListing->Price->FormattedPrice; $awsOfferListPriceDB=substr_replace($parsed_xml->Items->Item->Offers->Offer->OfferListing->Price->Amount, '.', -2, 0); if($type=='regular'){ if($awsListPrice!=$price){ $con = mysql_connect(dbhost,dbuser,dbpass); mysql_select_db(dbname,$con); mysql_query("UPDATE catalog_product_entity_decimal SET value=$awsListPriceDB WHERE entity_id=$id AND attribute_id='59'"); mysql_close($con); print $awsListPrice; }else{ print $price; } } if($type=='final'){ if($awsOfferListPrice!=$price){ $con = mysql_connect(dbhost,dbuser,dbpass); mysql_select_db(dbname,$con); mysql_query("UPDATE catalog_product_entity_decimal SET value=$awsOfferListPriceDB WHERE entity_id=$id AND attribute_id='60'"); mysql_close($con); print $awsOfferListPrice; }else{ print $price; } } } function priceCheckCheckout($id,$sku,$price){ $request = "http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=".KEYID."&AssociateTag=".AssocTag."&Version=2009-08-15&Operation=ItemLookup&ResponseGroup=ItemAttributes&ItemId=$sku&ResponseGroup=Medium,Offers"; $session = curl_init($request); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); $response = file_get_contents($request); $parsed_xml = simplexml_load_string($response); $awsListPrice=$parsed_xml->Items->Item->ItemAttributes->ListPrice->FormattedPrice; $awsListPriceDB=substr_replace($parsed_xml->Items->Item->ItemAttributes->ListPrice->Amount, '.', -2, 0); $awsOfferListPrice=$parsed_xml->Items->Item->Offers->Offer->OfferListing->Price->FormattedPrice; $awsOfferListPriceDB=substr_replace($parsed_xml->Items->Item->Offers->Offer->OfferListing->Price->Amount, '.', -2, 0); if($awsOfferListPrice!=$price){ $con = mysql_connect(dbhost,dbuser,dbpass); mysql_select_db(dbname,$con); mysql_query("UPDATE catalog_product_entity_decimal SET value=$awsOfferListPriceDB WHERE entity_id=$id AND attribute_id='60'"); mysql_close($con); } } function itemLookup($sku, $qty){ $request = "http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=".KEYID."&AssociateTag=".AssocTag."&Version=2009-08-15&Operation=ItemLookup&ResponseGroup=ItemAttributes&ItemId=$sku&ResponseGroup=Medium,Offers"; $session = curl_init($request); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); $response = file_get_contents($request); $parsed_xml = simplexml_load_string($response); $offerListingId = urlencode($parsed_xml->Items->Item->Offers->Offer->OfferListing->OfferListingId); cartCreate($offerListingId, $qty); } function cartCreate($offerListingId, $qty){ $request = "http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=".KEYID."&AssociateTag=".AssocTag."&Version=2009-08-15&Operation=CartCreate&Item.1.OfferListingId=$offerListingId&Item.1.Quantity=$qty"; $session = curl_init($request); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); $response = file_get_contents($request); $parsed_xml = simplexml_load_string($response); showCartContents($parsed_xml); } function itemLookupAdd($sku, $qty, $cart, $hmac){ $request = "http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=".KEYID."&AssociateTag=".AssocTag."&Version=2009-08-15&Operation=ItemLookup&ItemId=$sku&ResponseGroup=Medium,Offers"; $session = curl_init($request); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); $response = file_get_contents($request); $parsed_xml = simplexml_load_string($response); $offerListingId = urlencode($parsed_xml->Items->Item->Offers->Offer->OfferListing->OfferListingId); cartAdd($offerListingId, $qty, $cart, $hmac); } function cartAdd($offerListingId, $qty, $cart, $hmac){ $request="http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=".KEYID."&AssociateTag=".AssocTag."&Version=2009-08-15&Operation=CartAdd&CartId=$cart&HMAC=$hmac&Item.1.OfferListingId=$offerListingId&Item.1.Quantity=$qty"; $session = curl_init($request); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); $response = file_get_contents($request); $parsed_xml = simplexml_load_string($response); showCartContents($parsed_xml); } function showCartContents($parsed_xml){ global $checkout; global $CartId; global $HMAC; $checkout = $parsed_xml->Cart->PurchaseURL; $CartId = $parsed_xml->Cart->CartId; $HMAC = $parsed_xml->Cart->URLEncodedHMAC; } ?> |