ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Hide Price (Call for Price) for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\HidePrice\Model\Config\Backend\Popup;
|
||||
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Amasty\HidePrice\Model\Source\ReplaceButton;
|
||||
|
||||
class Customform extends \Magento\Framework\App\Config\Value
|
||||
{
|
||||
/**
|
||||
* @return $this
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
if ($this->getValue() == ReplaceButton::CUSTOM_FORM
|
||||
&& $this->getModuleManager()
|
||||
&& $this->getModuleManager()->isEnabled('Amasty_Customform') === false
|
||||
) {
|
||||
throw new LocalizedException(
|
||||
__('Custom Forms module was not installed.')
|
||||
);
|
||||
}
|
||||
|
||||
return parent::save();
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
<?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\Model;
|
||||
|
||||
use Amasty\Base\Model\ConfigProviderAbstract;
|
||||
|
||||
class ConfigProvider extends ConfigProviderAbstract
|
||||
{
|
||||
private const ENABLE = 'general/enabled';
|
||||
private const HIDE_WISHLIST = 'information/hide_wishlist';
|
||||
private const HIDE_COMPARE = 'information/hide_compare';
|
||||
private const HIDE_ADD_TO_CART = 'information/hide_button';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $pathPrefix = 'amasty_hide_price/';
|
||||
|
||||
public function isEnabled(?int $storeId = null): bool
|
||||
{
|
||||
return $this->isSetFlag(self::ENABLE, $storeId);
|
||||
}
|
||||
|
||||
public function isHideWishlist(?int $storeId = null): bool
|
||||
{
|
||||
return $this->isSetFlag(self::HIDE_WISHLIST, $storeId);
|
||||
}
|
||||
|
||||
public function isHideCompare(?int $storeId = null): bool
|
||||
{
|
||||
return $this->isSetFlag(self::HIDE_COMPARE, $storeId);
|
||||
}
|
||||
|
||||
public function isHideAddToCart(?int $storeId = null): bool
|
||||
{
|
||||
return $this->isSetFlag(self::HIDE_ADD_TO_CART, $storeId);
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Hide Price (Call for Price) for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\HidePrice\Model;
|
||||
|
||||
class DomWrapper
|
||||
{
|
||||
/**
|
||||
* @var null|\Laminas\Dom\Query|\Zend\Dom\Query|\Zend_Dom_Query
|
||||
*/
|
||||
private $domQuery = null;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $initialized = false;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $executeMethod = 'query';
|
||||
|
||||
/**
|
||||
* @param \DOMDocument $domDocument
|
||||
*/
|
||||
public function setContent(\DOMDocument $domDocument)
|
||||
{
|
||||
if (class_exists(\Laminas\Dom\Query::class)) {
|
||||
$this->domQuery = new \Laminas\Dom\Query($domDocument->saveHTML());
|
||||
$this->executeMethod = 'execute';
|
||||
$this->initialized = true;
|
||||
} elseif (class_exists(\Zend\Dom\Query::class)) {
|
||||
$this->domQuery = new \Zend\Dom\Query($domDocument->saveHTML());
|
||||
$this->executeMethod = 'execute';
|
||||
} elseif (class_exists(\Zend_Dom_Query::class)) {
|
||||
$this->domQuery = new \Zend_Dom_Query($domDocument);
|
||||
$this->initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $selector
|
||||
*
|
||||
* @return \Laminas\Dom\NodeList|array
|
||||
*/
|
||||
public function query($selector)
|
||||
{
|
||||
if ($this->domQuery) {
|
||||
$result = $this->domQuery->{$this->executeMethod}($selector);
|
||||
} else {
|
||||
$result = [];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDocument()
|
||||
{
|
||||
if ($this->domQuery) {
|
||||
/** @var string|\DOMDocument $document */
|
||||
$document = $this->domQuery->getDocument();
|
||||
if (!is_string($document)) {
|
||||
$document = $document->saveHTML();
|
||||
}
|
||||
} else {
|
||||
$document = '';
|
||||
}
|
||||
|
||||
return $document;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isInitialized()
|
||||
{
|
||||
return $this->initialized;
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
<?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\Model;
|
||||
|
||||
use Amasty\HidePrice\Helper\Data;
|
||||
use Magento\Catalog\Api\Data\ProductInterface;
|
||||
use Magento\Framework\Pricing\Render as PricingRender;
|
||||
use Magento\Framework\Pricing\SaleableInterface;
|
||||
|
||||
class IsNeedRenderPrice
|
||||
{
|
||||
/**
|
||||
* @var ConfigProvider
|
||||
*/
|
||||
private $configProvider;
|
||||
|
||||
/**
|
||||
* @var Data
|
||||
*/
|
||||
private $helper;
|
||||
|
||||
public function __construct(
|
||||
ConfigProvider $configProvider,
|
||||
Data $helper
|
||||
) {
|
||||
$this->configProvider = $configProvider;
|
||||
$this->helper = $helper;
|
||||
}
|
||||
|
||||
public function execute(SaleableInterface $saleableItem, array $arguments): bool
|
||||
{
|
||||
// if Item not a product - show price
|
||||
$isNotProduct = !($saleableItem instanceof ProductInterface);
|
||||
// is current price block zone is not list, view or option
|
||||
$isNoZone = (key_exists('zone', $arguments)
|
||||
&& !in_array(
|
||||
$arguments['zone'],
|
||||
[PricingRender::ZONE_ITEM_LIST, PricingRender::ZONE_ITEM_VIEW, PricingRender::ZONE_ITEM_OPTION]
|
||||
)
|
||||
);
|
||||
$isShowPrice = !$this->configProvider->isEnabled()
|
||||
|| $isNotProduct
|
||||
|| $isNoZone
|
||||
|| !$this->helper->isNeedHideProduct($saleableItem);
|
||||
|
||||
return $isShowPrice;
|
||||
}
|
||||
}
|
||||
Executable
+189
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Hide Price (Call for Price) for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\HidePrice\Model;
|
||||
|
||||
class Request extends \Magento\Framework\Model\AbstractModel implements \Amasty\HidePrice\Api\Data\RequestInterface
|
||||
{
|
||||
/**
|
||||
* Model Init
|
||||
*
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
parent::_construct();
|
||||
$this->_init('Amasty\HidePrice\Model\ResourceModel\Request');
|
||||
$this->setIdFieldName('request_id');
|
||||
}
|
||||
|
||||
/**#@+
|
||||
* Standard Getter and Setters start
|
||||
*/
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRequestId()
|
||||
{
|
||||
return $this->getData(self::REQUEST_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setRequestId($requestId)
|
||||
{
|
||||
return $this->setData(self::REQUEST_ID, $requestId);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->getData(self::NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
return $this->setData(self::NAME, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getProductId()
|
||||
{
|
||||
return $this->getData(self::PRODUCT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setProductId($productId)
|
||||
{
|
||||
return $this->setData(self::PRODUCT_ID, $productId);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getStoreId()
|
||||
{
|
||||
return $this->getData(self::STORE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setStoreId($storeId)
|
||||
{
|
||||
return $this->setData(self::STORE_ID, $storeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getEmail()
|
||||
{
|
||||
return $this->getData(self::EMAIL);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setEmail($email)
|
||||
{
|
||||
return $this->setData(self::EMAIL, $email);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPhone()
|
||||
{
|
||||
return $this->getData(self::PHONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setPhone($phone)
|
||||
{
|
||||
return $this->setData(self::PHONE, $phone);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getComment()
|
||||
{
|
||||
return $this->getData(self::COMMENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setComment($comment)
|
||||
{
|
||||
return $this->setData(self::COMMENT, $comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCreatedAt()
|
||||
{
|
||||
return $this->getData(self::CREATED_AT);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setCreatedAt($flag)
|
||||
{
|
||||
return $this->setData(self::CREATED_AT, $flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getStatus()
|
||||
{
|
||||
return $this->getData(self::STATUS);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setStatus($status)
|
||||
{
|
||||
return $this->setData(self::STATUS, $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMessageText()
|
||||
{
|
||||
return $this->getData(self::MESSAGE_TEXT);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setMessageText($text)
|
||||
{
|
||||
return $this->setData(self::MESSAGE_TEXT, $text);
|
||||
}
|
||||
/**#@-
|
||||
* Standard Getter and Setters finish
|
||||
*/
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Hide Price (Call for Price) for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\HidePrice\Model;
|
||||
|
||||
use Amasty\HidePrice\Api\Data;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Exception\CouldNotDeleteException;
|
||||
use Magento\Framework\Exception\CouldNotSaveException;
|
||||
|
||||
class RequestRepository implements \Amasty\HidePrice\Api\RequestRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $request = [];
|
||||
|
||||
/**
|
||||
* @var ResourceModel\Request
|
||||
*/
|
||||
private $requestResource;
|
||||
|
||||
/**
|
||||
* @var RequestFactory
|
||||
*/
|
||||
private $requestFactory;
|
||||
|
||||
public function __construct(
|
||||
\Amasty\HidePrice\Model\ResourceModel\Request $requestResource,
|
||||
\Amasty\HidePrice\Model\RequestFactory $requestFactory
|
||||
) {
|
||||
$this->requestResource = $requestResource;
|
||||
$this->requestFactory = $requestFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function save(Data\RequestInterface $request)
|
||||
{
|
||||
if ($request->getRequestId()) {
|
||||
$request = $this->get($request->getRequestId())->addData($request->getData());
|
||||
}
|
||||
|
||||
try {
|
||||
$this->requestResource->save($request);
|
||||
unset($this->request[$request->getRequestId()]);
|
||||
} catch (\Exception $e) {
|
||||
if ($request->getRequestId()) {
|
||||
throw new CouldNotSaveException(
|
||||
__('Unable to save request with ID %1. Error: %2', [$request->getRequestId(), $e->getMessage()])
|
||||
);
|
||||
}
|
||||
throw new CouldNotSaveException(__('Unable to save new request. Error: %1', $e->getMessage()));
|
||||
}
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($requestId)
|
||||
{
|
||||
if (!isset($this->request[$requestId])) {
|
||||
/** @var \Amasty\HidePrice\Model\Request $request */
|
||||
$request = $this->requestFactory->create();
|
||||
$this->requestResource->load($request, $requestId);
|
||||
if (!$request->getRequestId()) {
|
||||
throw new NoSuchEntityException(__('Request with specified ID "%1" not found.', $requestId));
|
||||
}
|
||||
$this->request[$requestId] = $request;
|
||||
}
|
||||
return $this->request[$requestId];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete(Data\RequestInterface $request)
|
||||
{
|
||||
try {
|
||||
$this->requestResource->delete($request);
|
||||
unset($this->request[$request->getRequestId()]);
|
||||
} catch (\Exception $e) {
|
||||
if ($request->getRequestId()) {
|
||||
throw new CouldNotDeleteException(
|
||||
__('Unable to remove request with ID %1. Error: %2', [$request->getRequestId(), $e->getMessage()])
|
||||
);
|
||||
}
|
||||
throw new CouldNotDeleteException(__('Unable to remove request rule. Error: %1', $e->getMessage()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteById($requestId)
|
||||
{
|
||||
$model = $this->get($requestId);
|
||||
$this->delete($model);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Hide Price (Call for Price) for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\HidePrice\Model\ResourceModel;
|
||||
|
||||
class Request extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
|
||||
{
|
||||
/**
|
||||
* Model Initialization
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init('amasty_hideprice_request', 'request_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Hide Price (Call for Price) for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\HidePrice\Model\ResourceModel\Request;
|
||||
|
||||
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
|
||||
{
|
||||
/**
|
||||
* Define resource model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(\Amasty\HidePrice\Model\Request::class, \Amasty\HidePrice\Model\ResourceModel\Request::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $ids
|
||||
*/
|
||||
public function deleteByIds(array $ids)
|
||||
{
|
||||
$this->getConnection()->delete(
|
||||
$this->getMainTable(),
|
||||
['request_id IN(?)' => $ids]
|
||||
);
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
<?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\Model\Source;
|
||||
|
||||
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory;
|
||||
use Magento\Framework\Api\SortOrder;
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use Magento\Framework\Data\OptionSourceInterface;
|
||||
use Magento\Store\Model\Store;
|
||||
|
||||
class Category implements OptionSourceInterface
|
||||
{
|
||||
public const NONE = 0;
|
||||
public const SYSTEM_CATEGORY_ID = 0;
|
||||
public const ROOT_LEVEL = 0;
|
||||
|
||||
/**
|
||||
* @var CollectionFactory
|
||||
*/
|
||||
private $collectionFactory;
|
||||
|
||||
/**
|
||||
* @var RequestInterface
|
||||
*/
|
||||
private $request;
|
||||
|
||||
public function __construct(
|
||||
CollectionFactory $collectionFactory,
|
||||
RequestInterface $request
|
||||
) {
|
||||
$this->collectionFactory = $collectionFactory;
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options getter
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toOptionArray(): array
|
||||
{
|
||||
$optionArray = [];
|
||||
$arr = $this->toArray();
|
||||
foreach ($arr as $value => $label) {
|
||||
$optionArray[] = [
|
||||
'value' => $value,
|
||||
'label' => $label
|
||||
];
|
||||
}
|
||||
|
||||
return $optionArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get options in "key-value" format
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return $this->getChildren(self::SYSTEM_CATEGORY_ID, self::ROOT_LEVEL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $parentCategoryId
|
||||
* @param $level
|
||||
* @return array
|
||||
*/
|
||||
private function getChildren(int $parentCategoryId, int $level)
|
||||
{
|
||||
$storeId = (int) $this->request->getParam(Store::ENTITY, Store::DEFAULT_STORE_ID);
|
||||
$options[self::NONE] = __('None');
|
||||
$collection = $this->collectionFactory->create();
|
||||
$collection->setStoreId($storeId);
|
||||
$collection->addAttributeToSelect('name');
|
||||
$collection->addAttributeToFilter('level', $level);
|
||||
$collection->addAttributeToFilter('parent_id', $parentCategoryId);
|
||||
$collection->setOrder('position', SortOrder::SORT_ASC);
|
||||
|
||||
foreach ($collection as $category) {
|
||||
$options[$category->getId()] =
|
||||
str_repeat(". ", max(0, ($category->getLevel() - 1) * 3)) . $category->getName();
|
||||
if ($category->hasChildren()) {
|
||||
$options = array_replace(
|
||||
$options,
|
||||
$this->getChildren((int) $category->getId(), $category->getLevel() + 1)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Hide Price (Call for Price) for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\HidePrice\Model\Source;
|
||||
|
||||
use Magento\Framework\App\ResourceConnection;
|
||||
use Magento\Framework\Option\ArrayInterface;
|
||||
use Magento\Framework\DB\Select;
|
||||
|
||||
class CustomForm implements ArrayInterface
|
||||
{
|
||||
public const CUSTOMFORM_TABLE = 'amasty_customform_form';
|
||||
|
||||
/**
|
||||
* @var ResourceConnection
|
||||
*/
|
||||
private $resource;
|
||||
|
||||
public function __construct(ResourceConnection $resource)
|
||||
{
|
||||
$this->resource = $resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toOptionArray()
|
||||
{
|
||||
$options = [];
|
||||
$connection = $this->resource->getConnection();
|
||||
$tableName = $this->resource->getTableName(self::CUSTOMFORM_TABLE);
|
||||
if ($connection->isTableExists($tableName)) {
|
||||
$select = $connection->select()
|
||||
->from($tableName)
|
||||
->reset(Select::COLUMNS)
|
||||
->columns(['value' => 'form_id', 'label' => 'title']);
|
||||
|
||||
$options = $connection->fetchAll($select);
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Hide Price (Call for Price) for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\HidePrice\Model\Source;
|
||||
|
||||
use Amasty\HidePrice\Helper\Data as Helper;
|
||||
|
||||
class Group extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource implements \Magento\Framework\Option\ArrayInterface
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Customer\Model\Customer\Attribute\Source\Group
|
||||
*/
|
||||
private $groupSource;
|
||||
|
||||
public function __construct(\Magento\Customer\Model\Customer\Attribute\Source\Group $groupSource)
|
||||
{
|
||||
$this->groupSource = $groupSource;
|
||||
}
|
||||
|
||||
public function toOptionArray()
|
||||
{
|
||||
return array_merge(
|
||||
[
|
||||
[
|
||||
'value' => Helper::DISABLED_GROUP_KEY,
|
||||
'label' => __('NONE')
|
||||
],
|
||||
[
|
||||
'value' => Helper::NOT_LOGGED_KEY,
|
||||
'label' => __('NOT LOGGED IN')
|
||||
]
|
||||
],
|
||||
$this->groupSource->getAllOptions()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get options in "key-value" format
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
$optionArray = $this->toOptionArray();
|
||||
$labels = array_column($optionArray, 'label');
|
||||
$values = array_column($optionArray, 'value');
|
||||
return array_combine($values, $labels);
|
||||
}
|
||||
|
||||
public function getAllOptions()
|
||||
{
|
||||
return $this->toOptionArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getFlatColumns()
|
||||
{
|
||||
$columns = [];
|
||||
|
||||
$columns[$this->getAttribute()->getAttributeCode()] = [
|
||||
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
|
||||
'length' => '255',
|
||||
'unsigned' => false,
|
||||
'nullable' => true,
|
||||
'default' => null,
|
||||
'extra' => null
|
||||
];
|
||||
|
||||
return $columns;
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Hide Price (Call for Price) for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\HidePrice\Model\Source;
|
||||
|
||||
class HideButton implements \Magento\Framework\Option\ArrayInterface
|
||||
{
|
||||
public const SHOW = 0;
|
||||
public const HIDE = 1;
|
||||
public const REPLACE_WITH_NEW_ONE = 2;
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toOptionArray()
|
||||
{
|
||||
$options = [
|
||||
[
|
||||
'value' => self::SHOW,
|
||||
'label' => __('No')
|
||||
],
|
||||
[
|
||||
'value' => self::HIDE,
|
||||
'label' => __('Yes')
|
||||
],
|
||||
[
|
||||
'value' => self::REPLACE_WITH_NEW_ONE,
|
||||
'label' => __('Replace with custom button')
|
||||
]
|
||||
];
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Hide Price (Call for Price) for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\HidePrice\Model\Source;
|
||||
|
||||
class PriceMode implements \Magento\Framework\Option\ArrayInterface
|
||||
{
|
||||
public const HIDE = 0;
|
||||
public const SHOW = 1;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toOptionArray()
|
||||
{
|
||||
$options = [
|
||||
[
|
||||
'value' => self::HIDE,
|
||||
'label' => __('Hide')
|
||||
],
|
||||
[
|
||||
'value' => self::SHOW,
|
||||
'label' => __('Show')
|
||||
]
|
||||
];
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewrite method for using in mass update attribute
|
||||
* @param $attribute
|
||||
* @return $this
|
||||
*/
|
||||
public function setAttribute($attribute)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Full Option values array
|
||||
*
|
||||
* @param bool $withEmpty Add empty option to array
|
||||
* @param bool $defaultValues
|
||||
* @return array
|
||||
*/
|
||||
public function getAllOptions($withEmpty = true, $defaultValues = false)
|
||||
{
|
||||
$options = $this->toOptionArray();
|
||||
$options[] = [
|
||||
'value' => '',
|
||||
'label' => __('-- Default Config --')
|
||||
];
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Hide Price (Call for Price) for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\HidePrice\Model\Source;
|
||||
|
||||
use Magento\Framework\Module\Manager;
|
||||
use Magento\Framework\Option\ArrayInterface;
|
||||
|
||||
class ReplaceButton implements ArrayInterface
|
||||
{
|
||||
public const REDIRECT_URL = 0;
|
||||
public const HIDE_PRICE_POPUP = 1;
|
||||
public const CUSTOM_FORM = 2;
|
||||
|
||||
/**
|
||||
* @var Manager
|
||||
*/
|
||||
private $moduleManager;
|
||||
|
||||
public function __construct(Manager $moduleManager)
|
||||
{
|
||||
$this->moduleManager = $moduleManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toOptionArray()
|
||||
{
|
||||
$options = [
|
||||
[
|
||||
'value' => self::REDIRECT_URL,
|
||||
'label' => __('Link to Custom URL')
|
||||
],
|
||||
[
|
||||
'value' => self::HIDE_PRICE_POPUP,
|
||||
'label' => __('Amasty Hide Price Popup')
|
||||
],
|
||||
[
|
||||
'value' => self::CUSTOM_FORM,
|
||||
'label' => __('Popup with Custom Form')
|
||||
]
|
||||
];
|
||||
if ($this->moduleManager->isEnabled('Amasty_Customform') === false) {
|
||||
$options[self::CUSTOM_FORM]['label'] .= ' (' . __('not installed') . ')';
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Hide Price (Call for Price) for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\HidePrice\Model\Source;
|
||||
|
||||
class Status implements \Magento\Framework\Option\ArrayInterface
|
||||
{
|
||||
public const PENDING = 0;
|
||||
public const VIEWED = 1;
|
||||
public const ANSWERED = 2;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toOptionArray()
|
||||
{
|
||||
if (!$this->options) {
|
||||
$this->options = [
|
||||
[
|
||||
'value' => self::PENDING,
|
||||
'label' => __('Pending')
|
||||
],
|
||||
[
|
||||
'value' => self::VIEWED,
|
||||
'label' => __('Viewed')
|
||||
],
|
||||
[
|
||||
'value' => self::ANSWERED,
|
||||
'label' => __('Answered')
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
public function getOptionByValue($value)
|
||||
{
|
||||
$options = $this->toOptionArray();
|
||||
foreach ($options as $option) {
|
||||
if ($option['value'] == $value) {
|
||||
return $option['label'];
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Hide Price (Call for Price) for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\HidePrice\Model\Source;
|
||||
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Option\ArrayInterface;
|
||||
use Magento\Eav\Api\AttributeRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product;
|
||||
|
||||
class StockStatus implements ArrayInterface
|
||||
{
|
||||
/**
|
||||
* @var array|null
|
||||
*/
|
||||
private $options = null;
|
||||
|
||||
/**
|
||||
* @var AttributeRepositoryInterface
|
||||
*/
|
||||
private $attributeRepository;
|
||||
|
||||
public function __construct(AttributeRepositoryInterface $attributeRepository)
|
||||
{
|
||||
$this->attributeRepository = $attributeRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toOptionArray()
|
||||
{
|
||||
if (!isset($this->options)) {
|
||||
$this->options = [];
|
||||
try {
|
||||
$attribute = $this->attributeRepository->get(Product::ENTITY, 'custom_stock_status');
|
||||
$this->options = $attribute->getSource()->getAllOptions(false);
|
||||
} catch (NoSuchEntityException $exception) {
|
||||
$this->options = [];
|
||||
}
|
||||
array_unshift($this->options, [
|
||||
'label' => __('NONE'),
|
||||
'value' => ''
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->options;
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
<?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\Model;
|
||||
|
||||
use Laminas\Validator\EmailAddress;
|
||||
use Laminas\Validator\NotEmpty;
|
||||
|
||||
class Validator
|
||||
{
|
||||
/**
|
||||
* @var EmailAddress
|
||||
*/
|
||||
private $emailAddressValidator;
|
||||
|
||||
/**
|
||||
* @var NotEmpty
|
||||
*/
|
||||
private $notEmptyValidator;
|
||||
|
||||
public function __construct(
|
||||
EmailAddress $emailAddressValidator,
|
||||
NotEmpty $notEmptyValidator
|
||||
) {
|
||||
$this->emailAddressValidator = $emailAddressValidator;
|
||||
$this->notEmptyValidator = $notEmptyValidator;
|
||||
}
|
||||
|
||||
public function isValidEmail(string $email): bool
|
||||
{
|
||||
return $this->emailAddressValidator->isValid($email);
|
||||
}
|
||||
|
||||
public function isNotEmpty(string $data): bool
|
||||
{
|
||||
return $this->notEmptyValidator->isValid($data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?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\Model\Xsearch;
|
||||
|
||||
use Amasty\HidePrice\Helper\Data;
|
||||
use Amasty\HidePrice\Model\ConfigProvider;
|
||||
use Amasty\HidePrice\Model\IsNeedRenderPrice;
|
||||
use Amasty\HidePrice\Plugin\Framework\Pricing\Render;
|
||||
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
|
||||
|
||||
class HidePopupData
|
||||
{
|
||||
public const IS_COMPARE_ALLOWED = 'amhideprice_is_compare_allowed';
|
||||
public const IS_WISHLIST_ALLOWED = 'amhideprice_is_wishlist_allowed';
|
||||
public const IS_ADD_TO_CART_ALLOWED = 'amhideprice_is_add_to_cart_allowed';
|
||||
|
||||
/**
|
||||
* @var Render
|
||||
*/
|
||||
private $render;
|
||||
|
||||
/**
|
||||
* @var ProductCollectionFactory
|
||||
*/
|
||||
private $productCollectionFactory;
|
||||
|
||||
/**
|
||||
* @var IsNeedRenderPrice
|
||||
*/
|
||||
private $isNeedRenderPrice;
|
||||
|
||||
/**
|
||||
* @var Data
|
||||
*/
|
||||
private $helper;
|
||||
|
||||
/**
|
||||
* @var ConfigProvider
|
||||
*/
|
||||
private $configProvider;
|
||||
|
||||
public function __construct(
|
||||
Render $render,
|
||||
ProductCollectionFactory $productCollectionFactory,
|
||||
IsNeedRenderPrice $isNeedRenderPrice,
|
||||
Data $helper,
|
||||
ConfigProvider $configProvider
|
||||
) {
|
||||
$this->render = $render;
|
||||
$this->productCollectionFactory = $productCollectionFactory;
|
||||
$this->isNeedRenderPrice = $isNeedRenderPrice;
|
||||
$this->helper = $helper;
|
||||
$this->configProvider = $configProvider;
|
||||
}
|
||||
|
||||
public function execute(array $productsData): array
|
||||
{
|
||||
$ids = array_column($productsData, 'entity_id');
|
||||
$collection = $this->productCollectionFactory->create();
|
||||
$collection->addIdFilter($ids);
|
||||
foreach ($collection as $product) {
|
||||
$id = $product->getEntityId();
|
||||
if (!$this->isNeedRenderPrice->execute($product, [])) {
|
||||
$productsData[$id]['price'] = $this->helper->getNewPriceHtmlBox($product);
|
||||
}
|
||||
$isApplied = $this->helper->isApplied($product);
|
||||
$productsData[$id][self::IS_COMPARE_ALLOWED] = !($this->configProvider->isHideCompare() && $isApplied);
|
||||
$productsData[$id][self::IS_WISHLIST_ALLOWED] = !($this->configProvider->isHideWishlist() && $isApplied);
|
||||
$productsData[$id][self::IS_ADD_TO_CART_ALLOWED]
|
||||
= !($this->configProvider->isHideAddToCart() && $isApplied);
|
||||
}
|
||||
|
||||
return $productsData;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user