OpenCart PHP error in VQCache file - php

We just launched a redesign of a client's ecommerce site running on OpenCart. We're trying to track down an error we're seeing in the Error Logs, but it's been eluding us thus far:
PHP Notice: Undefined index: route in .../vqmod/vqcache/vq2-catalog_view_theme_margaretha_template_common_header.tpl on line 360
The code on that line is:
<?php if ($this->request->get['route'] != 'common/home') { ?>
<div id="free-shipping">
<p>Free shipping on all orders!</p>
</div>
<?php } ?>
I'm not sure why this is throwing an error. Any ideas?

Change your if condition as follows:
<?php if (isset($this->request->get['route']) && $this->request->get['route'] != 'common/home') { ?>
<div id="free-shipping">
<p>Free shipping on all orders!</p>
</div>
<?php } ?>
The code may be in your theme folder's common/header.tpl or in some vqmod xml file (editing the file /vqmod/vqcache/vq2-catalog_view_theme_margaretha_template_common_header.tpl won't make any change).
Have a nice day !!

Related

Wordpress basics

Firstly, I'm a total beginner in this business but I decided to learn some php and now I'm trying to follow wordpress course .. which is by the way 5 years old. Anyway, I did the following code and it worked fine but vs code editor is saying that I am trying to use unknown function PHP(PHP0417).
The code is like this and according to vscode have_posts(), the_title(), the_content() is unknown function
Is the course outdated or what is going on?
<?php
while(have_posts( )) {
the_post(); ?>
<h2><?php the_title();?></h2>
<?php the_content();?>
<hr>
<?php }
?>

WordPress Shortcode Crashes Site

So, to make my story a little short. I'm doing some changes to a client's website, a past freelancer made them a custom theme that made it extremely hard to actually do any changes to the website itself. I'm not that experienced in PHP but I'm learning as I go.
The client asks me to create a slider and I'm using SlideAnything slider plugin that includes shortcodes to be easily added to a page through the editor.
The Shortcode is this "echo do_shortcode("[slide-anything id="2320"]");"
And the way I inserted it in the website was like this:
<section id="feature-courses" class="pt pt-sm-80 feature-section">
<div class="wow fadeInLeft container text-center">
<h2>Cursos de Inglés Destacados</h2>
<div class="spacer-60"></div>
<div class="row">
<?php echo do_shortcode("[slide-anything id="2320"]"); ?>
</div>
</div>
</section>
However, whenever I add it, it crashes the site with a message that says
Parse error: syntax error, unexpected '2320' (T_LNUMBER), expecting ',' or ')' in /home/tuirland/public_html/wp-content/themes/laukoa-tuirlanda/page-homepage.php on line 61
I searched and the shortcodes.php file is inside the WordPress folder.
I recreated my client's website from the ground-up in my local environment and it works flawlessly, however, when I try to do it on his website, the whole thing keeps crashing.
Any reason as to why this is happening on his server but not on my local testing environment? any help would be appreciated. Thanks in advance.
When you using " after the ID atrribute, it's closing the do_shortcode function so it will throw an error. Your code should be:
<?php echo do_shortcode('[slide-anything id="2320"]'); ?>
Or:
<?php echo do_shortcode("[slide-anything id='2320']"); ?>

PHP unexpected end of file happens in online testing environment, but doesn't happen in development environment

After I pulled the last code updates to an AWS instance where a test environment is running, a page displayed HTTP Error 500. I'm using CodeIgniter and the AWS instance was set to run as "production" (SetEnv CI_ENV production on .htaccess), so I changed that to "development" to display PHP error messagens. That's when I get the following mesage.
An uncaught Exception was encountered
Type: ParseError
Message: syntax error, unexpected end of file
Filename: /var/www/html/flip/application/views/flip_list.php
Line Number: 58
Backtrace:
File: /var/www/html/flip/application/controllers/Flip.php
Line: 131
Function: view
File: /var/www/html/flip/index.php
Line: 315
Function: require_once
On my localhost environment it does not happen, the page is displayed without errors or warnings.
Localhost is running PHP 7.0.15-0ubuntu0.16.04.4. And the AWS instance is running PHP 7.0.14 on CentOS. CodeIgniter version is 3.1.3.
I checked flip_list.php and Flip.php, but I didn't find where the problem is.
The controller file (Flip.php) is 350+ lines long, so I'm posting it on a pastebin: https://pastebin.com/agyMuf1T
Below the code of the view (flip_list.php):
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<?php
$first = true;
$second = false;
foreach ($editions->result() as $edition) {
$edition_hash = $this->flip->encrypt_decrypt_edition_id($edition->edition_id, 'encrypt');
$date = date_create($edition->edition_date);
$date = date_format($date, 'd\/m\/Y');
if( $first ) {
$first = false;
$second = true;
?>
<div class="latest">
<div class="item">
<a href="<?php echo base_url('flip/'.$slug.'/view/'.$edition_hash); ?>" class="view-edition">
<img src="<?php echo $edition->edition_cover; ?>" class="edition-cover">
<span>Edição <?php echo $date; ?></span>
<span>Número <?php echo $edition->edition_number; ?></span>
</a>
</div>
</div>
<?php
}
else {
if( $second ) {
$second = false;
?>
<div class="editions">
<div class="d-flex flex-row align-content-stretch flex-wrap">
<?
}
?>
<div class="item">
<a href="<?php echo base_url('flip/'.$slug.'/view/'.$edition_hash); ?>" class="view-edition">
<img src="<?php echo $edition->edition_cover; ?>" class="edition-cover">
<span><?php echo $date; ?></span>
</a>
</div>
<?php
}
} // foreach
?>
</div><!-- .d-flex -->
</div><!-- .editions -->
I'd like some help debbuging this. Thanks!
You probably have short tags (http://php.net/manual/en/language.basic-syntax.phptags.php) disabled on your test server. You have two choices, enable short tags in your php.ini or change <? to <?php. It's generally not considered great practice to use short tags, and errors like this are one reason why, so I'd suggest changing your tags to use <?php.
I'll post part of the view which has your short tag:
<div class="editions">
<div class="d-flex flex-row align-content-stretch flex-wrap">
<?
}
?>
<div class="item">
Unexpected end of file in server may happens as normally live server are on linux. And you may be testing on windows server so while transferring file it may be modified as windows and linux have different mechanism to denote new line. So, set as following(in Filezilla FTP Client):
Go to Transfer > Transfer type > select Binary and again upload all of your view files.
I found out that HEREDOC and NOWDOC syntax is supported in PHP 7.3+. I'm new to PHP development, and I absolutely prefer HEREDOC syntax to the mixed open/close tags.
Later realized that I had version 7.4 running locally and version 7.0 running remotely. There were a couple HEREDOC assignments in my code that were running without issue on my local machine, but I found an "unexpected end of file" error in /var/log/nginx/error.log which was showing as a 500 Internal Server Error in the console.
Was super confused by this for a few hours until I was out of ideas and removed the HEREDOCs. Then it worked. Hope this helps someone else. Lesson learned: keep your PHP versions the same in development and production envs.

Failed opening and inclusion

I really hope that someone can help me, because I have tried everything now in 4 days, and I am just stuck. I had a question with this before that did not get solved.
When I click one of my buttons "register" I get the following error:
Warning: include(resources/includes/header.html): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/website/php/global/registernumbers.php on line 5
Warning: include(): Failed opening 'resources/includes/header.html' for inclusion (include_path='.:/Applications/MAMP/bin/php/php5.6.2/lib/php') in /Applications/MAMP/htdocs/website/php/global/registernumbers.php on line 5
Here is the relevant code:
header.html:
<!-- 1 button in the header -->
<li>
Register 1 <!-- Error -->
</li>
<!-- registernumbers.php is called fine. I can see my <h1> and <h2> text -->
registernumbers.php:
<?php
if( !isset( $_SESSION ) ) session_start();
?>
<?php include 'resources/includes/header.html'; ?>
<h1>Register Numbers</h1>
<h2>global/registernumbers</h2>
My folder structure is looking like this:
../../php/resources/includes/header.html
Is working, but the CSS is ofcourse not called.
resources/includes/header.html
This is the correct path, but here I get the error
<?php include(ROOT_PATH . 'resources/includes/header.html'); ?>
Does not work either
The path to the header is correct, and I even tried to uinstall MAMP.
When I use this:
When I put the header.html and registernumbers.php, where my index.php is, everything is working fine.
Does anybody have a clue on what I can do? I would really like to seperate my files in folders like this.
Updated code after response
<?php
if( !isset( $_SESSION ) ) session_start();
?>
<?php define 'APP_ROOT', '/resources/includes/header.html'; ?>
<h1>Register Numbers</h1>
<h2>global/registernumbers</h2>
<?php define ('APP_ROOT', '/resources/includes/header.html'); ?>
// Here I do not get any errors, but the header is not called either
<?php define 'APP_ROOT', '/resources/includes/header.html'; ?>
//Parse error: syntax error, unexpected ''APP_ROOT'' (T_CONSTANT_ENCAPSED_STRING) in /Applications/MAMP/htdocs/website/php/global/registernumbers.php on line 5

Undefined variable in OpenCart

i got alot of these messages
Notice: Undefined variable: config_facontact_address in /home/oclasico/public_html/catalog/view/theme/shoppa/template/common/footer.tpl on line 50
i already seen this answer
Undefined variable (opencart)
, and i tried to do it , but i didn`t find the code to replace :(
and here is my footer.tpl line 50 look like
<?php if ($config_facontact_address) { ?>
<div class="address"><?php echo $config_facontact_address; ?></div>
<?php } ?>
my OpenCart Version 1.5.4
thanks
variable $config_facontact_address is not set,
to avoid this error use if(isset($config_facontact_address))
The reason why it's undefined is because it hasn't been set in the controller file first.
Opencart uses the MVC architecture, varibles are defined in the Controller, then used within the Template / View files. For this reason, it will always evaluate false using isset()
The code missing from the controller file (located: catalog/controller/common/footer.php) would be:
$this->data['config_facontact_address'] = $this->config->get('config_facontact_address');
If your not comfortable editing the controller, then you can replace your problem code with this:
<?php if ($this->config->get('config_facontact_address')) { ?>
<div class="address"><?php echo $this->config->get('config_facontact_address'); ?></div>
<?php } ?>

Categories