Here is what I need:
In file vendor/magento/module-sales-rule/Model/Rule/Action/Discount/CartFixed.php there is a public function calculate
I want to comment an If condition inside this function without modifying this core file.
if ($availableDiscountAmount > 0) {
I have created a preference inside a custom module but it is not working as expected. I really appreciate if anyone can help me on this.
5
Answers
Use like this
To customize Magento core file, you can use Preference or Plugin. More detail here
In your case, you can use preference as the following steps:
<preference for="MagentoSalesRuleModelRuleActionDiscountCartFixed" type="TrainingTestModelRuleActionDiscountCartFixed" />
Create TrainingTestModelRuleActionDiscountCartFixed.php:
*/
namespace TrainingTestModelRuleActionDiscount;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkPricingPriceCurrencyInterface;
use MagentoSalesRuleModelDeltaPriceRound;
use MagentoSalesRuleModelValidator;
use MagentoSalesRuleModelRuleActionDiscountFactory;
class CartFixed extends MagentoSalesRuleModelRuleActionDiscountCartFixed
{
/**
* @var string
*/
private static $discountType = ‘CartFixed’;
/**
* @var DeltaPriceRound
*/
private $deltaPriceRound;
}
Or you can use cweagans/composer-patches following this question to edit core Magento files
Regards
App/Code/Magento/SalesRule/model/ *
Please use it like this
After adding this please use compile command
It works for me it will work for you also
First add folders
App/Code/Magento/SalesRule/model/folder/file.php
And thank use “setup:upgrade” to update the files.
Than command “setup:di:compile”.
Regards
Naseem