diff --git a/app/Http/Requests/Preview/DesignPreviewRequest.php b/app/Http/Requests/Preview/DesignPreviewRequest.php index 21d47405e2d1..f3706c9f5b20 100644 --- a/app/Http/Requests/Preview/DesignPreviewRequest.php +++ b/app/Http/Requests/Preview/DesignPreviewRequest.php @@ -47,6 +47,7 @@ class DesignPreviewRequest extends Request 'settings' => 'sometimes', 'group_id' => 'sometimes', 'client_id' => 'sometimes', + 'design' => 'bail|sometimes|array' ]; return $rules; diff --git a/app/Services/Pdf/PdfDesigner.php b/app/Services/Pdf/PdfDesigner.php index 5db92b32a390..70dadec985c5 100644 --- a/app/Services/Pdf/PdfDesigner.php +++ b/app/Services/Pdf/PdfDesigner.php @@ -47,6 +47,15 @@ class PdfDesigner return $this; } + public function buildFromPartials(array $partials): self + { + + $this->template = $this->composeFromPartials($partials); + + return $this; + + } + /** * If the user has implemented a custom design, then we need to rebuild the design at this point */ @@ -54,10 +63,8 @@ class PdfDesigner /** * Returns the custom HTML design as * a string - * - * @param array + * @param array $partials * @return string - * */ private function composeFromPartials(array $partials) :string { diff --git a/app/Services/Pdf/PdfMock.php b/app/Services/Pdf/PdfMock.php index 698490f7f08f..b4afd3ebd8ba 100644 --- a/app/Services/Pdf/PdfMock.php +++ b/app/Services/Pdf/PdfMock.php @@ -69,7 +69,11 @@ class PdfMock $pdf_service->config = $pdf_config; - $pdf_designer = (new PdfDesigner($pdf_service))->build(); + if(isset($this->request['design'])) + $pdf_designer = (new PdfDesigner($pdf_service))->buildFromPartials($this->request['design']); + else + $pdf_designer = (new PdfDesigner($pdf_service))->build(); + $pdf_service->designer = $pdf_designer; $pdf_service->html_variables = $document_type == 'purchase_order' ? $this->getVendorStubVariables() : $this->getStubVariables(); diff --git a/tests/Feature/LiveDesignTest.php b/tests/Feature/LiveDesignTest.php index f00b1805b38a..03ce04551e54 100644 --- a/tests/Feature/LiveDesignTest.php +++ b/tests/Feature/LiveDesignTest.php @@ -11,10 +11,11 @@ namespace Tests\Feature; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Routing\Middleware\ThrottleRequests; -use Tests\MockAccountData; use Tests\TestCase; +use App\Models\Design; +use Tests\MockAccountData; +use Illuminate\Routing\Middleware\ThrottleRequests; +use Illuminate\Foundation\Testing\DatabaseTransactions; /** * @test @@ -55,4 +56,26 @@ class LiveDesignTest extends TestCase $response->assertStatus(200); } + + public function testDesignWithCustomDesign() + { + + $d = Design::find(1); + + + $data = [ + 'entity_type' => 'invoice', + 'settings_type' => 'company', + 'settings' => (array)$this->company->settings, + 'design' => (array)$d->design, + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->post('/api/v1/live_design/', $data); + + $response->assertStatus(200); + + } }