I am newbie in Prestashop module development so sorry if it is a fool question... I have been reading the docs but I haven't found what I am looking for so here I go,
I'd like to show a message on the screen (just for debugging purpose) with different context vars and so forth when actionCartSave. Something similar to "console.log()" or "alert()" in js.
Impossible to add the product to the cart.
textStatus: 'parsererror'
errorThrown: 'SyntaxError: JSON Parse error: Unrecognized token '<''
responseText:
< xmp style="text-align: left;" > message: < /xmp>
*{
"products": [...] *
I have already test this code:
public function hookActionCartSave( $params )
{
ppp('message: ');
return true;
}
...inside the module class definition but I am getting this error when I add a product to the cart:
I get this text in a different browser window.
So please, what is the best way to go?
Hope everything is clear. Thanks.
What you have done is correct, this error message is something thrown by javascript running in your browser since the additional information you are printing out using ppp isn't valid JSON.
If you use Chrome, use developer tools and select the Network tab. You will see the ajax call here. You can inspect this call in more detail by clicking on it.
Not sure it's the best option, but I found it useful to debug with a simple
throw new Exception('Custom message ' . $someVariable);
Related
There are a bunch of questions relating to errors with the count() logic in some phpmyadmin libraries but they all seem slightly different to this one.
I'm at a bit of a loss with this strange behavior in the 'Designer' tab. I'm informed that 'errors have been detected on the server!' and that I should 'look at the bottom of this window', but as you can see from the image there is nothing in the console and the error message is obscured:
After getting this popup every time I opened the Designer tab, I decided to track it down:
... and looking at the line in question, #405, in /usr/share/phpmyadmin/libraries/pmd_common.php, I found:
if (count($min_page_no[0])) {
... but isn't this a perfectly legal use of the count() function?
This is in a library file so how can I debug this? - I tried to var_dump($min_page_no[0]); and reload the page to see what I'm dealing with, but nothing was displayed.
Update your installation of phpMyAdmin.
I believe 4.7.8 addresses this, as evidenced by the release tag on this commit:
https://github.com/phpmyadmin/phpmyadmin/commit/c77cfa7d13370a7f1e3236c5896f89981e61406f
[Edit: And an explanation of why count isn't valid in this case: That particular index isn't always set. If they try to use count() on an array index that isn't set, it'll throw that warning.]
My goal is fairly simple, this is a PHP file and I included it into my header because I want to display the last bitcoin price using bitstamp.net not any other bitcoin exchange prices.
<?php
function getprice($url){
$decode = file_get_contents($url);
return json_decode($decode, true);
}
$btcUSD = getPrice('https://www.bitstamp.net/api/ticker/ '); //bitstamp
$btcPrice = $btcUSD["last"];
$tempround = round($btcPrice, 2);
$btc_Display = "$".$tempround;
?>
Well, this seems to work, but some times upon refreshing the page I get an error.
Warning: file_get_contents(https://www.bitstamp.net/api/ticker/ ):
failed to open stream: HTTP request failed! HTTP/1.1 400 BAD_REQUEST
in C:\xampp\htdocs\hidden\btcprice.php on line 3
The error doesn't happen often its very random in timing, but what does it mean and how can I prevent it?
It took me a while to get the error because I don't know what is causing it. I'm curious how to prevent it, am I leaving something out? I used a guide to learn how to do this that got the last bitcoin price from btc-e, but I don't want to use btc-e. I have to use bitstamp last price.
Also no JavaScript is allowed (or should I say I'm trying to avoid JavaScript for this little project) and I don't understand PHP OOP stuff, so please no examples in that.
Your code is working for me. The w3.org defines 400 as follows:
The request could not be understood by the server due to malformed
syntax. The client SHOULD NOT repeat the request without
modifications.
However, that can happen when you use a Web-Api. Espacially Api's from Bitcoin-exchanges can be pretty unstable and answer with errors from time to time, according to my own experience. How RobotMind already mentioned, you should put a
try
{
}
catch
{
}
around the getPricefunction.
Another option is to use Curl. This way you can easily access the Status-Code and react accordingly if an error should happen.
Ok, I can't figure this one out for the life of me. I'm using Yii 1.1.8.
If I do this:
function actionEdit()
{
$this->render('//user/edit');
}
I get a PHP error after the content saying that LogDetailFilter couldn’t be found when it was trying to autoload it in Yiibase.php on line 421.
But if I do this:
function actionEdit()
{
$this->render('//user/edit');
die;
}
I have no problems. Any thoughts how I could fix this?
It's an error in your config file related to what / how you are logging things. Yii runs all of the Yii::log / Yii::trace calls after it has rendered content (using the onApplicationEnd event), which is why using die prevents your logging from having errors.
If you post your logging info, we can point out the exact spot if you need it
When using Magentos log facility Mage::log() it sometimes causes a white screen. No error messages are outputted either to the screen or any of the log files (var/log/system.log, var/log/exception.log )
This seems to happen only when I'm trying to log a very large object. for example when I'm trying this
Mage::log(Mage::helper('catalog/category')->getStoreCategories());
inside a block controller it causes a white screen.
the same happens when I'm trying to log the current product in app/design/frontend/enterprise/default/template/catalog/product/view/media.phtml
using
Mage::log($_product);
Usually Mage::log() works fine and writes everything to the system.log file.
I was wondering if this has happened to anybody else or if anybody has an idea about why this is happening?
Mage::log works a lot like print_r, private and protected values are printed too which includes extensive resource details. You can avoid these by using the purpose made Varien_Object::debug method.
Mage::log($_product->debug());
debug is also preferred because it detects recursion which not all versions of PHP do.
I guess it happens to everyone.
Try not to log large objects.
In case you need I would advice you to use die.
for example like this
$object = ...;
die($object);
or
die('pre html tag'.print_r($object,true).'pre html tag');
I have this page which used to return some other JavaScript errors, but it seems I fixed them since the system now complains differently :)
Here is the page:
http://www.comehike.com/outdoors/parks/trailhead.php
And here is the JS error I am getting in the console:
Unable to post message to http://googleads.g.doubleclick.net. Recipient has origin http://www.comehike.com.
Also there is this error which is very cryptic:
Unsafe JavaScript attempt to access frame with URL http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-1884332214318974&output=html&h=90&slotname=6750679790&w=728&lmt=1307311140&flash=10.3.181&url=http%3A%2F%2Fwww.comehike.com%2Foutdoors%2Fparks%2Ftrailhead.php&dt=1307285940734&bpp=5&shv=r20110527&jsv=r20110506&correlator=1307285940857&frm=4&adk=540157337&ga_vid=898509444.1299013740&ga_sid=1307285941&ga_hid=824315563&ga_fc=1&u_tz=-420&u_his=10&u_java=1&u_h=768&u_w=1366&u_ah=720&u_aw=1366&u_cd=32&u_nplug=14&u_nmime=51&biw=1345&bih=149&ref=http%3A%2F%2Fwww.comehike.com%2F&fu=0&ifi=1&dtd=291&xpc=egJ5ygbjaM&p=http%3A//www.comehike.com from frame with URL http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-1884332214318974&output=html&h=90&slotname=6750679790&w=728&lmt=1307311140&flash=10.3.181&url=http%3A%2F%2Fwww.comehike.com%2Foutdoors%2Fparks%2Ftrailhead.php&dt=1307285940734&bpp=5&shv=r20110527&jsv=r20110506&correlator=1307285940857&frm=4&adk=540157337&ga_vid=898509444.1299013740&ga_sid=1307285941&ga_hid=824315563&ga_fc=1&u_tz=-420&u_his=10&u_java=1&u_h=768&u_w=1366&u_ah=720&u_aw=1366&u_cd=32&u_nplug=14&u_nmime=51&biw=1345&bih=149&ref=http%3A%2F%2Fwww.comehike.com%2F&fu=0&ifi=1&dtd=291&xpc=egJ5ygbjaM&p=http%3A//www.comehike.com. Domains, protocols and ports must match.
Any idea why they are happening and how to resolve them?
Here is how I try to return the XML in the AJAX:
echo '<markers>';
$str =
<<<EOD
<marker>
trail_id=$trail_id
trailhead_id=$trailhead_id
park_id=$park_id
editor_member_id=$editor_member_id
trailhead_name=$trailhead_name
trailhead_description=$trailhead_description
parking=$parking
cost_details=$cost_details
parking_spots=$parking_spots
is_free=$is_free
wheelchair_accessible=$wheelchair_accessible
bathrooms_nearby=$bathrooms_nearby
lat=$lat
lng=$lng
</marker>
EOD;
echo $str;
// End XML file
echo '</markers>';
The error most likely is a side effect of something else going on on the page. Specifically something with the google maps API. The error Firefox throws is Error: uncaught exception: [Exception... "An invalid or illegal string was specified" code: "12" nsresult: "0x8053000c (NS_ERROR_DOM_SYNTAX_ERR)" location: "http://maps.gstatic.com/intl/en_us/mapfiles/api-3/5/5/main.js Line: 93"]. I would try and remove everything Google Maps related from the page and see if the page loads without errors. Also I would try and create another blank page and copy everything Google Maps related from this page the way it is there and see if just Google Maps code runs without errors. That would show me that: 1) either the code that works with the map is doing something funky, or 2) The google maps code is conflicting with something else on the page.
P.S. i suspect the culprit is initializeTrailheads() method. Try removing it from onload and see what happens.