Jump to content

How to override classes in src folder?


promt

Recommended Posts

Hi all,

 

Is it possible to override classes in src folder?

 

Especially I need to add an additional field to the OrderPresenter's present() method which is located at /src/Adapter/Order/OrderPresenter.php

 

PrestaShop version: 1.7.0.6

 

Thank you in advance for any help!

 

 

BR,
Paulius

 

Link to comment
Share on other sites

  • 4 months later...

Is this what you looking for? 

 

Presta 1.7 overriding->

 

PrestaShop’s controllers are all stored in the /controllers folder, and use the “Core” suffix.

For instance, when working with the Category controller:

  • File: /controllers/CategoryController.php
  • Class: CategoryControllerCore

In order to override a controller, you must first create a new class without the “Core” suffix, and place its file in the /override/controllers folder.

For instance, when overriding the Category controller:

  • File: /override/controllers/front/CategoryController.php
  • Class: CategoryController

 

Do not forget to delete cache in admin...

 

http://developers.prestashop.com/module/04-DivingIntoPSCoreDevelopment/03-ControllersWithinPrestaShop.html

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

  • 6 months later...
  • 9 months later...

It looks like PS team has 0 experience working with shops and clients. If they are going to move Core and disallow overrides.. either migration to another platform will be needed OR no upgrades for client shops due to modified code. Maintaining such mess would be a pain.

Maybe we OR other devs will think how to do overrides to src..

Edited by innercode (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 2 months later...
  • 2 months later...

What is your Prestashop version ?

What are your needs ?

Impossible to suggest you some hooks if we don’t know your needs...

Override is not available anymore for src folder due to architecture change. But we can use hooks or we can create your own implementation based on same class interface http://build.prestashop.com/news/prestashop-in-2019-and-beyond-part-1-current-architecture/

Link to comment
Share on other sites

  • 8 months later...
On 5/27/2019 at 9:37 AM, Janett said:

What is your Prestashop version ?

What are your needs ?

Impossible to suggest you some hooks if we don’t know your needs...

Override is not available anymore for src folder due to architecture change. But we can use hooks or we can create your own implementation based on same class interface http://build.prestashop.com/news/prestashop-in-2019-and-beyond-part-1-current-architecture/

 

Hey. I have exactly the same problem. PS 1.7.6.3

I want to hide the delivery if it is free, but only the value gets into the template and checking all languages for the text “Free” is very difficult

In src "src/Adapter/Presenter/Cart/CartPresenter.php"

	        $subtotals['shipping'] = array(
	            'type' => 'shipping',
	            'label' => $this->translator->trans('Shipping', array(), 'Shop.Theme.Checkout'),
	            'amount' => $shippingCost,
	            'value' => $shippingCost != 0
	                ? $this->priceFormatter->format($shippingCost)
	                : $this->translator->trans('Free', array(), 'Shop.Theme.Checkout'),
	        );

 

replace

 

        if($shippingCost != 0){
	        $subtotals['shipping'] = array(
	            'type' => 'shipping',
	            'label' => $this->translator->trans('Shipping', array(), 'Shop.Theme.Checkout'),
	            'amount' => $shippingCost,
	            'value' => $shippingCost != 0
	                ? $this->priceFormatter->format($shippingCost)
	                : $this->translator->trans('Free', array(), 'Shop.Theme.Checkout'),
	        );
        }

 

But how to do it right?

 

Link to comment
Share on other sites

  • 10 months later...
On 2/17/2020 at 9:51 AM, rewuxiin said:

 

Hey. I have exactly the same problem. PS 1.7.6.3

I want to hide the delivery if it is free, but only the value gets into the template and checking all languages for the text “Free” is very difficult

In src "src/Adapter/Presenter/Cart/CartPresenter.php"


	        $subtotals['shipping'] = array(
	            'type' => 'shipping',
	            'label' => $this->translator->trans('Shipping', array(), 'Shop.Theme.Checkout'),
	            'amount' => $shippingCost,
	            'value' => $shippingCost != 0
	                ? $this->priceFormatter->format($shippingCost)
	                : $this->translator->trans('Free', array(), 'Shop.Theme.Checkout'),
	        );

 

replace

 


        if($shippingCost != 0){
	        $subtotals['shipping'] = array(
	            'type' => 'shipping',
	            'label' => $this->translator->trans('Shipping', array(), 'Shop.Theme.Checkout'),
	            'amount' => $shippingCost,
	            'value' => $shippingCost != 0
	                ? $this->priceFormatter->format($shippingCost)
	                : $this->translator->trans('Free', array(), 'Shop.Theme.Checkout'),
	        );
        }

 

But how to do it right?

 

I think you are talking about frontend, no need to override anything, just play with your template (tpl file) to display or not the value.

Simone

Link to comment
Share on other sites

  • 9 months later...
  • 10 months later...
On 9/29/2022 at 9:59 AM, [email protected] said:

Hi! I need to do a modificaction in the file /src/PrestaShopBundle/Entity/Repository/StockRepository.php to modify the SQL for stock manager (line 257).

The only way that I find is edit this file. But now you say is not possible to do a override, so what do you recommend me to do?

Thanks!

Hi!

There is nothing you can really do.
You can just edit the file directly without using the override mechanic of prestashop.

Link to comment
Share on other sites

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...