I've tried to get the config i created in admin, this's the core_config_data table
|config_id|scope |scope_id|path |value|
|123 |websites|2 |myappgeneral/current_time/second|3600 |
|124 |websites|3 |myappgeneral/current_time/second|7200 |
|125 |websites|4 |myappgeneral/current_time/second|1800 |
I have 1 page to show all info like this
Website 2 will be started in 3600 seconds
Website 3 will be started in 7200 seconds
Website 4 will be started in 1800 seconds
How can i get the values?
thks
You may use
Mage::app()->getWebsite($website_id)
->getConfig('myappgeneral/current_time/second')
The $website_id parameter is optional, by default current website used.
But normally you need a storeview value, which you can retrieve using
Mage::getStoreConfig('myappgeneral/current_time/second', $store_id)
The $store_id parameter is optional and may contain store view id or store view code, by default current store view used.
More info here - http://alanstorm.com/custom_magento_system_configuration, section "Retrieving Values"
Related
I am using "file storage" for my session. When I run this:
Session::set('awesomekey', 'myVal123');
And refresh the page, I can see new files being created in /storage/session each time. I assumed it would update the same file each time. This basically means sessions don't work at all. In other words, if it keeps recreating a session file, this never works:
Session::get('awesomekey');
Or at least, it returns a blank. What am I missing that could possibly be causing a new session key to be created each time a page is loaded?
UPDATE
On further investigation, it seems the cookie is regenerated on each page load. What could be causing that?
I am not even looking at logging in yet, so this information is useless to me --> http://willworkforbanjos.com/2014/02/laravel-sessions-not-working-in-4-1/
My problem is happening when I simply put the above set and get code in the master.blade.php file. It should set it, store the info, and on the next reload get the right information from session. But it can't because on reload it changed the cookie to some other code.
Anyone know why this is happening?
UPDATE 2
Adding: 'lifetime' => 120 to session.php did not work. (#Sheikh Heera)
Placing the code in the controller only, does not work. (#Phill Sparks)
I tried chrome and firefox, same result (#The Shift Exchange)
Just to be clear on what I'm trying to do. I add the following code in HomeController.php:
public function index()
{
Session::put('awesomekey', 'myVal123');
return View::make('home.index');
}
Then I put this in my master.blade.php:
print Session::get('awesomekey');
I do not include any "dies" or random echos in my controller side of the code, except for this. When I open the file the first time, I can see myVal123 being printed out.
I then take out this part in the controller:
Session::put('awesomekey', 'myVal123');
And reload the page. It now prints nothing. I can see in my browser that the cookie has changed. Generating a new cookie will lose the reference to the session, so I'm stuck trying to understand why it's doing that each time, even though it saves the session on the first load.
Any more ideas?
UPDATE 3
I also tried:
Running "php artisan dump-autoload" ... still doesn't work
I went here: http://www.whatismybrowser.com/are-cookies-enabled ... and yes, cookies are enabled.
I'm really running out of ideas here...
UPDATE 4
I went to SessionManager.php and just underneath this:
$lifetime = $this->app['config']['session.lifetime'];
I printed out the value of life time:
print $lifetime; die();
And this code was never hit on page reload?! However, adding this in my controller:
$d = Config::get('session.lifetime');
print $d;
Does in fact print out my value for lifetime.... :(
The problem was this line:
'cookie' => 'xxxx.com',
in session.php. Apparently it loses the cookie if you have a "." in the cookie name. I can't believe Laravel doesn't like that. Or maybe it's browser's in general.
I believe you are using:
'lifetime' => 0 // number of minutes
in your app/config/session.php file. Make it something like this:
'lifetime' => 120 // number of minutes or whatever you want
It'll work. I tried same settings as you described and just used 0 and I get same result, each time a new file is being created but once I change it to 120 or so, it works. So, it make sense that, if it's set to 'lifetime' => 0 in the session config then every time it just creates a new file for a new session because the session doesn't live. So, go to your app/config/session.php file and you'll find something like this, change the value:
/*
|--------------------------------------------------------------------------
| Session Lifetime
|--------------------------------------------------------------------------
|
| Here you may specify the number of minutes that you wish the session
| to be allowed to remain idle before it expires. If you want them
| to immediately expire on the browser closing, set that option.
|
*/
Update:
You may use following code to get the lifetime value set in the app/config/session.php file:
Config::get('session.lifetime');
Have a look at the cookie's expire time in Chrome developer tools, or Firebug. If it is set to 0 then the cookie will expire immediately.
Also, double-check if your clock is setup correctly - strange things could happen if there's a disparity between your host's and the browser's clock. Make both systems consult NTP to ensure this is not an issue.
I had a similar problem with the sessions, if you're using the model User and your users table doesn't have the primaryKey as Id, you must overwrite that variable at the model.
class User extends Eloquent {
protected $primaryKey = 'admin_id';
}
In /app/config/session.php check the "HTTPS Only Cookie" setting.
Make sure it's "secure => false" if you are not using SSL!
I've experienced issues related to this. The session file wasn't created every time but sometimes I just can't get the session variable displayed. After hours of experiments I found that the problem was related to Debugbar.
If you're using Debugbar and having session issues, disable it and try again to confirm.
Use Session::put('value') instead of set.
http://laravel.com/docs/session#session-usage
I don't know much about joomla. I found this:
JFactory::getSession();
Here I found that there is an expire date, but I can't make it work.
http://www.techportal.co.za/joomla/joomla-tutorials/304
Could you give an working example?
Just want when a user reopen the browser the data stored in the last session to be available. Also have to say that I'm using an outside domain to login, so in this case I don't care about internal ways of joomla handling users.
The 4 sections you can see in the documentation you're using there need to be passed through in an array (called $options in the API)
So you'd need to pass
$time=99; //time in minutes
$options = array(
"expire" => $time,
);
$session =& JFactory::getSession($options);
Note by default this is handled by a param in the config area of Joomla in 2.5 upwards! This might well also be the case in 1.5 - I don't have a copy of 1.5 to hand.
I have searched for more than two hours, my problem is:
I need to use cookies but I found my magento's cookie time is not right.
I have reinstalled my magento and in the system/configuration/general/locale options choose my timezone.
But when I went to my website, I found the cookies time still using GMT and the Path is not right too..(and they are magento's cookies "frontend" and "adminhtml", not the cookies I set, since I need to fix the cookie time first and them start to work on my own cookies).
But I use <?php echo Mage::getModel('core/date')->date();?> in the header.phtml to print my time, and this time is right.
So it means the place which set the cookies don't use the timezone.
And are you sure that the settings haven't been set at a lower configuration scope (website or store level)? Use the GUI tool in upper left corner of System > Configuration screen or use a query:
SELECT * FROM `core_config_data`
WHERE `scope` != 'default'
AND `path` LIKE 'web/cookie%';
If you get any results for the above query, there are values set at the store or website level.
This might get a little confusing as I have tried everything to make this work. All I want is a link in my brand site (domain.com) which shows the qty in my magento 1.5.1 cart (domain.com/shop) I quite easily pulled in product data and navigation blocks but no matter what I do, cart qty is always 0 from outside magento.
The main way I tried was just in my brand site to go:
require_once $_SERVER['DOCUMENT_ROOT'].'/shop/app/Mage.php';
umask(0);
Mage::app();
Mage::getSingleton('core/session', array('name'=>'frontend'));
// trying everything
Mage::getSingleton('checkout/cart')->getItemsCount(); // returns 0
Mage::helper('checkout/cart')->getItemsCount(); // returns 0
Mage::getSingleton('customer/session')->isLoggedIn(); // returns blank
Mage::helper('checkout/cart')->getCart()->getItemsCount(); // returns 0
Mage::helper('checkout/cart')->getCart()->getQuote()->getItemsCount(); // returns blank
Then, when none of those worked, I created a template in Magento just to give me the cart qty as a block which returns the block fine but still zero in the cart!
$block = $this->layout->createBlock('core/template');
$block->setTemplate('page/html/cartForBrand.phtml');
return $block->renderView();
and the block in magento is simply
Mage::getSingleton('core/session', array('name'=>'frontend'));
$cart = Mage::getModel('checkout/cart')->getQuote()->getData()['items_qty'];
I've seen a lot of people having similar issues: / session_cookie_management, .domain.com cookie_domain(even though that's subdomain specific), I've read and tried everything I could find for 2 days. Constantly deleting session and cache directories and clearing cache and cookies with magento caching disabled.
This is the first question I've posted on this site after using it for years, I've been stuck on this for 3 days! Pulling my hair out!
I copied your code and tested it on Magento 1.5, 1.6 and 1.7.
I placed the code in a PHP file called test.php in the Magento root directory. This is the code I used:
umask(0);
require_once 'app/Mage.php';
Mage::app();
Mage::getSingleton('core/session', array('name'=>'frontend'));
var_dump(array(
"Mage::getSingleton('checkout/cart')->getItemsCount()" =>
Mage::getSingleton('checkout/cart')->getItemsCount()
)); // returns number of items (w/o qty)
var_dump(array(
"Mage::helper('checkout/cart')->getSummaryCount()" =>
Mage::helper('checkout/cart')->getSummaryCount()
)); // returns number according to configuration
var_dump(array(
"Mage::getSingleton('customer/session')->isLoggedIn()" =>
Mage::getSingleton('customer/session')->isLoggedIn()
)); // returns bool true|false
The Magento instances use the local test host names magento15.dev, magento16.dev and magento17.dev.
The I requested the corresponding Magento instances and placed a product in the cart (tested with a configurable and a simple product), and then updated the quantity of the product in the cart.
Between each step I reloaded the test.php file in the browser.
The result is always the same: it works as expected. Each call returns the same values as on the Magento site.
So this means your code is correct, it might be your domain and/or setup (is the browser sending the Magento frontend cookie when you request your test script)?
Your code is good, but by default Magento's "frontend" cookie isn't accessible outside of Magento (and so you can't access session data). You'll need to change the cookie's path in Admin > System > Configuration > Web > Session Cookie Management > Cookie Path. Try setting that to /
If all you want is the qty why instantiate magento at all. Just set a client side cookie (ie cart_qty) and then read this cookie on your main site header.
Think you forgot:
Mage::app()->setCurrentStore(1); // replace 1 with your store id
after
Mage::app()
In Your Code: Instead of:
Mage::app();
use
Mage::app()->loadArea('frontend');
& u will get your output...
I am developing an online store for my customer and, we only have one website in our Magento setup.
In the admin panel when I go to Add a customer screen, in the "Associate to Website" field I see "Admin" selected by default. I would like to have my website there by default.
I think one possible way would be to write some code in:
Mage_Adminhtml_Block_Customer_Edit_Tab_Account::initForm
The cleanest way to do this is the just set the default value in your database. This will require no code changes at all.
UPDATE eav_attribute
SET default_value = 1
WHERE attribute_code = 'website_id'
The sample MySQL statement above sets your default website_id to 1.
Or You can simply edit array in:
Mage_Customer_Model_Customer_Attribute_Source_Website::getAllOptions()
I took the hint from Lrrr's answer and populated the drop-down with only user added websites, that is "Please Select" and "Admin" are no more available as options there by adding the following line:
$form->getElement('website_id')->setValues(Mage::getSingleton('adminhtml/system_store')->getWebsiteValuesForForm());
at the end of this function:
Mage_Adminhtml_Block_Customer_Edit_Tab_Account::initForm
The ideal way would be of course to override the above function in one's own module, but in our case overriding the above class creates conflict for another extension that we have installed, so I took this way round.