Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Pcompared.php
Go to the documentation of this file.
1 <?php
7 
9 
17 class Pcompared extends \Magento\Sales\Block\Adminhtml\Order\Create\Sidebar\AbstractSidebar
18 {
24  protected $_productFactory;
25 
31  protected $_event;
32 
43  public function __construct(
44  \Magento\Backend\Block\Template\Context $context,
45  \Magento\Backend\Model\Session\Quote $sessionQuote,
46  \Magento\Sales\Model\AdminOrder\Create $orderCreate,
48  \Magento\Sales\Model\Config $salesConfig,
49  \Magento\Reports\Model\ResourceModel\Event $event,
50  \Magento\Catalog\Model\ProductFactory $productFactory,
51  array $data = []
52  ) {
53  $this->_event = $event;
54  $this->_productFactory = $productFactory;
55  parent::__construct($context, $sessionQuote, $orderCreate, $priceCurrency, $salesConfig, $data);
56  }
57 
63  protected function _construct()
64  {
65  parent::_construct();
66  $this->setId('sales_order_create_sidebar_pcompared');
67  $this->setDataId('pcompared');
68  }
69 
75  public function getHeaderText()
76  {
77  return __('Recently Compared Products');
78  }
79 
85  public function getItemCollection()
86  {
87  $productCollection = $this->getData('item_collection');
88  if ($productCollection === null) {
89  // get products to skip
90  $skipProducts = [];
91  if ($collection = $this->getCreateOrderModel()->getCustomerCompareList()) {
92  $collection = $collection->getItemCollection()->useProductItem(
93  true
94  )->setStoreId(
95  $this->getStoreId()
96  )->setCustomerId(
97  $this->getCustomerId()
98  )->load();
99  foreach ($collection as $_item) {
100  $skipProducts[] = $_item->getProductId();
101  }
102  }
103 
104  // prepare products collection and apply visitors log to it
105  $productCollection = $this->_productFactory->create()->getCollection()->setStoreId(
106  $this->getQuote()->getStoreId()
107  )->addStoreFilter(
108  $this->getQuote()->getStoreId()
109  )->addAttributeToSelect(
110  'name'
111  )->addAttributeToSelect(
112  'price'
113  )->addAttributeToSelect(
114  'small_image'
115  );
116  $this->_event->applyLogToCollection(
118  \Magento\Reports\Model\Event::EVENT_PRODUCT_COMPARE,
119  $this->getCustomerId(),
120  0,
121  $skipProducts
122  );
123 
124  $productCollection->load();
125  $this->setData('item_collection', $productCollection);
126  }
127  return $productCollection;
128  }
129 
135  public function canRemoveItems()
136  {
137  return false;
138  }
139 
146  public function getIdentifierId($item)
147  {
148  return $item->getId();
149  }
150 
157  public function getProductId($item)
158  {
159  return $item->getId();
160  }
161 }
getData($key='', $index=null)
Definition: DataObject.php:119
__()
Definition: __.php:13
$_item
Definition: default.phtml:11
setData($key, $value=null)
Definition: DataObject.php:72
__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, \Magento\Reports\Model\ResourceModel\Event $event, \Magento\Catalog\Model\ProductFactory $productFactory, array $data=[])
Definition: Pcompared.php:43