1

I want to change the button style of the PayPal Express Checkout, but is not work, I have create a module to rewrite the PayPal but how I can add my changes there?

  1. I 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
}

and I have this function:

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 = $this->updateStyles($styles, $page);
    }
    return $styles;
}

I want to add only this, this are my changes:

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

in the private function getButtonStyles

so what I want to do is to not overwrite the vendor file. so this function private function getButtonStyles exist already in the vendor/magento/module-paypal/Model/SmartButtonConfig.php,

I just want to add in this function

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

and to be in a seperate module, because I don't want to lose the modifications when I'll upgrade the store .

Thank you

7
  • do you have any custom module, where you can override model ?
    – Pawan
    Sep 17, 2021 at 8:38
  • is the default PayPal module and I create the module that I posted here to rewrite that module, and I need to add that private function
    – Robert
    Sep 17, 2021 at 8:40
  • Vendor\Extension is your module ?
    – Pawan
    Sep 17, 2021 at 8:45
  • yesVendor\Extension, indeed I create that module to can extend the PayPal module
    – Robert
    Sep 17, 2021 at 9:12
  • so what I want to do is to not overwrite the vendor file. so this function private function getButtonStyles is already in the vendor/magento/module-paypal/Model/SmartButtonConfig.php, I just want to add in this function $styles['height'] = 55; $styles['tagline'] = false; $styles['fundingicons'] = false; and to be in a seperate module, because I don't want to lose the modifications when I'll upgrade the store . I hope this make sense
    – Robert
    Sep 17, 2021 at 12:07

1 Answer 1

1

No need to create preference, we can use type

create:

app/code/Vendor/Extension/etc/di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Paypal\Model\SmartButtonConfig">
        <arguments>
            <argument name="defaultStyles" xsi:type="array">
                <item name="checkout" xsi:type="array">
                    <item name="height" xsi:type="number">55</item>
                    <item name="tagline" xsi:type="boolean">false</item>
                    <item name="fundingicons" xsi:type="boolean">false</item>
                </item>
                <item name="cart" xsi:type="array">
                    <item name="height" xsi:type="number">55</item>
                    <item name="tagline" xsi:type="boolean">false</item>
                    <item name="fundingicons" xsi:type="boolean">false</item>
                </item>
                <item name="mini_cart" xsi:type="array">
                    <item name="height" xsi:type="number">55</item>
                    <item name="tagline" xsi:type="boolean">false</item>
                    <item name="fundingicons" xsi:type="boolean">false</item>
                </item>
                <item name="product" xsi:type="array">
                    <item name="height" xsi:type="number">55</item>
                    <item name="tagline" xsi:type="boolean">false</item>
                    <item name="fundingicons" xsi:type="boolean">false</item>
                </item>
            </argument>
        </arguments>
    </type>
</config>

Note: you can remove any node if don't require (i.e.checkout,cart,mini_cart,product)

2
  • is work fine, thank you
    – Robert
    Sep 20, 2021 at 10:07
  • welcome @Robert :)
    – Pawan
    Sep 20, 2021 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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