cancel
Showing results for 
Search instead for 
Did you mean: 

How to recreate a core magento file in my own theme?

How to recreate a core magento file in my own theme?

Hello,

To get around a current bug in 2.1.3+ (here), I've had to modify a core magento file in :

 

\vendor\magento\module-catalog\Pricing\Render\FinalPriceBox.php

 

If I want to place this modification under my own theme, instead of modifying the core files (which will get lost on upgrade), how/where do I place my own copy of this file ?

 

 

4 REPLIES

Re: How to recreate a core magento file in my own theme?

hi @trackwerks

 

  you cannot move the php file into your theme. you have to rewrite the file in your module to make it work also editing the code file is not good. here is solution for you. Create di.xml in



<?xml version="1.0"?>
<!--
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">  
<preference for="Magento\Catalog\Pricing\Render\FinalPriceBox" type="QaisarSatti\HelloWorld\Pricing\Render\FinalPriceBox" />
</config>

 

and then create the rewrite file  app/code/QaisarSatti/HelloWorld/Pricing/Render/FinalPriceBox.php



<?php
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace QaisarSatti\HelloWorld\Pricing\Render;

use Magento\Catalog\Pricing\Price;
use Magento\Framework\Pricing\Render;
use Magento\Framework\Pricing\Render\PriceBox as BasePriceBox;
use Magento\Msrp\Pricing\Price\MsrpPrice;

/**
 * Class for final_price rendering
 *
 * @method bool getUseLinkForAsLowAs()
 * @method bool getDisplayMinimalPrice()
 */
class FinalPriceBox extends BasePriceBox
{}

 
Then the update will not effect your code. here is hello world module sample

Find helpful ? Consider Giving Kudos to this post.
Problem solved? Click Accept as Solution!"
Qaisar Satti

Re: How to recreate a core magento file in my own theme?

So, I've implemented that, and unfortunately, it doesn't seem to work.

I didn't use your Hello world module (as I don't want any other items being posted to the main page), but I did use a previously created "Company_ApplyPatches" module that I created in the past, that has nothing more than the composer.json, registration.php etc/module.xml in its original version. I then added the di.xml file, and copied the FinalPriceBox.php and made the reference change, however this doesn't seem to work.

You can see the module here:
https://www.dropbox.com/s/jftvpthxlwkrtea/Company_ApplyPatches.zip?dl=0

 

Re: How to recreate a core magento file in my own theme?

hi @trackwerks

 

 i checked your code there was error. here is tested package

https://www.dropbox.com/s/bonx1dnjqbmj08p/ApplyPatches.tar.gz?dl=0

Find helpful ? Consider Giving Kudos to this post.
Problem solved? Click Accept as Solution!"
Qaisar Satti

Re: How to recreate a core magento file in my own theme?

Unfortunately, that seems to have done nothing at all.

 

The "As Low As" is still appearing. I was attempting to remove that text completely.  I tried commenting out that section in the code, but it still appears. So, I suspect this module isn't working (this is in CE 2.1.3)