VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: ibnati on July 13, 2018, 18:06:11 PM

Title: Undefined variable: percentage in line 166
Post by: ibnati on July 13, 2018, 18:06:11 PM
hello

i see a warning "Undefined variable: percentage in line  166" on the product page of Vm also the template use this cod to show Percentage             

<?php if(($isSaleLabel != 0) && $vm_labels_sales) : ?>
                     <div class="label-pro status-sale"><span><?php echo $percentage; ?></span></div>  //line 166
                  <?php endif; ?>


and this is the daclaration of the Percentage
   // Percentage
         if ($isSaleLabel) {
            $dtaxs = array();
            if($product->prices["DATax"]) $dtaxs = $product->prices["DATax"];
            if($product->prices["DBTax"]) $dtaxs = $product->prices["DBTax"];            
            foreach($dtaxs as $dtax){
               if(!empty($dtax)) {
                  $discount = rtrim(rtrim($dtax[1],'0'),'.');
                  $operation = $dtax[2];
                  $percentage = "";               
                  switch($operation) {
                     case '-':
                        $percentage = "-".$discount;
                        break;
                     case '+':
                        $percentage = "+".$discount;
                        break;
                     case '-%':
                        $percentage = "-".$discount."%";
                        break;
                     case '+%':
                        $percentage = "+".$discount."%";
                        break;
                     default:
                        return true;   
                  }
               }               
            }
         }
         // End Percentage


how can i fix this please ?

thanks
amine
Title: Re: Undefined variable: percentage in line 166
Post by: jenkinhill on July 13, 2018, 18:13:49 PM
In default VM3.2.15 $percentage is only used in the Paypal plugin ( paypalstd.php ).  So I guess the issue is with your template or overrides.
Title: Re: Undefined variable: percentage in line 166
Post by: Studio 42 on July 13, 2018, 18:56:08 PM
move
$percentage = "";
before
if ($isSaleLabel) {
Title: Re: Undefined variable: percentage in line 166
Post by: ibnati on July 13, 2018, 19:36:47 PM
thank you very much , the issue is fixed now