We are getting a couple of notices in prestashop when customers add products to cart, namely the following:
Impossible to add the product to the cart.
textStatus: 'parsererror'
errorThrown: 'SyntaxError: Unexpected token < in JSON at position 0'
responseText:
Notice: Use of undefined constant id_customization_field_width - assumed
'id_customization_field_width' in
/home/public_html/override/controllers/front/CartController.php
on line 83
Notice: Use of undefined constant id_customization_field_height - assumed
'id_customization_field_height' in
/home/public_html/override/controllers/front/CartController.php
on line 83
The code (line 83) which this refers to is as follows:
/*add new customization cart*/
$id_customization = 0;
if ($this->_newCustomization && id_customization_field_width && id_customization_field_height) {
if ($this->context->customer->isLogged()) {
$id_adv = $this->context->cart->id_address_delivery;
} else {
$id_adv = 0;
}
Can anyone help with this? We can't seem to find where the issue lies.
what is:
id_customization_field_width
and
id_customization_field_height
is it possible that it is:
$id_customization_field_width && $id_customization_field_height
or
$this->id_customization_field_width && $this->id_customization_field_height
?
Related
I've been searching through this and other sites and can't solve the notice I got every time I open the back office product page.
Notice on line 279 in file /home/librer16/public_html/tools/smarty/sysplugins/smarty_internal_templatebase.php(157) : eval()'d code
[8] Array to string conversion
Piece of code:
...
else {
//var_dump('renderTemplate', $_template->has_nocache_code, $_template->template_resource, $_template->properties['nocache_hash'], $_template->parent->properties['nocache_hash'], $_output);
//Line 279
if (!empty($_template->properties['nocache_hash']) && !empty($_template->parent->properties['nocache_hash'])) {
// replace nocache_hash
$_output = str_replace("{$_template->properties['nocache_hash']}", $_template->parent->properties['nocache_hash'], $_output);
$_template->parent->has_nocache_code = $_template->parent->has_nocache_code || $_template->has_nocache_code;
}
}
...
The website works, but this notice is very annoying.
Any suggestion to remove the notice?
Try to replace the line with this one:
if (is_array($_template->properties) && !empty($_template->properties['nocache_hash']) && is_array($_template->parent->properties) && !empty($_template->parent->properties['nocache_hash']))
Anyway, if you deactivated Debug Mode warningins won't show anymore.
Good luck.
My code sometimes give code undefinet offset error.
Error:
[03-Sep-2015 13:06:44] NOTICE: "Undefined offset: 6"
File: /home/mdmeds/public_html/includes/pages/game/class.ShowBuildingsPage.php | Line: 111
and
[04-Sep-2015 17:38:57] NOTICE: "Undefined offset: 8"
File: /home/mdmeds/public_html/includes/pages/game/class.ShowBuildingsPage.php | Line: 111
This is the part of the code
$Element = $CurrentQueue[$QueueID - 2][0]; /**this give the error*/
$BuildEndTime = $CurrentQueue[$QueueID - 2][3];
unset($CurrentQueue[$QueueID - 1]);
$NewQueueArray = array();
foreach($CurrentQueue as $ID => $ListIDArray)
{
if ($ID < $QueueID - 1) {
$NewQueueArray[] = $ListIDArray;
} else {
if($Element == $ListIDArray[0] || empty($ListIDArray[0]))
continue;
$BuildEndTime += BuildFunctions::getBuildingTime($USER, $PLANET, $ListIDArray[0]);
$ListIDArray[3] = $BuildEndTime;
$NewQueueArray[] = $ListIDArray;
}
}
I read lot of articles about this kind of errors but i do not know how to fix my code. Can someone help me please ?
You are trying to play with indexes that you are not sure they even exist...
things like
$CurrentQueue[$QueueID - 2]
is a guess... Get to find another way..
In this piece of code $CurrentQueue[$QueueID - 2][0], the key is generated dynamically based on $QueueID. WHen you get the error, it means that the specified key is not available in the array $CurrentQueue.
To avoid such run time exceptions, you can do something like this
if (!empty($CurrentQueue[$QueueID - 2])) {
// the actual functionality goes here.
}
I have this PrestaShop install which shows the following errors on the front-end:
Notice: Undefined offset: 0 in /home/username/public_html/modules/categoriesnc/categoriesnc.php on line 1677
Warning: array_key_exists() expects parameter 2 to be array, null given in /home/username/public_html/modules/categoriesnc/categoriesnc.php on line 1677
Line 1677 in categoriesnc.php has:
for ($i = 2; $i <= ($max_depth > 0 && $max_depth < $depth ? $max_depth : $depth) && array_key_exists('lev'.$i, $result[0]); $i++)
$breadcrumbs[] = $result[0]['lev'.$i];
Any advise on how to resolve it?
You can turn error reporting off to not see the message any more. But that is a custom non standard Prestashop module, so I would contact the developer with the error. They are just warning messages and they will not hurt anything if they are not addressed.
in my PHP code user can guess a number. variable 'number' in line 3 has been sent with post method which is in the same page and the code is called by 'PHP_SELF' and 'number' count number of guess but an error occurred in line 3 with this description: Notice: Undefined index: try
<?php
$target=13;
$try=(isset($_POST['number'])) ? $try+1 : 1;
if(!isset($_POST['guess'])){
$message="welcome to geuss machine";}
elseif(!is_numeric($_POST['guess'])){
$message="inpute is unidentify";}
elseif($_POST['guess']<$target){
$message="it's to small!";}
elseif($_POST['guess']>$target){
$message="it's to big!";}
elseif($_POST['guess']=$target){
$message="you win number was:$target";}
else
$message="it's confusing!";
?>
but in other system is working correctly.
is it related to Apache setting?
Your code doesn't make sense:
$try=(isset($_POST['number'])) ? $try+1 : 1;
means if number is set, then increment an undefined variable $try +1.
You should initialize it at least to 0 first.
trying to get every post and comment from a facebook page, I made this function that should go through the pagination:
$req = $facebook->api("/" . $pagename . "/?fields=posts.fields(message,link,created_time,shares,likes,comments)");
function parcours_arbre($ab)
{
GLOBAL $facebook;
GLOBAL $pagename;
$next = create_request($ab['posts']['paging']['next']);
$next_req = $facebook->api($pagename.$next);
$ab_next = $next_req['data'];
$prev = create_request($ab['posts']['paging']['previous']);
$prev_req = $facebook->api($prev);
$ab_prev = $prev_req['data'];
if (empty($ab)) {
display_results($ab['posts']['data']);
} else {
parcours_arbre($ab_next);
parcours_arbre($ab_prev);
}
}
I unfortunately get the following error:
Notice: Undefined index: posts in /form.php on line 36
Notice: Undefined offset: 3 in /utils.php on line 20
Notice: Undefined offset: 4 in /utils.php on line 20
Fatal error: Uncaught GraphMethodException: Unsupported get request. thrown in /sdk/src/base_facebook.php on line 1271
Any idea how i could avoid it or what is going on? Would this go away if i use the "until" statement in my api request?
Thanks a lot,
To explain each error
the variable $ab which is an argument to the function, does not have a "posts" index. You should try to var_dump this variable so you can see what it actually looks like.
same as above
same as above
the api function takes 3. The path which should just be #pagename. The method ("GET" or "POST") most likely POST because GET is causing an error. The parameters, which should be array("fields" => "posts.fields(message,link,created_time,shares,likes,comments)")
I noticed that for next you have the code
$next_req = $facebook->api($pagename.$next);
but for previous you have
$prev_req = $facebook->api($prev);
Might want to look into this.