Commit 916e8a05 by lmf

产品列表页面增加排序功能

parent aa151b37
...@@ -83,6 +83,7 @@ ...@@ -83,6 +83,7 @@
"phpseclib/mcrypt_compat": "1.0.8", "phpseclib/mcrypt_compat": "1.0.8",
"phpseclib/phpseclib": "2.0.*", "phpseclib/phpseclib": "2.0.*",
"ramsey/uuid": "~4.1.0", "ramsey/uuid": "~4.1.0",
"sparsh/magento-2-advanced-sorting-extension": "^1.3",
"swissup/breeze-blank": "^1.2", "swissup/breeze-blank": "^1.2",
"symfony/console": "~4.4.0", "symfony/console": "~4.4.0",
"symfony/event-dispatcher": "~4.4.0", "symfony/event-dispatcher": "~4.4.0",
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "5b32d8725a620fa542a680503d480986", "content-hash": "29cabf37a1ac686d49544a0cb5aaa6e7",
"packages": [ "packages": [
{ {
"name": "airwallex/payments-plugin-magento", "name": "airwallex/payments-plugin-magento",
...@@ -6480,6 +6480,31 @@ ...@@ -6480,6 +6480,31 @@
"time": "2022-08-31T10:31:18+00:00" "time": "2022-08-31T10:31:18+00:00"
}, },
{ {
"name": "sparsh/magento-2-advanced-sorting-extension",
"version": "1.3.0",
"dist": {
"type": "zip",
"url": "https://repo.magento.com/archives/sparsh/magento-2-advanced-sorting-extension/sparsh-magento-2-advanced-sorting-extension-1.3.0.0.zip",
"shasum": "e73d7dd19c088f427f72db5bd4c03836202aa304"
},
"require": {
"php": "~7.0.13|~7.1.0|~7.2.0|~7.3.0|~7.4.0|^8.0"
},
"type": "magento2-module",
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Sparsh\\AdvancedSorting\\": ""
}
},
"license": [
"OSL-3.0"
],
"description": "Sparsh Advanced Sorting for Magento 2"
},
{
"name": "spomky-labs/aes-key-wrap", "name": "spomky-labs/aes-key-wrap",
"version": "v6.0.0", "version": "v6.0.0",
"source": { "source": {
......
...@@ -140,5 +140,6 @@ return array( ...@@ -140,5 +140,6 @@ return array(
'3109cb1a231dcd04bee1f9f620d46975' => $vendorDir . '/paragonie/sodium_compat/autoload.php', '3109cb1a231dcd04bee1f9f620d46975' => $vendorDir . '/paragonie/sodium_compat/autoload.php',
'aa75ea0761a2f40c1f3b32ad314f86c4' => $vendorDir . '/phpseclib/mcrypt_compat/lib/mcrypt.php', 'aa75ea0761a2f40c1f3b32ad314f86c4' => $vendorDir . '/phpseclib/mcrypt_compat/lib/mcrypt.php',
'9b38cf48e83f5d8f60375221cd213eee' => $vendorDir . '/phpstan/phpstan/bootstrap.php', '9b38cf48e83f5d8f60375221cd213eee' => $vendorDir . '/phpstan/phpstan/bootstrap.php',
'550719157da16285530f4f2ca5eee610' => $vendorDir . '/sparsh/magento-2-advanced-sorting-extension/registration.php',
'27a5783f6a5e8d8d1a4f54dff608a187' => $baseDir . '/app/etc/NonComposerComponentRegistration.php', '27a5783f6a5e8d8d1a4f54dff608a187' => $baseDir . '/app/etc/NonComposerComponentRegistration.php',
); );
...@@ -44,6 +44,7 @@ return array( ...@@ -44,6 +44,7 @@ return array(
'Swissup\\Rtl\\' => array($vendorDir . '/swissup/module-rtl'), 'Swissup\\Rtl\\' => array($vendorDir . '/swissup/module-rtl'),
'Swissup\\Breeze\\' => array($vendorDir . '/swissup/module-breeze'), 'Swissup\\Breeze\\' => array($vendorDir . '/swissup/module-breeze'),
'Swissup\\BreezeIntegrations\\' => array($vendorDir . '/swissup/module-breeze-integrations'), 'Swissup\\BreezeIntegrations\\' => array($vendorDir . '/swissup/module-breeze-integrations'),
'Sparsh\\AdvancedSorting\\' => array($vendorDir . '/sparsh/magento-2-advanced-sorting-extension'),
'Seld\\PharUtils\\' => array($vendorDir . '/seld/phar-utils/src'), 'Seld\\PharUtils\\' => array($vendorDir . '/seld/phar-utils/src'),
'Seld\\JsonLint\\' => array($vendorDir . '/seld/jsonlint/src/Seld/JsonLint'), 'Seld\\JsonLint\\' => array($vendorDir . '/seld/jsonlint/src/Seld/JsonLint'),
'Safe\\' => array($vendorDir . '/thecodingmachine/safe/lib', $vendorDir . '/thecodingmachine/safe/deprecated', $vendorDir . '/thecodingmachine/safe/generated'), 'Safe\\' => array($vendorDir . '/thecodingmachine/safe/lib', $vendorDir . '/thecodingmachine/safe/deprecated', $vendorDir . '/thecodingmachine/safe/generated'),
......
...@@ -141,6 +141,7 @@ class ComposerStaticInitb71ce7c407b65980cf51508f463c8dcf ...@@ -141,6 +141,7 @@ class ComposerStaticInitb71ce7c407b65980cf51508f463c8dcf
'3109cb1a231dcd04bee1f9f620d46975' => __DIR__ . '/..' . '/paragonie/sodium_compat/autoload.php', '3109cb1a231dcd04bee1f9f620d46975' => __DIR__ . '/..' . '/paragonie/sodium_compat/autoload.php',
'aa75ea0761a2f40c1f3b32ad314f86c4' => __DIR__ . '/..' . '/phpseclib/mcrypt_compat/lib/mcrypt.php', 'aa75ea0761a2f40c1f3b32ad314f86c4' => __DIR__ . '/..' . '/phpseclib/mcrypt_compat/lib/mcrypt.php',
'9b38cf48e83f5d8f60375221cd213eee' => __DIR__ . '/..' . '/phpstan/phpstan/bootstrap.php', '9b38cf48e83f5d8f60375221cd213eee' => __DIR__ . '/..' . '/phpstan/phpstan/bootstrap.php',
'550719157da16285530f4f2ca5eee610' => __DIR__ . '/..' . '/sparsh/magento-2-advanced-sorting-extension/registration.php',
'27a5783f6a5e8d8d1a4f54dff608a187' => __DIR__ . '/../..' . '/app/etc/NonComposerComponentRegistration.php', '27a5783f6a5e8d8d1a4f54dff608a187' => __DIR__ . '/../..' . '/app/etc/NonComposerComponentRegistration.php',
); );
...@@ -197,6 +198,7 @@ class ComposerStaticInitb71ce7c407b65980cf51508f463c8dcf ...@@ -197,6 +198,7 @@ class ComposerStaticInitb71ce7c407b65980cf51508f463c8dcf
'Swissup\\Rtl\\' => 12, 'Swissup\\Rtl\\' => 12,
'Swissup\\Breeze\\' => 15, 'Swissup\\Breeze\\' => 15,
'Swissup\\BreezeIntegrations\\' => 27, 'Swissup\\BreezeIntegrations\\' => 27,
'Sparsh\\AdvancedSorting\\' => 23,
'Seld\\PharUtils\\' => 15, 'Seld\\PharUtils\\' => 15,
'Seld\\JsonLint\\' => 14, 'Seld\\JsonLint\\' => 14,
'Safe\\' => 5, 'Safe\\' => 5,
...@@ -524,6 +526,10 @@ class ComposerStaticInitb71ce7c407b65980cf51508f463c8dcf ...@@ -524,6 +526,10 @@ class ComposerStaticInitb71ce7c407b65980cf51508f463c8dcf
array ( array (
0 => __DIR__ . '/..' . '/swissup/module-breeze-integrations', 0 => __DIR__ . '/..' . '/swissup/module-breeze-integrations',
), ),
'Sparsh\\AdvancedSorting\\' =>
array (
0 => __DIR__ . '/..' . '/sparsh/magento-2-advanced-sorting-extension',
),
'Seld\\PharUtils\\' => 'Seld\\PharUtils\\' =>
array ( array (
0 => __DIR__ . '/..' . '/seld/phar-utils/src', 0 => __DIR__ . '/..' . '/seld/phar-utils/src',
......
...@@ -11059,6 +11059,34 @@ ...@@ -11059,6 +11059,34 @@
"install-path": "../seld/phar-utils" "install-path": "../seld/phar-utils"
}, },
{ {
"name": "sparsh/magento-2-advanced-sorting-extension",
"version": "1.3.0",
"version_normalized": "1.3.0.0",
"dist": {
"type": "zip",
"url": "https://repo.magento.com/archives/sparsh/magento-2-advanced-sorting-extension/sparsh-magento-2-advanced-sorting-extension-1.3.0.0.zip",
"shasum": "e73d7dd19c088f427f72db5bd4c03836202aa304"
},
"require": {
"php": "~7.0.13|~7.1.0|~7.2.0|~7.3.0|~7.4.0|^8.0"
},
"type": "magento2-module",
"installation-source": "dist",
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Sparsh\\AdvancedSorting\\": ""
}
},
"license": [
"OSL-3.0"
],
"description": "Sparsh Advanced Sorting for Magento 2",
"install-path": "../sparsh/magento-2-advanced-sorting-extension"
},
{
"name": "spomky-labs/aes-key-wrap", "name": "spomky-labs/aes-key-wrap",
"version": "v6.0.0", "version": "v6.0.0",
"version_normalized": "6.0.0.0", "version_normalized": "6.0.0.0",
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
'type' => 'project', 'type' => 'project',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),
'reference' => 'c5782803e86afdd01eda85af4ba6279f106ab8df', 'reference' => 'aa151b3790b9ffbf345a885f0b2152bbb0af129b',
'name' => 'magento/magento2ce', 'name' => 'magento/magento2ce',
'dev' => true, 'dev' => true,
), ),
...@@ -1015,7 +1015,7 @@ ...@@ -1015,7 +1015,7 @@
'type' => 'project', 'type' => 'project',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),
'reference' => 'c5782803e86afdd01eda85af4ba6279f106ab8df', 'reference' => 'aa151b3790b9ffbf345a885f0b2152bbb0af129b',
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'magento/module-admin-analytics' => array( 'magento/module-admin-analytics' => array(
...@@ -2877,6 +2877,15 @@ ...@@ -2877,6 +2877,15 @@
'reference' => 'ea2f4014f163c1be4c601b9b7bd6af81ba8d701c', 'reference' => 'ea2f4014f163c1be4c601b9b7bd6af81ba8d701c',
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'sparsh/magento-2-advanced-sorting-extension' => array(
'pretty_version' => '1.3.0',
'version' => '1.3.0.0',
'type' => 'magento2-module',
'install_path' => __DIR__ . '/../sparsh/magento-2-advanced-sorting-extension',
'aliases' => array(),
'reference' => NULL,
'dev_requirement' => false,
),
'spomky-labs/aes-key-wrap' => array( 'spomky-labs/aes-key-wrap' => array(
'pretty_version' => 'v6.0.0', 'pretty_version' => 'v6.0.0',
'version' => '6.0.0.0', 'version' => '6.0.0.0',
......
<?php
/**
* Class Toolbar
*
* PHP version 7
*
* @category Sparsh
* @package Sparsh_AdvancedSorting
* @author Sparsh <magento@sparsh-technologies.com>
* @license https://www.sparsh-technologies.com Open Software License (OSL 3.0)
* @link https://www.sparsh-technologies.com
*/
namespace Sparsh\AdvancedSorting\Block\Product\ProductList;
/**
* Class Toolbar
*
* @category Sparsh
* @package Sparsh_AdvancedSorting
* @author Sparsh <magento@sparsh-technologies.com>
* @license https://www.sparsh-technologies.com Open Software License (OSL 3.0)
* @link https://www.sparsh-technologies.com
*/
class Toolbar extends \Magento\Catalog\Block\Product\ProductList\Toolbar
{
/**
* Set collection to sorting option
*
* @param \Magento\Framework\Data\Collection $collection
*
* @return $this
*/
public function setCollection($collection)
{
$this->_collection = $collection;
$this->_collection->setCurPage($this->getCurrentPage());
$limit = (int)$this->getLimit();
if ($limit) {
$this->_collection->setPageSize($limit);
}
if ($this->getCurrentOrder()) {
switch ($this->getCurrentOrder()) {
case 'created_at':
$this->_collection->setOrder('created_at', $this->getCurrentDirectionReverse());
break;
case 'best_seller':
$this->_collection->setOrder('best_seller', $this->getCurrentDirectionReverse());
break;
case 'most_viewed':
$this->_collection->setOrder('top_rated', $this->getCurrentDirectionReverse());
break;
default:
$this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
break;
}
}
return $this;
}
/**
* Return Reverse direction of current direction
*
* @return string
*/
public function getCurrentDirectionReverse()
{
if ($this->getCurrentDirection() == 'asc') {
return 'desc';
} elseif ($this->getCurrentDirection() == 'desc') {
return 'asc';
} else {
return $this->getCurrentDirection();
}
}
}
<?php
/**
* Class Indexer
*
* PHP version 7
*
* @category Sparsh
* @package Sparsh_AdvancedSorting
* @author Sparsh <magento@sparsh-technologies.com>
* @license https://www.sparsh-technologies.com Open Software License (OSL 3.0)
* @link https://www.sparsh-technologies.com
*/
namespace Sparsh\AdvancedSorting\Model\Indexer;
/**
* Class Index
*
* @category Sparsh
* @package Sparsh_AdvancedSorting
* @author Sparsh <magento@sparsh-technologies.com>
* @license https://www.sparsh-technologies.com Open Software License (OSL 3.0)
* @link https://www.sparsh-technologies.com
*/
class Index implements \Magento\Framework\Indexer\ActionInterface, \Magento\Framework\Mview\ActionInterface
{
/**
* @var \Magento\Framework\App\ResourceConnection
*/
protected $_resource;
/**
* @var \Magento\Catalog\Model\ResourceModel\Product\Action
*/
private $action;
/**
* @var \Magento\Framework\DB\Adapter\AdapterInterface
*/
protected $_connection;
/**
* Index constructor.
* @param \Magento\Framework\App\ResourceConnection $resource
* @param \Magento\Catalog\Model\ResourceModel\Product\Action $action
*/
public function __construct(
\Magento\Framework\App\ResourceConnection $resource,
\Magento\Catalog\Model\ResourceModel\Product\Action $action
)
{
$this->_resource = $resource;
$this->action = $action;
}
/*
* Used by mview, allows process indexer in the "Update on schedule" mode
*/
public function execute($ids){
$this->executeFull();
}
/*
* Will take all of the data and reindex
* Will run when reindex via command line
*/
public function executeFull(){
$connection = $this->_getConnection();
$select = $connection->select()
->from(
['soi' => $this->_resource->getTableName('sales_order_item')],
[
'product_id' => 'product_id',
'best_seller' => 'SUM(qty_ordered)'
]
)
->join(
['cpe' => $this->_resource->getTableName('catalog_product_entity')],
'cpe.entity_id = soi.product_id'
)
->group('soi.product_id');
$data = $connection->fetchAll($select);
foreach ($data as $item) {
$this->action->updateAttributes(
[$item['product_id']],
['best_seller' => $item['best_seller']],
0);
}
$select = $connection->select()
->from(
['res' => $this->_resource->getTableName('review_entity_summary')],
[
'product_id' => 'entity_pk_value',
'top_rated' => 'rating_summary'
]
)
->join(
['cpe' => $this->_resource->getTableName('catalog_product_entity')],
'cpe.entity_id = res.entity_pk_value'
)
->group('res.entity_pk_value');
$data = $connection->fetchAll($select);
foreach ($data as $item) {
$this->action->updateAttributes(
[$item['product_id']],
['top_rated' => $item['top_rated']],
0);
}
$select = $connection->select()
->from(
['rvpi' => $this->_resource->getTableName('report_viewed_product_index')],
[
'product_id' => 'product_id',
'most_viewed' => 'COUNT(rvpi.product_id)'
]
)
->join(
['cpe' => $this->_resource->getTableName('catalog_product_entity')],
'cpe.entity_id = rvpi.product_id'
)
->group('rvpi.product_id');
$data = $connection->fetchAll($select);
foreach ($data as $item) {
$this->action->updateAttributes(
[$item['product_id']],
['most_viewed' => $item['most_viewed']],
0);
}
$select = $connection->select()
->from(
['res' => $this->_resource->getTableName('review_entity_summary')],
[
'product_id' => 'entity_pk_value',
'review_count' => 'reviews_count'
]
)
->join(
['cpe' => $this->_resource->getTableName('catalog_product_entity')],
'cpe.entity_id = res.entity_pk_value'
)
->group('res.entity_pk_value');
$data = $connection->fetchAll($select);
foreach ($data as $item) {
$this->action->updateAttributes(
[$item['product_id']],
['review_count' => $item['review_count']],
0);
}
}
/**
* Retrieve connection instance
*
* @return bool|\Magento\Framework\DB\Adapter\AdapterInterface
*/
protected function _getConnection()
{
if (null === $this->_connection) {
$this->_connection = $this->_resource->getConnection();
}
return $this->_connection;
}
/*
* Works with a set of entity changed (may be massaction)
*/
public function executeList(array $ids){
$this->executeFull();
}
/*
* Works in runtime for a single entity using plugins
*/
public function executeRow($id){
$this->executeFull();
}
}
<?php
/**
* Class SortType
*
* PHP version 7
*
* @category Sparsh
* @package Sparsh_AdvancedSorting
* @author Sparsh <magento@sparsh-technologies.com>
* @license https://www.sparsh-technologies.com Open Software License (OSL 3.0)
* @link https://www.sparsh-technologies.com
*/
namespace Sparsh\AdvancedSorting\Model\System;
use Magento\Framework\Option\ArrayInterface;
/**
* Class SortType
*
* @category Sparsh
* @package Sparsh_AdvancedSorting
* @author Sparsh <magento@sparsh-technologies.com>
* @license https://www.sparsh-technologies.com Open Software License (OSL 3.0)
* @link https://www.sparsh-technologies.com
*/
class SortType implements ArrayInterface
{
const BEST_SELLER = "best_seller";
const TOP_RATED = "top_rated";
const NEW_ARRIVALS = "created_at";
const MOST_VIEWED = "most_viewed";
const REVIEW_COUNT = "review_count";
/**
* Return array of options as value-label pairs
*
* @return array Format: array(array('value' => '<value>', 'label' => '<label>'), ...)
*/
public function toOptionArray()
{
$options = [];
foreach ($this->getOptionHash() as $value => $label) {
$options[] = [
'value' => $value,
'label' => $label
];
}
return $options;
}
/**
* Return options
*
* @return array
*/
public function getOptionHash()
{
return [
self::BEST_SELLER => __('Best Seller'),
self::TOP_RATED => __('Top Rated'),
self::NEW_ARRIVALS => __('New Arrivals'),
self::MOST_VIEWED => __('Most Viewed'),
self::REVIEW_COUNT => __('Review Count'),
];
}
}
<?php
/**
* Class AddSortOption
*
* PHP version 7
*
* @category Sparsh
* @package Sparsh_AdvancedSorting
* @author Sparsh <magento@sparsh-technologies.com>
* @license https://www.sparsh-technologies.com Open Software License (OSL 3.0)
* @link https://www.sparsh-technologies.com
*/
namespace Sparsh\AdvancedSorting\Plugin;
use Sparsh\AdvancedSorting\Model\System\SortType;
use Magento\Store\Model\ScopeInterface;
use Magento\Framework\App\Helper\Context;
use Magento\Store\Model\StoreManagerInterface;
/**
* Class AddSortOption
*
* @category Sparsh
* @package Sparsh_AdvancedSorting
* @author Sparsh <magento@sparsh-technologies.com>
* @license https://www.sparsh-technologies.com Open Software License (OSL 3.0)
* @link https://www.sparsh-technologies.com
*/
class AddSortOption extends \Magento\Framework\App\Helper\AbstractHelper
{
/**
* StoreManager
*
* @var StoreManagerInterface
*/
public $storeManager;
/**
* SortType
*
* @var array
*/
public $SortType;
/**
* AddSortOption constructor.
*
* @param Context $context
* @param StoreManagerInterface $storeManager
* @param SortType $SortType
*/
public function __construct(
Context $context,
StoreManagerInterface $storeManager,
SortType $SortType
) {
$this->storeManager = $storeManager;
$this->SortType = $SortType->toOptionArray();
parent::__construct($context);
}
/**
* Add sort order option created_at to frontend
*
* @param \Magento\Catalog\Model\Config $configmodel
* @param array $options
*
* @return mixed
*/
public function afterGetAttributeUsedForSortByArray($configmodel, $options)
{
$isEnabled = $this->scopeConfig->getValue(
'sparshadvancedsorting/general/enabled',
ScopeInterface::SCOPE_STORE,
null
);
if ($isEnabled) {
$SortByList = $this->scopeConfig->getValue(
'sparshadvancedsorting/general/selectsort',
ScopeInterface::SCOPE_STORE,
null
);
foreach ($this->SortType as $optionlist) {
if (isset($options[$optionlist['value']])) {
unset($options[$optionlist['value']]);
}
}
unset($options['created_at']);
foreach (explode(',', $SortByList) as $items) {
foreach ($this->SortType as $optionlist) {
if (in_array($items, $optionlist)) {
$options[$optionlist['value']] = $optionlist['label']->getText();
}
}
}
}
return $options;
}
}
##Sparsh Advanced Sorting Extension
Advanced Sorting extension allows customers to sort products by Best Sellers, Top Rated, New Arrivals, Most Viewed, and Reviews Count options on catalog listing page.
##Support:
version - 2.3.x, 2.4.x
##How to install Extension
1. Download the archive file.
2. Unzip the files
3. Create a folder [Magento_Root]/app/code/Sparsh/AdvancedSorting
4. Drop/move the unzipped files to directory '[Magento_Root]/app/code/Sparsh/AdvancedSorting'
#Enable Extension:
- php bin/magento module:enable Sparsh_AdvancedSorting
- php bin/magento setup:upgrade
- php bin/magento setup:di:compile
- php bin/magento setup:static-content:deploy
- php bin/magento cache:flush
#Disable Extension:
- php bin/magento module:disable Sparsh_AdvancedSorting
- php bin/magento setup:upgrade
- php bin/magento setup:di:compile
- php bin/magento setup:static-content:deploy
- php bin/magento cache:flush
<?php
/**
* Class AddEavAttribute
*
* PHP version 7
*
* @category Sparsh
* @package Sparsh_AdvancedSorting
* @author Sparsh <magento@sparsh-technologies.com>
* @license https://www.sparsh-technologies.com Open Software License (OSL 3.0)
* @link https://www.sparsh-technologies.com
*/
namespace Sparsh\AdvancedSorting\Setup\Patch\Data;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchRevertableInterface;
use Magento\Eav\Setup\EavSetupFactory;
class AddEavAttribute
implements DataPatchInterface,
PatchRevertableInterface
{
/**
* Eav setup factory
*
* @var EavSetupFactory
*/
private $eavSetupFactory;
/**
* @var ModuleDataSetupInterface
*/
private $moduleDataSetup;
/**
* @param ModuleDataSetupInterface $moduleDataSetup
*/
public function __construct(
ModuleDataSetupInterface $moduleDataSetup,
EavSetupFactory $eavSetupFactory
) {
$this->moduleDataSetup = $moduleDataSetup;
$this->eavSetupFactory = $eavSetupFactory;
}
/**
* @inheritdoc
*/
public function apply()
{
$this->moduleDataSetup->getConnection()->startSetup();
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'review_count',
[
'type' => 'int',
'backend' => '',
'frontend' => '',
'label' => 'Review Count',
'input' => 'text',
'class' => '',
'source' => '',
'global'=> \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'visible' => false,
'required' => false,
'user_defined' => false,
'default' => 0,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_for_sort_by' => true,
'unique' => false,
'apply_to' => ''
]
);
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'best_seller',
[
'type' => 'int',
'backend' => '',
'frontend' => '',
'label' => 'Best Seller',
'input' => 'text',
'class' => '',
'source' => '',
'global'=> \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'visible' => false,
'required' => false,
'user_defined' => false,
'default' => 0,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_for_sort_by' => true,
'unique' => false,
'apply_to' => ''
]
);
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'top_rated',
[
'type' => 'int',
'backend' => '',
'frontend' => '',
'label' => 'Top Rated',
'input' => 'text',
'class' => '',
'source' => '',
'global'=> \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'visible' => false,
'required' => false,
'user_defined' => false,
'default' => 0,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_for_sort_by' => true,
'unique' => false,
'apply_to' => ''
]
);
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'most_viewed',
[
'type' => 'int',
'backend' => '',
'frontend' => '',
'label' => 'Most Viewed',
'input' => 'text',
'class' => '',
'source' => '',
'global'=> \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'visible' => false,
'required' => false,
'user_defined' => false,
'default' => 0,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_for_sort_by' => true,
'unique' => false,
'apply_to' => ''
]
);
$eavSetup->updateAttribute( \Magento\Catalog\Model\Product::ENTITY, 'created_at', 'used_for_sort_by', 1);
$this->moduleDataSetup->getConnection()->endSetup();
}
/**
* @inheritdoc
*/
public static function getDependencies()
{
return [
];
}
/**
* @inheritdoc
*/
public function revert()
{
$this->moduleDataSetup->getConnection()->startSetup();
$this->moduleDataSetup->getConnection()->endSetup();
}
/**
* @inheritdoc
*/
public function getAliases()
{
/**
* This internal Magento method, that means that some patches with time can change their names,
* but changing name should not affect installation process, that's why if we will change name of the patch
* we will add alias here
*/
return [];
}
}
\ No newline at end of file
{
"name": "sparsh/magento-2-advanced-sorting-extension",
"description": "Sparsh Advanced Sorting for Magento 2",
"type": "magento2-module",
"version": "1.3.0",
"license": "OSL-3.0",
"require": {
"php": "~7.0.13|~7.1.0|~7.2.0|~7.3.0|~7.4.0|^8.0"
},
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Sparsh\\AdvancedSorting\\": ""
}
}
}
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<tab id="sparsh" translate="label" sortOrder="500">
<label>Sparsh Extensions</label>
</tab>
<section id="sparshadvancedsorting" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
<class>separator-top</class>
<label>Advanced Sorting</label>
<tab>sparsh</tab>
<resource>Sparsh_AdvancedSorting::configuration</resource>
<group id="general" translate="label comment" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>General Configuration</label>
<field id="enabled" translate="label comment" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Enable</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment><![CDATA[Select <strong>Yes</strong> to enable this module]]></comment>
</field>
<field id="selectsort" translate="label" type="multiselect" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<source_model>Sparsh\AdvancedSorting\Model\System\SortType</source_model>
<label>Select Catalog Sort Type</label>
<depends>
<field id="enabled">1</field>
</depends>
</field>
</group>
</section>
</system>
</config>
<?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>
<sparshadvancedsorting>
<general>
<enabled>1</enabled>
<selectsort>best_seller,top_rated,created_at,most_viewed,review_count</selectsort>
</general>
</sparshadvancedsorting>
</default>
</config>
<?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\Catalog\Model\Config">
<plugin name="sortoption" type="Sparsh\AdvancedSorting\Plugin\AddSortOption" />
</type>
<preference for="Magento\Catalog\Block\Product\ProductList\Toolbar" type="Sparsh\AdvancedSorting\Block\Product\ProductList\Toolbar" />
</config>
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Indexer/etc/indexer.xsd">
<indexer id="sparsh_advanced_sorting_indexer" view_id="sparsh_advanced_sorting_indexer" class="Sparsh\AdvancedSorting\Model\Indexer\Index">
<title translate="true">Sparsh Advanced Sorting</title>
<description translate="true">Advanced Sorting Indexer</description>
</indexer>
</config>
<?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="Sparsh_AdvancedSorting" setup_version="1.3.0">
<sequence>
<module name="Magento_Catalog"/>
</sequence>
</module>
</config>
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Mview/etc/mview.xsd">
<view id="sparsh_advanced_sorting_indexer" class="Sparsh\AdvancedSorting\Model\Indexer\Index" group="indexer" />
</config>
<?php
/**
* Sparsh AdvancedSorting
*
* PHP version 7
*
* @category Sparsh
* @package Sparsh_AdvancedSorting
* @author Sparsh <magento@sparsh-technologies.com>
* @license https://www.sparsh-technologies.com Open Software License (OSL 3.0)
* @link https://www.sparsh-technologies.com
*/
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Sparsh_AdvancedSorting',
__DIR__
);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment