Skip to content

Instantly share code, notes, and snippets.

@kandy

kandy/Test.php Secret

Created Oct 14, 2015
Embed
What would you like to do?
<?php
namespace Magento\Catalog\Block;
use Magento\Catalog\Helper\Product\ProductList;
use Magento\Catalog\Model\Product\ProductList\Toolbar as ToolbarModel;
use Magento\Framework\View\Element\Template;
use Magento\Framework\Registry;
class Test extends \Magento\Catalog\Block\Product\ProductList\Toolbar
{
/**
* @var \Magento\Framework\Registry
*/
private $_registry;
/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Catalog\Model\Session $catalogSession
* @param \Magento\Catalog\Model\Config $catalogConfig
* @param ToolbarModel $toolbarModel
* @param \Magento\Framework\Url\EncoderInterface $urlEncoder
* @param ProductList $productListHelper
* @param \Magento\Framework\Data\Helper\PostHelper $postDataHelper
* @param Registry $registry
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Catalog\Model\Session $catalogSession,
\Magento\Catalog\Model\Config $catalogConfig,
ToolbarModel $toolbarModel,
\Magento\Framework\Url\EncoderInterface $urlEncoder,
ProductList $productListHelper,
\Magento\Framework\Data\Helper\PostHelper $postDataHelper,
\Magento\Framework\Registry $registry,
array $data
) {
parent::__construct(
$context,
$catalogSession,
$catalogConfig,
$toolbarModel,
$urlEncoder,
$productListHelper,
$postDataHelper,
$data
);
$this->_registry = $registry;
}
public function getCurrentMode()
{
$category= $this->_registry->registry('current_category');
print_r($category->getId());
$mode = $this->_getData('_current_grid_mode');
if ($mode) {
return $mode;
}
$defaultMode = $this->_productListHelper->getDefaultViewMode($this->getModes());
$mode = $this->_toolbarModel->getMode();
if (!$mode || !isset($this->_availableMode[$mode])) {
$mode = $defaultMode;
}
$this->setData('_current_grid_mode', $mode);
return $mode;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment