Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Carts.php
Go to the documentation of this file.
1 <?php
7 
15 {
19  protected $_shareConfig;
20 
25 
29  protected $dataObjectHelper;
30 
38  public function __construct(
39  \Magento\Backend\Block\Template\Context $context,
40  \Magento\Customer\Model\Config\Share $shareConfig,
41  \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerDataFactory,
42  \Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
43  array $data = []
44  ) {
45  $this->_shareConfig = $shareConfig;
46  $this->customerDataFactory = $customerDataFactory;
47  $this->dataObjectHelper = $dataObjectHelper;
48  parent::__construct($context, $data);
49  }
50 
56  protected function _prepareLayout()
57  {
58  $sharedWebsiteIds = $this->_shareConfig->getSharedWebsiteIds($this->_getCustomer()->getWebsiteId());
59  $isShared = count($sharedWebsiteIds) > 1;
60  foreach ($sharedWebsiteIds as $websiteId) {
61  $blockName = 'customer_cart_' . $websiteId;
62  $block = $this->getLayout()->createBlock(
63  \Magento\Customer\Block\Adminhtml\Edit\Tab\Cart::class,
64  $blockName,
65  ['data' => ['website_id' => $websiteId]]
66  );
67  if ($isShared) {
68  $websiteName = $this->_storeManager->getWebsite($websiteId)->getName();
69  $block->setCartHeader(__('Shopping Cart from %1', $websiteName));
70  }
71  $this->setChild($blockName, $block);
72  }
73  return parent::_prepareLayout();
74  }
75 
81  protected function _toHtml()
82  {
83  $this->_eventManager->dispatch('adminhtml_block_html_before', ['block' => $this]);
84  return $this->getChildHtml();
85  }
86 
90  protected function _getCustomer()
91  {
92  $customerDataObject = $this->customerDataFactory->create();
93  $this->dataObjectHelper->populateWithArray(
94  $customerDataObject,
95  $this->_backendSession->getCustomerData()['account'],
96  \Magento\Customer\Api\Data\CustomerInterface::class
97  );
98  return $customerDataObject;
99  }
100 }
__()
Definition: __.php:13
$block
Definition: block.php:8
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Customer\Model\Config\Share $shareConfig, \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerDataFactory, \Magento\Framework\Api\DataObjectHelper $dataObjectHelper, array $data=[])
Definition: Carts.php:38