ltsecurityinc安防产品在线商城代码

This commit is contained in:
2026-09-14 17:47:10 +08:00
parent 57d8444c15
commit 6a3c9c5bd8
14539 changed files with 1775310 additions and 0 deletions
@@ -0,0 +1,14 @@
<?php
/**
* @author Olegnax
* @package Olegnax_InfiniteScroll
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
* See COPYING.txt for license details.
*/
namespace Olegnax\InfiniteScroll\Block\Adminhtml\System\Config\Form;
class Info extends \Olegnax\Core\Block\Adminhtml\System\Config\Form\Info
{
}
+99
View File
@@ -0,0 +1,99 @@
<?php
/**
* @author Olegnax
* @package Olegnax_InfiniteScroll
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
* See COPYING.txt for license details.
*/
namespace Olegnax\InfiniteScroll\Block;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Olegnax\InfiniteScroll\Helper\Helper;
class Scroll extends Template
{
/**
* @var Helper
*/
public $helper;
/**
* @var Json
*/
public $json;
/**
* Constructor
*
* InfiniteScroll constructor.
* @param Context $context
* @param Helper $helper
* @param array $data
* @param Json|null $json
*/
public function __construct(
Context $context,
Helper $helper,
array $data = [],
Json $json = null
) {
$this->helper = $helper;
$this->json = $json ?: ObjectManager::getInstance()->get(Json::class);
parent::__construct($context, $data);
}
/**
* @return bool
*/
public function isEnabled()
{
return $this->helper->isEnabled();
}
/**
* @return bool|false|string
*/
public function getConfig()
{
$config = [
'mode' => $this->getModuleConfig('type'),
'container' => trim($this->getSelectorProducts()),
'item' => trim($this->getSelectorProduct()),
'loader' => (bool)$this->getModuleConfig('loader_type'),
];
return $this->json->serialize($config);
}
/**
* @param string $path
* @param null $storeCode
* @return mixed
*/
public function getModuleConfig($path = '', $storeCode = null)
{
return $this->helper->getModuleConfig('general/' . $path, $storeCode);
}
/**
* @return string
*/
public function getSelectorProducts()
{
$products_container = $this->getModuleConfig('products_container') ?: '.column.main .products.products-grid, .column.main .products.products-list, .column.main .products-grid.grid';
return $products_container;
}
/**
* @return string
*/
public function getSelectorProduct()
{
$product_container = $this->getModuleConfig('product_container') ?: '.item.product.product-item';
return $product_container;
}
}
+9
View File
@@ -0,0 +1,9 @@
Copyright © 2019 Olegnax (http://olegnax.com/)
Each Olegnax Infinite Scroll extension source file included in this distribution is licensed under OSL 3.0 or the Olegnax Proprietary License.
http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
Please see LICENSE.txt for the full text of the OSL 3.0 license or contact maile@olegnax.com for a copy.
Subject to Licensee's payment of fees and compliance with the terms and conditions of the Olegnax Proprietary License, the Olegnax Proprietary License supersedes the OSL 3.0 license for each source file.
Please visit https://olegnax.com/license/ for the full text of the Olegnax Proprietary License.
+31
View File
@@ -0,0 +1,31 @@
<?php
/**
* @author Olegnax
* @package Olegnax_InfiniteScroll
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
* See COPYING.txt for license details.
*/
namespace Olegnax\InfiniteScroll\Helper;
use Olegnax\Core\Helper\Helper as CoreHelperHelper;
use Olegnax\InfiniteScroll\Model\Config\Source\Type;
class Helper extends CoreHelperHelper
{
const CONFIG_MODULE = 'olegnax_infinitescroll';
public function SelectRewardTemplate()
{
return $this->isEnabled() ? 'Olegnax_InfiniteScroll::rewards-highlight.phtml' : 'Amasty_Rewards::catalog/highlight-category.phtml';
}
/**
* @return bool
*/
public function isEnabled()
{
return Type::TYPE_DISABLED != $this->getModuleConfig('general/type');
}
}
+48
View File
@@ -0,0 +1,48 @@
Open Software License ("OSL") v. 3.0
This Open Software License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work:
Licensed under the Open Software License version 3.0
1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following:
1. to reproduce the Original Work in copies, either alone or as part of a collective work;
2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work;
3. to distribute or communicate copies of the Original Work and Derivative Works to the public, with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License;
4. to perform the Original Work publicly; and
5. to display the Original Work publicly.
2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works.
3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work.
4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license.
5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c).
6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work.
7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer.
8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation.
9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including 'fair use' or 'fair dealing'). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c).
10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware.
11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License.
12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License.
13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable.
14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You.
16. Modification of This License. This License is Copyright (C) 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under <insert your license name here>" or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process.
+48
View File
@@ -0,0 +1,48 @@
Academic Free License ("AFL") v. 3.0
This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work:
Licensed under the Academic Free License version 3.0
1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following:
1. to reproduce the Original Work in copies, either alone or as part of a collective work;
2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work;
3. to distribute or communicate copies of the Original Work and Derivative Works to the public, under any license of your choice that does not contradict the terms and conditions, including Licensor's reserved rights and remedies, in this Academic Free License;
4. to perform the Original Work publicly; and
5. to display the Original Work publicly.
2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works.
3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work.
4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license.
5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c).
6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work.
7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer.
8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation.
9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including "fair use" or "fair dealing"). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c).
10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware.
11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License.
12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License.
13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable.
14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You.
16. Modification of This License. This License is Copyright © 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Academic Free License" or "AFL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under <insert your license name here>" or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process.
@@ -0,0 +1,39 @@
<?php
/**
* @author Olegnax
* @package Olegnax_InfiniteScroll
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
* See COPYING.txt for license details.
*/
namespace Olegnax\InfiniteScroll\Model\Config\Source;
use Magento\Framework\Option\ArrayInterface;
class LoaderType implements ArrayInterface
{
const TYPE_THEME = 'theme';
const TYPE_MAGENTO = 'magento';
const TYPE_BLOCK = 'css';
const TYPE_IMAGE = 'image';
public function toOptionArray()
{
return [
['value' => '', 'label' => __('Disabled')],
['value' => static::TYPE_MAGENTO, 'label' => __('Magento Default')],
['value' => static::TYPE_BLOCK, 'label' => __('CSS Preloader')],
['value' => static::TYPE_THEME, 'label' => __('Theme Preloader')],
['value' => static::TYPE_IMAGE, 'label' => __('Custom Image')]
];
}
public function toArray()
{
$array = [];
foreach ($this->toOptionArray() as $item) {
$array[$item['value']] = $item['label'];
}
return $array;
}
}
@@ -0,0 +1,27 @@
<?php
/**
* @author Olegnax
* @package Olegnax_InfiniteScroll
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
* See COPYING.txt for license details.
*/
namespace Olegnax\InfiniteScroll\Model\Config\Source;
use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;
class Spacer extends Field {
public function __construct(
Context $context, array $data = []
) {
parent::__construct($context, $data);
}
protected function _decorateRowHtml( AbstractElement $element, $html)
{
return '<tr id="row_' . $element->getHtmlId() . '"><td></td><td colspan="2"><hr class="ox-settings-spacer"></td></tr>';
}
}
@@ -0,0 +1,36 @@
<?php
/**
* @author Olegnax
* @package Olegnax_InfiniteScroll
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
* See COPYING.txt for license details.
*/
namespace Olegnax\InfiniteScroll\Model\Config\Source;
use Magento\Framework\Option\ArrayInterface;
class Type implements ArrayInterface
{
const TYPE_DISABLED = '';
const TYPE_AUTO = 'auto';
const TYPE_BUTTON = 'button';
public function toOptionArray()
{
return [
['value' => static::TYPE_DISABLED, 'label' => __('Disable Module')],
['value' => static::TYPE_AUTO, 'label' => __('On Scroll - automatically on page scroll')],
['value' => static::TYPE_BUTTON, 'label' => __('Button - Manually on button click')]
];
}
public function toArray()
{
$array = [];
foreach ($this->toOptionArray() as $item) {
$array[$item['value']] = $item['label'];
}
return $array;
}
}
+270
View File
@@ -0,0 +1,270 @@
<?php
/**
* @author Olegnax
* @package Olegnax_InfiniteScroll
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
* See COPYING.txt for license details.
*/
namespace Olegnax\InfiniteScroll\Plugin;
use Amasty\Label\Plugin\Catalog\Product\ListProduct;
use Exception;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\Request\Http;
use Magento\Framework\Controller\Result\RawFactory;
use Magento\Framework\DataObject\IdentityInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Registry;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\Url\DecoderInterface;
use Magento\Framework\Url\Helper\Data as UrlHelper;
use Magento\Framework\View\LayoutInterface;
use Magento\PageCache\Model\Cache\Type;
use Olegnax\InfiniteScroll\Helper\Helper;
/**
* Description of Ajax
*
* @author Master
*/
class Ajax
{
const AJAX_ATTR = 'scrollAjax';
const BLOCK_PRODUCTS = 'category.products.list';
const BLOCK_PRODUCTS_SEARCH = 'search_result_list';
const REGEX_URLS = '@aHR0c(Dov|HM6)[A-Za-z0-9_-]+@u';
/**
* @var Helper
*/
protected $helper;
/**
* @var RawFactory
*/
protected $resultRaw;
/**
* @var Http
*/
protected $request;
/**
* @var Json
*/
protected $json;
/**
* @var DecoderInterface
*/
protected $urlDecoder;
/**
* @var UrlHelper
*/
protected $urlHelper;
/**
* @var LayoutInterface
*/
protected $layout;
/**
* @var Registry
*/
protected $registry;
/**
* Ajax constructor.
* @param Helper $helper
* @param RawFactory $resultRaw
* @param Http $request
* @param UrlHelper $urlHelper
* @param DecoderInterface $urlDecoder
* @param LayoutInterface $layout
* @param Registry $registry
* @param Json $json
*/
public function __construct(
Helper $helper,
RawFactory $resultRaw,
Http $request,
UrlHelper $urlHelper,
DecoderInterface $urlDecoder,
LayoutInterface $layout,
Registry $registry,
Json $json
) {
$this->helper = $helper;
$this->resultRaw = $resultRaw;
$this->request = $request;
$this->urlHelper = $urlHelper;
$this->urlDecoder = $urlDecoder;
$this->layout = $layout;
$this->registry = $registry;
$this->json = $json;
}
/**
* @param string $html
* @return string
*/
public function removeArgs($html)
{
$html = str_replace(['?' . static::AJAX_ATTR . '=1&amp;', '?' . static::AJAX_ATTR . '=1&'], '?', $html);
$html = str_replace([
'?' . static::AJAX_ATTR . '=1',
'&amp;' . static::AJAX_ATTR . '=1',
'&' . static::AJAX_ATTR . '=1',
], '', $html);
return $html;
}
public function removeEncodedArgsItem($match)
{
$code_string = $match[0];
$url = $this->urlDecoder->decode($code_string);
if (false !== $url) {
$newUrl = $this->urlHelper->removeRequestParam($url, static::AJAX_ATTR);
$newUrl = $this->removeEncodedArgs($newUrl);
if ($url != $newUrl) {
$code_string = $this->urlHelper->getEncodedUrl($newUrl);
}
}
return $code_string;
}
/**
* @param string $html
* @return string
*/
public function removeEncodedArgs($html)
{
$_html = preg_replace_callback(static::REGEX_URLS, [$this, 'removeEncodedArgsItem'], $html);
if ($_html) {
$html = $_html;
}
return $html;
}
/**
* @return bool
*/
protected function isAjax()
{
return $this->helper->isEnabled() &&
$this->request->isXmlHttpRequest() &&
$this->request->isAjax() &&
$this->request->getParam(static::AJAX_ATTR, '');
}
protected function getAjaxContent()
{
/** @var LayoutInterface $layout */
$layout = $this->layout;
$layout->getOutput(); // @todo temporary fix: magenta ignoring the product limit parameter per page, per page with ajax request
$blocks = $this->getLayoutBlock($layout);
$page = (int)$this->request->getParam('p', 1);
$firstNum = 0;
$lastNum = 0;
$productsCount = 0;
$isFirst = false;
$isLast = false;
if ($blocks['products']) {
$collection = $blocks['products']->getLoadedProductCollection();
$pageSize = $collection->getPageSize() * 1;
$firstNum = $pageSize * ($page - 1) + 1;
$lastNum = $pageSize * ($page - 1) + $collection->count();
$productsCount = $collection->getSize();
$isFirst = $firstNum <= 1;
$isLast = $lastNum >= $productsCount;
}
$html = [];
$cache_tags = [];
foreach ($blocks as $key => $block) {
$cache_tags = $this->addIdentities($block, $cache_tags);
$html[$key] = $block ? $block->toHtml() : '';
}
$response = compact('productsCount', 'page', 'pageSize', 'firstNum', 'lastNum', 'isFirst', 'isLast', 'html');
$response['html']['_before'] = '';
$response['html']['_after'] = '';
try {
$response = $this->prepareForPlugins($response, $blocks);
} catch ( Exception $exception){
// @todo do nothing or log
}
$response = $this->changeResponse($response, $cache_tags, $page);
return $response;
}
/**
* @param LayoutInterface $layout
* @return array
*/
protected function getLayoutBlock($layout)
{
return [
'products' => $layout->getBlock(self::BLOCK_PRODUCTS) ?: $layout->getBlock(self::BLOCK_PRODUCTS_SEARCH),
];
}
protected function addIdentities($block, array $data = [])
{
if ($block instanceof IdentityInterface) {
$data = array_merge($data, $block->getIdentities());
}
return $data;
}
/**
* @param array $response
* @param array $blocks
* @return array
* @throws LocalizedException
*/
protected function prepareForPlugins(array $response, array $blocks)
{
if (array_key_exists('products', $blocks) && class_exists('\Amasty\Label\Plugin\Catalog\Product\ListProduct')) {
/** @var ListProduct $amastyLabelListProduct */
$amastyLabelListProduct = ObjectManager::getInstance()->get('\Amasty\Label\Plugin\Catalog\Product\ListProduct');
$this->registry->register('amlabel_category_observer', false);
$blocks['products']->setIsAmLabelObserved(false);
$response['html']['_after'] .= $amastyLabelListProduct->afterToHtml($blocks['products'], '');
}
return $response;
}
protected function changeResponse($response, $cache_tags)
{
$cache_tags[] = Type::CACHE_TAG;
$cache_tags = array_unique($cache_tags);
$cache_tags = implode(',', $cache_tags);
$response['cache_tags'] = $cache_tags;
$response['html'] = array_map([$this, 'removeArgs'], $response['html']);
$response['html'] = array_map([$this, 'removeEncodedArgs'], $response['html']);
return $response;
}
protected function json(array $data)
{
$response = $this->resultRaw->create();
$response->setHeader('Content-type', 'application/json');
if (array_key_exists('cache_tags', $data)) {
if (!empty($data['cache_tags'])) {
$response->setHeader('X-Magento-Tags', $data['cache_tags']);
}
unset($data['cache_tags']);
}
$data = $this->json->serialize($data);
$response->setContents($data);
return $response;
}
}
@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
namespace Olegnax\InfiniteScroll\Plugin\Frontend\Bss\AddMultipleProducts\Helper;
use Magento\Framework\App\Request\Http;
use Olegnax\InfiniteScroll\Helper\Helper;
use Olegnax\InfiniteScroll\Plugin\Ajax;
class Data
{
/**
* @var Http
*/
protected $request;
/**
* @var Helper
*/
protected $helper;
/**
* Data constructor.
* @param Helper $helper
* @param Http $request
*/
public function __construct(
Helper $helper,
Http $request
) {
$this->helper = $helper;
$this->request = $request;
}
/**
* @param \Bss\AddMultipleProducts\Helper\Data $subject
* @param bool $result
* @return bool
*/
public function afterIsModuleOutputEnabled(
\Bss\AddMultipleProducts\Helper\Data $subject,
$result
) {
return $result && !$this->isAjax();
}
/**
* @return bool
*/
protected function isAjax()
{
return $this->helper->isEnabled() &&
$this->request->isXmlHttpRequest() &&
$this->request->isAjax() &&
$this->request->getParam(Ajax::AJAX_ATTR, '');
}
}
@@ -0,0 +1,68 @@
<?php
namespace Olegnax\InfiniteScroll\Plugin\Frontend\Magento\Framework\App;
use Closure;
use Magento\Framework\App\Request\Http;
use Magento\Framework\App\Response\Http as ResponseHttp;
use Magento\Framework\Controller\Result\RawFactory;
use Magento\Framework\Registry;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\Url\DecoderInterface;
use Magento\Framework\Url\Helper\Data as UrlHelper;
use Magento\Framework\View\LayoutInterface;
use Olegnax\InfiniteScroll\Helper\Helper;
use Olegnax\InfiniteScroll\Plugin\Ajax;
class View extends Ajax
{
/**
* @var ResponseHttp
*/
private $response;
/**
* View constructor.
* @param Helper $helper
* @param RawFactory $resultRaw
* @param Http $request
* @param UrlHelper $urlHelper
* @param DecoderInterface $urlDecoder
* @param LayoutInterface $layout
* @param ResponseHttp $response
* @param Registry $registry
* @param Json $json
*/
public function __construct(
Helper $helper,
RawFactory $resultRaw,
Http $request,
UrlHelper $urlHelper,
DecoderInterface $urlDecoder,
LayoutInterface $layout,
ResponseHttp $response,
Registry $registry,
Json $json
) {
$this->response = $response;
parent::__construct($helper, $resultRaw, $request, $urlHelper, $urlDecoder, $layout, $registry, $json);
}
public function aroundRenderLayout(
\Magento\Framework\App\View $subject,
Closure $proceed,
$output = ''
) {
if ($this->isAjax() && $this->request->getRouteName() === 'catalogsearch') {
$content = $this->getAjaxContent();
$content = $this->json->serialize($content);
$this->response->setBody($content);
} else {
return $proceed($output);
}
return false;
}
}
@@ -0,0 +1,45 @@
<?php
/**
* @author Olegnax
* @package Olegnax_InfiniteScroll
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
* See COPYING.txt for license details.
*/
namespace Olegnax\InfiniteScroll\Plugin\Frontend\Magento\Theme\Block\Html;
use Olegnax\InfiniteScroll\Helper\Helper;
class Pager
{
/**
* @var Helper
*/
public $helper;
/**
* Pager constructor.
* @param Helper $helper
*/
public function __construct(Helper $helper)
{
$this->helper = $helper;
}
/**
* @param \Magento\Theme\Block\Html\Pager $subject
* @param string $result
* @return string
*/
public function afterToHtml(
\Magento\Theme\Block\Html\Pager $subject,
$result
) {
if ($this->helper->isEnabled()) {
$last = (int)$subject->getLastPageNum();
$result .= '<div id="ox-page-count" style="display: none">' . $last . '</div>';
}
return $result;
}
}
@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
namespace Olegnax\InfiniteScroll\Plugin\Frontend\Mageplaza\AjaxLayer\Helper;
use Magento\Framework\App\Request\Http;
use Olegnax\InfiniteScroll\Helper\Helper;
use Olegnax\InfiniteScroll\Plugin\Ajax;
class Data
{
/**
* @var Http
*/
protected $request;
/**
* @var Helper
*/
protected $helper;
/**
* Data constructor.
* @param Helper $helper
* @param Http $request
*/
public function __construct(
Helper $helper,
Http $request
) {
$this->helper = $helper;
$this->request = $request;
}
/**
* @param \Mageplaza\AjaxLayer\Helper\Data $subject
* @param bool $result
* @return bool
*/
public function afterAjaxEnabled(
\Mageplaza\AjaxLayer\Helper\Data $subject,
$result
) {
return $result && !$this->isAjax();
}
/**
* @return bool
*/
protected function isAjax()
{
return $this->helper->isEnabled() &&
$this->request->isXmlHttpRequest() &&
$this->request->isAjax() &&
$this->request->getParam(Ajax::AJAX_ATTR, '');
}
}
+30
View File
@@ -0,0 +1,30 @@
<?php
/**
* @author Olegnax
* @package Olegnax_InfiniteScroll
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
* See COPYING.txt for license details.
*/
namespace Olegnax\InfiniteScroll\Plugin;
use Magento\Framework\App\Action\Action;
use Magento\Framework\Controller\Result\Raw;
use Magento\Framework\View\Result\Page;
class ListAjax extends Ajax
{
/**
* @param Action $controller
* @param Page $page
* @return Raw
*/
public function afterExecute(Action $controller, $page)
{
if ($this->isAjax() && $page instanceof Page) {
$page = $this->json($this->getAjaxContent($page));
}
return $page;
}
}
@@ -0,0 +1,34 @@
<?php
/**
* Copyright © All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Olegnax\InfiniteScroll\Rewrite\Amasty\Shopby\Plugin\Ajax;
use Magento\Framework\App\RequestInterface;
if (class_exists('\Amasty\Shopby\Plugin\Ajax\Ajax')) {
class Ajax extends \Amasty\Shopby\Plugin\Ajax\Ajax
{
/**
* @param RequestInterface $request
* @return bool
*/
protected function isAjax(RequestInterface $request)
{
$result = parent::isAjax($request);
if ($result) {
$result = $result && !$request->getParam(\Olegnax\InfiniteScroll\Plugin\Ajax::AJAX_ATTR);
}
return $result;
}
}
} else {
class Ajax
{
}
}
@@ -0,0 +1,34 @@
<?php
/**
* Copyright © All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Olegnax\InfiniteScroll\Rewrite\Amasty\Shopby\Plugin\Ajax;
use Magento\Framework\App\RequestInterface;
if (class_exists('\Amasty\Shopby\Plugin\Ajax\CategoryViewAjax')) {
class CategoryViewAjax extends \Amasty\Shopby\Plugin\Ajax\CategoryViewAjax
{
/**
* @param RequestInterface $request
* @return bool
*/
protected function isAjax(RequestInterface $request)
{
$result = parent::isAjax($request);
if ($result) {
$result = $result && !$request->getParam(\Olegnax\InfiniteScroll\Plugin\Ajax::AJAX_ATTR);
}
return $result;
}
}
} else {
class CategoryViewAjax
{
}
}
@@ -0,0 +1,35 @@
<?php
/**
* Copyright © All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Olegnax\InfiniteScroll\Rewrite\Amasty\Shopby\Plugin\Ajax;
use Magento\Framework\App\RequestInterface;
if (class_exists('\Amasty\Shopby\Plugin\Ajax\CmsControllerIndexIndexAjax')) {
class CmsControllerIndexIndexAjax extends \Amasty\Shopby\Plugin\Ajax\CmsControllerIndexIndexAjax
{
/**
* @param RequestInterface $request
* @return bool
*/
protected function isAjax(RequestInterface $request)
{
$result = parent::isAjax($request);
if ($result) {
$result = $result && !$request->getParam(\Olegnax\InfiniteScroll\Plugin\Ajax::AJAX_ATTR);
}
return $result;
}
}
} else {
class CmsControllerIndexIndexAjax
{
}
}
+30
View File
@@ -0,0 +1,30 @@
{
"name": "olegnax/module-scroll",
"description": "Load products without reloading the page automatically on scroll or manually on button click",
"version": "1.2.0.5",
"type": "magento2-module",
"license": [
"OSL-3.0",
"AFL-3.0"
],
"authors": [
{
"name": "Olegnax",
"email": "mail@olegnax.com",
"homepage": "https://olegnax.com",
"role": "Technical Support"
}
],
"minimum-stability": "dev",
"require": {
"olegnax/module-core": ">=1.3.1"
},
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Olegnax\\InfiniteScroll\\": ""
}
}
}
+13
View File
@@ -0,0 +1,13 @@
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
<acl>
<resources>
<resource id="Magento_Backend::admin">
<resource id="Olegnax_Core::Olegnax_Core">
<resource id="Olegnax_InfiniteScroll::scroll" sortOrder="10" title="Infinite Scroll"/>
</resource>
</resource>
</resources>
</acl>
</config>
+13
View File
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
<menu>
<add id="Olegnax_InfiniteScroll::scroll" title="InfiniteScroll" translate="title"
module="Olegnax_InfiniteScroll" sortOrder="999" parent="Olegnax_Core::Olegnax_Core"
resource="Olegnax_InfiniteScroll::scroll"/>
<add id="Olegnax_InfiniteScroll::config" title="Configuration" translate="title"
module="Olegnax_InfiniteScroll" sortOrder="10"
action="adminhtml/system_config/edit/section/olegnax_infinitescroll"
parent="Olegnax_InfiniteScroll::scroll" resource="Olegnax_InfiniteScroll::scroll"/>
</menu>
</config>
+110
View File
@@ -0,0 +1,110 @@
<?xml version="1.0" ?>
<!--
/**
* @author Olegnax
* @package Olegnax_InfiniteScroll
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<tab id="olegnax" sortOrder="999" translate="label">
<label>Olegnax</label>
</tab>
<section id="olegnax_infinitescroll" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10"
translate="label">
<label>InfiniteScroll</label>
<tab>olegnax</tab>
<resource>Olegnax_InfiniteScroll::scroll</resource>
<group id="info" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="0" translate="label">
<frontend_model>Olegnax\InfiniteScroll\Block\Adminhtml\System\Config\Form\Info</frontend_model>
</group>
<group id="general" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label">
<label>General</label>
<field id="type" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label comment"
type="select">
<label>Load Action</label>
<comment>Choose the way products are loaded. Automatically on scroll or Manually on button click.
</comment>
<source_model>Olegnax\InfiniteScroll\Model\Config\Source\Type</source_model>
</field>
<field id="button_label" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="12"
translate="label" type="text">
<label>Load more Button text</label>
<depends>
<field id="type">button</field>
</depends>
</field>
<field id="spacer_1" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<frontend_model>Olegnax\InfiniteScroll\Model\Config\Source\Spacer</frontend_model>
</field>
<field id="loader_type" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="22"
translate="label"
type="select">
<label>AJAX Progress Loader</label>
<source_model>Olegnax\InfiniteScroll\Model\Config\Source\LoaderType</source_model>
</field>
<field id="loader" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="24" translate="label comment"
type="text">
<label>AJAX Progress Loader Image</label>
<comment>Set url to preloader image. E.g.: "images/preloader.svg" will link to images folder in your
current theme. E.g.: app\design\frontend\Olegnax\athlete2\web\images.
</comment>
<depends>
<field id="loader_type">image</field>
</depends>
</field>
<field id="spacer_2" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<frontend_model>Olegnax\InfiniteScroll\Model\Config\Source\Spacer</frontend_model>
</field>
<field id="progress_counter" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="31" translate="label comment"
type="select">
<label>Show Products Amount Info</label>
<comment>Show loaded/total progress info (above load more button)with progress line </comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="progress_label1" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="32"
translate="label comment" type="text">
<label>Text before numbers</label>
<comment>Default: "You've viewed ". Don't forget the spaces.</comment>
<depends>
<field id="progress_counter">1</field>
</depends>
</field>
<field id="progress_label2" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="33"
translate="label comment" type="text">
<label>Text between numbers</label>
<comment>Default:" of "</comment>
<depends>
<field id="progress_counter">1</field>
</depends>
</field>
<field id="progress_label3" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="34"
translate="label comment" type="text">
<label>Text after bumbers</label>
<comment>Default: " products"</comment>
<depends>
<field id="progress_counter">1</field>
</depends>
</field>
<field id="spacer_3" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
<frontend_model>Olegnax\InfiniteScroll\Model\Config\Source\Spacer</frontend_model>
</field>
<field id="products_container" showInDefault="1" showInStore="1" showInWebsite="1"
sortOrder="42" translate="label comment" type="text">
<label>Custom DOM Selectors for Products Container</label>
<comment>Default selectors: ".column.main .products.products-grid, .column.main
.products.products-list, .column.main .products-grid.grid"
</comment>
</field>
<field id="product_container" showInDefault="1" showInStore="1" showInWebsite="1"
sortOrder="44" translate="label comment" type="text">
<label>Custom DOM Selectors for Product Item</label>
<comment>Default selector: ".item.product.product-item"</comment>
</field>
</group>
</section>
</system>
</config>
+20
View File
@@ -0,0 +1,20 @@
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<olegnax_infinitescroll>
<general>
<type>button</type>
<button_label>Load more</button_label>
<loader_type>theme</loader_type>
<loader></loader>
<progress_counter>1</progress_counter>
<progress_label1>You've viewed </progress_label1>
<progress_label2> of </progress_label2>
<progress_label3> products</progress_label3>
<products_container></products_container>
<product_container></product_container>
</general>
</olegnax_infinitescroll>
</default>
</config>
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Amasty\Shopby\Plugin\Ajax\Ajax" type="Olegnax\InfiniteScroll\Rewrite\Amasty\Shopby\Plugin\Ajax\Ajax"/>
<preference for="Amasty\Shopby\Plugin\Ajax\CategoryViewAjax" type="Olegnax\InfiniteScroll\Rewrite\Amasty\Shopby\Plugin\Ajax\CategoryViewAjax"/>
<preference for="Amasty\Shopby\Plugin\Ajax\CmsControllerIndexIndexAjax" type="Olegnax\InfiniteScroll\Rewrite\Amasty\Shopby\Plugin\Ajax\CmsControllerIndexIndexAjax"/>
</config>
+64
View File
@@ -0,0 +1,64 @@
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Theme\Block\Html\Pager">
<plugin name="Olegnax_InfiniteScroll_Plugin_Frontend_Magento_Theme_Block_Html_Pager"
sortOrder="0"
type="Olegnax\InfiniteScroll\Plugin\Frontend\Magento\Theme\Block\Html\Pager"/>
</type>
<type name="Magento\Framework\App\View">
<plugin name="Olegnax_InfiniteScroll_Plugin_Frontend_Magento_Framework_App_View"
sortOrder="0"
type="Olegnax\InfiniteScroll\Plugin\Frontend\Magento\Framework\App\View"/>
</type>
<type name="Amasty\Finder\Controller\Index\Index">
<plugin name="Olegnax_InfiniteScroll_Plugin_Frontend_Amasty_Finder_Controller_Index_Index"
sortOrder="0"
type="Olegnax\InfiniteScroll\Plugin\ListAjax"/>
</type>
<type name="Amasty\ShopbyBrand\Controller\Index\Index">
<plugin name="Olegnax_InfiniteScroll_Plugin_Frontend_Amasty_ShopbyBrand_Controller_Index_Index"
sortOrder="0"
type="Olegnax\InfiniteScroll\Plugin\ListAjax"/>
</type>
<type name="Amasty\Shopby\Controller\Index\Index">
<plugin name="Olegnax_InfiniteScroll_Plugin_Frontend_Amasty_Shopby_Controller_Index_Index"
sortOrder="0"
type="Olegnax\InfiniteScroll\Plugin\ListAjax"/>
</type>
<type name="Amasty\Shopby\Controller\Search\Result\Index">
<plugin name="Olegnax_InfiniteScroll_Plugin_Frontend_Amasty_Shopby_Controller_Search_Result_Index"
sortOrder="0"
type="Olegnax\InfiniteScroll\Plugin\ListAjax"/>
</type>
<type name="Amasty\Xlanding\Controller\Page\View">
<plugin name="Olegnax_InfiniteScroll_Plugin_Frontend_Amasty_Xlanding_Controller_Page_View"
sortOrder="0"
type="Olegnax\InfiniteScroll\Plugin\ListAjax"/>
</type>
<type name="Magento\CatalogSearch\Controller\Result\Index">
<plugin name="Olegnax_InfiniteScroll_Plugin_Frontend_Magento_CatalogSearch_Controller_Result_Index"
sortOrder="0"
type="Olegnax\InfiniteScroll\Plugin\ListAjax"/>
</type>
<type name="Magento\Catalog\Controller\Category\View">
<plugin name="Olegnax_InfiniteScroll_Plugin_Frontend_Magento_Catalog_Controller_Category_View"
sortOrder="0"
type="Olegnax\InfiniteScroll\Plugin\ListAjax"/>
</type>
<type name="Smartwave\Porto\Controller\CatalogSearch\Result">
<plugin name="Olegnax_InfiniteScroll_Plugin_Frontend_Smartwave_Porto_Controller_CatalogSearch_Result"
sortOrder="0"
type="Olegnax\InfiniteScroll\Plugin\ListAjax"/>
</type>
<type name="Bss\AddMultipleProducts\Helper\Data">
<plugin name="Olegnax_InfiniteScroll_Plugin_Frontend_Bss_AddMultipleProducts_Helper_Data"
sortOrder="10"
type="Olegnax\InfiniteScroll\Plugin\Frontend\Bss\AddMultipleProducts\Helper\Data"/>
</type>
<type name="Mageplaza\AjaxLayer\Helper\Data">
<plugin name="Olegnax_InfiniteScroll_Plugin_Frontend_Mageplaza_AjaxLayer_Helper_Data"
sortOrder="10"
type="Olegnax\InfiniteScroll\Plugin\Frontend\Mageplaza\AjaxLayer\Helper\Data"/>
</type>
</config>
+11
View File
@@ -0,0 +1,11 @@
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Olegnax_InfiniteScroll" setup_version="1.2.0.5">
<sequence>
<module name="Magento_Theme"/>
<module name="Magento_Framework"/>
<module name="Magento_Catalog"/>
</sequence>
</module>
</config>
+9
View File
@@ -0,0 +1,9 @@
<?php
use Magento\Framework\Component\ComponentRegistrar;
ComponentRegistrar::register(
ComponentRegistrar::MODULE,
'Olegnax_InfiniteScroll',
__DIR__
);
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="scroll_handle"/>
</page>
@@ -0,0 +1,5 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="scroll_handle"/>
</page>
@@ -0,0 +1,4 @@
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="scroll_handle"/>
</page>
@@ -0,0 +1,17 @@
<?xml version="1.0" ?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="amasty.rewards.highlight.category">
<action method="setTemplate">
<argument name="template" xsi:type="helper" helper="Olegnax\InfiniteScroll\Helper\Helper::SelectRewardTemplate"/>
</action>
</referenceBlock>
<referenceContainer name="before.body.end">
<block class="Magento\Framework\View\Element\Template" name="ox_infinitescroll_loader"
template="Olegnax_InfiniteScroll::loader.phtml"/>
<block class="Olegnax\InfiniteScroll\Block\Scroll" name="ox_infinitescroll"
template="Olegnax_InfiniteScroll::scroll.phtml"/>
</referenceContainer>
</body>
</page>
@@ -0,0 +1,15 @@
var config = {
map: {
'*': {
'oxFormValues': 'Olegnax_InfiniteScroll/js/form-values',
'OxInfiniteScroll': 'Olegnax_InfiniteScroll/js/scroll',
}
},
config: {
mixins: {
'Magento_Swatches/js/swatch-renderer': {
'Olegnax_InfiniteScroll/js/swatch-renderer': true
}
}
}
};
@@ -0,0 +1,42 @@
<?php
/**
* @author Olegnax
* @package Olegnax_InfiniteScroll
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
* See COPYING.txt for license details.
*/
use Olegnax\InfiniteScroll\Helper\Helper;
use Olegnax\InfiniteScroll\Model\Config\Source\LoaderType;
use Olegnax\InfiniteScroll\Model\Config\Source\Type;
/** @var Helper $_helper */
$config = $this->helper(Helper::class)->getModuleConfig('general');
if (('' !== $config['loader_type'] && Type::TYPE_DISABLED !== $config['type']) || Type::TYPE_BUTTON == $config['type']): ?>
<script data-role="ox-infinity-scroll" type="text/x-magento-template">
<div class="ox-product-scroll ox-product-scroll__loader--<?= $config['loader_type']; ?> ox-product-scroll__type--<?= $config['type']; ?>">
<?php if ($config['progress_counter']): ?>
<div class="ox-product-scroll__amount">
<div class="amount-wrap">
<?= $config['progress_label1']; ?> <span class="toolbar-number-first"></span> - <span class="toolbar-number-last"></span> <?= $config['progress_label2']; ?> <span class="toolbar-number-total"></span> <?= $config['progress_label3']; ?>
</div>
<div class="amount-count-line"><span style="width: 0%;"></span></div>
</div>
<?php endif; ?>
<?php if ('' !== $config['loader_type'] && Type::TYPE_DISABLED !== $config['type']): ?>
<div class="ox-product-scroll__loader">
<?php if (LoaderType::TYPE_IMAGE == $config['loader_type']): ?>
<img src="<?= $this->getViewFileUrl($config['loader']) ?>"
class="ox-product-scroll__loader-image"/>
<?php endif; ?>
</div>
<?php endif; ?>
<div class="button ox-product-scroll__button">
<span class="label"><?= $config['button_label']; ?></span>
</div>
</div>
</script>
<?php endif; ?>
@@ -0,0 +1,24 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2020 Amasty (https://www.amasty.com)
* @package Amasty_Rewards
*/
use Amasty\Rewards\Block\Frontend\Catalog\HighlightCategory;
?>
<?php /** @var HighlightCategory $block */ ?>
<div data-bind="scope: 'amasty-rewards-highlight-catalog-<?= (int)$block->getProductId();?>'">
<div class="amasty-rewards-loader" data-bind="visible: loader()" style="display: none;">
<img src="<?= $block->escapeUrl($block->getViewFileUrl('Amasty_Rewards::images/ajax-loader.gif')); ?>" />
</div>
<!-- ko template: getTemplate() --><!-- /ko -->
<script type="text/x-magento-init">
{
"*": {
"Olegnax_InfiniteScroll/js/rewards-highlight": <?= /** @no-escape */ $block->getJsLayout();?>
}
}
</script>
</div>
@@ -0,0 +1,24 @@
<?php
/**
* @author Olegnax
* @package Olegnax_InfiniteScroll
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
* See COPYING.txt for license details.
*/
/** var \Olegnax\LayeredNavigation\Block\Scroll $block */
if ($block->isEnabled()) : ?>
<script>
require([
'jquery',
'OxInfiniteScroll'
], function ($) {
var $body = $('body');
if ($body.data('OxInfiniteScroll')) {
$body.OxInfiniteScroll('init');
} else {
$body.OxInfiniteScroll(<?= $block->getConfig();?>);
}
});
</script>
<?php endif; ?>
@@ -0,0 +1,125 @@
// /**
// * Copyright � Olegnax (http://olegnax.com/). All rights reserved.
// */
//
// Variables
// _____________________________________________
@css-preloader-color: #000000;
@css-preloader-size: 35px;
@css-preloader-border-size: 4px;
@progress-line-background-color:#e6e6e6;
@progress-line-active-background-color:#000000;
//
// Common
// _____________________________________________
& when (@media-common = true) {
.ox-product-scroll + .toolbar-products,
.ox-infinite-scroll-enabled .products.wrapper ~ .toolbar-products{
display: none;
}
.ox-product-scroll__type--auto{
.ox-product-scroll__loader{
margin-top: 20px;
}
}
.ox-product-scroll{
&.ox-ps-hide{
&.ox-product-scroll-prev{
display:none!important;
}
&.ox-product-scroll-next {
.ox-product-scroll__button,
.ox-product-scroll__loader{
display:none!important;
}
}
}
margin-top:20px;
.ox-product-scroll__loader{
display:none;
}
&.active{
.ox-product-scroll__loader{
display:block;
}
}
.ox-product-scroll__loader{
margin-left: auto;
margin-right: auto;
}
&.ox-product-scroll__loader--magento{
.ox-product-scroll__loader{
.lib-loading();
width: @loader-icon__width;
height: @loader-icon__height;
margin-top: 0;
}
}
&.ox-product-scroll__loader--css{
.ox-product-scroll__loader{
display: block;
width: @css-preloader-size;
height: @css-preloader-size;
border: @css-preloader-border-size solid rgba(0, 0, 0, 0);
border-radius: @css-preloader-size;
border-left: @css-preloader-border-size solid @css-preloader-color;
border-right: @css-preloader-border-size solid @css-preloader-color;
border-top: @css-preloader-border-size solid @css-preloader-color;
animation: spin .65s infinite linear;
transition: all 600ms ease-in-out;
}
}
}
.ox-product-scroll{
.ox-product-scroll__button{
width: 100%;
max-width: 300px;
display: block;
margin: 16px auto 0;
padding: 15px;
line-height: normal;
&.active{
display:none;
}
}
}
.ox-product-scroll__amount {
width: 100%;
max-width: 240px;
display: block;
margin: 16px auto 0;
display:none;
&.ox-product-scroll__amount-loaded{
display:block;
}
.amount-wrap{
text-align: center;
margin-bottom: 8px;
}
.amount-count-line {
display: block;
height: 2px;
background: @progress-line-background-color;
overflow: hidden;
span {
display: block;
height: 2px;
background: @progress-line-active-background-color;
}
}
}
@keyframes spin {
from{
transform: rotate(0deg);
}to{
transform: rotate(360deg);
}
}
}
@@ -0,0 +1,61 @@
define([
'jquery',
], function ($) {
'use strict';
$.getValues = function (query) {
var query = query || '',
vars = query.split('&'),
result = {},
getName = function (name) {
var regex;
if ((regex = /^(.+?)\[(.*?)$/).test(name)) {
name = name.match(regex);
name[2] = name[2].replace(/\]/g, '').split('[');
name[2].unshift(name[1]);
name = name[2].map(function (v) {
return '' === v ? 0 : v;
});
} else {
name = [name];
}
return name;
},
setValue = function (form, names, value) {
var name = names.shift();
if (names.length) {
var _form = form.hasOwnProperty(name) ? form[name] : {};
form[name] = setValue(_form, names, value);
} else {
if (0 === name) {
for (; form.hasOwnProperty(name); name++) {
}
}
form[name] = value;
}
return form
};
for (var i = 0; i < vars.length; i++)
if (vars[i].length) {
var pair = vars[i].split('=').map(decodeURIComponent);
result = setValue(result, getName(pair[0]), pair[1]);
}
return $.extend(true, {}, result);
};
$.getURLValues = function (href) {
var href = href || window.location.href,
url = new URL(href);
return $.getValues(url.search.replace(/^\?/, ''));
};
$.fn.getFormValues = function () {
return $.getValues($(this).serialize());
};
return $.fn.getFormValues;
});
@@ -0,0 +1,48 @@
/**
* Olegnax
* Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
*/
define([
'jquery',
'text!Amasty_Rewards/template/highlight.html',
'mage/translate',
], function ($, template, $t) {
'use strict';
var xhr = {};
return function (config) {
$.each(config.components, function (index, config) {
var item = $('[data-bind="scope: \'' + index + '\'"]'),
loader = item.find('.amasty-rewards-loader');
if (xhr.hasOwnProperty(config.productId)) {
xhr[config.productId].abort();
}
loader.show();
xhr[config.productId] = $.ajax({
url: config.refreshUrl,
data: JSON.stringify({
productId: this.productId,
attributes: $(this.formSelector).serialize()
}),
cache: true,
method: 'post',
dataType: 'json',
contentType: "application/json",
success: function (result) {
var c = '.amasty-rewards-highlight';
if (result) {
if (!item.find(c).length) {
loader.after(template);
item.find(c + ' .caption strong').prepend($t('Earn'));
}
item.find(c).toggle(result.visible).find('b[data-bind]').html(result.caption_text).css('color', result.caption_color);
}
},
complete: function () {
loader.hide();
delete xhr[config.productId];
}
});
});
};
});
@@ -0,0 +1,646 @@
/**
* Olegnax Infinite Scroll
* Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
*/
define([
'jquery',
'jquery-ui-modules/widget',
'oxFormValues'
], function ($) {
$.widget('mage.OxInfiniteScroll', {
options: {
mode: "auto",
container: ".column.main .products.products-grid, .column.main .products.products-list, .column.main .products-grid.grid",
item: ".column.main .item.product.product-item",
pagesCountSelector: 'ox-page-count',
loader: false,
diff: .9,
pagerDiff: .1,
updateUrl: true,
prevPages: true,
hideOnlyButton: false,
disabled: false,
},
_create: function () {
this._button_mode = 'button';
this._infinity_mode = 'auto';
this._button_class = 'ox-product-scroll__button';
this._item_new_class = 'ox-scroll-loaded';
this._body_class = 'ox-infinite-scroll-enabled';
this._loader_class = 'ox-product-scroll';
this._loader_last_class = 'ox-ps-hide';
this._hidden_block_class = 'ox-hidden-content';
this._loader_last_without_progress_class = 'ox-product-scroll-no-needed-button';
this._loader_loading_class = 'active';
this._progress_amount = '.ox-product-scroll__amount';
this._progress_amount_loaded_class = 'ox-product-scroll__amount-loaded';
this._select_template = 'script[data-role="ox-infinity-scroll"]';
this.pagesCount = 0;
this.pageCurrent = 0;
this.lastPosition = 0;
this.pagesLoaded = [];
this.pagesCache = {};
this.pagesLoading = {};
this.loading_next = false;
this.loading_prev = false;
this.manadev_content_replaced = false;
this.window = $(window);
$(document).on("amscroll_refresh", $.proxy(function () {
this.initialize();
}, this));
$(document).on('mana-after-content-replaced', $.proxy(function () {
this.manadev_content_replaced = true;
}, this));
$(document).on('mana-after-show', $.proxy(function () {
if (this.manadev_content_replaced) {
$("body").trigger('OxInfiniteScroll');
}
}, this));
$("body").addClass(this._body_class).on("OxInfiniteScroll amscroll_refresh", $.proxy(function () {
this.initialize();
}, this));
this.initialize();
},
init: function () {
this.initialize();
},
initialize: function () {
this.options.disabled = false;
this.pagesLoaded = [];
this.pagesCache = {};
this.pagesLoading = {};
this.loading_next = false;
this.loading_prev = false;
this._initPagesCount();
this.pagesCache = {};
$('.' + this._loader_class).remove();
if (!this._checkContainer() || this.options.disabled) {
this._disable();
return;
}
this.window.on('scroll', $.proxy(this._initPaginator, this));
setTimeout($.proxy(this._initPaginator, this), 7000);
$(document).ready($.proxy(function () {
this._preloadPages();
switch (this.options.mode) {
case this._infinity_mode:
this._initPaginator();
break;
case this._button_mode:
if (this.pagesCount > this._currentPage())
this._generateButton();
break;
}
}, this));
},
_initPaginator: function () {
if (this.options.disabled) {
return;
}
var scrollTop = this.window.scrollTop(),
windowHeight = this.window.height(),
$container = $(this.options.container).last(),
elementTop = $container.offset().top,
elementHeight = $container.outerHeight(true);
if (this._infinity_mode === this.options.mode && scrollTop + windowHeight >= elementTop + elementHeight * this.options.diff) {
this.loadNextContent();
}
if (this.options.updateUrl)
this._calculateCurrentPage(scrollTop, windowHeight);
},
_disable: function () {
$('.' + this._loader_class + ' + .toolbar-products, .' + this._body_class + ' .products.wrapper ~' +
' .toolbar-products').show().find('.pages').show();
$('.' + this._loader_class).remove();
this.options.disabled = true;
},
_generateButton: function (type) {
this._createLoader(type);
this._selectButton(type)
.off('click' + this._namespace())
.on('click' + this._namespace(), $.proxy(
'prev' === type
? this.loadPrevContent
: this.loadNextContent
, this));
},
_namespace: function () {
return this.eventNamespace.replace(this.uuid, '');
},
loadPrevContent: function () {
if (this.loading_prev || this.options.disabled) {
return;
}
var page = this._getFirstPageId() - 1,
cache = this._getPrevPagesCache();
if (cache) {
this._showPrevContent(cache);
} else if (page > 0) {
this._showLoader('prev');
this.loading_prev = true;
var _self = this;
this._loadPage(page, function (response) {
if (response.hasOwnProperty('html')) {
_self._showPrevContent(_self._setPagesCache(page, response));
} else {
console.warn('Incorrect response please refresh the page!');
_self._disable();
}
_self._hideLoader('prev');
_self.loading_prev = false;
_self.loadPrevContent();
}, function () {
_self._hideLoader('prev');
_self.loading = false;
console.warn('Error requesting page number ' + page + '!');
});
}
},
_showPrevContent: function (data) {
if (data.hasOwnProperty('html') && data.html.hasOwnProperty('products')) {
var page = data.page;
if (0 > this.pagesLoaded.indexOf(page)) {
var html = $(data.html.products),
products = html.find(this.options.item).addClass(this._item_new_class + ' ' + this._item_new_class + '-' + page).data('pageItem', page).detach(),
scripts = html.find('script').filter($.proxy(function (i, el) {
return $(el).parents(this.options.item).length == 0
}, this)).add(html.filter('script'));
this._inserBeforeProducts(products);
this._insertAfterHidden(scripts);
this.appendExternalHTML(data);
this.pagesLoaded.unshift(page);
this._afterShow(page, data, -1);
this._preloadPagePrev(page);
}
} else {
console.warn('Missing product display data!', data);
}
},
loadNextContent: function () {
if (this.loading_next || this.options.disabled) {
return;
}
var page = this._getLastPageId() + 1,
cache = this._getNextPagesCache();
if (cache) {
this._showNextContent(cache);
} else if (page <= this.pagesCount) {
this._showLoader('next');
this.loading_next = true;
var _self = this;
this._loadPage(page, function (response) {
if (response.hasOwnProperty('html')) {
_self._showNextContent(_self._setPagesCache(page, response));
} else {
console.warn('Incorrect response please refresh the page!');
_self._disable();
}
_self._hideLoader('next');
_self.loading_next = false;
}, function () {
_self._hideLoader('next');
_self.loading_next = false;
console.warn('Error requesting page number ' + page + '!');
var isFirst = true;
$.each(_self.pagesCache, function () {
isFirst = false;
return false;
});
if (isFirst) {
_self._disable();
}
});
}
},
_showNextContent: function (data) {
if (data.hasOwnProperty('html') && data.html.hasOwnProperty('products')) {
var page = data.page;
if (0 > this.pagesLoaded.indexOf(page)) {
var html = $(data.html.products),
products = html.find(this.options.item).addClass(this._item_new_class + ' ' + this._item_new_class + '-' + page).data('pageItem', page).detach(),
scripts = html.find('script').filter($.proxy(function (i, el) {
return $(el).parents(this.options.item).length == 0
}, this)).add(html.filter('script'));
this._insertAfterProducts(products);
this._insertAfterHidden(scripts);
this.appendExternalHTML(data);
this.pagesLoaded.push(page);
this._afterShow(page, data, 1);
this._preloadPageNext(page);
}
} else {
console.warn('Missing product display data!', data);
}
},
_getNextPagesCache: function () {
return this._getPagesCache(this._getLastPageId() + 1);
},
_getPrevPagesCache: function () {
return this._getPagesCache(this._getFirstPageId() - 1);
},
__calculateCurrentPage: function (windowHeight) {
windowHeight = windowHeight || this.window.height();
var newPage = 0,
lastStatus = false,
topStep = this.__additionalSpace();
windowHeight -= topStep;
$(this.options.container).find(this.options.item + ":visible").each($.proxy(function (i, item) {
if (this.__isVisible(item, windowHeight, topStep)) {
var page = $(item).data('pageItem');
if (page > newPage) {
newPage = page;
}
lastStatus = true;
} else if (lastStatus) {
return false;
}
}, this));
if (newPage && this._currentPage() != newPage) {
this.updateUrl(this._setAjaxData(newPage));
this.pageCurrent = newPage;
}
},
_calculateCurrentPage: function (scrollTop, windowHeight) {
if (Math.abs(scrollTop - this.lastPosition) > windowHeight * this.options.pagerDiff) {
this.lastPosition = scrollTop;
this.__calculateCurrentPage(windowHeight);
}
},
updateUrl: function (data, url) {
var _url = url || this._getClearURL(),
_data = data || {};
if (data.hasOwnProperty('scrollAjax')) {
delete data.scrollAjax;
}
var new_url = new URL(_url);
$.each(_data, function (i, v) {
if ($.isArray(v)) {
new_url.searchParams.set(i, v.join(','));
} else {
new_url.searchParams.set(i, v);
}
});
new_url = new_url.toString();
if (typeof window.history.replaceState === 'function' && (!window.history.state || new_url !== window.history.state.url)) {
window.history.replaceState({url: new_url}, null, new_url);
}
return new_url;
},
__additionalSpace: function () {
var topStep = $('.page-header .sticky-wrapper');
if (topStep.length)
return topStep.outerHeight(true);
return 0;
},
__isVisible: function (item, windowHeight, topStep) {
var sizes = item.getBoundingClientRect();
sizes = [sizes.top - topStep, sizes.bottom - topStep];
if (sizes[1] < 0 || sizes[0] > windowHeight) {
return false;
} else if (sizes[0] < 0 || sizes[1] > windowHeight) {
return (((sizes[0] > 0 ? sizes[0] : 0) - (sizes[1] < windowHeight ? sizes[1] : windowHeight)) / (sizes[0] - sizes[1])) > 0.75; // if more than 75% of the element is visible
}
return true;
},
_getPagesCache: function (pageid) {
if (this.pagesCache.hasOwnProperty(pageid)) {
return this.pagesCache[pageid];
}
return null;
},
_setPagesCache: function (page, data) {
if (data.hasOwnProperty('html') && data.html.hasOwnProperty('products')) {
data.page = page;
this.pagesCache[page] = data;
}
return data;
},
_getLastPageId: function () {
if (0 == this.pagesLoaded.length) {
return this.pageCurrent;
}
if (1 == this.pagesLoaded.length) {
return this.pagesLoaded[0];
}
if (this.pagesLoaded.__proto__.hasOwnProperty('max')) {
return this.pagesLoaded.max();
}
return this.pagesLoaded[this.pagesLoaded.length - 1];
},
_getFirstPageId: function () {
if (this.pagesLoaded.__proto__.hasOwnProperty('min')) {
return this.pagesLoaded.min();
}
return this.pagesLoaded[0];
},
_selectButton: function (type) {
var type = type || 'next';
return $('.' + this._loader_class + '.' + this._loader_class + '-' + type + ' .' + this._button_class);
},
_createLoader: function (type) {
var type = type || 'next';
var $parent = $(this.options.container).filter($.proxy(function (i, el) {
return $(el).find(this.options.item).length;
}, this)).last();
var $loader = $parent.parent().children('.' + this._loader_class + '.' + this._loader_class + '-' + type);
if (!$loader.length) {
var content = $(this._select_template).html();
$loader = $(content).addClass(this._loader_class + '-' + type);
if ('prev' === type) {
$parent.before($loader);
} else {
$parent.after($loader);
}
}
if ($(this._progress_amount).length)
this._preloadPageNextFirts();
return $loader;
},
_showLoader: function (type) {
if (this.options.loader) {
this._createLoader(type).addClass(this._loader_loading_class);
}
},
_hideLoader: function (type) {
if (this.options.loader) {
$('.' + this._loader_class + '.' + this._loader_class + '-' + type).removeClass(this._loader_loading_class);
}
},
_insertAfterProducts: function ($elements) {
$(this.options.container).find(this.options.item).parent().append($elements);
},
_inserBeforeProducts: function ($elements) {
$(this.options.container).find(this.options.item).parent().prepend($elements);
},
_insertAfterHidden: function ($elements) {
var $parent = $(this.options.container).parent().children('.' + this._hidden_block_class);
if (!$parent.length) {
$parent = $('<div>').attr({
'class': this._hidden_block_class,
'style': 'display: none'
});
$(this.options.container).parent().append($parent);
}
$parent.html($elements);
},
_insertAfter: function ($elements) {
var $parent = $(this.options.container).filter($.proxy(function (i, el) {
return $(el).find(this.options.item).length;
}, this));
$parent.after($elements);
},
_insertBefore: function ($elements) {
var $parent = $(this.options.container).filter($.proxy(function (i, el) {
return $(el).find(this.options.item).length;
}, this));
$parent.before($elements);
},
_currentPage: function () {
if (!this.pageCurrent) {
var args = $.getURLValues();
this.pageCurrent = parseInt(args.hasOwnProperty('p') ? args.p : 1);
}
return this.pageCurrent;
},
_initPagesCount: function () {
var $pagesCount = $('[id="' + this.options.pagesCountSelector + '"]');
if ($pagesCount && $pagesCount.length) {
this.pagesCount = parseInt($pagesCount.eq(0).html());
$pagesCount.prev('.pages').hide();
return;
}
this.pagesCount = 1;
},
_checkContainer: function () {
if (!this.options.container || 0 === $(this.options.container).length) {
console.warn('Please specify DOM selectors in module settings.');
return false;
}
return this.pagesCount > 1;
},
_preloadPages: function () {
var page = this._currentPage();
$(this.options.container).find(this.options.item).data('pageItem', page);
this.pagesLoaded.push(page);
this._preloadPageNext(page);
if (this.options.prevPages)
this._preloadPagePrev(page);
},
_getClearURL: function () {
var url = (new URL(window.location.href));
url.hash = '';
url.search = '';
return url.toString();
},
_setAjaxData: function (page) {
var data = $.getURLValues();
data['p'] = page;
data['scrollAjax'] = 1;
if (1 >= data['p']) {
delete data.p;
}
return data;
},
_loadPage: function (page, callback, error_callback) {
var _self = this,
callback = callback || function () {
},
error_callback = error_callback || function (jqXHR, textStatus, errorThrown) {
console.warn('Request failed!', jqXHR, textStatus, errorThrown)
var isFirst = true
$.each(_self.pagesCache, function () {
isFirst = false
return false
})
if (isFirst) {
_self._disable()
}
},
data
if ('number' == typeof page) {
data = this._setAjaxData(page)
}
if (!this.pagesLoading.hasOwnProperty(page)) this.pagesLoading[page] = []
this.pagesLoading[page].push({ success: callback, error: error_callback })
var queryString = Object.keys(data).map(function (key) {
return key + '=' + data[key]
}).join('&')
$.ajax({
url: this._getClearURL() + '?' + queryString,
cache: true,
dataType: 'json',
success: function (data, textStatus, jqXHR) {
if (_self.pagesLoading.hasOwnProperty(page)) {
for (let i = 0; i < _self.pagesLoading[page].length; i++) {
_self.pagesLoading[page][i].success.call(_self, data, textStatus, jqXHR)
}
delete _self.pagesLoading[page]
}
},
error: function (jqXHR, textStatus, errorThrown) {
if (_self.pagesLoading.hasOwnProperty(page)) {
for (let i = 0; i < _self.pagesLoading[page].length; i++) {
_self.pagesLoading[page][i].error.call(_self, data, textStatus, jqXHR)
}
delete _self.pagesLoading[page]
}
}
})
},
_preloadPage: function (page) {
var _self = this;
this._loadPage(page, function (response) {
if (response.hasOwnProperty('html')) {
_self._setPagesCache(page, response);
} else {
console.warn('Incorrect response please refresh the page!');
_self._disable();
}
});
},
_preloadPageNext: function (page) {
var _page = page + 1;
if (_page && _page <= this.pagesCount) {
this._preloadPage(_page);
}
},
_preloadPageNextFirts: function (page) {
var page = page || this._getLastPageId(),
_page = page + 1,
__page = page - 1,
_self = this,
cache;
if (_page && _page <= this.pagesCount) {
cache = this._getNextPagesCache();
if (cache) {
_self._firstValueToolbar(cache, -1);
} else {
this._loadPage(_page, function (response) {
if (response.hasOwnProperty('html')) {
_self._firstValueToolbar(_self._setPagesCache(_page, response), -1);
} else {
console.warn('Incorrect response please refresh the page!');
_self._disable();
}
});
}
} else if (__page && __page >= 1) {
cache = this._getPrevPagesCache();
if (cache) {
_self._firstValueToolbar(cache, 1);
} else {
this._loadPage(__page, function (response) {
if (response.hasOwnProperty('html')) {
_self._firstValueToolbar(_self._setPagesCache(__page, response), 1);
} else {
console.warn('Incorrect response please refresh the page!');
_self._disable();
}
});
}
}
},
_preloadPagePrev: function (page) {
var _page = page - 1;
if (_page && _page >= 1) {
this._preloadPage(_page);
}
},
_afterShow: function (page, data, action) {
if (data.isFirst || 1 >= page) {
$('.' + this._loader_class + '.' + this._loader_class + '-prev').addClass(this.options.hideOnlyButton ? this._loader_last_without_progress_class : this._loader_last_class);
}
if (data.isLast || this.pagesCount <= page) {
$('.' + this._loader_class + '.' + this._loader_class + '-next').addClass(this.options.hideOnlyButton ? this._loader_last_without_progress_class : this._loader_last_class);
}
this._fixValueToolbar(data, action);
if (this.options.updateUrl)
this.__calculateCurrentPage();
if (data.hasOwnProperty('html')) {
if (data.html.hasOwnProperty('_before') && data.html['_before']) {
$(this.options.container).before(data.html['_before']);
}
if (data.html.hasOwnProperty('_after') && data.html['_after']) {
$(this.options.container).after(data.html['_after']);
}
}
if ('function' === typeof $.mage.cookies?.get) {
$(this.options.container).last().find('[name="form_key"]').val($.mage.cookies.get('form_key'))
} else if ('function' === typeof window.Cookies?.get) {
$(this.options.container).last().find('[name="form_key"]').val(window.Cookies.get('form_key'))
}
this.element.trigger('contentUpdated');
},
_firstValueToolbar: function (data, action) {
var firstNum, lastNum;
if (-1 == action) {
lastNum = data.firstNum - 1;
} else {
firstNum = data.lastNum + 1;
}
this._fixValueToolbar(data, action, firstNum, lastNum);
},
_fixValueToolbar: function (data, action, firstNum, lastNum) {
var container = this.options.container,
item = this.options.item,
loaded_class = this._progress_amount_loaded_class,
items_count = $(container).find(item).length,
productsCount = data.productsCount,
progress = items_count * 100 / productsCount;
u = 'undefined';
if (u == typeof firstNum && u == typeof lastNum) {
if (-1 == action) {
firstNum = data.firstNum;
} else {
lastNum = data.lastNum;
}
}
if (u == typeof firstNum) {
firstNum = lastNum - items_count + 1;
}
if (u == typeof lastNum) {
lastNum = firstNum + items_count - 1;
}
if (1 > firstNum || lastNum - firstNum + 1 != items_count || data.pageSize > items_count) {
firstNum = 1;
lastNum = items_count;
}
$('.toolbar-amount, ' + this._progress_amount).each(function () {
var $toolbar = $(this),
$number = $toolbar.find('.toolbar-number');
if (3 == $number.length) {
$number.eq(0).html(firstNum);
$number.eq(1).html(lastNum);
$number.eq(2).html(productsCount);
}
$toolbar.find('.toolbar-number-first').html(firstNum);
$toolbar.find('.toolbar-number-last').html(lastNum);
$toolbar.find('.toolbar-number-total').html(productsCount);
$toolbar.find('.amount-count-line span').css('width', progress + "%");
$toolbar.addClass(loaded_class);
});
$('body').trigger('oxToggleUpdated');
},
appendExternalHTML: function (data) {
//Amasty Label
var html = $(data.html.products),
labels = html.filter('div.amasty-label-container').filter($.proxy(function (i, el) {
return $(el).parents(this.options.item).length == 0
}, this));
this._insertAfter(labels);
}
});
return $.mage.OxInfiniteScroll;
});
@@ -0,0 +1,20 @@
define([
'jquery'
], function ($) {
'use strict';
return function (widget) {
$.widget('mage.SwatchRenderer', widget, {
_RenderControls: function () {
var container = this.element,
classes = this.options.classes;
if (container.find('.' + classes.attributeClass).length) {
return;
}
return this._super();
}
});
return $.mage.SwatchRenderer;
}
});