1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Amazon Plugin Mod

Discussion in 'PHP' started by locpicker, Nov 5, 2012.

  1. #1
    I want to modify this code to exclude items that are below a value that I set.

    Any help would be appreciated.

    <?php
    /*
    Plugin URI: http://wpnicheground.blogspot.com
    Plugin Name: WpZon Plugin for Wordpress
    Description: Add products from the Amazon Marketplace.
    Version: 1.1.1
    Date: September 13th, 2012
    Author: Lora 
    /*
    Licence: GNU General Public License v3.0
    More info: http://www.gnu.org/copyleft/gpl.html
    */
    
    function truncate($string, $limit, $break=".", $pad="") { 
        if(strlen($string) <= $limit) return $string;
        if (false !== ($breakpoint = strpos($string, $break, $limit))) {
          if($breakpoint < strlen($string) - 1) {
    	    $string = substr($string, 0, $breakpoint) . $pad;
    	  }
        }
        return $string;
      }
    
     
    
    function wpzon_shortcode( $atts ) {
     extract(shortcode_atts(array('keywords' => '', 'sindex' => '', 'snode' => '', 'listing' => '', 'sort' => '',  ), $atts));
    add_option( 'az_public', '' );
    add_option( 'az_secret', '' );
    add_option( 'az_atag', '' );
    add_option( 'az_country', '' ); 
    add_option( 'az_col', '' ); 
    add_option( 'az_pricecol', '' );  
    
    $publickey = get_option('az_public');
    $secretkey = get_option('az_secret');
    $atag = get_option('az_atag');
    $country = get_option('az_country');
    $col = get_option('az_col');
    $pricecol = get_option('az_pricecol');
     
    if ($pricecol == "") {$pricecol = "CD2323";}
    else {$pricecol = $pricecol;}
    
    $time = gmdate("Y-m-d\TH:i:s\Z");
    $uri = 'Operation=ItemSearch&Condition=All&Availability=Available&ResponseGroup=Large,EditorialReview,ItemAttributes,OfferFull,Offers&Version=2011-08-01';
    $uri .= "&Keywords=" . urlencode($keywords);
    $uri .= "&SearchIndex=$sindex";
    $uri .= "&BrowseNode=$snode";
    $uri .= "&Sort=$sort";
    $uri .= "&AWSAccessKeyId=$publickey";
    $uri .= "&AssociateTag=$atag";
    $uri .= "&Timestamp=$time";
    $uri .= "&Service=AWSECommerceService";
    $uri = str_replace(',','%2C', $uri);
    $uri = str_replace(':','%3A', $uri);
    $uri = str_replace('*','%2A', $uri);
    $uri = str_replace('~','%7E', $uri);
    $uri = str_replace('+','%20', $uri);
    $sign = explode('&',$uri);sort($sign);$host = implode("&", $sign);
    if ($country == "jp") {$host = "GET\necs.amazonaws.".$country."\n/onca/xml\n".$host;}
    else {$host = "GET\nwebservices.amazon.".$country."\n/onca/xml\n".$host;}
    $signed = urlencode(base64_encode(hash_hmac("sha256", $host, $secretkey, True)));
    $uri .= "&Signature=$signed";
    if ($country == "jp") {$uri = "http://ecs.amazonaws.".$country."/onca/xml?".$uri;}
    else {$uri = "http://webservices.amazon.".$country."/onca/xml?".$uri;}
    
    $ch = curl_init($uri); 
    curl_setopt($ch, CURLOPT_HEADER, false); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 15);
    $xml = curl_exec($ch); 
    curl_close($ch); 
    
    $pxml = simplexml_load_string($xml); 
    
    $breaklist=0;
    $all = &$pxml->Items->Item;
    $param = array();
    for($count = count($all)-1; $count >= 0; --$count) { 
    $param[(string)$all[$count]->ItemAttributes->Title] = &$all[$count];}
    
    foreach ($pxml->Items->Item as $item){
    
    $link = $item->DetailPageURL;
    $sprice = $item->Offers->Offer->OfferListing->Price->FormattedPrice;
    $lprice = $item->ItemAttributes->ListPrice->FormattedPrice;
    $ava = $item->EditorialReviews->EditorialReview->Content ;
    $rev = $item->CustomerReviews->TotalReviews ;
    $avab =$item->Offers->Offer->OfferListing->Availability;
    $img = $item->SmallImage->URL;
    
    $rev =$item->Offers->Offer->OfferListing->IsEligibleForSuperSaverShipping;
    
    if ($rev == "1") {$rev = "FREE with Super Saver Shipping";}
    if ($rev == "0") {$rev = "";}
    
    
    if ($country == "com" && $sprice == "")  {$seed = "See Details >>"; $sprice = "Various"; } elseif ($country == "com" && $sprice == $sprice) {$sprice=$sprice; $seed = "See Details >>";}
    if ($country == "ca" && $sprice == "")  {$seed = "See Details >>"; $sprice = "Various"; } elseif ($country == "ca" && $sprice == $sprice) {$sprice=$sprice; $seed = "See Details >>";}
    if ($country == "co.uk" && $sprice == "")  {$seed = "See Details >>"; $sprice = "Various"; } elseif ($country == "co.uk" && $sprice == $sprice) {$sprice=$sprice; $seed = "See Details >>";}
    
    if ($country == "fr" &&  $sprice == "") {$seed = "En Savoir +"; $sprice = "Voir les Prix";} elseif ($country == "fr" &&  $sprice == $sprice) {$sprice=$sprice; $seed = "En Savoir +";}
    if ($country == "jp" &&  $sprice == "") {$seed = "その他の情報を見る >>"; $sprice = "価格を見る";} elseif ($country == "jp" &&  $sprice == $sprice) {$sprice=$sprice; $seed = "その他の情報を見る >>";}
    if ($country == "de" && $sprice == "") {$seed = "Mehr Infos >>"; $sprice = "Siehe Preisliste";} elseif ($country == "de" && $sprice == $sprice) {$sprice=$sprice; $seed = "Mehr Infos >>";}
    if ($country == "it" && $sprice == "") {$seed = "Dettagli >>"; $sprice = "Vedere il Prezzo";} elseif ($country == "it" && $sprice == $sprice) {$sprice=$sprice; $seed = "Dettagli >>";}
    if ($country == "es" && $sprice == "") {$seed = "Detalles >>"; $sprice = "Ver los Precios";} elseif ($country == "es" && $sprice == $sprice) {$sprice=$sprice; $seed = "Detalles >>";}
    if ($country == "cn" && $sprice == "") {$seed = "详细信息 >>"; $sprice = "查看价格";} elseif ($country == "cn" && $sprice == $sprice) {$sprice=$sprice; $seed = "详细信息 >>";}
    
    
    $title = $item->ItemAttributes->Title;
    $title = preg_replace('`\[[^\]]*\]`','',$title);
    $title = preg_replace('`\([^\]]*\)`','',$title);
    $title = str_replace("\"","",$title);
    $title = truncate($title, 25, " ");
    
    $titlel = $item->ItemAttributes->Title;
    $titlel = preg_replace('`\[[^\]]*\]`','',$titlel);
    $titlel = preg_replace('`\([^\]]*\)`','',$titlel);
    $titlel = str_replace("\"","",$titlel);
    $titlel = truncate($titlel, 60, " ");
    
    $ava = preg_replace('`\[[^\]]*\]`','',$ava);
    $ava = preg_replace('`\([^\]]*\)`','',$ava);
    $ava = str_replace("\"","",$ava);
    $ava = truncate($ava, 100, " ");
    $avab = truncate($avab, 69, " ");
    
    
    
    if ($img == "") {$content .= '';}
    
    else{
    if ($col == "1") {
    
    $content .= '<a href="'.$link.'" rel="nofollow" style="text-decoration:none;font-weight:600;">'.$titlel.'</a>
    <div style="margin:1px 0 5px 0;height:155px;width:540px;">
    <div style="float:left;width:100px;">
    <img src="'.$img.'" style="margin:0;padding:0;float:left;border:none;" /></div>
    <div style="float:left;margin:10px 0 0 0;width:440px;"><a href="'.$link.'" rel="nofollow" style="color: #'.$pricecol.';font-size:15px;text-decoration:none;font-weight:600;"> '.$sprice.' </a> <strike style="color:#444;"><span style="font-size:13px;text-decoration:none;font-weight:500;color:#000;">'.$lprice.'</span></strike></br><div style="font-size:12px;clear:left;">'.$avab.'</div><a href="'.$link.'" rel="nofollow" style="text-decoration:none;font-weight:600;">'.$seed.'</a></div></div>';}
    
    else {
    if(($i % 2)==0){
    
    
    $content .= '<div style="margin-bottom:20px;float:left;width:47%;margin-right:6%;height:230px;">
    <div style="width:250px;height:97px;" >
    <img src="'.$img.'"  style="margin:0;padding:0 0 20px 30px;border:none;" /></div>
    <a href="'.$link.'" rel="nofollow" style="text-decoration:none;font-weight:600;float:left;">'.$title.'</a>
    <div style="float:left;margin:3px 0 0px 0;;width:250px;"><a href="'.$link.'" rel="nofollow" style="color: #'.$pricecol.';font-size:15px;text-decoration:none;font-weight:600;"> '.$sprice.'</a>  <strike style="color:#444;"><span style="font-size:13px;color:#252525;;">'.$lprice.'</span></strike><br><span style="font-size:12px;">'.$avab.'</span></div></div>';
    }
    
    else {
    $content .= '<div style="margin-bottom:20px;float:left;width:47%;margin-right:0%;height:230px;">
    <div style="width:250px;height:97px;" >
    <img src="'.$img.'"  style="margin:0;padding:0 0 20px 30px;border:none;" /></div>
    <a href="'.$link.'" rel="nofollow" style="text-decoration:none;font-weight:600;float:left;">'.$title.'</a>
    <div style="float:left;margin:3px 0 0px 0;;width:250px;"><a href="'.$link.'" rel="nofollow" style="color: #'.$pricecol.';font-size:15px;text-decoration:none;font-weight:600;"> '.$sprice.'</a>  <strike style="color:#444;"><span style="font-size:13px;color:#252525;;">'.$lprice.'</span></strike><br><span style="font-size:12px;">'.$avab.'</span></div></div>';
    }
    
    $i++;
    		
    if(($i % 2)==0){$content .= '<div style="clear:both"></div>';}
    }
    
    
    $breaklist++; 
    if ($breaklist >=$listing){break;}
    }
    }
    return $content;
    
    }
    
    function add_wpzon_panel() {
    if (function_exists('add_options_page')) {
    add_options_page('wpzon', 'wpzon', 8, 'wpzon', 'wpzon_admin_panel');
    }
    }
    
    function wpzon_admin_panel() { if ($_POST["az_\165pda\x74e\144"]){
    update_option('az_public',$_POST['az_public']); 
    update_option('az_secret',$_POST['az_secret']); 
    update_option('az_atag',$_POST['az_atag']); 
    update_option('az_country',$_POST['az_country']);
    update_option('az_col',$_POST['az_col']);
    update_option('az_pricecol',$_POST['az_pricecol']);
    
    echo '<div id="message" style="padding:2px 2px 2px 4px; font-size:12px;" class="updated"><strong>' . Updated . '</strong></div>';}?>
    
    	<div class="wrap">
    	<div style="width:99%; height:570px;">
    <div style="float:left;width:65%;margin-right:4%;">
    	<h3 style="color:#0066cc;">WpZon Options</h3>	
    	<form method="post" id="cj_options">
    		<table cellspacing="10" cellpadding="5" > 
    				
    <tr valign="top">
    <td width="17%"><strong>AWS Access Key</strong></td>
    <td><input type="text" name="az_public" id="az_public" value="<?php echo get_option('az_public');?>" maxlength="300" style="width:400px;" /><p>To get your keys in your Amazon Associates account go to Product Advertising Api (sidebar) -> Manage Your Account -> Access Identifiers.<br><font style="color:#D3133E;">Please make sure that there are no spaces before or after the numbers.</font></td>
    </tr>					
    <tr valign="top">
    <td><strong>AWS Secret Access Key</strong></td>
    <td><input type="text" name="az_secret" id="az_secret" value="<?php echo get_option('az_secret');?>" maxlength="300" style="width:400px;" /></br></td>
    </tr>
    <tr valign="top">
    <td><strong>Tracking ID</strong></td>
    <td><input type="text" name="az_atag" id="az_atag" value="<?php echo get_option('az_atag');?>" maxlength="40"/>
    </br></td>
    </tr>	
    <tr valign="top">
    <td><strong>Country</strong></td>
    <td><select name="az_country" id="az_country">
    <option value="com" <?php if(get_option('az_country')=="com"){_e('selected');}?>>US</option>
    <option value="de" <?php if(get_option('az_country')=="de"){_e('selected');}?>>DE</option>
    <option value="co.uk" <?php if(get_option('az_country')=="co.uk"){_e('selected');}?>>UK</option>
    <option value="ca" <?php if(get_option('az_country')=="ca"){_e('selected');}?>>CA</option>
    <option value="fr" <?php if(get_option('az_country')=="fr"){_e('selected');}?>>FR</option>
    <option value="jp" <?php if(get_option('az_country')=="jp"){_e('selected');}?>>JP</option>
    <option value="es" <?php if(get_option('az_country')=="es"){_e('selected');}?>>ES</option>
    <option value="it" <?php if(get_option('az_country')=="it"){_e('selected');}?>>IT</option>
    <option value="cn" <?php if(get_option('az_country')=="cn"){_e('selected');}?>>CN</option>
    </td></tr>
    <tr valign="top">
    <td><strong>Columns</strong></td>
    <td><select name="az_col" id="az_col">
    <option value="1" <?php if(get_option('az_col')=="1"){_e('selected');}?>>1</option>
    <option value="2" <?php if(get_option('az_col')=="2"){_e('selected');}?>>2</option>
    </td></tr>
    <tr valign="top">
    <td><strong>Price Color</strong></td>
    <td><input type="text" name="az_pricecol" id="az_pricecol" value="<?php echo get_option('az_pricecol');?>" maxlength="6" style="width:100px;" /><p>Enter color code (6 characters). For example <strong>FFA500</strong> for orange or <strong>000000</strong> for black. You can find all the color codes <a href="http://quackit.com/html/html_color_codes.cfm" target="_blank">here</a> . *If left blank will be automaticaly set to red</br></td>
    </tr>
    
    		</table>
    		<p class="submit"><input type="submit" name="az_updated" value="Update Settings &raquo;" /></p>
    		
    </p>
    
    </form>
    </div>
    <div style="float:right;width:20%;margin-right:10%;">
    			<h3 style="color:#0066cc;font-size:19px;">Support the World</h3>
    <a href="http://gift.savethechildren.org/site/apps/ka/ec/product.asp?c=dvKSIbOSIlJcH&b=6885593&ProductID=951306" target="_blank" ><img border="0" src="http://4.bp.blogspot.com/-I0hvG1Svg4s/UFu-MixUv8I/AAAAAAAAARg/scFPa5UREn4/s1600/save+the+children.jpg" width="270" height="160" style="margin:0px 0 15px 0;" /></a>
    <br>
    <a href="http://www.doctorswithoutborders.com" target="_blank" ><img border="0" src="http://3.bp.blogspot.com/-r8JyKw1ZhaQ/UFMYK7A9V_I/AAAAAAAAAO4/tjeGBR6c0dU/s1600/doctorborders.jpg" width="270" height="127" /></a>
    
    
    		</div>		</div>	
    			
    <div style="padding:0px 15px 15px 15px; margin:10px 0 0 0;border:3px solid #ccc;width:90%;">
    <h3 style="color:#0066cc;">Please Read - How to use WpZon</h3>
    <p style="margin:30px 0 0 0;">Code format: <strong>[wpzon keywords="pressure cooker" sindex="Kitchen" snode="289825" sort="salesrank" listing="10"]</strong></p>
    <ul style="list-style:square;padding: 0 0 10px 30px;"><li><p style="margin:20px 0 0 0;"><strong>keywords</strong> = products you would like to display. Please do not use special characters, like &, @ etc.</li>
    <li><strong>sindex</strong> = Amazon category (also known as SearchIndex. These are: Electronics, Shoes, Kitchen etc. You can find them all <a href="http://docs.amazonwebservices.com/AWSECommerceService/2011-08-01/DG/APPNDX_SearchIndexParamForItemsearch.html" target="_blank">here</a> by country.</li>
    <li><strong>snode</strong> = Amazon subcategory (also known as BrowseNode). For instance if you want to narrow down results and display products from the Electronics category and Computer Accessories subcategory then the snode would be 172456. To find all the browsenodes go to <a href="http://www.findbrowsenodes.com" target="_blank">http://www.findbrowsenodes.com</a></li>
    <li><strong>sort</strong> = sort products by price, bestselling, reviews etc.  For the sort values go to <a href="http://docs.amazonwebservices.com/AWSECommerceService/2011-08-01/DG/APPNDX_SortValuesArticle.html" target="_blank">Amazon Docs</a> then select your locale and category. For example for US Electronics you can set the sort value to one of the following: pmrank (Featured Items), salesrank (Bestselling), reviewrank (Avg review rank), price (Low to high), -price (High to low) or titlerank (Alphabetical: A to Z)</li>
    <li><strong>listing</strong> = number of products you would like to display (from 1 to 10) Amazon Api only returns a maximum of 10 products per call.</li></ul>
    <p>As an illustration the following shortcode: 
    <br><strong>[wpzon keywords="pressure cooker" sindex="Kitchen" snode="289825" sort="salesrank" listing="8"]</strong>
    <br>will show 8 pressure cookers from the Kitchen category, Pressure Cookers subcategory(289825) sorted by bestselling.<p>
    <p><span style="font-weight:600;">Note</span> - In order the code to work properly you must set the values for the <strong>keywords</strong>, <strong>sindex</strong> and <strong>listing</strong>. The other two <strong>snode</strong> and <strong>sort</strong> are optional.
    
    <p style="margin:30px 0 30px 0;font-size:15px;"><strong>For feature requests and more help <a href="http://wpnicheground.blogspot.com/2010/03/free-amazon-wordpress-plugin.html" target="_blank">visit plugin site</a></strong></p></td>
    </div>
    	
    
    
    	</div>
    <?php
    }
    add_shortcode('wpzon', 'wpzon_shortcode');
    add_action('admin_menu', 'add_wpzon_panel'); ?>
    Code (markup):
     
    locpicker, Nov 5, 2012 IP
  2. locpicker

    locpicker Well-Known Member

    Messages:
    789
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    160
    #2
    I think the place to do this would be here -

    $sprice = $item->Offers->Offer->OfferListing->Price->FormattedPrice;
    $lprice = $item->ItemAttributes->ListPrice->FormattedPrice;
    Code (markup):
     
    locpicker, Nov 5, 2012 IP
  3. locpicker

    locpicker Well-Known Member

    Messages:
    789
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    160
    #3
    OK. How about using a php filiter. Namely filter_var to compare the xml feed to $sprice = $item->Offers->Offer->OfferListing->Price->FormattedPrice; which I think is the suggested price.

    Any body out there?
     
    locpicker, Nov 8, 2012 IP
  4. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #4
    here is a simple solution

    find this line of code

    
    $uri = 'Operation=ItemSearch&Condition=All&Availability=Available&ResponseGroup=Large,EditorialReview,ItemAttributes,OfferFull,Offers&Version=2011-08-01';
    
    PHP:
    then there are 2 parameters you can add MinimumPrice and MaximumPrice. Both are optional. So you can add only MinimumPrice or only MaximumPrice or both or non. For both you need to format the number 32.99 would be 3299 1.99 would be 199 so hope you see what I mean.

    So if you want all products to be at least $50 you would do this

    
    $uri = 'Operation=ItemSearch&Condition=All&Availability=Available&ResponseGroup=Large,EditorialReview,ItemAttributes,OfferFull,Offers&Version=2011-08-01&MinimumPrice=5000';
    
    PHP:
    here are more details if needed
    http://docs.amazonwebservices.com/AWSECommerceService/2011-08-01/DG/ItemSearch.html
     
    stephan2307, Nov 8, 2012 IP
    locpicker likes this.
  5. locpicker

    locpicker Well-Known Member

    Messages:
    789
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    160
    #5
    Thanks. That is doing it.
     
    locpicker, Nov 8, 2012 IP