Jump to content

Call to a member function trans() on a non-object


bissio

Recommended Posts

Hi guys,

first of all these are my settings: PHP 5.4.45 - PS 1.7.1.1 (latest stable) - Mysql 5.5.50
I installed the latest release of PS and all works fine except on the products section. When i try to insert a new product and set title and i try to insert an image, the (enabling the debug mode) i get the error reported on the attached file. Also, on my apache error log i get the following: PHP Fatal error:  Call to a member function trans() on a non-object in /mysite_root/classes/controller/AdminController.php on line 2735 and this is the interested funcion:
public function l($string, $class = null, $addslashes = false, $htmlentities = true)
    {
        $translated = $this->translator->trans($string);
        if ($translated !== $string) {
            return $translated;
        }

        if ($class === null || $class == 'AdminTab') {
            $class = substr(get_class($this), 0, -10);
        } elseif (strtolower(substr($class, -10)) == 'controller') {
            /* classname has changed, from AdminXXX to AdminXXXController, so we remove 10 characters and we keep same keys */
            $class = substr($class, 0, -10);
        }
        return Translate::getAdminTranslation($string, $class, $addslashes, $htmlentities);
    }

I also tried to import some products by CSV file but i get the same errors.
It seems a symfony issue but the error is related to a PHP controller core file.
i Checked on all forums but i did not find anything about this issue. Can someone help me?

Thanks

post-388825-0-44333900-1493372079_thumb.jpg

Link to comment
Share on other sites

Hi Flavio and thank you for you help.

 

in the meantime i solved reinstalling a new new and blank version of PS 1.7.1... it was a strange behaviour because with the same environment, into the new version i did not get this error.. even importin a lot of items by CSV, or inserting them one by one. I translated meny CSM pages and modules as well but at the moment i did not get this annoying error... However i will keep in my box your suggestion so if i should get this error again, i will try to apply it.

Thanks again ;-)

Link to comment
Share on other sites

  • 4 months later...
  • 5 months later...
On 3/5/2017 at 6:51 AM, Flávio's said:

Hi bissio,

I found the solution here https://www.h-hennes.fr/blog/2017/04/11/prestashop-1-7-correction-bug-traduction-dans-controller-admin-dun-module/  I just edited the line $translated = $this->translator->trans($string);  

to

$translated = Context::getContext()->getTranslator()->trans($string);

 

and all works fine, I hope it help you!


I do what you say. and it works fine but when I go to confirm the payment (the last step) it shows nothing. should show the order confirmation page but nothing comes out this is the result link www.mynamestore.com/module/universalpay/payment?id_universalpay_system=2

why?? 

Thanks

Link to comment
Share on other sites

1 hour ago, musicmaster said:


Thanks for answering

After Changing

$translated = $this->translator->trans($string);  

to

$translated = Context::getContext()->getTranslator()->trans($string);

I get this in the final step (when confirming the order)

[PrestaShopException]

No template found for payment_execution.tpl
at line 68 in file classes/Smarty/TemplateFinder.php

63.                     return $tpl;
64.                 }
65.             }
66.         }
67. 
68.         throw new PrestaShopException('No template found for '.$template);
69.     }
70. 
71.     private function getTemplateHierarchy($template, $entity, $id)
72.     {
73.         $entity = basename($entity);
  • TemplateFinderCore->getTemplate - [line 1392 - classes/controller/FrontController.php] - [4 Arguments]
    1387.         return $this->getTemplateFinder()->getTemplate(
    1388.             $template,
    1389.             $params['entity'],
    1390.             $params['id'],
    1391.             $locale
    1392.         );
    1393.     }
    1394. 
    1395.     /**
    1396.      * Renders and adds color list HTML for each product in a list.
    1397.      *
    
  • FrontControllerCore->getTemplateFile - [line 1282 - classes/controller/FrontController.php] - [3 Arguments]
    1277.      * @param string $default_template
    1278.      */
    1279.     public function setTemplate($template, $params = array(), $locale = null)
    1280.     {
    1281.         parent::setTemplate(
    1282.             $this->getTemplateFile($template, $params, $locale)
    1283.         );
    1284.     }
    1285. 
    1286.     /**
    1287.      * Removed in PrestaShop 1.7.
    
  • FrontControllerCore->setTemplate - [line 61 - classes/controller/ModuleFrontController.php] - [3 Arguments]
    56.     public function setTemplate($template, $params = array(), $locale = null)
    57.     {
    58.         if (strpos($template, 'module:') === 0) {
    59.             $this->template = $template;
    60.         } else {
    61.             parent::setTemplate($template, $params, $locale);
    62.         }
    63.     }
    64. 
    65.     public function initContent()
    66.     {
    
  • ModuleFrontControllerCore->setTemplate - [line 54 - modules/universalpay/controllers/front/payment.php] - [1 Arguments]
    49.             'this_path' => $this->module->getPathUri(),
    50.             'this_path_ssl' => Tools::getShopDomainSsl(true,
    51.                     true) . __PS_BASE_URI__ . 'modules/' . $this->module->name . '/'
    52.         ));
    53. 
    54.         $this->setTemplate('payment_execution.tpl');
    55.     }
    56. }
    
  • UniversalPaypaymentModuleFrontController->initContent - [line 205 - classes/controller/Controller.php]
    200.             if (!$this->content_only && ($this->display_header || (isset($this->className) && $this->className))) {
    201.                 $this->initHeader();
    202.             }
    203. 
    204.             if ($this->viewAccess()) {
    205.                 $this->initContent();
    206.             } else {
    207.                 $this->errors[] = $this->trans('Access denied.', array(), 'Admin.Notifications.Error');
    208.             }
    209. 
    210.             if (!$this->content_only && ($this->display_footer || (isset($this->className) && $this->className))) {
    
  • ControllerCore->run - [line 428 - classes/Dispatcher.php]
    423.             if (isset($params_hook_action_dispatcher)) {
    424.                 Hook::exec('actionDispatcher', $params_hook_action_dispatcher);
    425.             }
    426. 
    427.             // Running controller
    428.             $controller->run();
    429. 
    430.             // Execute hook dispatcher after
    431.             if (isset($params_hook_action_dispatcher)) {
    432.                 Hook::exec('actionDispatcherAfter', $params_hook_action_dispatcher);
    433.             }
    
  • DispatcherCore->dispatch - [line 28 - index.php]
    23.  * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
    24.  * International Registered Trademark & Property of PrestaShop SA
    25.  */
    26. 
    27. require(dirname(__FILE__).'/config/config.inc.php');
    28. Dispatcher::getInstance()->dispatch();
Link to comment
Share on other sites

50 minutes ago, musicmaster said:

The big question is whether it is in the same directory as where Smarty looks for it.

Excuse my ignorance and insistence. In what directory does that seek or should it be?
I know little or nothing about the subject, Thank you in advance for your patience

Link to comment
Share on other sites

5 hours ago, musicmaster said:

I don't know either. The minimum what you could do is provide me with all the information that you can find - and to be creative looking for it. Maybe that will bring up something interesting.

 

Hi @musicmaster, I use PS 1.7.3.0 and installed UniversalPay V3.0.0.
First when I click on Pay Systems tab

Captura.JPG.9715f67f30da30b6c8fc79a48964ea9b.JPG

I get error 500, this is PHP error:

Fatal error: Call to a member function trans () on null in ...... / classes / controller / AdminController.php on line 2754

Captura2.thumb.JPG.f4ea0ff4e3d6f98ad93e3344af8c225e.JPG

Then I made a change in  .../classes/controller/AdminController.php

edited the line $translated = $this->translator->trans($string); 

to 

$ translated = Context :: getContext () -> getTranslator () -> trans ($ string); 
As the message said back and error 500 was solved.
Add two Payment Methods for testing and I proceed to make a purchase, when I am in the final step just when It should show the confirmation of the purchase I see another error and it does does not show me the order confirmation.

This error appears (this https://www.prestashop.com/forums/topic/607468-call-to-a-member-function-trans-on-a-non-object/?tab=comments#comment-2699736 )

this is the content of the folder ../modules/universalpay/views/templates/front

 1.JPG.178bfe25b9ca5b52eaa74f1aea05a336.JPG

this is the content of the folder ../modules/universalpay/views/templates/hook

2.JPG.43831da7823cc8f10b34b104867d2e4d.JPG

Please if you need more info :) thanks

 

 

Edited by eridamega (see edit history)
Link to comment
Share on other sites

1.7.3: that is the bleeding is edge.

Problem with being so up-to-date is that you never can be sure that your modules are compatible with it. So i suggest that you build a test installation on your localhost - with PS 1.7.3 but the default template - where you test each of your special modules.

The error "Call to a member function trans() on a non-object" that you mention once again should by now be solvable. Just find out where it happens and apply the lessons from this thread. 

Link to comment
Share on other sites

  • 2 years later...
On 5/3/2017 at 1:51 PM, Flávio's said:

Hi bissio,

I found the solution here https://www.h-hennes.fr/blog/2017/04/11/prestashop-1-7-correction-bug-traduction-dans-controller-admin-dun-module/  I just edited the line $translated = $this->translator->trans($string);  

to

$translated = Context::getContext()->getTranslator()->trans($string);

 

and all works fine, I hope it help you!

Thank you Flávio's, works very well, have this error with the pcbuilder module, php 7.0.33

 

Many thanks

Link to comment
Share on other sites

  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...