Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProductTemplateGeneratorFactory.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Bundle\Model\Product\Type as BundleType;
13 
18 {
22  private $objectManager;
23 
27  private $templateEntityMap = [
28  Type::TYPE_SIMPLE => SimpleProductTemplateGenerator::class,
29  BundleType::TYPE_CODE => BundleProductTemplateGenerator::class,
30  Configurable::TYPE_CODE => ConfigurableProductTemplateGenerator::class,
31  ];
32 
36  public function __construct(ObjectManagerInterface $objectManager)
37  {
38  $this->objectManager = $objectManager;
39  }
40 
46  public function create(array $fixture)
47  {
48  $type = isset($fixture['type_id']) ? $fixture['type_id'] : Type::TYPE_SIMPLE;
49  if (!isset($this->templateEntityMap[$type])) {
50  throw new \InvalidArgumentException(sprintf(
51  'Cannot instantiate product template generator. Wrong type_id "%s" passed',
52  $type
53  ));
54  }
55 
56  return $this->objectManager->create($this->templateEntityMap[$type], ['fixture' => $fixture]);
57  }
58 }
$objectManager
Definition: bootstrap.php:17
$type
Definition: item.phtml:13