Skip to content

Commit a2a1bdb

Browse files
committed
Merge branch 'ACP2E-1216' of https://github.com/magento-l3/magento2ce into PR-L3-2023-01-31
2 parents 69c32b1 + 642fbd2 commit a2a1bdb

File tree

10 files changed

+140
-23
lines changed

10 files changed

+140
-23
lines changed

app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function draw()
101101
}
102102

103103
if (!isset($drawItems[$optionId])) {
104-
$drawItems[$optionId] = ['lines' => [], 'height' => 15];
104+
$drawItems[$optionId] = ['lines' => [], 'height' => 20];
105105
}
106106

107107
// draw selection attributes
@@ -112,7 +112,7 @@ public function draw()
112112
'feed' => $x,
113113
];
114114

115-
$drawItems[$optionId] = ['lines' => [$line], 'height' => 15];
115+
$drawItems[$optionId] = ['lines' => [$line], 'height' => 20];
116116

117117
$line = [];
118118
$prevOptionId = $attributes['option_id'];
@@ -199,17 +199,18 @@ public function draw()
199199
if ($option['value']) {
200200
$text = [];
201201
$printValue = $option['print_value'] ?? $this->filterManager->stripTags($option['value']);
202+
$printValue = str_replace(PHP_EOL, ', ', $printValue);
202203
$values = explode(', ', $printValue);
203204
foreach ($values as $value) {
204-
foreach ($this->string->split($value, 30, true, true) as $subValue) {
205+
foreach ($this->string->split($value, 50, true, true) as $subValue) {
205206
$text[] = $subValue;
206207
}
207208
}
208209

209210
$lines[][] = ['text' => $text, 'feed' => $leftBound + 5];
210211
}
211212

212-
$drawItems[] = ['lines' => $lines, 'height' => 15];
213+
$drawItems[] = ['lines' => $lines, 'height' => 20, 'shift' => 5];
213214
}
214215
}
215216

app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private function drawChildrenItems(): array
105105
}
106106

107107
if (!isset($drawItems[$optionId])) {
108-
$drawItems[$optionId] = ['lines' => [], 'height' => 15];
108+
$drawItems[$optionId] = ['lines' => [], 'height' => 20];
109109
}
110110

111111
if ($childItem->getOrderItem()->getParentItem() && $prevOptionId != $attributes['option_id']) {
@@ -239,17 +239,18 @@ private function drawCustomOptions(array $draw): array
239239
if ($option['value']) {
240240
$text = [];
241241
$printValue = $option['print_value'] ?? $this->filterManager->stripTags($option['value']);
242+
$printValue = str_replace(PHP_EOL, ', ', $printValue);
242243
$values = explode(', ', $printValue);
243244
foreach ($values as $value) {
244-
foreach ($this->string->split($value, 30, true, true) as $subValue) {
245+
foreach ($this->string->split($value, 50, true, true) as $subValue) {
245246
$text[] = $subValue;
246247
}
247248
}
248249

249250
$lines[][] = ['text' => $text, 'feed' => 40];
250251
}
251252

252-
$draw[] = ['lines' => $lines, 'height' => 15];
253+
$draw[] = ['lines' => $lines, 'height' => 20, 'shift' => 5];
253254
}
254255
}
255256

app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function draw()
9999
}
100100

101101
if (!isset($drawItems[$optionId])) {
102-
$drawItems[$optionId] = ['lines' => [], 'height' => 15];
102+
$drawItems[$optionId] = ['lines' => [], 'height' => 20];
103103
}
104104

105105
if ($childItem->getParentItem() && $prevOptionId != $attributes['option_id']) {
@@ -109,7 +109,7 @@ public function draw()
109109
'feed' => 100,
110110
];
111111

112-
$drawItems[$optionId] = ['lines' => [$line], 'height' => 15];
112+
$drawItems[$optionId] = ['lines' => [$line], 'height' => 20];
113113

114114
$line = [];
115115

@@ -169,23 +169,24 @@ public function draw()
169169
true
170170
),
171171
'font' => 'italic',
172-
'feed' => 60,
172+
'feed' => 110,
173173
];
174174

175175
if ($option['value']) {
176176
$text = [];
177177
$printValue = $option['print_value'] ?? $this->filterManager->stripTags($option['value']);
178+
$printValue = str_replace(PHP_EOL, ', ', $printValue);
178179
$values = explode(', ', $printValue);
179180
foreach ($values as $value) {
180181
foreach ($this->string->split($value, 50, true, true) as $subValue) {
181182
$text[] = $subValue;
182183
}
183184
}
184185

185-
$lines[][] = ['text' => $text, 'feed' => 65];
186+
$lines[][] = ['text' => $text, 'feed' => 115];
186187
}
187188

188-
$drawItems[] = ['lines' => $lines, 'height' => 15];
189+
$drawItems[] = ['lines' => $lines, 'height' => 20, 'shift' => 5];
189190
}
190191
}
191192

app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/InvoiceTestProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function getData(): array
2424
'display_both' => [
2525
'expected' => [
2626
1 => [
27-
'height' => 15,
27+
'height' => 20,
2828
'lines' => [
2929
[
3030
[
@@ -176,7 +176,7 @@ public function getData(): array
176176
'including_tax' => [
177177
'expected' => [
178178
1 => [
179-
'height' => 15,
179+
'height' => 20,
180180
'lines' => [
181181
[
182182
[
@@ -251,7 +251,7 @@ public function getData(): array
251251
'excluding_tax' => [
252252
'expected' => [
253253
1 => [
254-
'height' => 15,
254+
'height' => 20,
255255
'lines' => [
256256
[
257257
[

app/code/Magento/Sales/Model/Order/Pdf/AbstractPdf.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,8 +1108,9 @@ private function correctText($column, $height, $font, $page) :int
11081108
$lineSpacing = !empty($column['height']) ? $column['height'] : $height;
11091109
$fontSize = empty($column['font_size']) ? 10 : $column['font_size'];
11101110
foreach ($column['text'] as $part) {
1111-
if ($this->y - $lineSpacing < 15) {
1111+
if ($this->y - $top < 15) {
11121112
$page = $this->newPage($this->pageSettings);
1113+
$top = 0;
11131114
}
11141115

11151116
$feed = $column['feed'];

app/code/Magento/Sales/Model/Order/Pdf/Creditmemo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected function _drawHeader(\Zend_Pdf_Page $page)
8787
$page->setFillColor(new \Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
8888
$page->setLineColor(new \Zend_Pdf_Color_GrayScale(0.5));
8989
$page->setLineWidth(0.5);
90-
$page->drawRectangle(25, $this->y, 570, $this->y - 30);
90+
$page->drawRectangle(25, $this->y, 570, $this->y - 15);
9191
$this->y -= 10;
9292
$page->setFillColor(new \Zend_Pdf_Color_Rgb(0, 0, 0));
9393

app/code/Magento/Sales/Model/Order/Pdf/Items/Creditmemo/DefaultCreditmemo.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,20 @@ public function draw()
140140
) ? $option['print_value'] : $this->filterManager->stripTags(
141141
$option['value']
142142
);
143-
$lines[][] = ['text' => $this->string->split($printValue, 30, true, true), 'feed' => 40];
143+
144+
$values = explode(PHP_EOL, $printValue);
145+
$text = [];
146+
foreach ($values as $value) {
147+
foreach ($this->string->split($value, 50, true, true) as $subValue) {
148+
$text[] = $subValue;
149+
}
150+
}
151+
152+
$lines[][] = ['text' => $text, 'feed' => 40];
144153
}
145154
}
146155

147-
$lineBlock = ['lines' => $lines, 'height' => 20];
156+
$lineBlock = ['lines' => $lines, 'height' => 20, 'shift' => 5];
148157

149158
$page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true]);
150159
$this->setPage($page);

app/code/Magento/Sales/Model/Order/Pdf/Items/Invoice/DefaultInvoice.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,21 @@ public function draw()
151151
} else {
152152
$printValue = $this->filterManager->stripTags($option['value']);
153153
}
154+
$printValue = str_replace(PHP_EOL, ', ', $printValue);
154155
$values = explode(', ', $printValue);
156+
$text = [];
155157
foreach ($values as $value) {
156-
$lines[][] = ['text' => $this->string->split($value, 30, true, true), 'feed' => 40];
158+
foreach ($this->string->split($value, 50, true, true) as $subValue) {
159+
$text[] = $subValue;
160+
}
157161
}
162+
163+
$lines[][] = ['text' => $text, 'feed' => 40];
158164
}
159165
}
160166
}
161167

162-
$lineBlock = ['lines' => $lines, 'height' => 20];
168+
$lineBlock = ['lines' => $lines, 'height' => 20, 'shift' => 5];
163169

164170
$page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true]);
165171
$this->setPage($page);

app/code/Magento/Sales/Model/Order/Pdf/Items/Shipment/DefaultShipment.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,21 @@ public function draw()
104104
) ? $option['print_value'] : $this->filterManager->stripTags(
105105
$option['value']
106106
);
107+
$printValue = str_replace(PHP_EOL, ', ', $printValue);
107108
$values = explode(', ', $printValue);
109+
$text = [];
108110
foreach ($values as $value) {
109-
$lines[][] = ['text' => $this->string->split($value, 50, true, true), 'feed' => 115];
111+
foreach ($this->string->split($value, 50, true, true) as $subValue) {
112+
$text[] = $subValue;
113+
}
110114
}
115+
116+
$lines[][] = ['text' => $text, 'feed' => 115];
111117
}
112118
}
113119
}
114120

115-
$lineBlock = ['lines' => $lines, 'height' => 20];
121+
$lineBlock = ['lines' => $lines, 'height' => 20, 'shift' => 5];
116122

117123
$page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true]);
118124
$this->setPage($page);

app/code/Magento/Sales/Test/Unit/Model/Order/Pdf/AbstractTest.php

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,96 @@ public function testInsertTotals()
114114

115115
$this->assertSame($page, $actual);
116116
}
117+
118+
/**
119+
* Test for the multiline text will be correctly wrapped between multiple pages
120+
*
121+
* @return void
122+
* @throws \ReflectionException
123+
*/
124+
public function testDrawLineBlocks()
125+
{
126+
// Setup constructor dependencies
127+
$paymentData = $this->createMock(Data::class);
128+
$string = $this->createMock(StringUtils::class);
129+
$scopeConfig = $this->getMockForAbstractClass(ScopeConfigInterface::class);
130+
$filesystem = $this->createMock(Filesystem::class);
131+
$pdfConfig = $this->createMock(Config::class);
132+
$pdfTotalFactory = $this->createMock(Factory::class);
133+
$pdfItemsFactory = $this->createMock(ItemsFactory::class);
134+
$localeMock = $this->getMockForAbstractClass(TimezoneInterface::class);
135+
$translate = $this->getMockForAbstractClass(StateInterface::class);
136+
$addressRenderer = $this->createMock(Renderer::class);
137+
138+
$abstractPdfMock = $this->getMockForAbstractClass(
139+
AbstractPdf::class,
140+
[
141+
$paymentData,
142+
$string,
143+
$scopeConfig,
144+
$filesystem,
145+
$pdfConfig,
146+
$pdfTotalFactory,
147+
$pdfItemsFactory,
148+
$localeMock,
149+
$translate,
150+
$addressRenderer
151+
],
152+
'',
153+
true,
154+
false,
155+
true,
156+
['_setFontRegular', '_getPdf']
157+
);
158+
159+
$page = $this->createMock(\Zend_Pdf_Page::class);
160+
$zendFont = $this->createMock(\Zend_Pdf_Font::class);
161+
$zendPdf = $this->createMock(\Zend_Pdf::class);
162+
163+
// Make sure that the newPage will be called 3 times to correctly break 200 lines into pages
164+
$zendPdf->expects($this->exactly(3))->method('newPage')->willReturn($page);
165+
166+
$abstractPdfMock->expects($this->once())->method('_setFontRegular')->willReturn($zendFont);
167+
$abstractPdfMock->expects($this->any())->method('_getPdf')->willReturn($zendPdf);
168+
169+
$reflectionMethod = new \ReflectionMethod(AbstractPdf::class, 'drawLineBlocks');
170+
171+
$drawBlockLineData = $this->generateMultilineDrawBlock(200);
172+
$pageSettings = [
173+
'table_header' => true
174+
];
175+
176+
$reflectionMethod->invoke($abstractPdfMock, $page, $drawBlockLineData, $pageSettings);
177+
}
178+
179+
/**
180+
* Generate the array for multiline block
181+
*
182+
* @param int $numberOfLines
183+
* @return array[]
184+
*/
185+
private function generateMultilineDrawBlock(int $numberOfLines): array
186+
{
187+
$lines = [];
188+
for ($x = 0; $x < $numberOfLines; $x++) {
189+
$lines [] = $x;
190+
}
191+
192+
$block = [
193+
[
194+
'lines' =>
195+
[
196+
[
197+
[
198+
'text' => $lines,
199+
'feed' => 40
200+
]
201+
]
202+
],
203+
'shift' => 5
204+
]
205+
];
206+
207+
return $block;
208+
}
117209
}

0 commit comments

Comments
 (0)