![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/app/code/Soon/AjaxScroll/Block/ |
<?php /** * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @author Hervé Guétin <[email protected]> <@herveguetin> * @copyright Copyright (c) 2017 Agence Soon (http://www.agence-soon.fr) */ namespace Soon\AjaxScroll\Block; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Serialize\Serializer\Json as JsonSerializer; use Magento\Framework\View\Element\Template; use Magento\Framework\View\Element\Template\Context; use Magento\Store\Model\ScopeInterface; use Magento\Theme\Block\Html\Pager; class JsConfig extends Template { const IS_INFINITE_CONFIG_PATH = 'catalog/soon_ajaxscroll/is_infinite'; const REPEAT_CONTAINER_CONFIG_PATH = 'catalog/soon_ajaxscroll/repeat_container'; /** * @var Context */ private $context; /** * @var JsonSerializer */ private $jsonSerializer; /** * JsConfig constructor. * @param Context $context * @param JsonSerializer $jsonSerializer * @param array $data */ public function __construct( Context $context, JsonSerializer $jsonSerializer, array $data = [] ) { parent::__construct($context, $data); $this->context = $context; $this->jsonSerializer = $jsonSerializer; } /** * @return string * @throws LocalizedException */ public function jsConfig() { return $this->jsonSerializer->serialize( $this->jsonConfig() ); } /** * @return Pager * @throws LocalizedException */ private function pager() { /** @var Pager $pager */ $pager = $this->getLayout()->getBlock('product_list_toolbar_pager'); return $pager; } /** * @return array * @throws LocalizedException */ private function jsonConfig() { $jsonConfig = []; $pager = $this->pager(); if ($pager && $pager->getCollection()) { $jsonConfig = [ 'current_page' => $this->pager()->getCurrentPage(), 'last_page' => $this->pager()->getLastPageNum(), 'items_per_page' => $this->pager()->getLimit(), 'collection_count' => $this->pager()->getTotalNum(), 'is_infinite' => (bool)$this->context->getScopeConfig()->getValue(self::IS_INFINITE_CONFIG_PATH, ScopeInterface::SCOPE_STORE), 'repeat_container' => (bool)$this->context->getScopeConfig()->getValue(self::REPEAT_CONTAINER_CONFIG_PATH, ScopeInterface::SCOPE_STORE) ]; } return $jsonConfig; } }