ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_Base
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license/ End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\Base\ViewModel\Catalog;
|
||||
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Framework\View\Element\Block\ArgumentInterface;
|
||||
|
||||
/**
|
||||
* @since 2.3.6
|
||||
*/
|
||||
class CurrentProductRetriever implements ArgumentInterface
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\Registry
|
||||
*/
|
||||
private $coreRegistry;
|
||||
|
||||
/**
|
||||
* GetCurrentProduct constructor.
|
||||
*
|
||||
* @param \Magento\Framework\Registry $coreRegistry
|
||||
*/
|
||||
public function __construct(Registry $coreRegistry)
|
||||
{
|
||||
$this->coreRegistry = $coreRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current product model.
|
||||
*
|
||||
* @return null|\Magento\Catalog\Model\Product|\Magento\Catalog\Api\Data\ProductInterface
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
/** @var \Magento\Catalog\Model\Product $product */
|
||||
$product = $this->coreRegistry->registry('product');
|
||||
|
||||
return $product ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current product id.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->get() ? (int) $this->get()->getId() : 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_Base
|
||||
* @copyright Copyright (c) 2024 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\Base\ViewModel;
|
||||
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Magento\Framework\View\Element\Block\ArgumentInterface;
|
||||
|
||||
/**
|
||||
* @since 2.11.5
|
||||
*/
|
||||
class CspNonce implements ArgumentInterface
|
||||
{
|
||||
public function getNonce(): string
|
||||
{
|
||||
if (class_exists(\Magento\Csp\Helper\CspNonceProvider::class)) {
|
||||
$cspNonceProvider = ObjectManager::getInstance()->get(\Magento\Csp\Helper\CspNonceProvider::class);
|
||||
return ' nonce="' . $cspNonceProvider->generateNonce() . '"';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_Base
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license/ End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\Base\ViewModel;
|
||||
|
||||
use Magento\Framework\Exception\NotFoundException;
|
||||
use Plumrocket\Base\Api\GetExtensionInformationInterface;
|
||||
use Plumrocket\Base\Model\Extension\GetListOfInstalled;
|
||||
use Plumrocket\Base\Model\Extension\Updates\Get as GetUpdates;
|
||||
|
||||
/**
|
||||
* @since 2.3.0
|
||||
*/
|
||||
class GetExtensionInformationWithUpdates
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\GetListOfInstalled
|
||||
*/
|
||||
private $getPlumrocketInstalledExtensions;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\Updates\Get
|
||||
*/
|
||||
private $getUpdates;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Api\GetExtensionInformationInterface
|
||||
*/
|
||||
private $getExtensionInformation;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\Base\Model\Extension\GetListOfInstalled $getPlumrocketInstalledExtensions
|
||||
* @param \Plumrocket\Base\Model\Extension\Updates\Get $getUpdates
|
||||
* @param \Plumrocket\Base\Api\GetExtensionInformationInterface $getExtensionInformation
|
||||
*/
|
||||
public function __construct(
|
||||
GetListOfInstalled $getPlumrocketInstalledExtensions,
|
||||
GetUpdates $getUpdates,
|
||||
GetExtensionInformationInterface $getExtensionInformation
|
||||
) {
|
||||
$this->getPlumrocketInstalledExtensions = $getPlumrocketInstalledExtensions;
|
||||
$this->getUpdates = $getUpdates;
|
||||
$this->getExtensionInformation = $getExtensionInformation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get extensions updates information.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function execute(): array
|
||||
{
|
||||
$extensions = $this->getPlumrocketInstalledExtensions->execute();
|
||||
try {
|
||||
$updates = $this->getUpdates->execute($extensions);
|
||||
} catch (NotFoundException $e) {
|
||||
$updates = false;
|
||||
}
|
||||
|
||||
$result = [];
|
||||
foreach ($extensions as $extensionName) {
|
||||
$extensionInfo = $this->getExtensionInformation->execute($extensionName);
|
||||
if ($extensionInfo->isService()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$extensionData = [
|
||||
'moduleName' => $extensionInfo->getModuleName(),
|
||||
'name' => $extensionInfo->getTitle() ?: $extensionName,
|
||||
'documentation' => $extensionInfo->getDocumentationLink(),
|
||||
'installedVersion' => $extensionInfo->getInstalledVersion(),
|
||||
];
|
||||
|
||||
if (false !== $updates) {
|
||||
$extensionData['successFetchUpdates'] = true;
|
||||
$extensionData['updates'] = $updates[$extensionName];
|
||||
} else {
|
||||
$extensionData['successFetchUpdates'] = false;
|
||||
$extensionData['updates'] = [];
|
||||
}
|
||||
|
||||
$result[] = $extensionData;
|
||||
}
|
||||
|
||||
usort(
|
||||
$result,
|
||||
static function ($extension1, $extension2) {
|
||||
$hasUpdates1 = empty($extension1['updates']);
|
||||
$hasUpdates2 = empty($extension2['updates']);
|
||||
if ($hasUpdates1 !== $hasUpdates2) {
|
||||
return $hasUpdates1 <=> $hasUpdates2;
|
||||
}
|
||||
|
||||
return $extension1['name'] <=> $extension2['name'];
|
||||
}
|
||||
);
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user