Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Sidebar.php
Go to the documentation of this file.
1 <?php
7 
9 
16 class Sidebar extends AbstractCart
17 {
21  const XML_PATH_CHECKOUT_SIDEBAR_DISPLAY = 'checkout/sidebar/display';
22 
26  const XML_PATH_CHECKOUT_SIDEBAR_COUNT = 'checkout/sidebar/count';
27 
31  protected $imageHelper;
32 
36  private $serializer;
37 
48  public function __construct(
49  \Magento\Framework\View\Element\Template\Context $context,
50  \Magento\Customer\Model\Session $customerSession,
51  \Magento\Checkout\Model\Session $checkoutSession,
52  \Magento\Catalog\Helper\Image $imageHelper,
53  \Magento\Customer\CustomerData\JsLayoutDataProviderPoolInterface $jsLayoutDataProvider,
54  array $data = [],
55  \Magento\Framework\Serialize\Serializer\Json $serializer = null
56  ) {
57  if (isset($data['jsLayout'])) {
58  $this->jsLayout = array_merge_recursive($jsLayoutDataProvider->getData(), $data['jsLayout']);
59  unset($data['jsLayout']);
60  } else {
61  $this->jsLayout = $jsLayoutDataProvider->getData();
62  }
63  parent::__construct($context, $customerSession, $checkoutSession, $data);
64  $this->_isScopePrivate = false;
65  $this->imageHelper = $imageHelper;
66  $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
67  ->get(\Magento\Framework\Serialize\Serializer\Json::class);
68  }
69 
75  public function getConfig()
76  {
77  return [
78  'shoppingCartUrl' => $this->getShoppingCartUrl(),
79  'checkoutUrl' => $this->getCheckoutUrl(),
80  'updateItemQtyUrl' => $this->getUpdateItemQtyUrl(),
81  'removeItemUrl' => $this->getRemoveItemUrl(),
82  'imageTemplate' => $this->getImageHtmlTemplate(),
83  'baseUrl' => $this->getBaseUrl(),
84  'minicartMaxItemsVisible' => $this->getMiniCartMaxItemsCount(),
85  'websiteId' => $this->_storeManager->getStore()->getWebsiteId(),
86  'maxItemsToDisplay' => $this->getMaxItemsToDisplay()
87  ];
88  }
89 
94  public function getSerializedConfig()
95  {
96  return $this->serializer->serialize($this->getConfig());
97  }
98 
102  public function getImageHtmlTemplate()
103  {
104  return 'Magento_Catalog/product/image_with_borders';
105  }
106 
113  public function getCheckoutUrl()
114  {
115  return $this->getUrl('checkout');
116  }
117 
124  public function getShoppingCartUrl()
125  {
126  return $this->getUrl('checkout/cart');
127  }
128 
135  public function getUpdateItemQtyUrl()
136  {
137  return $this->getUrl('checkout/sidebar/updateItemQty', ['_secure' => $this->getRequest()->isSecure()]);
138  }
139 
146  public function getRemoveItemUrl()
147  {
148  return $this->getUrl('checkout/sidebar/removeItem', ['_secure' => $this->getRequest()->isSecure()]);
149  }
150 
158  public function getIsNeedToDisplaySideBar()
159  {
160  return (bool)$this->_scopeConfig->getValue(
161  self::XML_PATH_CHECKOUT_SIDEBAR_DISPLAY,
162  ScopeInterface::SCOPE_STORE
163  );
164  }
165 
171  public function getTotalsCache()
172  {
173  if (empty($this->_totals)) {
174  $quote = $this->getCustomQuote() ? $this->getCustomQuote() : $this->getQuote();
175  $this->_totals = $quote->getTotals();
176  }
177  return $this->_totals;
178  }
179 
186  public function getTotalsHtml()
187  {
188  return $this->getLayout()->getBlock('checkout.cart.minicart.totals')->toHtml();
189  }
190 
197  public function getBaseUrl()
198  {
199  return $this->_storeManager->getStore()->getBaseUrl();
200  }
201 
207  private function getMiniCartMaxItemsCount()
208  {
209  return (int)$this->_scopeConfig->getValue('checkout/sidebar/count', ScopeInterface::SCOPE_STORE);
210  }
211 
218  private function getMaxItemsToDisplay()
219  {
220  return (int)$this->_scopeConfig->getValue(
221  'checkout/sidebar/max_items_display_count',
222  ScopeInterface::SCOPE_STORE
223  );
224  }
225 }
$quote
__construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\Customer\Model\Session $customerSession, \Magento\Checkout\Model\Session $checkoutSession, \Magento\Catalog\Helper\Image $imageHelper, \Magento\Customer\CustomerData\JsLayoutDataProviderPoolInterface $jsLayoutDataProvider, array $data=[], \Magento\Framework\Serialize\Serializer\Json $serializer=null)
Definition: Sidebar.php:48