Fatal error: Call to undefined method ModelExtensionExtension::getExtensions() - opencart

I have read the other undefined method questions and tried to apply the suggestions to my error with no luck. The full error is
Fatal error: Call to undefined method ModelExtensionExtension::getExtensions() in /home/*user*/public_html/*domain*/system/storage/modification/catalog/controller/common/header.php on line 9
Here is the code, line 9 is: $analytics = $this->model_extension_extension->getExtensions('analytics');
<?php
class ControllerCommonHeader extends Controller {
public function index() {
// Analytics
$this->load->model('extension/extension');
$data['analytics'] = array();
$analytics = $this->model_extension_extension->getExtensions('analytics');
foreach ($analytics as $analytic) {
if ($this->config->get($analytic['code'] . '_status')) {
$data['analytics'][] = $this->load->controller('analytics/' . $analytic['code']);
}
}

This problem referrer to config.php file.
Verify that your CATALOG and MODIFICATION dir is correct.
In my case I solved this problem fixing this paths.

Related

My Opencart shows php warning undefined array key

I have a problem with a language extension I recently installed. Now I cannot login in the admin panel and I see these logs:
2022-12-30 16:30:17 - PHP Warning: Undefined array key "" in /var/www/html/opencart/admin-084AQ/controller/startup/language.php on line 21
2022-12-30 16:30:17 - PHP Warning: Trying to access array offset on value of type null in /var/www/html/opencart/admin-084AQ/controller/startup/language.php on line 21
2022-12-30 16:30:17 - PHP Warning: Undefined array key "" in /var/www/html/opencart/admin-084AQ/controller/startup/language.php on line 27
The language.php is:
<?php
namespace Opencart\Admin\Controller\Startup;
class Language extends \Opencart\System\Engine\Controller {
public function index(): void {
$language_data = [];
$this->load->model('localisation/language');
$results = $this->model_localisation_language->getLanguages();
foreach ($results as $result) $language_data[$result['code']] = $result;
// Language not available then use default
$code = $this->config->get('config_language_admin');
if (isset($this->request->cookie['language']) && array_key_exists($this->request->cookie['language'], $language_data)) {
$code = $this->request->cookie['language'];
}
// Set the config language_id
$this->config->set('config_language_id', $language_data[$code]['language_id']);
$this->config->set('config_language_admin', $code);
// Language
$language = new \Opencart\System\Library\Language($code);
if (!$language_data[$code]['extension']) {
$language->addPath(DIR_LANGUAGE);
} else {
$language->addPath(DIR_EXTENSION . $language_data[$code]['extension'] . '/admin/language/');
}
$language->load($code);
$this->registry->set('language', $language);
}
}
Opencart 4.0.1.1
PHP 8.0
Opencart expects the config_language_admin value in the key field of the oc_settings table. But it is most likely saved as config_admin_language there.
So the fix would be to rename config_admin_language to config_language_admin in the database.

Script compilation failed at line 19 in procedure 'BusComp_PreWriteRecord':

I am getting the following error, when tries to save the following script.
"Script compilation failed at line 19 in procedure 'BusComp_PreWriteRecord':
Syntax error at Line 31 position 59:Expected ')'
(SBL-SCR-00128)"
function BusComp_PreWriteRecord ()
{
var obj = TheApplication().GetBusObject("Service Request");
var optybc = obj.GetBusComp("Service Request");
optybc.ActivateField("SR Type");
//optybc.ActivateField(“Typeâ€);
optybc.SetViewMode(3);
optybc.ClearToQuery();
optybc.SetSearchSpec("SR Type",this.GetFieldV alue("SR Type"));
//optybc.SetSearchSpec(“Typeâ€,this.GetFieldV alue(“Typeâ€));
optybc.ExecuteQuery(ForwardOnly);
if(optybc.FirstRecord())
{
TheApplication().RaiseErrorText("Duplicate Records");
}
}
Does anyone knows the reason for the above error?
It might be that you are missing brackets in code that is "above" PreWriteRecord()
for example these methods
Siebel compiles all event code as one large code, so missing parentheses in other places will create issue in subsequent events.

undefined method FatalThrowableError::getStatusCode() - Testing Laravel 5.2

I'm starting to look into testing so thought id do something simple like see if a page loads correctly.
Here is my test;
<?php
use App\Users\Models\User;
class BlogPostsTest extends TestCase {
protected $baseUrl = 'http://localhost:8000';
public function testBlogPostsAreAccessible()
{
$this->be( User::findOrFail(1) );
$response = $this->call( 'GET', '/admin/blog-posts' );
$this->assertEquals( 200, $response->getStatusCode() );
}
}
Which returns and error
1) BlogPostsTest::testBlogPostsAreAccessible Error: Call to undefined
method
Symfony\Component\Debug\Exception\FatalThrowableError::getStatusCode()
/Users/ss/git/modules/admin/admin-blog/app/Exceptions/Handler.php:77
/Users/ss/git/modules/admin/admin-blog/app/Exceptions/Handler.php:58
/Users/ss/git/modules/admin/admin-blog/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:291
/Users/ss/git/modules/admin/admin-blog/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:107
/Users/ss/git/modules/admin/admin-blog/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:515
/Users/ss/git/modules/admin/admin-blog/tests/ExampleTest.php:12
FAILURES! Tests: 1, Assertions: 0, Errors: 1.
The error is coming from $this->call() does anyone know why this is?
regards
Are you sure your 'admin/blog-posts' returns an actual response object? Can you dd() the output in your test? So:
dd($response);
To see what it is your code is returning?

Unite Test: Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed

I'm trying to write white test to test my API with file uploads.
I'm following the docs about this using basic client request, not crawler.
The unit test is:
class RecordsControllerTest extends WebTestCase {
private $client;
public function __construct() {
parent::__construct();
$this->client = self::createClient();
$this->client->insulate();
}
public function testApiPostUpload($params){
$fileToUpload = realpath(__DIR__.'/../../resources/mpthreetest.mp3');
$file = new UploadedFile(
$fileToUpload,
'mpthreetest.mp3',
MimeTypeGuesser::getInstance()->guess($fileToUpload),
filesize($fileToUpload)
);
$this->client->request('POST', '/records/'.$params['createdRecordId'].'/upload', array(), array('file' => $file) );
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
}
}
When I execute the test I receive an error:
Exception: Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed
/path/to/project/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Client.php:165
/path/to/project/vendor/symfony/symfony/src/Symfony/Component/BrowserKit/Client.php:348
/path/to/project/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Client.php:143
/path/to/project/vendor/symfony/symfony/src/Symfony/Component/BrowserKit/Client.php:313
/path/to/project/src/Bundle/Tests/Functional/Controller/RecordsControllerTest.php:182
I have found this question for about the same error, but in this case the request is not sent to the controller and the problem is not the entity and implementing serialization.
Anyone who knows how to fix this?
Anyone who managed to make unit test for uploading file in symfony 2?
You could try to NOT insulate the requests passing false as argument to the insulate method so try this:
$this->client->insulate(false);
instead of this:
$this->client->insulate();
Hope this help
I was able to resolve it by setting the changeHistory parameter to false (7th and last parameter in the request method signature):
$crawler = $client->request($form->getMethod(), $form->getUri(), $values, $files, [], null, false);
This will prevent the serialize on following lines :
if ($this->followRedirects && $this->redirect) {
$this->redirects[serialize($this->history->current())] = true;
return $this->crawler = $this->followRedirect();
}

Test if file exists and executed even at the time of submission

I implemented a feature that tests if my file already exists; whether an error message is displayed and a pop up Java script. Otherwise it does nothing.
Except that at the time of registration of my content. He still enters the loop and as the file is already uploaded it still displays the error message and so I can never create my content.
In advance, thank you for your help.
function bportal_tesst_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'document_node_form') {
$form['field_document_file']['und'][0]['#upload_validators']['custom_document_upload_validation'] = array();
}
return $form;
}
function custom_document_upload_validation($file) {
$filename = $file->filename;
$errors = array();
if (file_exists('/var/www/vhosts/BP/docroot/sites/default/files-private/documents/'.$filename)) {
print_r($filename);
$errors[] = t("The new file already exists. Please use a different name.");
drupal_add_js(drupal_get_path('module','bportal_tesst') . '/js/pop-in.js');
}
return $errors;
}