/**
  * @param \Magento\Framework\App\Action\Action $subject
  * @param callable $proceed
  * @param \Magento\Framework\App\RequestInterface $request
  * @return mixed
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundDispatch(\Magento\Framework\App\Action\Action $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request)
 {
     $this->httpContext->setValue(Data::CONTEXT_CATALOG_SORT_DIRECTION, $this->toolbarModel->getDirection(), \Magento\Catalog\Helper\Product\ProductList::DEFAULT_SORT_DIRECTION);
     $this->httpContext->setValue(Data::CONTEXT_CATALOG_SORT_ORDER, $this->toolbarModel->getOrder(), $this->productListHelper->getDefaultSortField());
     $this->httpContext->setValue(Data::CONTEXT_CATALOG_DISPLAY_MODE, $this->toolbarModel->getMode(), $this->productListHelper->getDefaultViewMode());
     $this->httpContext->setValue(Data::CONTEXT_CATALOG_LIMIT, $this->toolbarModel->getLimit(), $this->productListHelper->getDefaultLimitPerPageValue($this->productListHelper->getDefaultViewMode()));
     return $proceed($request);
 }
Example #2
0
 public function testAroundDispatchHasSortDirection()
 {
     $this->toolbarModelMock->expects($this->exactly(1))->method('getDirection')->will($this->returnValue('asc'));
     $this->toolbarModelMock->expects($this->once())->method('getOrder')->will($this->returnValue('Name'));
     $this->toolbarModelMock->expects($this->once())->method('getMode')->will($this->returnValue('list'));
     $this->toolbarModelMock->expects($this->once())->method('getLimit')->will($this->returnValue(array(1 => 1, 2 => 2)));
     $this->productListHelperMock->expects($this->once())->method('getDefaultSortField')->will($this->returnValue('Field'));
     $this->productListHelperMock->expects($this->exactly(2))->method('getDefaultViewMode')->will($this->returnValue('grid'));
     $this->productListHelperMock->expects($this->once())->method('getDefaultLimitPerPageValue')->will($this->returnValue(array(10 => 10)));
     $this->httpContextMock->expects($this->exactly(4))->method('setValue')->will($this->returnValueMap(array(array(\Magento\Catalog\Helper\Data::CONTEXT_CATALOG_SORT_DIRECTION, 'asc', \Magento\Catalog\Helper\Product\ProductList::DEFAULT_SORT_DIRECTION, $this->httpContextMock), array(\Magento\Catalog\Helper\Data::CONTEXT_CATALOG_SORT_ORDER, 'Name', 'Field', $this->httpContextMock), array(\Magento\Catalog\Helper\Data::CONTEXT_CATALOG_DISPLAY_MODE, 'list', 'grid', $this->httpContextMock), array(\Magento\Catalog\Helper\Data::CONTEXT_CATALOG_LIMIT, array(1 => 1, 2 => 2), array(10 => 10)))));
     $this->assertEquals('ExpectedValue', $this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock));
 }
Example #3
0
 public function testGetLimit()
 {
     $this->assertNull($this->toolbar->getLimit());
     $_COOKIE[Toolbar::LIMIT_COOKIE_NAME] = 'limitCookie';
     $this->assertEquals('limitCookie', $this->toolbar->getLimit());
 }
Example #4
0
 /**
  * Get specified products limit display per page
  *
  * @return string
  */
 public function getLimit()
 {
     $limit = $this->_getData('_current_limit');
     if ($limit) {
         return $limit;
     }
     $limits = $this->getAvailableLimit();
     $defaultLimit = $this->getDefaultPerPageValue();
     if (!$defaultLimit || !isset($limits[$defaultLimit])) {
         $keys = array_keys($limits);
         $defaultLimit = $keys[0];
     }
     $limit = $this->_toolbarModel->getLimit();
     if (!$limit || !isset($limits[$limit])) {
         $limit = $defaultLimit;
     }
     if ($limit != $defaultLimit) {
         $this->_memorizeParam('limit_page', $limit);
     }
     $this->setData('_current_limit', $limit);
     return $limit;
 }
Example #5
0
 public function testGetCurrentPageNoParam()
 {
     $this->requestMock->expects($this->once())->method('getParam')->with(Toolbar::PAGE_PARM_NAME)->will($this->returnValue(false));
     $this->assertEquals(1, $this->toolbarModel->getCurrentPage());
 }