Mangeto how to get session subtotal value? - magento

I am currently using magento 1.9.1 and i'm trying to get the session subtotal value in external file.
So here it is the code that i am working around with:
<?PHP
require('app/Mage.php'); //Path to Magento
Mage::app();
echo Mage::getSingleton('checkout/session')->getQuote()->getSubtotal();
?>
The problem is that when i execute this script i receive blank screen. No value is displayed.
This is all the code in this php page.
What i am doing wrong, can you help me ?
Thanks!

Try
<?php echo Mage::helper('checkout/cart')->getQuote()->getSubtotal() ?>
To see whats behind the white screen:
Goto index.php and uncomment the following line:
#ini_set('display_errors', 1);

Related

Magento font_color phtml error no idea where to even start

I keep getting the following error filling up my system log constantly.
2014-03-04T11:52:56+00:00 ERR (3): Notice: Undefined index: font_color in /var/www/html/waxmanenergy.co.uk/magento/app/design/frontend/default/mt_gero/template/page/html/header.phtml on line 31
Im not sure whats wrong with it or how to go about fixing it.
This is whats in line 31 on the error path within the header.phtml file
$text_color = isset($_COOKIE['textColor']) ? $_COOKIE['textColor'] : $config['font_color'];
Anyone got any heads up to what could be the issue
$config of yours do not have any index like 'font_color'. Either $config is not an array of array without 'font_color' as its key.

Undefined Variable Errors

I receive a lot of undefined variable errors in zend studio 10.
I have a php file like this :
file var.php
<?php
$functions = $root."/requires/functions.php";
$top_utf = $root."/requires/top_utf.php" ;
$database = $root."/requires/db.php" ;
$footer = $root."/requires/pageFooter.php" ;
?>
Now if I use the following code in a php file, zend studio shows Undefined Variable errors on all the require_once lines. (If I access this page with a browser the page is displayed as expected and it works perfectly.)
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
require_once($root."/requires/vars.php") ;
require_once($functions);
require_once($top_utf);
require_once($database);
require_once($footer);
?>
Doesn't Zend Studio recognize the declared variables in an included file (var.php in this case)?
Since $functions and $top_utf variables are defined in var.php, I believe I shouldn't receive these errors.
Any kind of advice is much appreciated.
If you're going to use this style of programming, which I'm not advocating, I suggest you define constants in your var.php instead

CodeIgniter Cron Job through Cpanel

Ok I looked at every other thread and have done exactly what they've done and what it says in the manual and I can NOT figure this out for the life of me.
The results of the cron job are being emailed to one of my emails. ALL it is doing is printing out the html markup of the layout... And printing the base page content... It's like it's not registering anything.
php /home/jdstable/public_html/dev/index.php cron decrease_pets_stats
That's my command line.. I tried replacing php with the user/local/bin/php thing as well and it didn't work. The thing is is that I have other cron jobs running off procedural PHP code that work FINE with php path/to/cron.php... But it won't work with CI..
My controller is Cron and my method is decrease_pets_stats..
//decrease pets stats
public function decrease_pets_stats() {
$this->load->model('Cron_model', 'cron');
$this->cron->decrease_pets_stats();
echo 'Decreased pet stats';
}
And here is the logic of the method:
//decrease pets stats
//runs every hour
public function decrease_pets_stats() {
$this->db->set('hunger', 'hunger - 5');
$this->db->set('happiness', 'happiness - 5');
$this->db->set('loyalty', 'loyalty - 5');
$this->db->update('user_creature');
}
Does anyone have any idea why it's just printing the layout markup? My constructor looks like this:
public function __construct() {
parent::__construct();
if( ! $this->input->is_cli_request()) show_error('Direct access is not allowed');
$this->load->model('Cron_model', 'cron');
}
And my parent constructor holds quite a bit of stuff (loading helpers and libraries along with getting the user information to appear on each page if they are logged in.
Does it matter if this is at the top of the controller before even opening the controller Cron class?
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
The default PHP install you are using was probably compiled as CGI-FCGI, not for CLI. It depends on your host and/or server, but you'll need to search for your PHP install for the command line interface, and then use that in your cron job. I had the exact same problem on Hostmonster, and my cron command ended up being:
/ramdisk/bin/php5-cli ~/public_html/sitefolder/index.php controller method
For me, the PHP I needed was in /ramdisk/bin/php5-cli.
For CodeIgniter 2.2.0
You can try this two method:
php-cli /home/username/public_html/index.php controller method
wget http://www.example.com/controller/method
or at your case
php-cli /home/username/public_html/index.php Cron decrease_pets_stats
wget http://www.example.com/Cron/decrease_pets_stats
It works fine with me..
Cheers!
Had the same issue and after trying whatever I could thing the obvious worked...
/usr/local/bin/php /absolute/path/to/index.php cron
/usr/local/bin/php /home/jdstable/public_html/dev/index.php cron decrease_pets_stats
This fixed it.
Here is solution first you need to find path from phpinfo document_root file name
php5 /home/abc/public_html/index.php folder_name controller function

How to die Magento immediately when getting an exception?

I got a problem when try to get a helper:
Mage::helper('providers')
In fact, the provider helper is not exist.
But it just out an exception and save it into the file: var/log/exception.log and everything is ok, except I could not see the interface which I want.
I need a way to do if I got any exception, Magento will exit immediately and show the messages on the browser.
Turn on developer mode, and make sure PHP is showing errors.
Open up index.php and change this
if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
Mage::setIsDeveloperMode(true);
}
#ini_set('display_errors', 1);
To this
#if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
Mage::setIsDeveloperMode(true);
#}
ini_set('display_errors', 1);
With developer mode on Exceptions will halt execution instead of being logged.
Also, you could skip comment the if block out by adding the apache environmental variable to MAGE_IS_DEVELOPER_MODE to your .htaccess file and setting it to 1.
Try wrapping the call in a try catch block, i.e.
try {
Mage::helper('providers');
}
catch (Exception $e){
echo $e;
}

Write permissions with Codeigniter + Simplepie

I am trying to create a simple RSS parser using the two frameworks. However I am getting PHPerrors when trying to write to my cache directory:
set_cache_location(APPPATH.'cache/rss');
I am running windows 7 with XAMPP using the latest version of Simplepie from github
error:
A PHP Error was encountered
Severity: User Warning
Message: C:\xampp\htdocs\geekurls/system/application/cache/rss is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.
Filename: libraries/simplepie.php
Line Number: 1732
Tried like the below comment said and tried making a test file but to no luck
$file = APPPATH."cache/rss/testFile.txt";
$handle = fopen($file, 'w') or die("fail");
fclose($handle);
A simple checks to find out what might be happening,
Try creating a file in this directory using standard php - this could help solve permission problems.
$this->load->helper('file');
$data = 'Some file data';
if ( ! write_file('./path/to/file.php', $data))
{
echo 'Unable to write the file';
}
else
{
echo 'File written!';
}
Also how about using the default cache?
http://simplepie.org/wiki/faq/i_m_getting_cache_error_messages

Resources