66
77namespace Magento \Sales \Model \Order \Pdf ;
88
9-
10- use Magento \Framework \App \Config \ScopeConfigInterface ;
119use Magento \Framework \App \Filesystem \DirectoryList ;
1210use Magento \Framework \App \ObjectManager ;
13- use Magento \Framework \Exception \FileSystemException ;
1411use Magento \Framework \File \Pdf \Image ;
15- use Magento \Framework \Filesystem ;
16- use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
17- use Magento \Framework \Stdlib \StringUtils ;
18- use Magento \Framework \Translate \Inline \StateInterface ;
1912use Magento \MediaStorage \Helper \File \Storage \Database ;
20- use Magento \Payment \Helper \Data ;
21- use Magento \Sales \Model \Order \Address \Renderer ;
22- use Magento \Sales \Model \Order \Pdf \Total \Factory ;
2313use Magento \Sales \Model \RtlTextHandler ;
2414use Magento \Store \Model \ScopeInterface ;
2515use Magento \Tax \Helper \Data as TaxHelper ;
@@ -56,9 +46,7 @@ abstract class AbstractPdf extends \Magento\Framework\DataObject
5646 * Predefined constants
5747 */
5848 public const XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID = 'sales_pdf/invoice/put_order_id ' ;
59-
6049 public const XML_PATH_SALES_PDF_SHIPMENT_PUT_ORDER_ID = 'sales_pdf/shipment/put_order_id ' ;
61-
6250 public const XML_PATH_SALES_PDF_CREDITMEMO_PUT_ORDER_ID = 'sales_pdf/creditmemo/put_order_id ' ;
6351
6452 /**
@@ -145,7 +133,7 @@ abstract public function getPdf();
145133 /**
146134 * @var Magento\Tax\Helper\Data
147135 */
148- private $ taxHelper ;
136+ protected $ taxHelper ;
149137
150138 /**
151139 * @var array $pageSettings
@@ -158,40 +146,33 @@ abstract public function getPdf();
158146 private $ fileStorageDatabase ;
159147
160148 /**
161- * @param Data $paymentData
162- * @param StringUtils $string
163- * @param ScopeConfigInterface $scopeConfig
164- * @param Filesystem $filesystem
149+ * @param \Magento\Payment\Helper\ Data $paymentData
150+ * @param \Magento\Framework\Stdlib\ StringUtils $string
151+ * @param \Magento\Framework\App\Config\ ScopeConfigInterface $scopeConfig
152+ * @param \Magento\Framework\ Filesystem $filesystem
165153 * @param Config $pdfConfig
166- * @param Factory $pdfTotalFactory
154+ * @param Total\ Factory $pdfTotalFactory
167155 * @param ItemsFactory $pdfItemsFactory
168- * @param TimezoneInterface $localeDate
169- * @param StateInterface $inlineTranslation
170- * @param Renderer $addressRenderer
156+ * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
157+ * @param \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation
158+ * @param \Magento\Sales\Model\Order\Address\Renderer $addressRenderer
159+ * @param \Magento\Tax\Helper\Data $taxHelper
171160 * @param array $data
172- * @param TaxHelper|null $taxHelper
173- * @param Database|null $fileStorageDatabase
174- * @param RtlTextHandler|null $rtlTextHandler
175- * @param Image|null $image
176- * @throws FileSystemException
177161 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
178162 */
179163 public function __construct (
180164 \Magento \Payment \Helper \Data $ paymentData ,
181- \Magento \Framework \Stdlib \StringUtils $ string ,
182- \Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig ,
183- \Magento \Framework \Filesystem $ filesystem ,
184- Config $ pdfConfig ,
185- \Magento \Sales \Model \Order \Pdf \Total \Factory $ pdfTotalFactory ,
186- \Magento \Sales \Model \Order \Pdf \ItemsFactory $ pdfItemsFactory ,
165+ \Magento \Framework \Stdlib \StringUtils $ string ,
166+ \Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig ,
167+ \Magento \Framework \Filesystem $ filesystem ,
168+ Config $ pdfConfig ,
169+ \Magento \Sales \Model \Order \Pdf \Total \Factory $ pdfTotalFactory ,
170+ \Magento \Sales \Model \Order \Pdf \ItemsFactory $ pdfItemsFactory ,
187171 \Magento \Framework \Stdlib \DateTime \TimezoneInterface $ localeDate ,
188- \Magento \Framework \Translate \Inline \StateInterface $ inlineTranslation ,
189- \Magento \Sales \Model \Order \Address \Renderer $ addressRenderer ,
190- array $ data = [],
191- ?TaxHelper $ taxHelper = null ,
192- Database $ fileStorageDatabase = null ,
193- ?RtlTextHandler $ rtlTextHandler = null ,
194- ?Image $ image = null
172+ \Magento \Framework \Translate \Inline \StateInterface $ inlineTranslation ,
173+ \Magento \Sales \Model \Order \Address \Renderer $ addressRenderer ,
174+ \Magento \Tax \Helper \Data $ taxHelper ,
175+ array $ data = []
195176 ) {
196177 $ this ->addressRenderer = $ addressRenderer ;
197178 $ this ->_paymentData = $ paymentData ;
@@ -205,12 +186,45 @@ public function __construct(
205186 $ this ->_pdfItemsFactory = $ pdfItemsFactory ;
206187 $ this ->inlineTranslation = $ inlineTranslation ;
207188 $ this ->taxHelper = $ taxHelper ;
208- $ this ->fileStorageDatabase = $ fileStorageDatabase ?: ObjectManager::getInstance ()->get (Database::class);
209- $ this ->rtlTextHandler = $ rtlTextHandler ?: ObjectManager::getInstance ()->get (RtlTextHandler::class);
210- $ this ->image = $ image ?: ObjectManager::getInstance ()->get (Image::class);
189+
190+ // Initialize optional dependencies using ObjectManager if not provided
191+ $ objectManager = ObjectManager::getInstance ();
192+ $ this ->fileStorageDatabase = $ objectManager ->get (Database::class);
193+ $ this ->rtlTextHandler = $ objectManager ->get (RtlTextHandler::class);
194+ $ this ->image = $ objectManager ->get (Image::class);
195+
211196 parent ::__construct ($ data );
212197 }
213198
199+ /**
200+ * Set optional dependencies
201+ *
202+ * @param Database|null $fileStorageDatabase
203+ * @param RtlTextHandler|null $rtlTextHandler
204+ * @param Image|null $image
205+ * @return void
206+ */
207+ public function setOptionalDependencies (
208+ Database $ fileStorageDatabase = null ,
209+ RtlTextHandler $ rtlTextHandler = null ,
210+ Image $ image = null
211+
212+ )
213+ {
214+ if ($ fileStorageDatabase ) {
215+ $ this ->fileStorageDatabase = $ fileStorageDatabase ;
216+ }
217+ if ($ rtlTextHandler ) {
218+ $ this ->rtlTextHandler = $ rtlTextHandler ;
219+ }
220+ if ($ image ) {
221+ $ this ->image = $ image ;
222+ }
223+
224+ }
225+
226+
227+
214228 /**
215229 * Returns the total width in points of the string using the specified font and size.
216230 *
0 commit comments