Jump to content

How to override classes in src folder?


promt
 Share

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

 

Share this post


Link to post
Share on other sites

Overrides of other things than classes/controllers/modules with /override/ directory is not available anymore.

is it good? well, in my opinion no, it is not. But in this case we cant do anything, unfortunately.

  • Like 4

Share this post


Link to post
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)

Share this post


Link to post
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

Share this post


Link to post
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/

Share this post


Link to post
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?

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

  • 9 months 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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More