0

I want to change the following file: vendor/magento/module-paypal/Model/SmartButtonConfig.php but if I made the modifications directly in the vendor file when I will upgrade my store this modifications will be lost. How I can add this file in the app/code or what is the best way to can modify this file?

Thank you

Public function:

private function getButtonStyles(string $page): array
{
    $styles = $this->defaultStyles[$page];
    if ((boolean)$this->config->getValue("{$page}_page_button_customize")) {
        $styles['layout'] = $this->config->getValue("{$page}_page_button_layout");
        $styles['size'] = $this->config->getValue("{$page}_page_button_size");
        $styles['color'] = $this->config->getValue("{$page}_page_button_color");
        $styles['shape'] = $this->config->getValue("{$page}_page_button_shape");
        $styles['label'] = $this->config->getValue("{$page}_page_button_label");
        $styles['height'] = 55;
        $styles['tagline'] = false;
        $styles['fundingicons'] = false;
        $styles = $this->updateStyles($styles, $page);
    }
    return $styles;
}

I want to add only this:

$styles['height'] = 55;
$styles['tagline'] = false;
$styles['fundingicons'] = false;

in the private function getButtonStyles

1 Answer 1

1
  1. create di.xml file on following location

app\code\Vendor\Extension\etc\frontend\di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="\Magento\Paypal\Model\SmartButtonConfig" type="Vendor\Extension\Model\SmartButtonConfig" />
</config>
  1. create SmartButtonConfig.php on following location

app\code\Vendor\Extension\Model\SmartButtonConfig.php

namespace Vendor\Extension\Model;

class SmartButtonConfig extends \Magento\Paypal\Model\SmartButtonConfig
{
   //do the code
}
4
  • thank you, I have add your code exactly as you say and I see this: Module does not exist
    – Robert
    Commented Sep 16, 2021 at 14:17
  • There was my fault about the module not exist I fix the problem, I edit my post can you check please, because the module is not work and I can't add my code there ... can you give me an example please? Thank you
    – Robert
    Commented Sep 16, 2021 at 14:43
  • Do not modify question completely, ask the seprate questions for another things. Commented Sep 16, 2021 at 16:28
  • Hi thank you for your recommandation, but I don't think it is another question, all I just want is too extend that public function, in fact I need to add it in the module that you tell me.
    – Robert
    Commented Sep 16, 2021 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.