I have in some Vendor's Module di.xml file this entry :
<type name="Amasty\RequestQuote\Model\Pdf\PdfInformation">
<arguments>
<argument name="variables" xsi:type="array">
<item name="0" xsi:type="array">
<item name="objectType" xsi:type="string">quote</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::USERNAME</item>
<item name="method" xsi:type="string">getCustomerName</item>
</item>
<item name="1" xsi:type="array">
<item name="objectType" xsi:type="string">custom</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::CUSTOMER_STREET</item>
<item name="method" xsi:type="string">getBillingStreet</item>
</item>
<item name="2" xsi:type="array">
<item name="objectType" xsi:type="string">billing</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::CUSTOMER_CITY</item>
<item name="method" xsi:type="string">getCity</item>
</item>
<item name="3" xsi:type="array">
<item name="objectType" xsi:type="string">custom</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::CUSTOMER_REGION</item>
<item name="method" xsi:type="string">getBillingRegion</item>
</item>
<item name="4" xsi:type="array">
<item name="objectType" xsi:type="string">billing</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::CUSTOMER_POSTCODE</item>
<item name="method" xsi:type="string">getPostcode</item>
</item>
<item name="5" xsi:type="array">
<item name="objectType" xsi:type="string">custom</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::CUSTOMER_COUNTRY</item>
<item name="method" xsi:type="string">getBillingCountryName</item>
</item>
<item name="6" xsi:type="array">
<item name="objectType" xsi:type="string">billing</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::CUSTOMER_TELEPHONE</item>
<item name="method" xsi:type="string">getTelephone</item>
</item>
<item name="7" xsi:type="array">
<item name="objectType" xsi:type="string">quote</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::QUOTE_NUMBER</item>
<item name="method" xsi:type="string">getIncrementId</item>
</item>
<item name="8" xsi:type="array">
<item name="objectType" xsi:type="string">quote</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::QUOTE_STATUS</item>
<item name="method" xsi:type="string">getStatusLabel</item>
</item>
<item name="9" xsi:type="array">
<item name="objectType" xsi:type="string">quote</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::QUOTE_DATE</item>
<item name="method" xsi:type="string">getCreatedAt</item>
</item>
<item name="10" xsi:type="array">
<item name="objectType" xsi:type="string">quote</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::QUOTE_EXPIRY_DATE</item>
<item name="method" xsi:type="string">getExpiredDate</item>
</item>
<item name="11" xsi:type="array">
<item name="objectType" xsi:type="string">custom</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::SHIPPING_STREET</item>
<item name="method" xsi:type="string">getShippingStreet</item>
</item>
<item name="12" xsi:type="array">
<item name="objectType" xsi:type="string">shipping</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::SHIPPING_CITY</item>
<item name="method" xsi:type="string">getCity</item>
</item>
<item name="13" xsi:type="array">
<item name="objectType" xsi:type="string">custom</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::SHIPPING_REGION</item>
<item name="method" xsi:type="string">getShippingRegion</item>
</item>
<item name="14" xsi:type="array">
<item name="objectType" xsi:type="string">shipping</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::SHIPPING_POSTCODE</item>
<item name="method" xsi:type="string">getPostcode</item>
</item>
<item name="15" xsi:type="array">
<item name="objectType" xsi:type="string">custom</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::SHIPPING_COUNTRY</item>
<item name="method" xsi:type="string">getShippingCountryName</item>
</item>
<item name="16" xsi:type="array">
<item name="objectType" xsi:type="string">custom</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::SHIPPING_TELEPHONE</item>
<item name="method" xsi:type="string">getTelephone</item>
</item>
<item name="17" xsi:type="array">
<item name="objectType" xsi:type="string">custom</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::SHIPPING_METHOD</item>
<item name="method" xsi:type="string">getShippingMethod</item>
</item>
<item name="18" xsi:type="array">
<item name="objectType" xsi:type="string">custom</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::PRODUCT_GRID</item>
<item name="method" xsi:type="string">getProductGrid</item>
</item>
<item name="19" xsi:type="array">
<item name="objectType" xsi:type="string">custom</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::STORE_PHONE</item>
<item name="method" xsi:type="string">getStorePhone</item>
</item>
<item name="20" xsi:type="array">
<item name="objectType" xsi:type="string">custom</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::HAS_SHIPPING_INFO</item>
<item name="method" xsi:type="string">hasShippingInfo</item>
</item>
</argument>
</arguments>
</type>
I would like to add in this another argument like
<item name="21" xsi:type="array">
<item name="objectType" xsi:type="string">custom</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::QUOTE_REMARKS</item>
<item name="method" xsi:type="string">getComments</item>
</item>
I was able to ovveride the Model (with preferences in my own custom module di.xml), but how should I edit the original parameters ?
Thanks
Ill try to be a bit more descriptive.
What I try is to override some third party module; I succeed to do what I want, if I edit directly the vendor's files.
This is the vendor's edited di.xml file (see at the end)
<?xml version="1.0"?>
...
<type name="Amasty\RequestQuote\Model\Pdf\PdfInformation">
<arguments>
<argument name="variables" xsi:type="array">
<item name="0" xsi:type="array">
<item name="objectType" xsi:type="string">quote</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::USERNAME</item>
<item name="method" xsi:type="string">getCustomerName</item>
</item>
<item name="1" xsi:type="array">
<item name="objectType" xsi:type="string">custom</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::CUSTOMER_STREET</item>
<item name="method" xsi:type="string">getBillingStreet</item>
</item>
<item name="2" xsi:type="array">
<item name="objectType" xsi:type="string">billing</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::CUSTOMER_CITY</item>
<item name="method" xsi:type="string">getCity</item>
</item>
<item name="3" xsi:type="array">
<item name="objectType" xsi:type="string">custom</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::CUSTOMER_REGION</item>
<item name="method" xsi:type="string">getBillingRegion</item>
</item>
<item name="4" xsi:type="array">
<item name="objectType" xsi:type="string">billing</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::CUSTOMER_POSTCODE</item>
<item name="method" xsi:type="string">getPostcode</item>
</item>
<item name="5" xsi:type="array">
<item name="objectType" xsi:type="string">custom</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::CUSTOMER_COUNTRY</item>
<item name="method" xsi:type="string">getBillingCountryName</item>
</item>
<item name="6" xsi:type="array">
<item name="objectType" xsi:type="string">billing</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::CUSTOMER_TELEPHONE</item>
<item name="method" xsi:type="string">getTelephone</item>
</item>
<item name="7" xsi:type="array">
<item name="objectType" xsi:type="string">quote</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::QUOTE_NUMBER</item>
<item name="method" xsi:type="string">getIncrementId</item>
</item>
<item name="8" xsi:type="array">
<item name="objectType" xsi:type="string">quote</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::QUOTE_STATUS</item>
<item name="method" xsi:type="string">getStatusLabel</item>
</item>
<item name="9" xsi:type="array">
<item name="objectType" xsi:type="string">quote</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::QUOTE_DATE</item>
<item name="method" xsi:type="string">getCreatedAt</item>
</item>
<item name="10" xsi:type="array">
<item name="objectType" xsi:type="string">quote</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::QUOTE_EXPIRY_DATE</item>
<item name="method" xsi:type="string">getExpiredDate</item>
</item>
<item name="11" xsi:type="array">
<item name="objectType" xsi:type="string">custom</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::SHIPPING_STREET</item>
<item name="method" xsi:type="string">getShippingStreet</item>
</item>
<item name="12" xsi:type="array">
<item name="objectType" xsi:type="string">shipping</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::SHIPPING_CITY</item>
<item name="method" xsi:type="string">getCity</item>
</item>
<item name="13" xsi:type="array">
<item name="objectType" xsi:type="string">custom</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::SHIPPING_REGION</item>
<item name="method" xsi:type="string">getShippingRegion</item>
</item>
<item name="14" xsi:type="array">
<item name="objectType" xsi:type="string">shipping</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::SHIPPING_POSTCODE</item>
<item name="method" xsi:type="string">getPostcode</item>
</item>
<item name="15" xsi:type="array">
<item name="objectType" xsi:type="string">custom</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::SHIPPING_COUNTRY</item>
<item name="method" xsi:type="string">getShippingCountryName</item>
</item>
<item name="16" xsi:type="array">
<item name="objectType" xsi:type="string">custom</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::SHIPPING_TELEPHONE</item>
<item name="method" xsi:type="string">getTelephone</item>
</item>
<item name="17" xsi:type="array">
<item name="objectType" xsi:type="string">custom</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::SHIPPING_METHOD</item>
<item name="method" xsi:type="string">getShippingMethod</item>
</item>
<item name="18" xsi:type="array">
<item name="objectType" xsi:type="string">custom</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::PRODUCT_GRID</item>
<item name="method" xsi:type="string">getProductGrid</item>
</item>
<item name="19" xsi:type="array">
<item name="objectType" xsi:type="string">custom</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::STORE_PHONE</item>
<item name="method" xsi:type="string">getStorePhone</item>
</item>
<item name="20" xsi:type="array">
<item name="objectType" xsi:type="string">custom</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::HAS_SHIPPING_INFO</item>
<item name="method" xsi:type="string">hasShippingInfo</item>
</item>
<item name="21" xsi:type="array">
<item name="objectType" xsi:type="string">custom</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::QUOTE_REMARKS</item>
<item name="method" xsi:type="string">getComments</item>
</item>
</argument>
</arguments>
</type>
...
I just added the last argument :
<item name="21" xsi:type="array">
<item name="objectType" xsi:type="string">custom</item>
<item name="variable" xsi:type="const">\Amasty\RequestQuote\Model\Source\PdfVariables::QUOTE_REMARKS</item>
<item name="method" xsi:type="string">getComments</item>
</item>
This is the edited Amasty/RequestQuote/Model/Pdf/PdfInformation.php
class PdfInformation {
private $quote;
private $variables;
private $billing;
private $shipping;
private $dataObjectFactory;
private $countryInformationAcquirer;
private $status;
private $productGrid;
private $addressRepository;
private $registry;
private $scopeConfig;
public function __construct(
DataObjectFactory $dataObjectFactory,
CountryInformationAcquirerInterface $countryInformationAcquirer,
Status $status,
Items $productGrid,
AddressRepository $addressRepository,
Registry $registry,
ScopeConfigInterface $scopeConfig,
array $variables = []
) {
$this->variables = $variables;
$this->dataObjectFactory = $dataObjectFactory;
$this->countryInformationAcquirer = $countryInformationAcquirer;
$this->status = $status;
$this->productGrid = $productGrid;
$this->addressRepository = $addressRepository;
$this->registry = $registry;
$this->scopeConfig = $scopeConfig;
}
Where I just added the following function :
private function getComments(): string
{
$json = $this->quote->getRemarks();
if ($json != ""){
$object = json_decode($json);
foreach($object as $key=>$value){
$result = $key." : ".$value."<br />";
}
}
else {
$result = "";
}
return (string)$result;
}
And finally, I edited the file Amasty\RequestQuote\Model\Source\PdfVariables to add the constant REMARKS, so it becomes
class PdfVariables implements OptionSourceInterface {
public const USERNAME = 'username'; public const CUSTOMER_STREET = 'customer_street'; public const CUSTOMER_CITY = 'customer_city'; public const CUSTOMER_REGION = 'customer_region'; public const CUSTOMER_POSTCODE = 'customer_postcode'; public const CUSTOMER_COUNTRY = 'customer_country'; public const CUSTOMER_TELEPHONE = 'customer_telephone'; public const QUOTE_NUMBER = 'quote_number'; public const QUOTE_STATUS = 'quote_status'; public const QUOTE_DATE = 'quote_date'; public const QUOTE_EXPIRY_DATE = 'quote_expiry_date'; public const HAS_SHIPPING_INFO = 'has_shipping_info'; public const SHIPPING_STREET = 'shipping_street'; public const SHIPPING_CITY = 'shipping_city'; public const SHIPPING_REGION = 'shipping_region'; public const SHIPPING_POSTCODE = 'shipping_postcode'; public const SHIPPING_COUNTRY = 'shipping_country'; public const SHIPPING_TELEPHONE = 'shipping_telephone'; public const SHIPPING_METHOD = 'shipping_method'; public const PRODUCT_GRID = 'product_grid'; public const STORE_PHONE = 'store_phone'; public const QUOTE_REMARKS = 'quote_remarks';
/**
* @return array|array[]
*/
public function toOptionArray()
{
return [
[
'value' => self::USERNAME,
'label' => __('Username')
],
[
'value' => self::CUSTOMER_STREET,
'label' => __('Customer Street')
],
[
'value' => self::CUSTOMER_REGION,
'label' => __('Customer Region')
],
[
'value' => self::CUSTOMER_POSTCODE,
'label' => __('Customer Postcode')
],
[
'value' => self::CUSTOMER_COUNTRY,
'label' => __('Customer Country')
],
[
'value' => self::CUSTOMER_TELEPHONE,
'label' => __('Customer Telephone')
],
[
'value' => self::QUOTE_NUMBER,
'label' => __('Quote Number')
],
[
'value' => self::QUOTE_STATUS,
'label' => __('Quote Status')
],
[
'value' => self::QUOTE_DATE,
'label' => __('Quote Date')
],
[
'value' => self::QUOTE_EXPIRY_DATE,
'label' => __('Quote Expiry Date')
],
[
'value' => self::HAS_SHIPPING_INFO,
'label' => __('Has Shipping Info')
],
[
'value' => self::SHIPPING_STREET,
'label' => __('Shipping Street')
],
[
'value' => self::SHIPPING_CITY,
'label' => __('Shipping City')
],
[
'value' => self::SHIPPING_REGION,
'label' => __('Shipping Region')
],
[
'value' => self::SHIPPING_POSTCODE,
'label' => __('Shipping Postcode')
],
[
'value' => self::SHIPPING_COUNTRY,
'label' => __('Shipping Country')
],
[
'value' => self::SHIPPING_TELEPHONE,
'label' => __('Shipping Telephone')
],
[
'value' => self::SHIPPING_METHOD,
'label' => __('Shipping Method')
],
[
'value' => self::PRODUCT_GRID,
'label' => __('Product Grid')
],
[
'value' => self::STORE_PHONE,
'label' => __('Store Phone')
],
[
'value' => self::QUOTE_REMARKS,
'label' => __('Quote Remarks')
],
];
}
}
My question is : how to implement this with a custopm module without editing the vendor ?
These are my files into my own module Paul/RequestQuote/
my di.xml in Paul/RequestQuote/etc/
<preference for="Amasty\RequestQuote\Model\Pdf\PdfInformation"
type="Paul\RequestQuote\Model\Pdf\PdfInformation" />
<preference for="Amasty\RequestQuote\Model\Source\PdfVariables"
type="Paul\RequestQuote\Model\Source\PdfVariables" />
<type name="Amasty\RequestQuote\Model\Pdf\PdfInformation">
<arguments>
<argument name="variables" xsi:type="array">
<item name="21" xsi:type="array">
<item name="objectType" xsi:type="string">custom</item>
<item name="variable" xsi:type="const">\Paul\RequestQuote\Model\Source\PdfVariables::QUOTE_REMARKS</item>
<item name="method" xsi:type="string">getComments</item>
</item>
</argument>
</arguments>
</type>
This is my new Paul/RequestQuote/Model/Pdf/PdfInformation.php
namespace Paul\RequestQuote\Model\Pdf;
use Amasty\RequestQuote\Model\Quote;
class PdfInformation extends \Amasty\RequestQuote\Model\Pdf\PdfInformation {
private $quote;
private function getComments(): string
{
$json = $this->quote->getRemarks();
if ($json != ""){
$object = json_decode($json);
foreach($object as $key=>$value){
$result = $key." : ".$value."
";
}
}
else {
$result = "";
}
return (string)$result;
}
And finally,; for my new Class PdfVariables, I created a Paul/RequestQuote/Model/Source/Pdfvariables and added the constant like :
namespace Paul\RequestQuote\Model\Source;
use Magento\Framework\Data\OptionSourceInterface;
class PdfVariables extends \Amasty\RequestQuote\Model\Source\PdfVariables
{ ... and I add the constant and edited fuction
It does not work. I get the following error :
Firstly, the errors says that I'm trying to call a private function (getComments() in my overrided Pdfinformation class) from the amasty PdfInformation file.
Then I did change the "private" function getComments to "public"...but in that case the object "quote" is empty (it doesnt inherit from the original $this->quote
I got this error :
Error: Call to a member function getRemarks() on null in /var/www/site/app/code/Paul/RequestQuote/Model/Pdf/PdfInformation.php:20 Stack trace: #0 /var/www/site/vendor/amasty/module-request-quote/Model/Pdf/PdfInformation.php(115): Paul\RequestQuote\Model\Pdf\PdfInformation->getComments() #1 /var/www/site/vendor/amasty/module-request-quote/Model/Pdf/PdfInformation.php(106): Amasty\RequestQuote\Model\Pdf\PdfInformation->g ...