prestashop 1.5 core file overwrite - php

I want to overwrite prestashop 1.5 core file FrontController.php to overwrite from override\classes\controller folder but it didn't load my overwrite folder file.
<?php
class FrontController extends FrontControllerCore
{
/* Display a specific page if the user country is not allowed */
protected function displayRestrictedCountryPage() {
}
}
Any body have idea how to over write core prestashop file in 1.5
I also follow this document but no way to solve.

Prestashop 1.5.x automatically merge default override file and you custom file on module::install() function. You just need to create a correct hierarchy in your module folder: modules/your_package/override/classes/controller/FrontController.php with your custom functional.
If you don't have an extension and want to add override manually - you need to change the file override/classes/controller/FrontController.php

Just remove the class_index.php under /cache folder.
It carries Presta's Class & Controller file details. Once you delete and reload the page, prestashop will automatically generate the file with latest changes.

The problem may be, that one of your functions which contains parent::nameOfFunction, You should replace parent in the function by the inheritance of the parent function you want to override.

The function you're trying to override is called in the core function init(). what you should do is to override both init() and displayRestrictedCountryPage(). Then inside the init function use Controller::init() instead of parent::init()

After override whatever you want don"t forget to delete the cache folder contents and recreate them because that lost my time for a while till found the solution here

Related

How does WP file loading work? How does it work when used in WP MVC plugin?

I've created a video about one of the major problem that I have. I need to understand the file loading architecture, how it's done when writing a class in WP plugin development (how one class knows about the existence of another class), and how this compares with WP MVC file loading architecture. It's one big question, and I went through the various smaller questions that helped me arrived at the question summary in the video in the drive link below. I'm putting the plugin code in the Google Drive folder also: https://drive.google.com/open?id=1JVSSlkSJ5pCfNojRh6jen3ax2w-HZr5d
WP side:
plugin.php has this line: $wp_filter[ $tag ]->do_action( $args );
$tag = 'init'
This calls WP_Hook->do_action, then WP_Hook->apply_filters
WP MVC side:
This then calls MvcLoader->init, which then calls the needed load_controllers/libs/models/settings/functions (only the files under the bolded folder names will be loaded)
load_controllers will use the file_includer and make all files under the [plugin app path]/controllers be required
This means that any class under the specified folders above will be auto-required for the plugin that depends on WP MVC [tested]
This also explains why if one create a helper function, following the documentation, one would put the class under helper folder, but that doesn't get auto-loaded and one will get class not found error (because helpers doesn't get loaded/not in the list above)
Upon a closer inspection, it looks like only classes extending MvcController can load any helper files (base class MvcController is the only class that has load_helper() function). The helper files need to be named xyzHelper, under helpers folder, and needs to extend MvcHelper. In the child controller class, call $this->load_helper('xyz') and the base class will automatically try to load the helper class from the helpers folder. The controller class will now have a helper object named xyz (the class name, including underscores, without the _helper suffix). One can now have access to the helper class through the controller class (in the view classes also, etc. Used like $controller->xyz->function()) [tested]
How to get the above info:
Activate an example plugin from WP MVC and navigate to a public view
Put the breakpoint in mvc_file_includer.php require_file() [I actually just run the debugger without any breakpoint and there was a deprecated function warning at the above function. I didn't think to put a breakpoint at that function previous to seeing this, and I didn't know where to put the breakpoints previous to this realization]
Look at the stack trace and try to understand
Also, in WP MVC, there are other calls that will automatically include files
An example is render_view() - This will either call the controller's, or the helper's, render_view(), which will use the file_includer to find the desired file path, and call require on that file path. Therefore, it's more like this is a dynamic-loading of files that is being used.
Now, how did MvcLoader->init() get triggered?
In the main plugin's file: wp_mvc.php, depending on if it's in the admin/public functionality view, wp_mvc_load_global_functionality is called with the needed parameter. One of the actions in that function is add_action('init', array($loader, 'init')), which triggers the init hook for the MvcAdminLoader, which is a child of MvcLoader [tested by commenting out the add_action and it no longer works]

JomSocial was written to core and needs upgrade

I'm taking over a project where the original developer customized JomSocial and wrote directly to:
components/com_community/templates/jomsocial/layouts
And created there folders aswell as wrote into files like base.php and so on.
The current customized version of JomSocial is 4.0.9 and I need to update to the latest - 4.4.5, the Joomla version is - 3.8.1
I understand I need to create an override folder in my template folder like that for an example of the base.php file for each of the changes:
/templates/yourTemplateName/html/com_community/layouts/frontpage/base.php
But in order to keep the changes the developer made and have the latest version of JomSocial while not hindering further updates like in this situation I would have to if I'm not mistaken:
Separate the changes from the core files he made on 4.0.9.
Create folders and files in my templates folder for each core files I need to customize and have them include only the changes the developer made with an updated version of 4.4.5.
Am I getting this right? is there another way to do it? any help would be greatly appreciated.
You're correct on how to override the layout files in a template. Unfortunately it ties your overrides to a particular template - installing a different template and setting it as default will lose your overrides.
You can override any other file in a component by using a plugin and intercepting the call to the component's controller, substituting your own. You would have to copy all of the Jomsocial files between the entry point (controller) and the file you want to apply changes to with this approach, which is probably why the original developer just overwrote the core component files directly (can't safely update with this approach anyway, without checking for changes to the code you've copied from the core component files into your override). This approach would look something like:
class plgSystemComSocialOverride extends JPlugin {
public function __construct(&$subject, $config = array()) {
parent::__construct($subject, $config);
}
public function onAfterRoute() {
$app = JFactory::getApplication();
if('com_social' == JRequest::getCMD('option') && !$app->isSite()) {
require_once(dirname(__FILE__) . DS . 'comsocialoverride' . DS . 'my_jomsocial_controller.php');
}
}
}
I think you could combine the above approach with manipulating Joomla's class loader, to avoid having to directly copy Jomsocial files in order to change their include statements to your override files. In this approach, you'd override the controller as above and call the Jomsocial controller from that overridden controller. But before you do that, you'd add your overridden base.php or whatever to the class loader. I'm not sure if the new version of Jomsocial is using autoloading or not (i.e. import() instead of include()).

Overriding plugin renderer moodle

I have site running Moodle 2.9.3+ and i was trying to customize the renderer of one existing plugin, so i found this:
How to override a renderer such that the functionality of the overridden renderer also remains available?
I added the following into the core_renderer.php of my theme
include_once($CFG->dirroot . "/course/format/topcoll/renderer.php");
but when i tried to do
class topcoll_local_renderer extends format_topcoll_renderer {
protected function section_header($section, $course, $onsectionpage, $sectionreturn = null) {
...
}
}
it runs, but it's not loading the modified function. Do I need to do anything else? the modified function is running with no issues when I alter the code directly into the plugin, but not like this. I would greatly appreciate any possible hint.
Thanks
You need to do two things to get a theme renderer to override a core renderer:
You need to edit the theme's config.php to add the line: $THEME->rendererfactory = 'theme_overridden_renderer_factory';
You need to name your renderer class 'theme_NAMEOFTHEME_format_topcoll_renderer' (and extend 'format_topcoll_renderer', as you have done).
The theme_overridden_renderer_factory works by extending the process of instantiating a renderer to look for a class that matches the name 'theme_NAMEOFTHEME_NAMEOFRENDERER' - as long as that class exists, then it should be used (otherwise the original renderer is used).
See https://docs.moodle.org/dev/Overriding_a_renderer for more details.
Hmmm are you sure there isn't an error in the script inclusion? If you have error_reporting off in your ini settings you won't see the E_WARNING PHP might be raising. Set this to on, or use require_once() instead. See the accepted response to this SO post for the differences: Difference between require, include and require_once?

why invoke the function from the model in the template file there is no output?

I am a newbie of MVC and php. now in magento app/code/core/Mage/Review/Model/Review.php
i add code.
public function mgtest(){
return 'hello world!';
}
in the class
class Mage_Review_Model_Review extends Mage_Core_Model_Abstract
{ }
In magento cms page, i add code:
{{block type="core/template" name="review" template="catalog/product/reviewall.phtml"}}
the url key is review.html
then add file reviewall.phtml(app/design/frontend/default/mytheme/template/catalog/product/reviewall.phtml)
then add test code in its file.
<?php echo $this->mgtest();?>
when i access url. mysiteurl/review.html. there is no hello world output. why? thank you. how to correct it? what all the file in the model do? if i want to invoke the function the phtml file. how do i do?
Don't edit core to add new functionalities. Add all the additions/modifications in app/code/local directory.
In your existing code I see two issues:
The block's type in CMS page should be review/review and not core/template.
You have created function as matest(), but calling it as mgtest()
You have referenced $this from your reviewall.phtml, calling matest method which is/should residing in Review_Block_Review and NOT Core_Block_Template, so your CMS block type must be review/review.
I just see that you are placing matest method in your Model, please put it in Block, because you can't look in Model directly from template file using $this.
It's recommended to create your own custom module (in local directory) once you know how to get things done in Magento.

Can I extend the codeigniter core system, to use my custom functions on multiple sites?

I am currently using CodeIgniter to support one site, whose main purpose is to display multiple editable tablekit tables, and handle the AJAX that arrives when you edit them. A kind of PHPMyAdmin [VERY] Lite. It has a number of core helpers and controllers, which run the main workings of the site, mixed in with some site specific controllers and helpers.
I would like to restructure my site so that I can reuse the core code-base in another site. However, I would still like to be have some default controller functions and some cutsom functions in the same controller; i.e. in a system file somewhere:
class My_core extends Controller{
/*
Lots of base functions
*/
}
and on one site:
class site_1 extends My_Core{
/*
Site specific functions
*/
}
Then on the other site:
class site_2 extends My_Core{
/*
Site specific functions
*/
}
Does anyone have any guidance on how I can do this?
Thanks,
Lemiant
If you are using CodeIgniter 2.0 you can achieve most of this with with packages. They will let you load helpers, libraries and models from anywhere, so in each application simply configure a package to be loaded from that shared folder.
As for core libraries (which MY_Controller will be) you will have to implement your own __autoload() function:
http://php.net/manual/en/language.oop5.autoload.php
You can put an autoloader at the bottom of config.php. As long as it is checking the correct folders (local first, then the shared folder structure) it should all work pretty nicely.
I don't know if this is still helpful to you but heres what I've done.
say I have 2 websites, palladium.com and osmium.com.
my file tree looks like this
/var/www/system/ (the CI system folder)
/var/www/palladium/application
/var/www/palladium/public/index.php
/var/www/osmium/application
/var/www/osmium/public/index.php
inside those index.php files are lines that define where /system/ is stored. I've got that set to
$system_folder = "../../system";
Now inside /var/www/system/libraries i have a file named MY_TestClass
<?php
class MY_TestClass {
public function MY_TestClass() {
echo "this is a test of the emergency broadcast system";
}
}
From anywhere inside BOTH palladium.com and osmium.com i can call
$this->load->library('MY_TestClass');
and "this is a test of the emergency broadcast system" will show up.

Categories