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
+75
View File
@@ -0,0 +1,75 @@
<?php declare(strict_types=1);
/**
* Copyright (c) 2021
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Olegnax\Carousel\Model\ResourceModel;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Model\AbstractModel;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
class Carousel extends AbstractDb
{
/**
* Define resource model
*
* @return void
*/
protected function _construct()
{
$this->_init('olegnax_carousel_carousel', 'carousel_id');
}
protected function _beforeSave(AbstractModel $object)
{
$data = $object->getData('identifier');
if (empty($data)) {
$data = $object->getData('Title');
}
$data = str_replace(' ', '_', strtolower($data));
$object->setData('identifier', $data);
if (!$this->getIsUniqueCarousel($object)) {
throw new LocalizedException(
__('A Carousel identifier with the same properties already exists.')
);
}
return parent::_beforeSave($object);
}
private function getIsUniqueCarousel(AbstractModel $object)
{
$select = $this->getConnection()->select()
->from(['cb' => $this->getMainTable()])
->where('cb.identifier = ? ', $object->getData('identifier'));
if ($this->getConnection()->fetchRow($select)) {
return false;
}
return true;
}
}
@@ -0,0 +1,51 @@
<?php declare(strict_types=1);
/**
* Copyright (c) 2021
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Olegnax\Carousel\Model\ResourceModel\Carousel;
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
use Olegnax\Carousel\Model\ResourceModel\Carousel;
class Collection extends AbstractCollection
{
/**
* @var string
*/
protected $_idFieldName = 'carousel_id';
/**
* Define resource model
*
* @return void
*/
protected function _construct()
{
$this->_init(
\Olegnax\Carousel\Model\Carousel::class,
Carousel::class
);
}
}
+201
View File
@@ -0,0 +1,201 @@
<?php declare(strict_types=1);
/**
* Copyright (c) 2021
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Olegnax\Carousel\Model\ResourceModel;
use Magento\Catalog\Model\ImageUploader;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\File\Uploader;
use Magento\Framework\Filesystem;
use Magento\Framework\Model\AbstractModel;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
use Magento\Framework\Model\ResourceModel\Db\Context;
use Magento\Framework\Serialize\Serializer\Json;
use Olegnax\Carousel\Api\Data\SlideInterface;
use Psr\Log\LoggerInterface;
class Slide extends AbstractDb
{
/**
* @var Json
*/
protected $json;
/**
* @var ImageUploader
*/
private $imageUploader;
/**
* @var Filesystem
*/
private $_filesystem;
public function __construct(
Context $context,
Filesystem $filesystem,
Json $json,
LoggerInterface $logger,
$connectionName = null
) {
$this->_filesystem = $filesystem;
$this->json = $json;
$this->_logger = $logger;
parent::__construct($context, $connectionName);
}
/**
* Define resource model
*
* @return void
*/
protected function _construct()
{
$this->_init('olegnax_carousel_slide', 'slide_id');
}
protected function _beforeSave(AbstractModel $object)
{
$data = $object->getData('store_id');
if (!empty($data)) {
if (is_array($data)) {
$data = implode(',', $data);
$object->setData('store_id', $data);
}
} else {
$object->setData('store_id', 0);
}
$this->beforeSaveImage($object, SlideInterface::IMAGE);
$this->beforeSaveImage($object, SlideInterface::MOBILE_IMAGE);
return parent::_beforeSave($object);
}
private function beforeSaveImage($object, $attributeName)
{
$value = $object->getData($attributeName);
if ($this->fileResidesOutsideCategoryDir($value)) {
// use relative path for image attribute so we know it's outside of category dir when we fetch it
// phpcs:ignore Magento2.Functions.DiscouragedFunction
$value[0]['url'] = parse_url($value[0]['url'], PHP_URL_PATH);
$value[0]['name'] = $value[0]['url'];
}
if ($imageName = $this->getUploadedImageName($value)) {
if (!$this->fileResidesOutsideCategoryDir($value)) {
$imageName = $this->checkUniqueImageName($imageName);
}
$object->setData($attributeName, $imageName);
} elseif (!is_string($value)) {
$object->setData($attributeName, null);
}
return $this;
}
/**
* Check for file path resides outside of category media dir. The URL will be a path including pub/media if true
*
* @param array|null $value
* @return bool
*/
private function fileResidesOutsideCategoryDir($value)
{
if (!is_array($value) || !isset($value[0]['url'])) {
return false;
}
$fileUrl = ltrim((string)$value[0]['url'], '/');
$baseMediaDir = $this->_filesystem->getUri(DirectoryList::MEDIA);
if (!$baseMediaDir) {
return false;
}
return strpos($fileUrl, $baseMediaDir) !== false;
}
/**
* Gets image name from $value array.
*
* Will return empty string in a case when $value is not an array.
*
* @param array $value Attribute value
* @return string
*/
private function getUploadedImageName($value)
{
if (is_array($value) && isset($value[0]['name'])) {
return $value[0]['name'];
}
return '';
}
/**
* Check that image name exists in catalog/category directory and return new image name if it already exists.
*
* @param string $imageName
* @return string
*/
private function checkUniqueImageName(string $imageName): string
{
$imageUploader = $this->getImageUploader();
$mediaDirectory = $this->_filesystem->getDirectoryWrite(DirectoryList::MEDIA);
$imageAbsolutePath = $mediaDirectory->getAbsolutePath(
$imageUploader->getBasePath() . DIRECTORY_SEPARATOR . $imageName
);
$imageName = Uploader::getNewFilename($imageAbsolutePath);
return $imageName;
}
/**
* Get Instance of Category Image Uploader.
*
* @return ImageUploader
*
* @deprecated 101.0.0
*/
private function getImageUploader()
{
if ($this->imageUploader === null) {
$this->imageUploader = ObjectManager::getInstance()
->get(ImageUploader::class);
}
return $this->imageUploader;
}
protected function _afterLoad(AbstractModel $object)
{
$data = $object->getData('store_id');
if (!empty($data) && !is_array($data)) {
$data = explode(',', $data);
$object->setData('store_id', $data);
}
return parent::_afterLoad($object);
}
}
@@ -0,0 +1,124 @@
<?php declare(strict_types=1);
/**
* Copyright (c) 2021
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Olegnax\Carousel\Model\ResourceModel\Slide;
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
use Magento\Framework\Data\Collection\EntityFactoryInterface;
use Magento\Framework\DB\Adapter\AdapterInterface;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
use Magento\Store\Api\Data\StoreInterface;
use Magento\Store\Model\StoreManagerInterface;
use Olegnax\Carousel\Model\ResourceModel\Slide;
use Psr\Log\LoggerInterface;
class Collection extends AbstractCollection
{
/**
* @var string
*/
protected $_idFieldName = 'slide_id';
/**
* @var StoreManagerInterface
*/
protected $_storeManager;
private $_storeId;
public function __construct(
EntityFactoryInterface $entityFactory,
LoggerInterface $logger,
FetchStrategyInterface $fetchStrategy,
ManagerInterface $eventManager,
StoreManagerInterface $storeManager,
AdapterInterface $connection = null,
AbstractDb $resource = null
) {
$this->_storeManager = $storeManager;
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
}
/**
* Add store availability filter. Include availability product
* for store website
*
* @param null|string|bool|int $store
* @return \Olegnax\Carousel\Model\ResourceModel\Slide\Collection
*/
public function addStoreFilter($store = null)
{
if ($store === null) {
$store = $this->getStoreId();
}
$store = $this->_storeManager->getStore($store);
$this->getSelect()->where("(`store_id` = 0 OR `store_id` LIKE '?,%' OR `store_id` = ? OR `store_id` LIKE '%,?' OR `store_id` LIKE '%,?,%')", $store->getId(), 'int');
return $this;
}
/**
* Return current store id
*
* @return int
*/
public function getStoreId()
{
if ($this->_storeId === null) {
$this->setStoreId($this->_storeManager->getStore()->getId());
}
return $this->_storeId;
}
/**
* Set store scope
*
* @param int|string|StoreInterface $storeId
* @return $this
*/
public function setStoreId($storeId)
{
if ($storeId instanceof StoreInterface) {
$storeId = $storeId->getId();
}
$this->_storeId = (int)$storeId;
return $this;
}
/**
* Define resource model
*
* @return void
*/
protected function _construct()
{
$this->_init(
\Olegnax\Carousel\Model\Slide::class,
Slide::class
);
}
}