Prestashop 1.7 override front controller from custom theme - overriding

In PrestaShop 1.7, I have my own theme, which is currently the default.
In the product card, I need to display a list of multishop stores.
Since I don't know if it is possible to get information about multishop stores using the default controller controllers/front/ProductController.php, I want to extend this controller in my custom theme.
I am creating file themes/myTheme/override/controllers/front/ProductController.php with code like this:
class ProductController extends ProductControllerCore{
public $multiStores;
public function init()
{
parent::init();
echo 'test';
}
}
I expect that on the product card page I will be able to see my text "test".
But unfortunately nothing happens, I conclude that this controller is not connected for some reason.
Can you please tell me what I'm doing wrong and how to fix the situation?

You cannot override a front controller method in a theme like that.
You'll need to override the core frontcontroller by placing
your code inside /override/controllers/front
See : https://devdocs.prestashop.com/1.7/modules/concepts/overrides/
Anyway you can achieve the desired result in a cleaner way by
using a proper frontend hook (ie. hookDisplayHeader) and build a simple module, checking the context object to see in which id_shop you are connected.

Related

New export action for pages in magnolia cms

I need to create a new export action for the page app in magnolia cms that would always export selected page elements to a YAML file.
I would like to override the class definition and the dialog definition for the existing export action since I do not need a dialog that lets me select YAML or XML. It will always be YAML in my case.
I setup a new Maven module and created a new action for the Page app.
How do I configure a custom class for this action? How do I get the current context of the page in my class?
You have to remove the dialog attached to the action first. If you plan to have a custom action then simply do not configure one. We already have two actions for those two cases. If you are interested in YAML export use the following: info.magnolia.ui.framework.action.ExportYamlAction
My action configuration for exportYAML2
My actionbar configuration for exportYAML
* repeating the content of the comment below since I could not post pictures in the comment *
I configured two actions for exporting the YAML configuration of the node.
The second one (exportYAML2) using ExportYamlActionDefinition does not show up in the actionbar for the page even though I added it as an item.
Is there anything else I need to configure for it?
exportYaml with class info.magnolia.ui.framework.action.OpenExportDialogActionDefinition works. exportYaml2 with class info.magnolia.ui.framework.action.ExportYamlActionDefinition doesn't work. Availability for it is set to info.magnolia.ui.framework.availability.IsNotDeletedRule.
It is solved.
There are two things I needed to configure for a custom action in the pages app in magnolia.
configuration app modules>pages>apps>pages>subApps>browser>actions>MyAction withe class={custom or common class from https://documentation.magnolia-cms.com/display/DOCS61/Action+definition }
modules>pages>apps>pages>subApps>browser>actionbar>sections>pageActions>groups>uniquegroupname>items-MyAction

Drupal 8 - Programmatic Redirect In Form In Custom Block Module Not Working

I'm new to Drupal and have been asked to add a redirect in a custom module that was written for us. Unfortunately, the redirect is not working.
The module is implemented as a Block and is working without the redirect code. The module has a Form at the docroot\modules\custom\modulename\src\Form\filename.php location which is what I'm trying to edit.
This Form has a submitForm function in it in which I'm trying to use the following code:
$response = new RedirectResponse('/');
$response->send();
return;
This block has been placed on a page. Let's call it "/en/testpage". However, despite trying all sorts of valid pages in the RedirectResponse such as '/', '/en/members', etc., after the form is submitted, the user is always taken back to https://theNameOfTheWebsite/en/testpage#block-theNameOfTheBlock instead of what I'm trying to redirect to.
I would greatly appreciate if anyone would know how I could resolve this. I have been stuck on this problem for the last 2 days. Thanks. If it helps, the folder structure within the module's folder is similar to the following: "src\Form", "Plugin\Block", "template".
Hi mkha13 Welcome to Stackoverflow
your code is not working with your redirection code
Check your log messages first if there is any logged message about this
at
/admin/reports/dblog
Check if you are not including RedirectResponse class
If not included, include this with this line at top of your form class
use Symfony\Component\HttpFoundation\RedirectResponse;
Another solution is
/**
* {#inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state->setRedirect("routingName");
}
routingName is the machine name mentioned in the routing file.
Redirect to front page
$form_state->setRedirect('<front>');
Hope this helps you

Change Woocommerce Email Header using custom plugin

I want to change the WooCommerce email header template with a new one so that i could add conditions in header template to get value from dashboard or database. (To change color of header based on user input from dashboard). Please note that i am using a custom plugin file to do so.
I have followed several tutorials and all i received was bunch of errors.
What i did is, i have a class with following code.
public function __construct(){
add_action('woocommerce_email',array($this,'woocommerce_email'));
}
Now I have added code to remove default reset the hook:
public function woocommerce_email($mailer){
remove_action('woocommerce_header',array($mailer,'email_header'));
add_action('woocommerce_header',array($this,'email_header'));
}
Now calling the template:
public function email_header() {
wc_get_template( 'emails/email-header.php');
}
I am not passing anything to the template file. So no parameters are passed to functions. I just wanted to see that my template is being taken.
Also i assume $mailer to be a part of WooCommerce class.
Any help would be appreciated.
Please note that this is a plugin functionality so I am not interested in replacing the WooCommerce email templates.

Default custom route on SonataORMAdmin list view

Refering to the SoanataORMAdmin's documentation, it is possible to change the default route of object links.
By default, it's the edit route. I don't want it at all and need to change it to show without override all my admin class.
What is the better way to override the default route ?
Thanks.
The best way is to override the twig by extending SonataORMAdminBundle.
To do this, you need to :
install SonataEasyGenerate Bundle
use the command php app/console sonata:easy-extends:generate SonataORMAdminBundle
this will generate a new repository Application/Sonata/DoctrineORMAdminBundle
Then you need to go to Application/Sonata/DoctrineORMAdminBundle/Ressources/views/CRUD and paste the twigs from the vendors (vendor/Sonata/DoctrineORMAdminBundle/Ressources/views/CRUD)
Finally, change the links in the twigs.
For example, if you want to call the list view to call the show route for a many to one relation :
edit list_orm_many_to_one.html.twig to call generateObjectUrl('show',...) instead of generateObjectUrl('edit',...)
Hope this will help.

How does Symfony2 detect where to load templates from?

Where does Symfony2 detect where to load templates from: from app/Resourses/views/ or from Bundle/Resourses/views/?
I need to override it to look for templates in another directory before looking into app/Resourses/views/.
I found: Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplateFinder
Now I just need to override it. How?
Symfony2 works with this workflow
Access route, pass control to controller, render a view (template)
If the view is not overridden ( app/..../ ) then bundle template is render
If there's an override, then took it
So the question is: how can I override a template?
There are two different ways for override templates in symfony2
Define a template with same name into app/resources directory. Together "same name" you have to reproduce the same structure of the bundle. So, if your template is in, i.e., myFooBundle/views/mainTemplate.html.twig you have to override it by creating a new one template in app/resources/myFooBundle/views and call it mainTemplate.html.twig
You have to create a new bundle from scratch and override getParent() method that have to return a string containing bundle name that you want to override ( myfooBundle ). Now if you create a new template in the same position of the original, you have overwritten it. This method is not recommended since you have to override controller also.

Resources