Advertisement
sparkweb

FoxyShop Price Range Function

Jan 16th, 2012
598
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.62 KB | None | 0 0
  1. //Get High and Low Price
  2. function my_high_low_price($product) {
  3.    
  4.     //Set Starter Prices
  5.     $originalprice = $product['originalprice'];
  6.     $lowprice = $product['originalprice'];
  7.     $highprice = $product['originalprice'];
  8.    
  9.     foreach ($product['variations'] as $product_variation) {
  10.         $variations = preg_split("[\r\n|\r|\n]", $product_variation['value']);
  11.         foreach($variations as $val) {
  12.             if (strpos($val,"{") === false) continue;
  13.             $variation_modifiers = substr($val, strpos($val,"{")+1, strpos($val,"}") - (strpos($val,"{")+1));
  14.             $arr_variation_modifiers = explode("|",$variation_modifiers);
  15.             $pricechange = "";
  16.             $priceset = "";
  17.             foreach ($arr_variation_modifiers as $individual_modifier) {
  18.                 $individual_modifier = trim($individual_modifier);
  19.                 if (strtolower(substr($individual_modifier,0,2)) == "p:") {
  20.                     $priceset = substr($individual_modifier,2);
  21.                 } elseif (strtolower(substr($individual_modifier,0,1)) == "p") {
  22.                     $pricechange = substr($individual_modifier,1);
  23.                 }
  24.             }
  25.  
  26.             if ($pricechange != "") {
  27.                 $newprice = $originalprice + $pricechange;
  28.             } elseif ($priceset != "") {
  29.                 $newprice = $priceset;
  30.             } else {
  31.                 $newprice = $originalprice;
  32.             }
  33.             if ($newprice && $newprice > $highprice) $highprice = $newprice;
  34.             if ($newprice && $newprice < $lowprice) $lowprice = $newprice;
  35.         }
  36.     }
  37.  
  38.     //Show Price (and sale if applicable)
  39.     if ($lowprice != $highprice) {
  40.         $write = '<div class="foxyshop_price">';
  41.         $write .= foxyshop_currency($lowprice) . " - " . foxyshop_currency($highprice);
  42.         $write .= '</div>';
  43.     } else {
  44.         $write = foxyshop_price(0, 0);
  45.     }
  46.    
  47.     return $write;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement