diff --git a/src/PrintfulMockupGenerator.php b/src/PrintfulMockupGenerator.php index 2d54c1a..c4d6c08 100644 --- a/src/PrintfulMockupGenerator.php +++ b/src/PrintfulMockupGenerator.php @@ -91,10 +91,10 @@ public function groupPrintfiles(ProductPrintfiles $productPrintfiles) * Create an asynchronous generation task and return task that is in pending state * To retrieve the generation result use PrintfulMockupGenerator::getGenerationTask method. * - * @see PrintfulMockupGenerator::getGenerationTask * @param MockupGenerationParameters $parameters * @return GenerationResultItem Pending task * @throws Exceptions\PrintfulException + * @see PrintfulMockupGenerator::getGenerationTask */ public function createGenerationTask(MockupGenerationParameters $parameters) { @@ -185,12 +185,20 @@ private function parametersToArray(MockupGenerationParameters $parameters) * This includes background images and area positions. * * @param int $productId + * @param string|null $orientation Used for wall art only {@see TemplateItem::ORIENTATION_HORIZONTAL} {@see TemplateItem::ORIENTATION_VERTICAL} * @return ProductTemplates + * @throws Exceptions\PrintfulApiException * @throws Exceptions\PrintfulException */ - public function getProductTemplates($productId) + public function getProductTemplates($productId, $orientation = null) { - $response = $this->printfulClient->get('/mockup-generator/templates/' . $productId); + $query = []; + + if ($orientation) { + $query['orientation'] = $orientation; + } + + $response = $this->printfulClient->get('/mockup-generator/templates/' . $productId, $query); $templates = new ProductTemplates; $templates->version = (int)$response['version']; diff --git a/src/Structures/Generator/Templates/TemplateItem.php b/src/Structures/Generator/Templates/TemplateItem.php index 3e17c8b..1fac051 100644 --- a/src/Structures/Generator/Templates/TemplateItem.php +++ b/src/Structures/Generator/Templates/TemplateItem.php @@ -8,6 +8,19 @@ class TemplateItem extends BaseItem { + /** + * Horizontal template orientation (used for wall art) + */ + const ORIENTATION_HORIZONTAL = 'horizontal'; + /** + * Any template orientation (used for wall art, usually means that the template is a square) + */ + const ORIENTATION_ANY = 'any'; + /** + * Vertical template orientation (used for wall art) + */ + const ORIENTATION_VERTICAL = 'vertical'; + /** * Template's id * @var int @@ -84,6 +97,11 @@ class TemplateItem extends BaseItem */ public $printAreaLeft; + /** + * @var string + */ + public $orientation; + /** * @param array $raw * @return TemplateItem @@ -104,6 +122,7 @@ public static function fromArray(array $raw) $item->printAreaHeight = (int)$raw['print_area_height']; $item->printAreaTop = (int)$raw['print_area_top']; $item->printAreaLeft = (int)$raw['print_area_left']; + $item->orientation = (string)$raw['orientation']; return $item; } diff --git a/tests/MockupGenerator/TemplateTest.php b/tests/MockupGenerator/TemplateTest.php index 4732de3..6403bbd 100644 --- a/tests/MockupGenerator/TemplateTest.php +++ b/tests/MockupGenerator/TemplateTest.php @@ -6,6 +6,7 @@ use Printful\PrintfulMockupGenerator; use Printful\Structures\Generator\Templates\ProductTemplates; +use Printful\Structures\Generator\Templates\TemplateItem; use Printful\Tests\TestCase; class TemplateTest extends TestCase @@ -23,6 +24,38 @@ public function testTemplateRetrieval() self::assertNotEmpty($templates->variantMapping); self::assertGreaterThan(0, $templates->version); self::assertGreaterThan(0, $templates->minDpi); - self::assertCount(2, $templates->placementConflicts, 'Two placement conflicts exist (outside label, back)'); + self::assertCount(3, $templates->placementConflicts, 'Two placement conflicts exist (outside label, inside label, back)'); + } + + public function testVerticalTemplateRetrieval() + { + $generator = new PrintfulMockupGenerator($this->api); + $productId = 1; // Poster + + $templates = $generator->getProductTemplates($productId, TemplateItem::ORIENTATION_VERTICAL); + + foreach($templates->templates as $template){ + self::assertContains( + $template->orientation, + [TemplateItem::ORIENTATION_VERTICAL, TemplateItem::ORIENTATION_ANY], + 'Vertical or any orientation' + ); + } + } + + public function testHorizontalTemplateRetrieval() + { + $generator = new PrintfulMockupGenerator($this->api); + $productId = 1; // Poster + + $templates = $generator->getProductTemplates($productId, TemplateItem::ORIENTATION_HORIZONTAL); + + foreach($templates->templates as $template){ + self::assertContains( + $template->orientation, + [TemplateItem::ORIENTATION_HORIZONTAL, TemplateItem::ORIENTATION_ANY], + 'Horizontal or any orientation' + ); + } } } \ No newline at end of file