when might magento Mage::getModel('customer/form'); fail? - magento

I have the following two lines of code in within a controller class.
$customerForm = Mage::getModel('customer/form');
$customerForm->setFormCode('customer_account_create')
->setEntity($customer);
I am getting "Fatal error: Call to a member function setFormCode() on a non-object in ..."
on the second of those two lines.
what might cause the first line to return a "non-object" ? (I guess it fails and returns a null but why would this happen ?)
I am not sure if this is relevant but this is happening in a site that uses the Enterprise version of magento (Magento ver. 1.8.0.0).

Look into your exeption.log, you should find some ideas there. It might happen if Mage_Customer module is disabled, you have rewrite for 'customer/form' model, or even file with Mage_Customer_Model_Form class is missing.

Related

How to have usefull debugging or error messages from laravel

I'm a bit new to laravel, but I'm experienced in Php.
In previous works, I set a mecanism that allowed me to be informed when nearly any problem occurred on the server:
I got full stack
precise PHP error messages
for nearly all king of errors
a mail sent to me
So when I began to work with laravel, I tried to do the same things, and achieved:
full stack
a mail sent to me
But I can't have meaningful error in all case. One example:
$store = Store::create(...)
In this line I forget to specify the namespace (\App\Store::create), and I get those error messages:
first:
FatalThrowableError ; Type error: Argument 1 passed to App\Http\Controllers\User::create() must be an instance of Illuminate\Http\Request, array given, called in /var/www/html/laravel/blog/app/Http/Controllers/User.php on line 94
second:
ErrorException ; Trying to get property of non-object in VerifyCsrfToken.php (line 156)
third:
FatalThrowableError ; Type error: Argument 1 passed to Illuminate\Session\Middleware\StartSession::addCookieToResponse() must be an instance of Symfony\Component\HttpFoundation\Response, array given, called in /var/www/html/laravel/blog/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php on line 72
I understand that laravel is a complex framework but I can't figure why it produces this errors, and how I can have more useful errors (as as it is I can only know that "something is bad").
Has someone an idea ?
¹ There is some errors that Php prefers to keep to himself (in its logs) :-)
When you start a new Laravel project, error and exception handling is
already configured for you. The App\Exceptions\Handler class is where
all exceptions triggered by your application are logged and then
rendered back to the user.
https://laravel.com/docs/5.4/errors
I recommend you to dive into the official docs and into your App\Exceptions\Handler.
Maybe you are looking for report and render methods in that class.
I finally cornered the problem and I learned a lot.
I thank for their benevolence #Don't Panic and #Vitalmax !
The error was that I forgot that PHP namespaces are case insensitive: in my post I cleaned a bit the code as I knew that it didn't stick to the code's conventions (a controller's name must begin with a capital letter). Originally my controller name was user and the faulty code was:
$user = User::create(...)
As you can guess PHP believed that I wanted to call user::create (as I have such a method in my controller) and not User::create (as I wanted).
What I learned:
don't alter the code when asking for help
Laravel use a cache system that can get in the way of the debugging (see a question that I asked on laracast's forum )
take more time to read the error message; I know this rule but I keep doing otherwise

Joomla - Fatal error: Class 'JParameter' not found

I'm trying to upgrade Joomla 2.5.22 to 3.5.1, and last time I checked the progress bar, it was 86 %. I looked away for a moment and when I came back to check I saw the below error message.
Fatal error: Class 'JParameter' not found in
/home/mywebsite/public_html/plugins/system/bigshotgoogleanalytics/bigshotgoogleanalytics.php on line 24
What is the cause of this error and how would it be fixed?
Joomla can't find JParameter Class, so you have to use
jimport( 'joomla.html.parameter' );
before using JParameter class
bigshotanalytics is one of those plugins that cause a blank page or, at best, a fatal error when updating Joomla. This is because of its old code. I suggest you move the tracking code to your template. You can also add the tracking code to a custom HTML module (after removing the encapsulating div through an override) and then assign the module to a position in your template (the position should be in the section of the HTML).
Now to answer your question, Joomla no longer uses JParameter - it uses JRegistry instead. So something like:
$jparameter = new JParameter('param1');
Should be changed to:
$jregistry= new JRegistry();
$jparameter = $jregistry->get('param1');

Magento Mage class causes server error 500 in own php script

I got a few problems with the Mage Class, when we try to call any static method, e. g. in my case:
Mage::getModel('catalog/product')->load($productId);
It always causes an error 500. It´s been used in an own php design file.
Also, this post didn´t resolve the problem: Magento 1.7 - getModel in script outside web application fails
I searched a lot in the internet and found out, that
Mage::getModel();
is a factory method, so I actually don´t need to call
Mage::getConfig()->init();
Mage::getConfig()->loadModules();
Help me, please!
Edit: I solved the error with this code:
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$category = Mage::getModel('catalog/category')->load($categoryId);
$prodCollection = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($category);
$prodCollection->addAttributeToSelect('attribute_name');
The main problem was, that this line was missing:
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
The error might be caused by this:
Mage::getModel()->('catalog/product')->load($productId);
This is wrong. First of all getModel expects at least a parameter. Second, there is no method name here ->('catalog/product'). Your code should be:
Mage::getModel('catalog/product')->load($productId);
Also make sure that Mage.php is included in your script otherwise the class is not found.

zend framework 2 Set TextDomain in onBootstrap

I followed the instructions of this link successfully, now my web is multilanguage without requiring put "locale" in the "traslate()" calls.
But I have to put the TextDomain each time that I call it.
$this->traslate("Hello", __NAMESPACE__) //where __NAMESPACE__ is the text domain.
I would like set TextDomain in the onBootstrap method instead of put it in each call of the the "traslate()" helper.
I have tried with setTextDomain method, but it doesn't exist.
Somebody know how do it?
The onBootStrap Code is following:
.....//Code for define $locale.
$sm = $e->getApplication()->getServiceManager();
$translator = $sm->get('translator');
$translator->setLocale($locale);
$traslator->SetTextDomain($textdomain); //This line not work!!!!!
Didn't see this right the first time. Going by DASPRIDS Presentation about ZF2 I18N the correct function to call is:
$this->plugin('translate')->setTranslatorTextDomain('module-b');
Though if i see this correctly, that's from within the view Scripts. Getting the Translator from ServiceManager however - i haven't tested this - but try the following:
$translator->getPluginManager()->get('translate')->setTranslatorTextDomain('foo');
Okey. We have advanced one step.
The first solution works ok (the view solution), now my web page traduce texts only using this helper parameters, being Locale and TextDomain defined by the config:
$this->translate('HELLO');
But the second solution not works. I don't understand because the same plugin is accepted in the view and not in the onBootstrap when the name is the same.
I rewrite my onBootstrap code bellow:
$translator = $e->getApplication()->getServiceManager()->get('translator');
$pm = $translator->getPluginManager(); //until here works ok.
$pm->get('translate'); //this throws an error message how if 'translate' not found.

Why is Magento looking in 'base/default' for my template file?

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

Resources