Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ItemPool.php
Go to the documentation of this file.
1 <?php
8 
12 
16 class ItemPool implements ItemPoolInterface
17 {
23  protected $objectManager;
24 
30  protected $defaultItemId;
31 
37  protected $itemMap;
38 
47  public function __construct(
50  array $itemMap = []
51  ) {
52  $this->objectManager = $objectManager;
53  $this->defaultItemId = $defaultItemId;
54  $this->itemMap = $itemMap;
55  }
56 
61  public function getItemData(Item $item)
62  {
63  return $this->get($item->getProductType())->getItemData($item);
64  }
65 
73  protected function get($type)
74  {
75  $itemId = isset($this->itemMap[$type]) ? $this->itemMap[$type] : $this->defaultItemId;
76  $item = $this->objectManager->get($itemId);
77 
78  if (!$item instanceof ItemInterface) {
79  throw new LocalizedException(
80  __('%1 doesn\'t extend \Magento\Checkout\CustomerData\ItemInterface', $type)
81  );
82  }
83  return $item;
84  }
85 }
__()
Definition: __.php:13
$type
Definition: item.phtml:13
__construct(ObjectManagerInterface $objectManager, $defaultItemId, array $itemMap=[])
Definition: ItemPool.php:47