Advertisement
sparkweb

FoxyShop Quantity Viewer

Jan 16th, 2012
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.73 KB | None | 0 0
  1. //This function will show your product's computed amount discounts for Quantity purchases.
  2. //Can be placed on the FoxyShop single product template
  3.  
  4. function my_discount_viewer() {
  5.     global $product;
  6.     $discount_quantity_amount = $product['discount_quantity_amount'];
  7.     if (!$discount_quantity_amount) return;
  8.  
  9.     $title = substr($discount_quantity_amount, 0, strpos($discount_quantity_amount,"{"));
  10.     $str_discount = substr($discount_quantity_amount, strpos($discount_quantity_amount,"{") + 1);
  11.     $str_discount = str_replace("}","",$str_discount);
  12.     echo '<table class="foxyshop_discount_table">';
  13.     echo '<thead><tr><th colspan="2">' . $title . '</th></tr></thead><tbody>';
  14.  
  15.     $arr_discount = explode("|", $str_discount);
  16.  
  17.     for ($i = 0; $i <= sizeof($arr_discount); $i++) {
  18.         $discount = $arr_discount[$i];
  19.         $discount_total = 0;
  20.         if (strpos($discount,"-") === false && strpos($discount,"+") === false) continue;
  21.  
  22.         if (strpos($discount,"-") !== false) {
  23.             $discount_operator = "-";
  24.             $arr_inner_discount = explode("-",$discount);
  25.         } else {
  26.             $discount_operator = "+";
  27.             $arr_inner_discount = explode("+",$discount);
  28.         }
  29.         $discount_start = $arr_inner_discount[0];
  30.  
  31.         echo "<tr><td>";
  32.         echo $discount_start;
  33.         if (!isset($arr_discount[$i+1])) {
  34.             echo "+";
  35.         } else {
  36.             if (strpos($arr_discount[$i+1],"-") !== false) {
  37.                 $arr_second_inner_discount = explode("-",$arr_discount[$i+1]);
  38.             } else {
  39.                 $arr_second_inner_discount = explode("+",$arr_discount[$i+1]);
  40.             }
  41.             $discount_end = (int)$arr_second_inner_discount[0];
  42.             echo " - " . ($discount_end - 1);
  43.         }
  44.         echo "</td><td>";
  45.  
  46.         echo $discount_operator . foxyshop_currency($arr_inner_discount[1]) . '/ea.';
  47.  
  48.         echo "</td></tr>";
  49.     }
  50.  
  51.     echo "</tbody></table>";
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement