In Magento, the function getStoreConfig($path) will get the value of $path in table core_config_data. I've checked there is a value for the $path I use which is carriers/flatrate/infotext , but I still got nothing returned from the call Mage::getStoreConfig('carriers/flatrate2/infotext') .
I've tried to disable the cache as well as flushing all caches but it still doesn't work.
This happened when I try to install GLS extension for Magento, is there any case that somehow it interferes with this function ? Thanks
Update:
I've just found out something : this function actually returns the text, I find nothing wrong with it but it doesn't work, when I try to use Magento::getStoreConfig directly, it works.
protected function getInfoText($carrierCode)
{
if ($text = Mage::getStoreConfig('carriers/'.$carrierCode.'/infotext')) {
return $text;
}
return '';
}
Magento version: 1.7 CE
Magento caches the StoreConfig in memory, so make sure you flush all the cache after making change in config_store_data in Magento. This happens when you try to upgrade or install new extension - which is my case.
Related
i am using laravel 5 on local on window ..i am trying to redirect the page to some external url..but nothing seems to help me..
i tried
return \Response::make('',302)->header('Location','http://site2');
return redirect()->away("http://site2");
\Redirect::to('http://site2');
header('Location: http://site2');
but none of them working..gives no response..
Something like this :
return redirect()->away('http://site2');
Make sure you also add a return (i.e. return $this->checkSession();) in start().
I try to register global variable in magento, but it's doesn't work.
In /app/code/core/Mage/Checkout/controllers/CartController.php I register variable:
Mage::register('g_addressType', $addressType);
$mylog = print_r(Mage::registry('g_addressType'), true);
Mage::log("address_type1:".$mylog, null, 'mygento.log');
$this->_redirect('checkout/onepage/');
In /app/code/core/Mage/Checkout/Block/Onepage.php I try to get this variable:
$mylog = print_r(Mage::registry('g_addressType'), true);
Mage::log("address_type2:".$mylog, null, 'mygento.log');
return Mage::registry('g_addressType');
But it doesn`t work. I get this log:
2013-06-04T13:38:45+00:00 DEBUG (7): address_type1:private
2013-06-04T13:38:51+00:00 DEBUG (7): address_type2:
Where is the mistake? I use magento 1.7. Yes, I know that I can not make changes in core files. Thanks.
This doesn't work because the Magento registry is not persistent on page load. And changing from CartController (/checkout/cart/) to OnepageController (/checkout/onepage/) means reloading the page so your g_addressType is not kept between the two.
A better thing to do would be to use session like this :
Mage::getSingleton('checkout/session')->setGAddressType($addressType) in CartController.php
then
Mage::getSingleton('checkout/session')->getGAddressType() in OnepageController.php
Last reminder though: please make sure not to code this in Core Magento files. Please extend existing core classes.
I'm developing an extension for Joomla!; at the moment I'm trying to make it 3.0 compatible - as with 3.0 the logging changed a little (*). Building on the answer from this related question, my current code looks like this:
JLog::addLogger(array(
'text_file' => 'plg_system_myplg.log.php'
));
JLog::add('blah blah log msg');
The problem is that the log also goes to the messages which are shown to the user - this I want to prevent, I want the log msg only to go to the log file. I think it has to do with the "category" that JLog::add takes as a 3rd (optional) parameter, but I have no idea what to pass there?
Can anybody tell me how to hide the messages / or tell me if I'm on the right way with the categories and what value I should use?
Thanks!
(*) It actually changed already with 1.7 as far as I gathered so far, but the old method of calling addEntry on the return of JLog::getInstance(...) seems to have been removed from 2.5 to 3.0.
Edit: Think I found a way now; using:
JLog::addLogger(array(
'text_file' => 'plg_system_myplg.log.php',
JLog::ALL,
'myplg'
));
JLog::add('blah blah log msg', JLog::INFO, 'myplg');
all my log entries go only into my log file (and not to the messages shown to the user). However, I also get a few deprecation warnings - one about my code, but also some unrelated ones:
WARNING deprecated JAccess::getActions is deprecated. Use JAccess::getActionsFromFile or JAcces::getActionsFromData instead.
WARNING deprecated JSubMenuHelper::getEntries() is deprecated. Use JHtmlSidebar::getEntries() instead.
WARNING deprecated JSubMenuHelper::getFilters() is deprecated. Use JHtmlSidebar::getFilters() instead.
WARNING deprecated JSubMenuHelper::getAction() is deprecated. Use JHtmlSidebar::getAction() instead.
Not sure what to make of those - why do they appear in my log file, shouldn't they go to the default error.log file instead of my file ?
This is what I am using, works for Joomla 1.5 - 3.2:
if(version_compare(JVERSION,'1.7.0','ge')) {
jimport('joomla.log.log'); // Include the log library (J1.7+)
$priorities = JLog::ALL ^ JLog::WARNING; // exclude warning (because of deprecated)
// In J3.0 we need to ensure that log messages only go to our file, thus use the categories (already supported in J2.5)
if(version_compare(JVERSION,'2.5.0','ge')) {
$logCategory = 'com_mycomponent';
JLog::addLogger(array('text_file' => $logFileName), $priorities, $logCategory);
JLog::add($msg, JLog::INFO, $logCategory);
}else{
JLog::addLogger(array('text_file' => $logFileName), $priorities);
JLog::add($msg, JLog::INFO);
}
} else {
// Joomla! 1.6 and 1.5
jimport('joomla.error.log'); // Include the log library
$log = &JLog::getInstance($logFileName);
$log->addEntry(array('comment' => $msg, 'level' => 'INFO'));
}
This shows the trick for gettring of the deprecated messages.
And yes, you have to include a category for your messages to ensure they are not showing up as system messages.
Use
new JException('Something happened');
This will only add it to debug log but will not show anything.
It seems, that Joomla 3.0 has no default logger enabled. The same in Joomla 3.0.3. Nothing turns logging on by default - even Debug mode.
Finally I think I have solved my issue with unrelated log entries showing up.
A close look at the API documentation of the addLogger function revealed that the third parameter, $categories, is supposed to be an array of categories for which this log will be used.
This is in contradiction to the version of http://docs.joomla.org/Using_JLog that is current at the time of this writing, where a single category is given instead of an array.
Changing my call to addLogger to use an array, like this:
JLog::addLogger(array(
'text_file' => 'plg_system_myplg.log.php',
JLog::ALL,
array('myplg')
));
And keeping my fingers crossed that this will fix the issue!
Edit: unfortunately even this still doesn't solve my issue - still got unrelated entries :(.
I found the answer.. hope this script make you understand.. I already built as function . this code work on joomla 3. hope work in joomla 2
<?php
function logWrite($level, $values, $file='%s.php',$path='',$showOnTop=0,
$option='',$component=''){
/****
jlog Joomla 3.4
created by:gundambison (2015.04.26).
THX: hbit#stackoverflow
****/
jimport('joomla.log.log');
$level=strtoupper($level);
//You can change this com_name
$component= $component==''? 'com_gundambison': $component;
$date= date("Ymd");
$filename= sprintf($file, $date);
$format= $option=='' ?"{TIME}\t{CLIENTIP}\t{CATEGORY}\t{MESSAGE}": $option;
// create options and text
$txt = is_array($values)? json_encode($values): $values;
$options = array('text_file' => $filename,'text_entry_format'=>$format );
$options['text_file_path']=$path==''?'logs': $path;
JLog::addLogger ($options);
/*
if you want the error to show in your page. just see the different
*/
if($showOnTop==1){
JLog::add("$txt");
}
else{
JLog::add("$level\t$txt",$level,$component);
}
}
The method JComponentHelper::isEnabled('com_extension', true); checks if an extension is installed and returns a boolean.
The function will also throw an exception notice it the component is not installed due to the self::getComponent($option, $strict); in the same helper class.
Is there a way to avoid the notice if the component is not installed?
Check your database to see if the component is installed and enabled.
$db = JFactory::getDbo();
$db->setQuery("SELECT enabled FROM #__extensions WHERE name = 'component name'");
$is_enabled = $db->loadResult();
if the value of $is_enabled is 1, then your component is enabled.
While realizing that this is an old question, it is also one of Google's first results and I wanted to share what works for me while avoiding extra database queries.
To avoid the exception you can also check to see if the entry point file of the extension exists like:
if (file_exists(JPATH_ADMINISTRATOR . '/components/com_extension/extension.php') && JComponentHelper::isEnabled('com_extension', true))
{
// Your code here
}
You could use the same function isEnabled and catch that exception, so if the exception is thrown then the component is not installed.
Check out
JComponentHelper::isInstalled('com_extension');
I created a really simple module with a block class. This block uses a custom template that calls a class method to determine if it should show itself or not based on the current time of day (if support is open, show the phone number). This works great on my local dev server and our remote dev server. It seems to work well on our main site, but we started seeing errors in the log this morning on the main server.
The errors looked like this:
2011-08-11T18:14:49+00:00 ERR (3): Warning: include(/chroot/home/valuepet/valuepetsupplies.com/html/app/design/frontend/base/default/template/general/banner/orderbyphone.phtml) [function.include]: failed to open stream: No such file or directory in /chroot/home/valuepet/valuepetsupplies.com/html/var/ait_rewrite/67b58abff9e6bd7b400bb2fc1903bf2f.php on line 370
2011-08-11T18:14:49+00:00 ERR (3): Warning: include() [function.include]: Failed opening '/chroot/home/valuepet/valuepetsupplies.com/html/app/design/frontend/base/default/template/general/banner/orderbyphone.phtml' for inclusion (include_path='/chroot/home/valuepet/valuepetsupplies.com/html/app/code/local:/chroot/home/valuepet/valuepetsupplies.com/html/app/code/community:/chroot/home/valuepet/valuepetsupplies.com/html/app/code/core:/chroot/home/valuepet/valuepetsupplies.com/html/lib:.:/usr/share/pear') in /chroot/home/valuepet/valuepetsupplies.com/html/var/ait_rewrite/67b58abff9e6bd7b400bb2fc1903bf2f.php on line 370
The module I wrote doesn't have anything in frontend/base/default...it's all in our custom theme. So why was it looking in base for the files?
I added some log messages and found that it doesn't ALWAYS look for the file in base...only occasionally. So that suggests that either one page in the site is calling the block incorrectly or there's something strange going on that causes this randomly.
You'll notice from the error message that it's using AIT Rewrite for some of the PHP scripts. Does anyone have any experience with this? It came with another AITOC extension and I can't find any documentation on it. Perhaps that's the problem, but I have that same extension on my local server and this problem doesn't come up.
Any ideas?
=============================
Orderbyphone.php
class VPS_General_Block_Banner_Orderbyphone extends Mage_Core_Block_Template
{
protected $hours;
protected function _construct()
{
//GMT times for hours of operation
$this->hours = array('start' => 15,//15
'end' => 21);//20
parent::_construct();
$this->setTemplate("general/banner/orderbyphone.phtml");
}
/**
* Return true if you should show the OrderByPhone banner, false otherwise
* #return Boolean
*/
public function showBanner()
{
$GMTHour = (int)date('G');
if(($GMTHour < $this->hours['start']) || ($GMTHour >= $this->hours['end']))
{
return false;
}
return true;
}
}
orderbyphone.pthml
<?php if($this->showBanner()): ?>
<div><div class='orderbyphone'>Order By Phone 800-VALUEPET (800-825-8373)</div></div>
<?php endif; ?>
This block is added to a CMS pages by adding the following to the Layout Update XML
<block type="vps_general/banner_orderbyphone" name="orderbyphone">
<action method="setWidth"><name>400</name></action>
</block>
considering Magento's cascading way of searching for template assets the fact that it doesn't find an asset in /base/default/ doesn't necessarily mean that you specified that path.
In fact if you tell Magento to load a template asset in /yourpackage/yourtheme/ path and Magento doesn't find that asset it will search for the same asset in /base/default/ path.
If it doesn't find it even in /base/default/ it will throw an exception saying that the resource wasn't fount in the /base/default/ not in /yourpackage/yourtheme/ path.
I don't know if this is the case but maybe it can help you a bit.
In other words: are you sure the resource you are looking for is in /yourpackage/yourtheme/ path?
Pay attention to the fact that file names are case sensitive under Unix/Linux so what is found under Windows is not necessarily found under Unix/Linux.
Regards, Alessandro