Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractSidebar.php
Go to the documentation of this file.
1 <?php
7 
9 
17 class AbstractSidebar extends \Magento\Sales\Block\Adminhtml\Order\Create\AbstractCreate
18 {
24  protected $_sidebarStorageAction = 'add';
25 
31  protected $_salesConfig;
32 
41  public function __construct(
42  \Magento\Backend\Block\Template\Context $context,
43  \Magento\Backend\Model\Session\Quote $sessionQuote,
44  \Magento\Sales\Model\AdminOrder\Create $orderCreate,
46  \Magento\Sales\Model\Config $salesConfig,
47  array $data = []
48  ) {
49  parent::__construct($context, $sessionQuote, $orderCreate, $priceCurrency, $data);
50  $this->_salesConfig = $salesConfig;
51  }
52 
58  public function getSidebarStorageAction()
59  {
61  }
62 
68  public function canDisplay()
69  {
70  return $this->getCustomerId();
71  }
72 
78  public function canDisplayItemQty()
79  {
80  return false;
81  }
82 
88  public function canRemoveItems()
89  {
90  return true;
91  }
92 
99  public function getIdentifierId($item)
100  {
101  return $item->getProductId();
102  }
103 
110  public function getItemId($item)
111  {
112  return $item->getId();
113  }
114 
121  public function getProductId($item)
122  {
123  return $item->getId();
124  }
125 
131  public function getItemCount()
132  {
133  $count = $this->getData('item_count');
134  if ($count === null) {
135  $count = count($this->getItems());
136  $this->setData('item_count', $count);
137  }
138  return $count;
139  }
140 
147  public function getItems()
148  {
149  $items = [];
150  $collection = $this->getItemCollection();
151  if ($collection) {
152  $productTypes = $this->_salesConfig->getAvailableProductTypes();
153  if (is_array($collection)) {
155  } else {
156  $items = $collection->getItems();
157  }
158 
159  /*
160  * Filtering items by allowed product type
161  */
162  foreach ($items as $key => $item) {
163  if ($item instanceof \Magento\Catalog\Model\Product) {
164  $type = $item->getTypeId();
165  } elseif ($item instanceof \Magento\Sales\Model\Order\Item) {
166  $type = $item->getProductType();
167  } elseif ($item instanceof \Magento\Quote\Model\Quote\Item) {
168  $type = $item->getProductType();
169  } else {
170  $type = '';
171  // Maybe some item, that can give us product via getProduct()
172  if ($item instanceof \Magento\Framework\DataObject || method_exists($item, 'getProduct')) {
173  $product = $item->getProduct();
174  if ($product && $product instanceof \Magento\Catalog\Model\Product) {
175  $type = $product->getTypeId();
176  }
177  }
178  }
179  if (!in_array($type, $productTypes)) {
180  unset($items[$key]);
181  }
182  }
183  }
184 
185  return $items;
186  }
187 
193  public function getItemCollection()
194  {
195  return false;
196  }
197 
203  public function canDisplayPrice()
204  {
205  return true;
206  }
207 
214  public function getItemQty(\Magento\Framework\DataObject $item)
215  {
216  return $item->getQty() * 1 ? $item->getQty() * 1 : 1;
217  }
218 
226  public function isConfigurationRequired($productType)
227  {
228  return false;
229  }
230 }
getData($key='', $index=null)
Definition: DataObject.php:119
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$count
Definition: recent.phtml:13
$type
Definition: item.phtml:13
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Backend\Model\Session\Quote $sessionQuote, \Magento\Sales\Model\AdminOrder\Create $orderCreate, PriceCurrencyInterface $priceCurrency, \Magento\Sales\Model\Config $salesConfig, array $data=[])
setData($key, $value=null)
Definition: DataObject.php:72
$items