www.webdeveloper.com
Results 1 to 9 of 9

Thread: PHP issues undefined variables

  1. #1
    Join Date
    Apr 2012
    Posts
    48

    PHP issues undefined variables

    Hi

    I am working on a opencart website for a client and trying to display 3 prices like the following url

    http://irhwebsites.com/sites/simply-...6g?search=oreo

    but all I am getting is undefined variables error and null errors on the following url where I am trying to get the 3 prices displayed

    http://irhwebsites.com/sites/simply-...ch&search=oreo

    attached is the coding for the catalog/controller/product/search.php and catalog/view/theme/kvvaradha/template/product/search.tpl

    Can any one help please, just can't work it out

    Thank you in advance

    Kind regards

    Ian
    Attached Files Attached Files
    Last edited by ianhaney; 09-24-2014 at 10:25 AM. Reason: added coding

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    896
    Ok - you've had 200+ views and not one response. Perhaps because you didn't give us anything to look at nor the contents of the messages. Take a look at other forum posts and see how business is conducted here.

    1 - show the pertinent code for your problem.
    2 - if you have a message SHOW IT and furthermore find the line number that it points to and IDENTIFY IT in your posted code. Also be sure that you have php error checking turned on properly (only while you are developing) so that you get all the messages you can.
    3 - many people do not like to click on links here - I know I don't. So - that's why you need to show it. And do so properly using the forum's rules for posting code.

  3. #3
    Join Date
    Apr 2012
    Posts
    48
    Hi

    Thank you for the reply

    Below is the code for the search.php file inside the controller folder for the extra prices

    PHP Code:
    $this->data['text_price'] = $this->language->get('text_price');
            
    $this->data['text_list_price'] = $this->language->get('text_list_price');
            
    $this->data['text_collection_price'] = $this->language->get('text_collection_price'); 
    PHP Code:
    if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
                    
    $price $this->data['price'] = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
                } else {
                    
    $price $this->data['price'] = false;
                }
                    
                    if ((
    $this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
                    
    $list_price $this->data['list_price'] = $this->currency->format($this->tax->calculate($result['list_price'], $result['tax_class_id'], $this->config->get('config_tax')));
                } else {
                    
    $list_price $this->data['list_price'] = false;
                }
                
                if ((
    $this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
                    
    $payments_charges $this->config->get('payment_typechg_charge');
                    if (
    substr($payments_charges,0,1) == '%') {
                        
    $collection_discount = (substr($payments_charges,1)*-1);
                    } else {
                        
    $collection_discount 0;
                    }
                    
    $collection_price $result['price'] * ((100 $collection_discount)/100); // collection discount
                    
    $collection_price $this->data['collection_price'] = $this->currency->format($this->tax->calculate($collection_price$result['tax_class_id'], $this->config->get('config_tax')));
                } else {
                    
    $collection_price $this->data['collection_price'] = false;
                }

                    if ((float)
    $result['special']) {
                        
    $special $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
                    } else {
                        
    $special false;
                    }
                    
                    
                    
                    if ((float)
    $result['special']) {
                    
    $payments_charges $this->config->get('payment_typechg_charge');
                    if (
    substr($payments_charges,0,1) == '%') {
                        
    $collection_discount = (substr($payments_charges,1)*-1);
                    } else {
                        
    $collection_discount 0;
                    }
                    
    $collection_special $result['special'] * ((100 $collection_discount)/100); // collection discount
                    
    $collection_special $this->data['collection_special'] = $this->currency->format($this->tax->calculate($collection_special$result['tax_class_id'], $this->config->get('config_tax')));
                } else {
                    
    $collection_special $this->data['collection_special'] = false;
                } 
    PHP Code:
    'price'       => $price,
                        
    'list_price' => $list_price,
                        
    'collection_price' => $collection_price,
                        
    'collection_special' => $collection_special,
                        
    'special'     => $special
    PHP Code:
    if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
                        
    $price $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
                    } else {
                        
    $price false;
                    }
                    
                    if ((
    $this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
                    
    $list_price $this->currency->format($this->tax->calculate($result['list_price'], $result['tax_class_id'], $this->config->get('config_tax')));
                } else {
                    
    $list_price false;
                }
                
                if ((
    $this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
                    
    $payments_charges $this->config->get('payment_typechg_charge');
                    if (
    substr($payments_charges,0,1) == '%') {
                        
    $collection_discount = (substr($payments_charges,1)*-1);
                    } else {
                        
    $collection_discount 0;
                    }
                    
    $collection_price1 $result['price'] * ((100 $collection_discount)/100); // collection discount
                    
    $collection_price $this->currency->format($this->tax->calculate($collection_price1$result['tax_class_id'], $this->config->get('config_tax')));
                } else {
                    
    $collection_price false;
                }

                    
                    if ((float)
    $result['special']) {
                    
    $payments_charges $this->config->get('payment_typechg_charge');
                    if (
    substr($payments_charges,0,1) == '%') {
                        
    $collection_discount = (substr($payments_charges,1)*-1);
                    } else {
                        
    $collection_discount 0;
                    }
                    
    $collection_special1 $result['special'] * ((100 $collection_discount)/100); // collection discount
                    
    $collection_special $this->currency->format($this->tax->calculate($collection_special1$result['tax_class_id'], $this->config->get('config_tax')));
                } else {
                    
    $collection_special false;
                }
                    
                    if ((float)
    $result['special']) {
                        
    $special $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
                    } else {
                        
    $special false;
                    } 
    Below are the errors on the url

    Online Price: 6.99 Notice: Undefined variable: special in /home/sites/irhwebsites.com/public_html/sites/simply-heavenly/catalog/view/theme/kvvaradha/template/product/search.tpl on line 110

    Below is that line of coding

    Code:
    <span class="price-old"><?php echo $price; ?></span> <span class="price-new"><?php echo $special; ?></span></div>
    I can understand why people won't click as could be spam or something you know but can assure is a clients site I am working on

    Kind regards

    Ian

  4. #4
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    896
    So now that you know what the error is, figure out why your variable is not getting set. I see that the message refers to "search.tpl". What is that and how is the code you are posting related to it?

  5. #5
    Join Date
    Apr 2012
    Posts
    48
    Because the .php code is what is making the code work on the tpl file, is hard to explain but is how opencart works, it has a controller php file and then a themes tpl file that has the html in and php and the variables for example $special

  6. #6
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    896
    Well it's pretty simple to say that your problem is that the variable is not defined when it is referenced on line ### of that .tpl file. So - ensure that your code is executing in the order that you need it to in order to have that var defined. Not much we can do here since we can't see your whole flow.

  7. #7
    Join Date
    Apr 2012
    Posts
    48
    Quote Originally Posted by ginerjm View Post
    Well it's pretty simple to say that your problem is that the variable is not defined when it is referenced on line ### of that .tpl file. So - ensure that your code is executing in the order that you need it to in order to have that var defined. Not much we can do here since we can't see your whole flow.
    I did try and post the whole code but couldn't as is a limit of characters of 10000 and the whole message with code was 20500 or similar to that

  8. #8
    Join Date
    Apr 2012
    Posts
    48
    at the top is the attached files in txt format as was only way I could do it as php and tpl files are not allowed to upload on here as kept saying the format is wrong so put all the code in txt format and attached to the first post

  9. #9
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    896
    People post php code here constantly. Again - as I said in my first post - only post the pertinent code. Or better yet - you should go thru your code and make sure that the variable is being set. echo out the value to be sure it is what you expect. Do Some Debugging.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles