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,41 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Hide Price (Call for Price) for Magento 2
*/
namespace Amasty\HidePrice\Plugin\Catalog\Block\Product;
class Compare
{
/**
* @var \Amasty\HidePrice\Helper\Data
*/
private $helper;
public function __construct(
\Amasty\HidePrice\Helper\Data $helper
) {
$this->helper = $helper;
}
/**
* Hide add to Compare link
* @param $subject
* @param callable $proceed
* @return string
*/
public function aroundToHtml(
$subject,
callable $proceed
) {
if ($this->helper->getModuleConfig('information/hide_compare')
&& $this->helper->isApplied($subject->getProduct())
) {
return '';
}
return $proceed();
}
}
@@ -0,0 +1,217 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Hide Price (Call for Price) for Magento 2
*/
namespace Amasty\HidePrice\Plugin\Catalog\Block\Product\ProductList;
use Amasty\HidePrice\Helper\Data;
use Amasty\HidePrice\Model\Source\HideButton;
use Amasty\HidePrice\Model\DomWrapper;
use Amasty\HidePrice\Model\DomWrapperFactory;
class AbstractList
{
private $replacedJs;
/**
* @var Data
*/
private $helper;
/**
* @var \Magento\Framework\Registry
*/
private $coreRegistry;
/**
* @var \Psr\Log\LoggerInterface
*/
private $logger;
/**
* @var DomWrapperFactory
*/
private $domWrapperFactory;
public function __construct(
Data $helper,
\Magento\Framework\Registry $coreRegistry,
DomWrapperFactory $domWrapperFactory,
\Psr\Log\LoggerInterface $logger
) {
$this->helper = $helper;
$this->coreRegistry = $coreRegistry;
$this->logger = $logger;
$this->domWrapperFactory = $domWrapperFactory;
}
/**
* replace "add to cart" button if it needed
*
* @param string $html
* @return string
*/
protected function replaceButtonFromHtml($html)
{
if ($this->helper->getModuleConfig('information/hide_button') && $html) {
try {
$html = $this->processReplace($html);
} catch (\Exception $exception) {
$this->logger->critical($exception->getMessage());
}
}
return $html;
}
/**
* replace "add to cart" button if it needed
*
* @param string $html
* @return string
*/
protected function processReplace($html)
{
$html = $this->replaceJsCode($html);
$dom = new \DOMDocument('1.0', 'HTML-ENTITIES');
libxml_use_internal_errors(true);
$charset = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
$dom->loadHTML($charset . $html);
/** @var DomWrapper $domQuery */
$domQuery = $this->domWrapperFactory->create();
$domQuery->setContent($dom);
if ($domQuery->isInitialized()) {
foreach ($this->getProductsData() as $productData) {
$result = $domQuery->query(
$this->generateSelector($productData)
);
if ($result && count($result)) {
$domDoc = $result->getDocument();
$result->rewind();
$result = $result->current();
$replacement = $this->helper->getNewAddToCartHtml(null, $productData);
if ($this->helper->getModuleConfig('information/hide_button') == HideButton::HIDE
&& $result->parentNode
&& $result->parentNode->tagName == 'form'
) {
$result->parentNode->removeChild($result);
} else {
$replacementElement = $result->ownerDocument->createDocumentFragment();
$replacementElement->appendXML(htmlentities($replacement));
$result->parentNode->replaceChild($replacementElement, $result);
}
$domQuery->setContent($domDoc);
}
}
$html = $this->getHtml($domQuery->getDocument());
}
//phpcs:ignore
$html = html_entity_decode($html);
$html = str_replace($charset, '', $html);
$html = $this->revertJsCode($html);
return $html;
}
/**
* @param string $html
*
* @return string
*/
protected function replaceJsCode($html)
{
$this->replacedJs = [];
if (strpos($html, '<script') !== false) {
$html = preg_replace_callback(
'#(\<script[^\>]*\>)(.*?)(\<\/script\>)#ims',
[$this, 'replaceJS'],
$html
);
}
return $html;
}
/**
* @param string $html
*
* @return string
*/
protected function revertJsCode($html)
{
foreach ($this->replacedJs as $key => $js) {
$html = str_replace('{{HIDEPRICE_' . $key . '}}', $js, $html);
}
return $html;
}
/**
* @param string $docDocument
* @return mixed|null|string|string[]
*/
private function getHtml($docDocument)
{
$fragment = str_replace(
['<html>', '</html>', '<body>', '</body>', '<head>', '</head>'],
'',
$docDocument
);
$fragment = preg_replace('/^<!DOCTYPE.+?>/', '', $fragment);
return $fragment;
}
/**
* @param $matches
* @return string
*/
private function replaceJS($matches)
{
$text = '';
if (count($matches) >= 4) {
$this->replacedJs[] = $matches[2];
$text = $matches[1] . '{{HIDEPRICE_' . (count($this->replacedJs) - 1) . '}}' . $matches[3];
} elseif (isset($matches[0])) {
$text = $matches[0];
}
return $text;
}
/**
* @return array
*/
private function getProductsData()
{
$dataArray = $this->coreRegistry->registry('amasty_hideprice_data_array');
if (!$dataArray || !is_array($dataArray)) {
$dataArray = [];
}
return $dataArray;
}
/**
* get selector for one product
*
* @param array $productData
* @return string
*/
private function generateSelector($productData)
{
return 'form[data-product-sku="' . $productData['sku']
. '"] > button, form[data-role="tocart-form"][action*="product/' . $productData['id']
. '"] > button';
}
}
@@ -0,0 +1,25 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Hide Price (Call for Price) for Magento 2
*/
namespace Amasty\HidePrice\Plugin\Catalog\Block\Product\ProductList;
use Magento\Catalog\Block\Product\ListProduct;
class Category extends AbstractList
{
/**
* @param ListProduct $subject
* @param $html
* @return string
*/
public function afterToHtml(ListProduct $subject, $html)
{
$html = $this->replaceButtonFromHtml($html);
return $html;
}
}
@@ -0,0 +1,25 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Hide Price (Call for Price) for Magento 2
*/
namespace Amasty\HidePrice\Plugin\Catalog\Block\Product\ProductList;
use Magento\CatalogWidget\Block\Product\ProductsList;
class Widget extends AbstractList
{
/**
* @param ProductsList $subject
* @param $html
* @return string
*/
public function afterToHtml(ProductsList $subject, $html)
{
$html = $this->replaceButtonFromHtml($html);
return $html;
}
}
@@ -0,0 +1,80 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Hide Price (Call for Price) for Magento 2
*/
namespace Amasty\HidePrice\Plugin\Catalog\Block\Product;
use Magento\Catalog\Block\Product\View as MagentoView;
class View
{
/**
* @var \Amasty\HidePrice\Helper\Data
*/
private $helper;
/**
* @var \Magento\Framework\View\LayoutInterface
*/
private $layout;
public function __construct(
\Amasty\HidePrice\Helper\Data $helper,
\Magento\Framework\View\LayoutInterface $layout
) {
$this->helper = $helper;
$this->layout = $layout;
}
/**
* Hide Add to cart Button
* @param MagentoView $subject
* @param $result
* @return string
*/
public function afterToHtml(
MagentoView $subject,
$result
) {
$matchedNames = [
'product.info.addtocart.additional',
'product.info.addtocart',
'product.info.addtocart.bundle'
];
if (in_array($subject->getNameInLayout(), $matchedNames)
&& $this->helper->getModuleConfig('information/hide_button')
&& $this->helper->isApplied($subject->getProduct())
) {
preg_match('@<button[^>]*amquote-addto-button.*?<\/button>@s', $result, $quoteCartButton);
$result = $this->helper->getNewAddToCartHtml($subject->getProduct());
if (isset($quoteCartButton[0])) {
//compatibility with Amasty Request a Quote
$buttonBlock = $this->layout->createBlock(\Amasty\RequestQuote\Block\Product\Action::class);
if ($buttonBlock) {
$result .= $buttonBlock->toHtml();
}
}
}
return $result;
}
/**
* Hide meta data
* @param MagentoView $subject
*/
public function beforeToHtml(
MagentoView $subject
) {
if ($subject->getNameInLayout() == 'opengraph.general'
&& $subject->getProduct()
&& $this->helper->isNeedHideProduct($subject->getProduct())
) {
$subject->getProduct()->setData('final_price', 0);
}
}
}
@@ -0,0 +1,46 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Hide Price (Call for Price) for Magento 2
*/
namespace Amasty\HidePrice\Plugin\Catalog\Block\Product\View\Options;
class AbstractOptions
{
/**
* @var \Amasty\HidePrice\Helper\Data
*/
private $helper;
public function __construct(
\Amasty\HidePrice\Helper\Data $helper
) {
$this->helper = $helper;
}
/**
* Hide option price html
* @param $subject
* @param callable $proceed
* @return string
*/
public function aroundGetFormatedPrice(
$subject,
callable $proceed
) {
if ($this->helper->isNeedHideProduct($subject->getProduct())) {
return '';
}
return $proceed();
}
public function afterGetValuesHtml($subject, $result)
{
$result = str_replace('<span class="price-notice">+</span>', '', $result);
return $result;
}
}
@@ -0,0 +1,41 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Hide Price (Call for Price) for Magento 2
*/
namespace Amasty\HidePrice\Plugin\Catalog\Block\Product;
class Wishlist
{
/**
* @var \Amasty\HidePrice\Helper\Data
*/
private $helper;
public function __construct(
\Amasty\HidePrice\Helper\Data $helper
) {
$this->helper = $helper;
}
/**
* Hide Wishlist link
* @param $subject
* @param callable $proceed
* @return string
*/
public function aroundToHtml(
$subject,
callable $proceed
) {
if ($this->helper->getModuleConfig('information/hide_wishlist')
&& $this->helper->isApplied($subject->getProduct())
) {
return '';
}
return $proceed();
}
}
@@ -0,0 +1,35 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Hide Price (Call for Price) for Magento 2
*/
namespace Amasty\HidePrice\Plugin\Catalog\Model\Option;
class Value
{
/**
* @var \Amasty\HidePrice\Helper\Data
*/
private $helper;
public function __construct(
\Amasty\HidePrice\Helper\Data $helper
) {
$this->helper = $helper;
}
public function afterGetPrice(
$subject,
$result
) {
if ($this->helper->isNeedHideProduct($subject->getOption()->getProduct())
&& !$subject->getOption()->getDisableHideprice()
) {
return '';
}
return $result;
}
}
@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Hide Price (Call for Price) for Magento 2
*/
namespace Amasty\HidePrice\Plugin\Catalog\Model\Product\Option\Type;
use Magento\Catalog\Model\Product\Option\Type\Select;
class DisableOptionsHidePriceInQuote
{
/**
* @see Select::getOptionPrice()
*
* @param Select $subject
* @param string $result
*
* @return void
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function beforeGetOptionPrice(Select $subject, string $result): void
{
$subject->getOption()->setData('disable_hideprice', true);
}
}
@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Hide Price (Call for Price) for Magento 2
*/
namespace Amasty\HidePrice\Plugin\Catalog\Pricing\Price\FinalPrice;
use Amasty\HidePrice\Helper\Data;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Pricing\Price\FinalPrice;
use Magento\Framework\Pricing\Amount\AmountInterface;
use Magento\Framework\Pricing\Amount\BaseFactory as BaseAmountFactory;
use Magento\Framework\Registry;
class HideMinAndMaxPrice
{
/**
* @var Data
*/
private $helper;
/**
* @var Registry
*/
private $registry;
/**
* @var BaseAmountFactory
*/
private $baseAmountFactory;
public function __construct(
Data $helper,
Registry $registry,
BaseAmountFactory $baseAmountFactory
) {
$this->helper = $helper;
$this->registry = $registry;
$this->baseAmountFactory = $baseAmountFactory;
}
public function afterGetMinimalPrice(FinalPrice $subject, AmountInterface $result): AmountInterface
{
if ($this->isNeedHidePrice($subject->getProduct())) {
$result = $this->getZeroPrice();
}
return $result;
}
public function afterGetMaximalPrice(FinalPrice $subject, AmountInterface $result): AmountInterface
{
if ($this->isNeedHidePrice($subject->getProduct())) {
$result = $this->getZeroPrice();
}
return $result;
}
private function isNeedHidePrice(Product $product): bool
{
if ($this->helper->getModuleConfig('information/hide_price')
&& !$this->registry->registry('hideprice_off')
&& $this->helper->isApplied($product)
) {
return true;
}
return false;
}
private function getZeroPrice(): AmountInterface
{
return $this->baseAmountFactory->create(['amount' => 0]);
}
}
@@ -0,0 +1,36 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Hide Price (Call for Price) for Magento 2
*/
namespace Amasty\HidePrice\Plugin\Catalog\Pricing\Tier;
use Magento\Catalog\Pricing\Price\TierPrice as NativeTierPrice;
use Magento\Framework\Pricing\Amount\AmountInterface;
class TierPrice
{
/**
* @param NativeTierPrice $subject
* @param \Closure $proceed
* @param AmountInterface $amount
*
* @return int|mixed
*/
public function aroundGetSavePercent(
NativeTierPrice $subject,
\Closure $proceed,
AmountInterface $amount
) {
$result = 0;
if ($subject->getProduct()
&& $subject->getProduct()->getPriceInfo()->getPrice('final_price')->getAmount()->getValue()
) {
$result = $proceed($amount);;
}
return $result;
}
}