Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Factory.php
Go to the documentation of this file.
1 <?php
11 
14 
21 class Factory
22 {
28  protected $types = [];
29 
35  protected $objectManager;
36 
43  public function __construct(
44  array $types,
46  ) {
47  $this->types = $types;
48  $this->objectManager = $objectManager;
49  }
50 
59  public function create(SaleableInterface $saleableItem, array $arguments = [])
60  {
61  $type = $saleableItem->getTypeId();
62 
63  if (isset($this->types[$type]['infoClass'])) {
64  $priceInfo = $this->types[$type]['infoClass'];
65  } else {
66  $priceInfo = $this->types['default']['infoClass'];
67  }
68 
69  if (isset($this->types[$type]['prices'])) {
70  $priceCollection = $this->types[$type]['prices'];
71  } else {
72  $priceCollection = $this->types['default']['prices'];
73  }
74 
75  $arguments['saleableItem'] = $saleableItem;
76  $quantity = $saleableItem->getQty();
77  if ($quantity) {
78  $arguments['quantity'] = $quantity;
79  }
80 
81  $arguments['prices'] = $this->objectManager->create(
82  $priceCollection,
83  [
84  'saleableItem' => $arguments['saleableItem'],
85  'quantity' => $quantity
86  ]
87  );
88 
89  return $this->objectManager->create($priceInfo, $arguments);
90  }
91 }
$type
Definition: item.phtml:13
$arguments
__construct(array $types, ObjectManagerInterface $objectManager)
Definition: Factory.php:43
create(SaleableInterface $saleableItem, array $arguments=[])
Definition: Factory.php:59