Skip to content

Commit 1379269

Browse files
author
MBriedis
committed
Template retrieval now supports fetching specific orientation templates for wall art.
1 parent 5d905a9 commit 1379269

File tree

3 files changed

+64
-4
lines changed

3 files changed

+64
-4
lines changed

src/PrintfulMockupGenerator.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ public function groupPrintfiles(ProductPrintfiles $productPrintfiles)
9191
* Create an asynchronous generation task and return task that is in pending state
9292
* To retrieve the generation result use <b>PrintfulMockupGenerator::getGenerationTask</b> method.
9393
*
94-
* @see PrintfulMockupGenerator::getGenerationTask
9594
* @param MockupGenerationParameters $parameters
9695
* @return GenerationResultItem Pending task
9796
* @throws Exceptions\PrintfulException
97+
* @see PrintfulMockupGenerator::getGenerationTask
9898
*/
9999
public function createGenerationTask(MockupGenerationParameters $parameters)
100100
{
@@ -185,12 +185,20 @@ private function parametersToArray(MockupGenerationParameters $parameters)
185185
* This includes background images and area positions.
186186
*
187187
* @param int $productId
188+
* @param string|null $orientation Used for wall art only {@see TemplateItem::ORIENTATION_HORIZONTAL} {@see TemplateItem::ORIENTATION_VERTICAL}
188189
* @return ProductTemplates
190+
* @throws Exceptions\PrintfulApiException
189191
* @throws Exceptions\PrintfulException
190192
*/
191-
public function getProductTemplates($productId)
193+
public function getProductTemplates($productId, $orientation = null)
192194
{
193-
$response = $this->printfulClient->get('/mockup-generator/templates/' . $productId);
195+
$query = [];
196+
197+
if ($orientation) {
198+
$query['orientation'] = $orientation;
199+
}
200+
201+
$response = $this->printfulClient->get('/mockup-generator/templates/' . $productId, $query);
194202

195203
$templates = new ProductTemplates;
196204
$templates->version = (int)$response['version'];

src/Structures/Generator/Templates/TemplateItem.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@
88

99
class TemplateItem extends BaseItem
1010
{
11+
/**
12+
* Horizontal template orientation (used for wall art)
13+
*/
14+
const ORIENTATION_HORIZONTAL = 'horizontal';
15+
/**
16+
* Any template orientation (used for wall art, usually means that the template is a square)
17+
*/
18+
const ORIENTATION_ANY = 'any';
19+
/**
20+
* Vertical template orientation (used for wall art)
21+
*/
22+
const ORIENTATION_VERTICAL = 'vertical';
23+
1124
/**
1225
* Template's id
1326
* @var int
@@ -84,6 +97,11 @@ class TemplateItem extends BaseItem
8497
*/
8598
public $printAreaLeft;
8699

100+
/**
101+
* @var string
102+
*/
103+
public $orientation;
104+
87105
/**
88106
* @param array $raw
89107
* @return TemplateItem
@@ -104,6 +122,7 @@ public static function fromArray(array $raw)
104122
$item->printAreaHeight = (int)$raw['print_area_height'];
105123
$item->printAreaTop = (int)$raw['print_area_top'];
106124
$item->printAreaLeft = (int)$raw['print_area_left'];
125+
$item->orientation = (string)$raw['orientation'];
107126

108127
return $item;
109128
}

tests/MockupGenerator/TemplateTest.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Printful\PrintfulMockupGenerator;
88
use Printful\Structures\Generator\Templates\ProductTemplates;
9+
use Printful\Structures\Generator\Templates\TemplateItem;
910
use Printful\Tests\TestCase;
1011

1112
class TemplateTest extends TestCase
@@ -23,6 +24,38 @@ public function testTemplateRetrieval()
2324
self::assertNotEmpty($templates->variantMapping);
2425
self::assertGreaterThan(0, $templates->version);
2526
self::assertGreaterThan(0, $templates->minDpi);
26-
self::assertCount(2, $templates->placementConflicts, 'Two placement conflicts exist (outside label, back)');
27+
self::assertCount(3, $templates->placementConflicts, 'Two placement conflicts exist (outside label, inside label, back)');
28+
}
29+
30+
public function testVerticalTemplateRetrieval()
31+
{
32+
$generator = new PrintfulMockupGenerator($this->api);
33+
$productId = 1; // Poster
34+
35+
$templates = $generator->getProductTemplates($productId, TemplateItem::ORIENTATION_VERTICAL);
36+
37+
foreach($templates->templates as $template){
38+
self::assertContains(
39+
$template->orientation,
40+
[TemplateItem::ORIENTATION_VERTICAL, TemplateItem::ORIENTATION_ANY],
41+
'Vertical or any orientation'
42+
);
43+
}
44+
}
45+
46+
public function testHorizontalTemplateRetrieval()
47+
{
48+
$generator = new PrintfulMockupGenerator($this->api);
49+
$productId = 1; // Poster
50+
51+
$templates = $generator->getProductTemplates($productId, TemplateItem::ORIENTATION_HORIZONTAL);
52+
53+
foreach($templates->templates as $template){
54+
self::assertContains(
55+
$template->orientation,
56+
[TemplateItem::ORIENTATION_HORIZONTAL, TemplateItem::ORIENTATION_ANY],
57+
'Horizontal or any orientation'
58+
);
59+
}
2760
}
2861
}

0 commit comments

Comments
 (0)