6
6
7
7
namespace Magento \Sales \Model \Order \Pdf ;
8
8
9
-
10
- use Magento \Framework \App \Config \ScopeConfigInterface ;
11
9
use Magento \Framework \App \Filesystem \DirectoryList ;
12
10
use Magento \Framework \App \ObjectManager ;
13
- use Magento \Framework \Exception \FileSystemException ;
14
11
use 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 ;
19
12
use 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 ;
23
13
use Magento \Sales \Model \RtlTextHandler ;
24
14
use Magento \Store \Model \ScopeInterface ;
25
15
use Magento \Tax \Helper \Data as TaxHelper ;
@@ -56,9 +46,7 @@ abstract class AbstractPdf extends \Magento\Framework\DataObject
56
46
* Predefined constants
57
47
*/
58
48
public const XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID = 'sales_pdf/invoice/put_order_id ' ;
59
-
60
49
public const XML_PATH_SALES_PDF_SHIPMENT_PUT_ORDER_ID = 'sales_pdf/shipment/put_order_id ' ;
61
-
62
50
public const XML_PATH_SALES_PDF_CREDITMEMO_PUT_ORDER_ID = 'sales_pdf/creditmemo/put_order_id ' ;
63
51
64
52
/**
@@ -145,7 +133,7 @@ abstract public function getPdf();
145
133
/**
146
134
* @var Magento\Tax\Helper\Data
147
135
*/
148
- private $ taxHelper ;
136
+ protected $ taxHelper ;
149
137
150
138
/**
151
139
* @var array $pageSettings
@@ -158,40 +146,33 @@ abstract public function getPdf();
158
146
private $ fileStorageDatabase ;
159
147
160
148
/**
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
165
153
* @param Config $pdfConfig
166
- * @param Factory $pdfTotalFactory
154
+ * @param Total\ Factory $pdfTotalFactory
167
155
* @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
171
160
* @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
177
161
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
178
162
*/
179
163
public function __construct (
180
164
\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 ,
187
171
\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 = []
195
176
) {
196
177
$ this ->addressRenderer = $ addressRenderer ;
197
178
$ this ->_paymentData = $ paymentData ;
@@ -205,12 +186,45 @@ public function __construct(
205
186
$ this ->_pdfItemsFactory = $ pdfItemsFactory ;
206
187
$ this ->inlineTranslation = $ inlineTranslation ;
207
188
$ 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
+
211
196
parent ::__construct ($ data );
212
197
}
213
198
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
+
214
228
/**
215
229
* Returns the total width in points of the string using the specified font and size.
216
230
*
0 commit comments