ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Improved Sorting for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\Sorting\Model\Source;
|
||||
|
||||
/**
|
||||
* Class Stock
|
||||
*/
|
||||
abstract class AbstractShowLast implements \Magento\Framework\Data\OptionSourceInterface
|
||||
{
|
||||
public const DISABLED = 0;
|
||||
|
||||
public const SHOW_LAST = 1;
|
||||
|
||||
public const SHOW_LAST_FOR_CATALOG = 2;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toOptionArray()
|
||||
{
|
||||
$options = [
|
||||
[
|
||||
'value' => self::DISABLED,
|
||||
'label' => __('No')
|
||||
],
|
||||
[
|
||||
'value' => self::SHOW_LAST,
|
||||
'label' => __('Yes')
|
||||
],
|
||||
[
|
||||
'value' => self::SHOW_LAST_FOR_CATALOG,
|
||||
'label' => __('Yes for Catalog, No for Search')
|
||||
]
|
||||
];
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Improved Sorting for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\Sorting\Model\Source;
|
||||
|
||||
use Amasty\Sorting\Model\Plugin\Catalog\Config\DisplayAllFlag;
|
||||
use Magento\Catalog\Model\Config;
|
||||
use Magento\Framework\Data\OptionSourceInterface;
|
||||
|
||||
class AllSortingAttributes implements OptionSourceInterface
|
||||
{
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
private $catalogConfig;
|
||||
|
||||
/**
|
||||
* @var DisplayAllFlag
|
||||
*/
|
||||
private $displayAllFlag;
|
||||
|
||||
public function __construct(Config $catalogConfig, DisplayAllFlag $displayAllFlag)
|
||||
{
|
||||
$this->catalogConfig = $catalogConfig;
|
||||
$this->displayAllFlag = $displayAllFlag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array of options as value-label pairs
|
||||
*
|
||||
* @return array Format: array(array('value' => '<value>', 'label' => '<label>'), ...)
|
||||
*/
|
||||
public function toOptionArray()
|
||||
{
|
||||
$options = [];
|
||||
|
||||
$this->displayAllFlag->set(true);
|
||||
$allAttributes = $this->catalogConfig->getAttributeUsedForSortByArray();
|
||||
$this->displayAllFlag->set(false);
|
||||
|
||||
foreach ($allAttributes as $code => $label) {
|
||||
$options[] = [
|
||||
'label' => $label,
|
||||
'value' => $code
|
||||
];
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Improved Sorting for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\Sorting\Model\Source;
|
||||
|
||||
class CategorySortAfter extends AllSortingAttributes
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toOptionArray(): array
|
||||
{
|
||||
$options = parent::toOptionArray();
|
||||
array_unshift($options, [
|
||||
'value' => '',
|
||||
'label' => __('--Please Select--')
|
||||
]);
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Improved Sorting for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\Sorting\Model\Source;
|
||||
|
||||
/**
|
||||
* Class Image
|
||||
*/
|
||||
class Image extends AbstractShowLast
|
||||
{
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Improved Sorting for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\Sorting\Model\Source;
|
||||
|
||||
use Magento\Catalog\Model\Config\Source\ListSort as NativeListSort;
|
||||
|
||||
class ListSort extends NativeListSort
|
||||
{
|
||||
public const IGNORE_ATTRIBUTES = [
|
||||
'price_asc',
|
||||
'price_desc'
|
||||
];
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $enabledIgnoreAttributes = true;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toOptionArray()
|
||||
{
|
||||
$options = parent::toOptionArray();
|
||||
|
||||
foreach ($options as $key => $option) {
|
||||
if (isset($option['value'])
|
||||
&& $this->enabledIgnoreAttributes
|
||||
&& in_array($option['value'], self::IGNORE_ATTRIBUTES)
|
||||
) {
|
||||
unset($options[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function getAllOptions(): array
|
||||
{
|
||||
$this->enabledIgnoreAttributes = false;
|
||||
$options = $this->toOptionArray();
|
||||
$this->enabledIgnoreAttributes = true;
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Improved Sorting for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\Sorting\Model\Source;
|
||||
|
||||
/**
|
||||
* Class Methods
|
||||
*/
|
||||
class Methods implements \Magento\Framework\Data\OptionSourceInterface
|
||||
{
|
||||
/**
|
||||
* @var \Amasty\Sorting\Model\MethodProvider
|
||||
*/
|
||||
private $methodProvider;
|
||||
|
||||
public function __construct(
|
||||
\Amasty\Sorting\Model\MethodProvider $methodProvider
|
||||
) {
|
||||
$this->methodProvider = $methodProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toOptionArray()
|
||||
{
|
||||
$options = [];
|
||||
|
||||
foreach ($this->methodProvider->getMethods() as $methodObject) {
|
||||
$options[] = [
|
||||
'value' => $methodObject->getMethodCode(),
|
||||
'label' => $methodObject->getMethodName()
|
||||
];
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Improved Sorting for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\Sorting\Model\Source;
|
||||
|
||||
/**
|
||||
* Class Price
|
||||
*/
|
||||
class Price implements \Magento\Framework\Data\OptionSourceInterface
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toOptionArray()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'value' => 'min_price',
|
||||
'label' => __('Minimal Price'),
|
||||
],
|
||||
[
|
||||
'value' => 'price',
|
||||
'label' => __('Price'),
|
||||
],
|
||||
[
|
||||
'value' => 'final_price',
|
||||
'label' => __('Final Price'),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Improved Sorting for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\Sorting\Model\Source;
|
||||
|
||||
/**
|
||||
* Class ProductAttribute
|
||||
*/
|
||||
class ProductAttribute implements \Magento\Framework\Data\OptionSourceInterface
|
||||
{
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* @var \Magento\Eav\Model\Config
|
||||
*/
|
||||
private $eavConfig;
|
||||
|
||||
/**
|
||||
* ProductAttribute constructor.
|
||||
*
|
||||
* @param \Magento\Eav\Model\Config $eavConfig
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Eav\Model\Config $eavConfig
|
||||
) {
|
||||
$this->eavConfig = $eavConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toOptionArray()
|
||||
{
|
||||
if (!$this->options) {
|
||||
$this->options = [['value' => '', 'label' => ' ']];
|
||||
$attributes = $this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)
|
||||
->getAttributeCollection()
|
||||
->addFieldToFilter('frontend_input', ['nin' => ['multiselect', 'gallery', 'textarea']])
|
||||
->addFieldToFilter('used_in_product_listing', 1)
|
||||
->getItems();
|
||||
|
||||
foreach ($attributes as $item) {
|
||||
$this->options[] = [
|
||||
'value' => $item->getAttributeCode(),
|
||||
'label' => __($item->getFrontendLabel()),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->options;
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Improved Sorting for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\Sorting\Model\Source;
|
||||
|
||||
use Magento\Catalog\Model\Config\Source\ListSort;
|
||||
|
||||
class SearchSort extends ListSort
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toOptionArray()
|
||||
{
|
||||
$options = parent::toOptionArray();
|
||||
array_shift($options);
|
||||
array_unshift($options, [
|
||||
'value' => 'relevance',
|
||||
'label' => __('Relevance')
|
||||
]);
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Improved Sorting for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\Sorting\Model\Source;
|
||||
|
||||
class SearchSortAfter extends AllSortingAttributes
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toOptionArray(): array
|
||||
{
|
||||
$options = parent::toOptionArray();
|
||||
array_shift($options);
|
||||
array_unshift($options, [
|
||||
'value' => 'relevance',
|
||||
'label' => __('Relevance')
|
||||
]);
|
||||
array_unshift($options, [
|
||||
'value' => '',
|
||||
'label' => __('--Please Select--')
|
||||
]);
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Improved Sorting for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\Sorting\Model\Source;
|
||||
|
||||
use Amasty\Sorting\Model\ConfigProvider;
|
||||
|
||||
class SortOptions
|
||||
{
|
||||
/**
|
||||
* @var ConfigProvider
|
||||
*/
|
||||
private $configProvider;
|
||||
|
||||
public function __construct(
|
||||
ConfigProvider $configProvider
|
||||
) {
|
||||
$this->configProvider = $configProvider;
|
||||
}
|
||||
|
||||
public function execute(array $options): array
|
||||
{
|
||||
if ($this->configProvider->getSortOrder()) {
|
||||
uksort($options, [$this, "sortingRule"]);
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
private function sortingRule(string $leftItem, string $rightItem): int
|
||||
{
|
||||
$correctSortOrder = array_flip(array_keys($this->configProvider->getSortOrder()));
|
||||
$leftPos = $correctSortOrder[$leftItem] ?? 0;
|
||||
$rightPos = $correctSortOrder[$rightItem] ?? 0;
|
||||
|
||||
return $leftPos <=> $rightPos;
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Improved Sorting for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\Sorting\Model\Source;
|
||||
|
||||
use Magento\Framework\Data\OptionSourceInterface;
|
||||
|
||||
class SortOrder implements OptionSourceInterface
|
||||
{
|
||||
public const SORT_ASC = 'asc';
|
||||
public const SORT_DESC = 'desc';
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toOptionArray(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'value' => self::SORT_DESC,
|
||||
'label' => __('DESC')
|
||||
],
|
||||
[
|
||||
'value' => self::SORT_ASC,
|
||||
'label' => __('ASC')
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Improved Sorting for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\Sorting\Model\Source;
|
||||
|
||||
class State implements \Magento\Framework\Option\ArrayInterface
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* @var \Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory
|
||||
*/
|
||||
private $statusCollectionFactory;
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\ObjectManagerInterface $objectManager
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory $statusCollectionFactory
|
||||
) {
|
||||
$this->statusCollectionFactory = $statusCollectionFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toOptionArray()
|
||||
{
|
||||
if (!$this->options) {
|
||||
/** @var \Magento\Sales\Model\Order\Status[] $statusItems */
|
||||
$statusItems = $this->statusCollectionFactory->create()->getItems();
|
||||
|
||||
foreach ($statusItems as $status) {
|
||||
$this->options[] = ['value' => $status->getStatus(), 'label' => $status->getLabel()];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->options;
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Improved Sorting for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\Sorting\Model\Source;
|
||||
|
||||
/**
|
||||
* Class Stock
|
||||
*/
|
||||
class Stock extends AbstractShowLast
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user