ltsecurityinc安防产品在线商城代码
This commit is contained in:
+53
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Amasty Improved Sorting GraphQl for Magento 2 (System)
|
||||
*/
|
||||
|
||||
namespace Amasty\SortingGraphQl\Plugin\Block\Widget\Featured;
|
||||
|
||||
use Amasty\Sorting\Block\Widget\Featured;
|
||||
use Magento\Framework\Serialize\Serializer\Json;
|
||||
|
||||
class AddWidgetParams
|
||||
{
|
||||
/**
|
||||
* @var Json
|
||||
*/
|
||||
private $json;
|
||||
|
||||
public function __construct(Json $json)
|
||||
{
|
||||
$this->json = $json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save widget parameters for variable,
|
||||
* for future rerender widget with this parameters.
|
||||
*
|
||||
* @param Featured $subject
|
||||
* @param string $html
|
||||
* @return string
|
||||
*/
|
||||
public function afterToHtml(Featured $subject, string $html): string
|
||||
{
|
||||
$data = $subject->getData() + ['template' => $this->parseTemplateName($subject->getTemplate())];
|
||||
$html = sprintf(
|
||||
'<div class="amsorting-widget-wrapper"><script>var amSortingConfig%s = "%s"</script>%s</div>',
|
||||
uniqid(),
|
||||
$this->json->serialize($data),
|
||||
$html
|
||||
);
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
private function parseTemplateName(string $template): string
|
||||
{
|
||||
return preg_replace('@Amasty_Sorting::widget/featured/(.*?).phtml@s', '$1', $template);
|
||||
}
|
||||
}
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Amasty Improved Sorting GraphQl for Magento 2 (System)
|
||||
*/
|
||||
|
||||
namespace Amasty\SortingGraphQl\Plugin\Catalog\Model\ResourceModel\Product;
|
||||
|
||||
use Amasty\SortingGraphQl\Model\Resolver\FeaturedList;
|
||||
use Magento\Catalog\Model\ResourceModel\Product\Collection;
|
||||
|
||||
class CollectionPlugin
|
||||
{
|
||||
/**
|
||||
* @var \Magento\CatalogInventory\Helper\Stock
|
||||
*/
|
||||
protected $stockHelper;
|
||||
|
||||
/**
|
||||
* @param \Magento\CatalogInventory\Helper\Stock $stockHelper
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\CatalogInventory\Helper\Stock $stockHelper
|
||||
) {
|
||||
$this->stockHelper = $stockHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add stock filter to collection.
|
||||
*
|
||||
* @param Collection $productCollection
|
||||
* @param bool $printQuery
|
||||
* @param bool $logQuery
|
||||
* @return array
|
||||
*/
|
||||
public function beforeLoad(Collection $productCollection, $printQuery = false, $logQuery = false)
|
||||
{
|
||||
if ($productCollection->getFlag(FeaturedList::AM_FEATURED_WIDGET)) {
|
||||
$this->stockHelper->addIsInStockFilterToCollection($productCollection);
|
||||
}
|
||||
|
||||
return [$printQuery, $logQuery];
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Amasty Improved Sorting GraphQl for Magento 2 (System)
|
||||
*/
|
||||
|
||||
namespace Amasty\SortingGraphQl\Plugin\CatalogGraphQl\DataProvider\Product\SearchCriteriaBuilder;
|
||||
|
||||
use Amasty\Sorting\Model\Catalog\Toolbar\GetDefaultDirection;
|
||||
use Amasty\Sorting\Model\ConfigProvider;
|
||||
use Amasty\Sorting\Model\IsSearchPage;
|
||||
use Magento\CatalogGraphQl\DataProvider\Product\SearchCriteriaBuilder;
|
||||
use Magento\Framework\Api\SortOrder;
|
||||
|
||||
class AddDefaultOrders
|
||||
{
|
||||
/**
|
||||
* @var IsSearchPage
|
||||
*/
|
||||
private $isSearchPage;
|
||||
|
||||
/**
|
||||
* @var ConfigProvider
|
||||
*/
|
||||
private $configProvider;
|
||||
|
||||
/**
|
||||
* @var GetDefaultDirection
|
||||
*/
|
||||
private $getDefaultDirection;
|
||||
|
||||
public function __construct(
|
||||
IsSearchPage $isSearchPage,
|
||||
ConfigProvider $configProvider,
|
||||
GetDefaultDirection $getDefaultDirection
|
||||
) {
|
||||
$this->isSearchPage = $isSearchPage;
|
||||
$this->configProvider = $configProvider;
|
||||
$this->getDefaultDirection = $getDefaultDirection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add default orders.
|
||||
* @see SearchCriteriaBuilder::build
|
||||
*
|
||||
* @param SearchCriteriaBuilder $subject
|
||||
* @param array $args
|
||||
* @param bool $includeAggregation
|
||||
* @return array
|
||||
*/
|
||||
public function beforeBuild(SearchCriteriaBuilder $subject, array $args, bool $includeAggregation): array
|
||||
{
|
||||
$defaultOrders = $this->isSearchPage->execute()
|
||||
? $this->configProvider->getDefaultSortingSearchPages()
|
||||
: $this->configProvider->getDefaultSortingCategoryPages();
|
||||
|
||||
if (isset($args['sort'])) {
|
||||
// first order already in array
|
||||
array_shift($defaultOrders);
|
||||
} else {
|
||||
// if orders not passed , fill all with default
|
||||
$args['sort'] = [];
|
||||
}
|
||||
|
||||
foreach ($defaultOrders as $defaultOrder) {
|
||||
$direction = $this->getDefaultDirection->execute($defaultOrder);
|
||||
$args['sort'][$defaultOrder] = $direction === 'desc' ? SortOrder::SORT_DESC : SortOrder::SORT_ASC;
|
||||
}
|
||||
|
||||
return [$args, $includeAggregation];
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Amasty Improved Sorting GraphQl for Magento 2 (System)
|
||||
*/
|
||||
|
||||
namespace Amasty\SortingGraphQl\Plugin\CatalogGraphQl\DataProvider\Product\SearchCriteriaBuilder;
|
||||
|
||||
use Amasty\Sorting\Model\MethodProvider;
|
||||
use Amasty\SortingGraphQl\Model\MethodProvider\CodeMap;
|
||||
use Magento\CatalogGraphQl\DataProvider\Product\SearchCriteriaBuilder;
|
||||
|
||||
class FixSortOrderCode
|
||||
{
|
||||
/**
|
||||
* @var MethodProvider
|
||||
*/
|
||||
private $methodProvider;
|
||||
|
||||
/**
|
||||
* @var CodeMap
|
||||
*/
|
||||
private $codeMap;
|
||||
|
||||
public function __construct(MethodProvider $methodProvider, CodeMap $codeMap)
|
||||
{
|
||||
$this->methodProvider = $methodProvider;
|
||||
$this->codeMap = $codeMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace sort code with method alias(which used in catalogsearch_fulltext indexation) for elastic.
|
||||
* @see SearchCriteriaBuilder::build
|
||||
*
|
||||
* @param SearchCriteriaBuilder $subject
|
||||
* @param array $args
|
||||
* @param bool $includeAggregation
|
||||
* @return array
|
||||
*/
|
||||
public function beforeBuild(SearchCriteriaBuilder $subject, array $args, bool $includeAggregation): array
|
||||
{
|
||||
if (isset($args['sort'])) {
|
||||
foreach ($args['sort'] as $sortCode => $direction) {
|
||||
$method = $this->methodProvider->getMethodByCode($sortCode);
|
||||
unset($args['sort'][$sortCode]);
|
||||
if ($method) {
|
||||
$alias = $method->getAlias();
|
||||
$args['sort'][$alias] = $direction;
|
||||
$this->codeMap->set($sortCode, $alias);
|
||||
} else {
|
||||
$args['sort'][$sortCode] = $direction;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [$args, $includeAggregation];
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Amasty Improved Sorting GraphQl for Magento 2 (System)
|
||||
*/
|
||||
|
||||
namespace Amasty\SortingGraphQl\Plugin\CatalogGraphQl\Model\Resolver\Product\MediaGallery\Url;
|
||||
|
||||
use Amasty\SortingGraphQl\Model\Resolver\Product\Image as ProductImageResolver;
|
||||
use Magento\CatalogGraphQl\Model\Resolver\Product\MediaGallery\Url;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\GraphQl\Config\Element\Field;
|
||||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
|
||||
use Magento\Framework\UrlInterface;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
|
||||
class CutBaseUrl
|
||||
{
|
||||
/**
|
||||
* Store manager
|
||||
*
|
||||
* @var StoreManagerInterface
|
||||
*/
|
||||
private $storeManager;
|
||||
|
||||
/**
|
||||
* @param StoreManagerInterface $storeManager
|
||||
*/
|
||||
public function __construct(StoreManagerInterface $storeManager)
|
||||
{
|
||||
$this->storeManager = $storeManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Url $subject
|
||||
* @param $result
|
||||
* @param Field $field
|
||||
* @param $context
|
||||
* @param ResolveInfo $info
|
||||
* @param null $value
|
||||
* @return array
|
||||
* @throws NoSuchEntityException
|
||||
*/
|
||||
public function afterResolve(
|
||||
Url $subject,
|
||||
$result,
|
||||
Field $field,
|
||||
$context,
|
||||
ResolveInfo $info,
|
||||
$value = null
|
||||
) {
|
||||
$isAmastyQuery = ($value[ProductImageResolver::IS_AMASTY_FLAG] ?? false);
|
||||
if ($isAmastyQuery) {
|
||||
$result = str_replace(
|
||||
$this->storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA),
|
||||
'',
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Amasty Improved Sorting GraphQl for Magento 2 (System)
|
||||
*/
|
||||
|
||||
namespace Amasty\SortingGraphQl\Plugin\CatalogGraphQl\Model\Resolver\Products\Query\Search;
|
||||
|
||||
use Amasty\SortingGraphQl\Model\SearchPageFlag;
|
||||
use Magento\CatalogGraphQl\Model\Resolver\Products\Query\Search;
|
||||
|
||||
class SetSearchFlag
|
||||
{
|
||||
/**
|
||||
* @var SearchPageFlag
|
||||
*/
|
||||
private $searchPageFlag;
|
||||
|
||||
public function __construct(SearchPageFlag $searchPageFlag)
|
||||
{
|
||||
$this->searchPageFlag = $searchPageFlag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Search $subject
|
||||
* @param array $args
|
||||
* @return void
|
||||
*/
|
||||
public function beforeGetResult(Search $subject, array $args): void
|
||||
{
|
||||
if (isset($args['search'])) {
|
||||
$this->searchPageFlag->set(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Amasty Improved Sorting GraphQl for Magento 2 (System)
|
||||
*/
|
||||
|
||||
namespace Amasty\SortingGraphQl\Plugin\Sorting\Model\Elasticsearch\IsElasticSort;
|
||||
|
||||
use Amasty\Sorting\Model\Elasticsearch\IsElasticSort;
|
||||
use Magento\Framework\App\Area;
|
||||
use Magento\Framework\App\State;
|
||||
|
||||
/**
|
||||
* Disabling elastic sorting for graphql, since a collection is created in the graphql area and plugins
|
||||
* for the front-end collection do not work, which is why elastic sorting does not work and need to apply mysql sorting.
|
||||
*/
|
||||
class DisableElasticSortForGraphQl
|
||||
{
|
||||
/**
|
||||
* @var State
|
||||
*/
|
||||
private $state;
|
||||
|
||||
public function __construct(
|
||||
State $state
|
||||
) {
|
||||
$this->state = $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IsElasticSort::execute()
|
||||
*/
|
||||
public function aroundExecute(IsElasticSort $subject, callable $proceed): bool
|
||||
{
|
||||
if ($this->state->getAreaCode() === Area::AREA_GRAPHQL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $proceed();
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Amasty Improved Sorting GraphQl for Magento 2 (System)
|
||||
*/
|
||||
|
||||
namespace Amasty\SortingGraphQl\Plugin\Sorting\Model\IsSearchPage;
|
||||
|
||||
use Amasty\Sorting\Model\IsSearchPage;
|
||||
use Amasty\SortingGraphQl\Model\SearchPageFlag;
|
||||
|
||||
class DetectSearchPage
|
||||
{
|
||||
/**
|
||||
* @var SearchPageFlag
|
||||
*/
|
||||
private $searchPageFlag;
|
||||
|
||||
public function __construct(SearchPageFlag $searchPageFlag)
|
||||
{
|
||||
$this->searchPageFlag = $searchPageFlag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param IsSearchPage $subject
|
||||
* @return bool
|
||||
*/
|
||||
public function aroundExecute(IsSearchPage $subject): bool
|
||||
{
|
||||
return $this->searchPageFlag->get();
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Amasty Improved Sorting GraphQl for Magento 2 (System)
|
||||
*/
|
||||
|
||||
namespace Amasty\SortingGraphQl\Plugin\Sorting\Model\Method\GetAttributeCodesForSorting;
|
||||
|
||||
use Amasty\Sorting\Model\Method\GetAttributeCodesForSorting;
|
||||
use Amasty\SortingGraphQl\Model\MethodProvider\CodeMap;
|
||||
|
||||
class DisableCodeMap
|
||||
{
|
||||
/**
|
||||
* @var CodeMap
|
||||
*/
|
||||
private $codeMap;
|
||||
|
||||
public function __construct(CodeMap $codeMap)
|
||||
{
|
||||
$this->codeMap = $codeMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see GetAttributeCodesForSorting::execute
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function aroundExecute(GetAttributeCodesForSorting $subject, callable $proceed)
|
||||
{
|
||||
$codeMap = $this->codeMap->getMap();
|
||||
|
||||
$this->codeMap->setMap(null);
|
||||
$result = $proceed();
|
||||
$this->codeMap->setMap($codeMap);
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Amasty Improved Sorting GraphQl for Magento 2 (System)
|
||||
*/
|
||||
|
||||
namespace Amasty\SortingGraphQl\Plugin\Sorting\Model\MethodProvider;
|
||||
|
||||
use Amasty\Sorting\Model\MethodProvider;
|
||||
use Amasty\SortingGraphQl\Model\MethodProvider\CodeMap;
|
||||
|
||||
class FixMethodCode
|
||||
{
|
||||
/**
|
||||
* @var CodeMap
|
||||
*/
|
||||
private $codeMap;
|
||||
|
||||
public function __construct(CodeMap $codeMap)
|
||||
{
|
||||
$this->codeMap = $codeMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Need in case when we replace order code in criteria for correct elastic search.
|
||||
*
|
||||
* @see MethodProvider::getMethodByCode
|
||||
*
|
||||
* @param MethodProvider $subject
|
||||
* @param string $code
|
||||
* @return array
|
||||
*/
|
||||
public function beforeGetMethodByCode(MethodProvider $subject, string $code): array
|
||||
{
|
||||
if ($originalCode = $this->codeMap->get($code)) {
|
||||
$code = $originalCode;
|
||||
}
|
||||
|
||||
return [$code];
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Amasty Improved Sorting GraphQl for Magento 2 (System)
|
||||
*/
|
||||
|
||||
namespace Amasty\SortingGraphQl\Plugin\Sorting\Plugin\Catalog;
|
||||
|
||||
use Amasty\Sorting\Plugin\Catalog\Config;
|
||||
|
||||
class ConfigPlugin
|
||||
{
|
||||
/**
|
||||
* @param Config $subject
|
||||
* @param array $options
|
||||
* @return array
|
||||
*/
|
||||
public function afterAfterGetAttributesUsedForSortBy(Config $subject, array $options)
|
||||
{
|
||||
foreach ($options as $key => $option) {
|
||||
$options[$key] = [
|
||||
'attribute_code' => $option->getData('attribute_code'),
|
||||
'frontend_label' => $option->getStoreLabel()
|
||||
];
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user