Skip to content

Commit 4f47b45

Browse files
author
MBriedis
committed
Add orientation parameter for printfile endpoint.
1 parent 1379269 commit 4f47b45

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/PrintfulMockupGenerator.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
22

3-
43
namespace Printful;
54

6-
75
use Printful\Structures\Generator\GenerationResultItem;
86
use Printful\Structures\Generator\MockupGenerationFile;
97
use Printful\Structures\Generator\MockupGenerationParameters;
@@ -33,12 +31,19 @@ public function __construct(PrintfulApiClient $printfulClient)
3331
* Get all available templates for specific printful product
3432
*
3533
* @param int $productId Printful product id
34+
* @param string|null $orientation Used for products with multiple orientations (e.g. wall art) {@see TemplateItem::ORIENTATION_HORIZONTAL} {@see TemplateItem::ORIENTATION_VERTICAL}
3635
* @return ProductPrintfiles
3736
* @throws Exceptions\PrintfulException
3837
*/
39-
public function getProductPrintfiles($productId)
38+
public function getProductPrintfiles($productId, $orientation = null)
4039
{
41-
$raw = $this->printfulClient->get('mockup-generator/printfiles/' . $productId);
40+
$query = [];
41+
42+
if ($orientation) {
43+
$query['orientation'] = $orientation;
44+
}
45+
46+
$raw = $this->printfulClient->get('mockup-generator/printfiles/' . $productId, $query);
4247

4348
$productPrintfiles = new ProductPrintfiles;
4449

@@ -185,7 +190,7 @@ private function parametersToArray(MockupGenerationParameters $parameters)
185190
* This includes background images and area positions.
186191
*
187192
* @param int $productId
188-
* @param string|null $orientation Used for wall art only {@see TemplateItem::ORIENTATION_HORIZONTAL} {@see TemplateItem::ORIENTATION_VERTICAL}
193+
* @param string|null $orientation Used for products with multiple orientations (e.g. wall art) {@see TemplateItem::ORIENTATION_HORIZONTAL} {@see TemplateItem::ORIENTATION_VERTICAL}
189194
* @return ProductTemplates
190195
* @throws Exceptions\PrintfulApiException
191196
* @throws Exceptions\PrintfulException

tests/MockupGenerator/PrintfilesTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ class PrintfilesTest extends TestCase
1414
/**
1515
* @dataProvider productProvider
1616
* @param $productId
17+
* @param string|null $orientation
1718
* @throws \Printful\Exceptions\PrintfulException
1819
*/
19-
public function testPrintfileRetrieval($productId)
20+
public function testPrintfileRetrieval($productId, $orientation = null)
2021
{
2122
$generator = new PrintfulMockupGenerator($this->api);
2223

23-
$productPrintfiles = $generator->getProductPrintfiles($productId);
24+
$productPrintfiles = $generator->getProductPrintfiles($productId, $orientation);
2425

2526
self::assertEquals($productId, $productPrintfiles->productId);
2627

@@ -49,10 +50,11 @@ public function testPrintfileRetrieval($productId)
4950
public function productProvider()
5051
{
5152
return [
52-
[1], // Poster
53+
[1],
54+
[1, 'vertical'], // Poster
55+
[1, 'horizontal'], // Poster
5356
[19], // 11oz mug
5457
[83], // Square Pillow Case w/ stuffing
55-
[230], // PL401 Sublimation T-Shirt
5658
];
5759
}
5860
}

0 commit comments

Comments
 (0)