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,14 @@
<?php
/**
* @author Olegnax
* @package Olegnax_ProductLabel
* @copyright Copyright (c) 2023 Olegnax (http://olegnax.com/). All rights reserved.
* See COPYING.txt for license details.
*/
namespace Olegnax\ProductLabel\Block\Adminhtml\System\Config\Form;
class Info extends \Olegnax\Core\Block\Adminhtml\System\Config\Form\Info
{
}
+29
View File
@@ -0,0 +1,29 @@
<?php
/**
* Olegnax ProductLabel
*
* NOTICE OF LICENSE
*
* This source file is subject to the Olegnax.com license that is
* available through the world-wide-web at this URL:
* https://www.olegnax.com/license
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Olegnax
* @package Olegnax_ProductLabel
* @copyright Copyright (c) 2023 Olegnax (http://www.olegnax.com/)
* @license https://www.olegnax.com/license
*/
namespace Olegnax\ProductLabel\Block;
use Olegnax\Core\Block\SimpleTemplate as coreTemplate;
class ProductLabel extends coreTemplate {
}
+131
View File
@@ -0,0 +1,131 @@
<?php
namespace Olegnax\ProductLabel\Helper;
use InvalidArgumentException;
use Magento\Framework\App\Cache\State;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Store\Model\StoreManagerInterface;
class Cache extends AbstractHelper
{
const CACHE_TAG = 'BLOCK_HTML';
const CACHE_ID = 'block_html';
const CACHE_LIFETIME = 86400;
/**
* @var \Magento\Framework\App\Cache
*/
protected $cache;
/**
* @var State
*/
protected $cacheState;
/**
* @var StoreManagerInterface
*/
protected $storeManager;
/**
* @var Json
*/
protected $json;
/**
* @var int
*/
private $storeId;
/**
* Cache constructor.
* @param Context $context
* @param \Magento\Framework\App\Cache $cache
* @param State $cacheState
* @param StoreManagerInterface $storeManager
* @param Json|null $json
* @throws NoSuchEntityException
*/
public function __construct(
Context $context,
\Magento\Framework\App\Cache $cache,
State $cacheState,
StoreManagerInterface $storeManager,
Json $json = null
) {
$this->cache = $cache;
$this->cacheState = $cacheState;
$this->storeManager = $storeManager;
$this->storeId = $storeManager->getStore()->getId();
$this->json = $json ?: ObjectManager::getInstance()->get(Json::class);
parent::__construct($context);
}
/**
* @param string $method
* @param array $vars
* @return string
*/
public function getId($method, $vars = array())
{
return base64_encode($this->storeId . static::CACHE_ID . $method . implode('', (array)$vars));
}
/**
* @param string $cacheId
* @return bool|object
*/
public function loadObject($cacheId)
{
$result = $this->load($cacheId);
if (!empty($result)) {
try {
$result = $this->json->unserialize($result);
} catch (InvalidArgumentException $e) {
return false;
}
return $result;
}
return false;
}
/**
* @param string $cacheId
* @return bool|string
*/
public function load($cacheId)
{
if ($this->cacheState->isEnabled(static::CACHE_ID)) {
return $this->cache->load($cacheId);
}
return false;
}
/**
* @param string $data
* @param string $cacheId
* @param int $cacheLifetime
* @return bool
*/
public function save($data, $cacheId, $cacheLifetime = 0)
{
if (!is_string($data)) {
$data = $this->json->serialize($data);
}
if ($this->cacheState->isEnabled(static::CACHE_ID)) {
return $this->cache->save(
$data,
$cacheId,
[static::CACHE_TAG],
empty($cacheLifetime) ? static::CACHE_LIFETIME : $cacheLifetime
);
}
return false;
}
}
+745
View File
@@ -0,0 +1,745 @@
<?php /** @noinspection PhpDeprecationInspection */
/**
* Olegnax ProductLabel
*
* NOTICE OF LICENSE
*
* This source file is subject to the Olegnax.com license that is
* available through the world-wide-web at this URL:
* https://www.olegnax.com/license
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Olegnax
* @package Olegnax_ProductLabel
* @copyright Copyright (c) 2023 Olegnax (http://www.olegnax.com/)
* @license https://www.olegnax.com/license
*/
declare(strict_types=1);
namespace Olegnax\ProductLabel\Helper;
use DateTime;
use Magento\Catalog\Helper\Data;
use Magento\Catalog\Model\Product;
use Magento\Framework\Data\Collection;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Phrase;
use Magento\Framework\Registry;
use Magento\Sales\Model\ResourceModel\Report\Bestsellers\CollectionFactory;
use Magento\Store\Model\ScopeInterface;
use Olegnax\Core\Helper\Helper as CoreHelperHelper;
class Helper extends CoreHelperHelper
{
const CONFIG_MODULE = 'olegnax_productlabel';
/**
* @var \Magento\Framework\Stdlib\DateTime\DateTime
*/
protected $dateTime;
/**
* @var CollectionFactory
*/
protected $reportBestsellers;
/**
* @var array|int[]
*/
private $_bestsellerIds;
/**
* @var int
*/
private $storeCode;
/**
* @var array|array[]
*/
private $cacheCondition = [];
/**
* @param string $method
* @param array $args
*
* @return bool|string
* @throws LocalizedException
*/
public function __call($method, $args)
{
if (preg_match('/^showLabel(.+)$/', $method, $matches)) {
$label = strtolower($matches[1]);
$product = isset($args[0]) ? $args[0] : null;
return $this->getLabel($product, $label);
}
if (preg_match('/^isEnabledLabel(.+)$/', $method, $matches)) {
$label = strtolower($matches[1]);
return $this->isEnabledLabel($label);
}
throw new LocalizedException(
new Phrase('Invalid method %1::%2', [get_class($this), $method])
);
}
/**
* @param Product $product
* @param string $label
*
* @return string
*/
public function getLabel($product, $label)
{
if ($this->isEnabledLabel($label) && $this->isCondition($product, $label) && $this->isLoggedIn()) {
$style = $this->prepareStyle([
'color' => $this->getLabelAttr($label, 'color'),
'background-color' => $this->getLabelAttr($label, 'background_color'),
]);
if (!empty($style)) {
$style = ' style="' . $style . '"';
}
$text = (string)$this->getLabelAttr($label, 'text');
if (false !== strpos($text, '{{')) {
$text = $this->prepareText($text, $product);
}
$text = trim($text);
if (empty($text)) {
return '';
}
return '<span class="ox-product-label-' . $label . '"' . $style . '>' . $text . '</span>';
}
return '';
}
/**
* @param string $label
*
* @return bool
*/
public function isEnabledLabel($label)
{
return (bool)$this->isEnabled() && $this->getModuleConfig('label/' . $label);
}
/**
* @return bool
*/
public function isEnabled()
{
return (bool)$this->getModuleConfig('general/enable');
}
/**
* @param string $path
* @param null|int $storeCode
* @param string $scopeType
*
* @return mixed
*/
public function getModuleConfig($path = '', $storeCode = null, $scopeType = ScopeInterface::SCOPE_STORE)
{
return parent::getModuleConfig($path, $this->getStoreId());
}
/**
* @return int
*/
private function getStoreId()
{
if (empty($this->storeCode)) {
$this->storeCode = $this->getStore()->getId();
}
return $this->storeCode;
}
/**
* @param Product $product
* @param string $label
*
* @return bool|mixed
*/
protected function isCondition($product, $label)
{
$result = false;
$productId = $product->getId();
if (isset($this->cacheCondition[$productId]) && isset($this->cacheCondition[$productId][$label])) {
return $this->cacheCondition[$productId][$label];
}
switch ($label) {
case 'bestseller':
$result = $this->isConditionBestseller($productId);
break;
case 'custom':
$result = $this->isConditionCustom($product);
break;
case 'featured':
$result = $this->isConditionFeatured($product);
break;
case 'new':
$result = $this->isConditionNew($product);
break;
case 'sale':
$result = $this->isConditionSale($product);
break;
default:
$method = 'isCondition' . ucfirst($label);
if (method_exists($this, $method)) {
$result = call_user_func([$this, $method], $product);
}
}
$this->cacheCondition[$productId][$label] = $result;
return $result;
}
/**
* @param int $productId
*
* @return bool
*/
public function isConditionBestseller($productId)
{
return in_array($productId, $this->getBestsellerIds());
}
/**
* @return array
*/
protected function getBestsellerIds()
{
if (empty($this->_bestsellerIds)) {
$this->_bestsellerIds = [];
$collection = $this->getReportBestsellers()->create();
$period = $this->getModuleConfig('label/bestseller_period');
if ($period) {
$collection
->addFieldToFilter(
'period',
[
'date' => true,
'from' => (new DateTime())
->modify('-1 ' . $period)
->setTime(0, 0, 0)
->getTimestamp(),
]
);
}
if (method_exists($collection, 'addStoreRestrictions')) {
$collection->addStoreRestrictions([0, $this->getStoreId()]);
}
$bestsellers = $collection
->setOrder('MIN(rating_pos)', Collection::SORT_ORDER_ASC)
->setPageSize(
max(
(int)($this->getModuleConfig('label/bestseller_count') ?: 200),
10
)
);
foreach ($bestsellers as $item) {
$this->_bestsellerIds[] = $item->getProductId();
}
}
return $this->_bestsellerIds;
}
/**
* @return CollectionFactory
*/
protected function getReportBestsellers()
{
if (!$this->reportBestsellers) {
$this->reportBestsellers = $this->_loadObject(CollectionFactory::class);
}
return $this->reportBestsellers;
}
/**
* @param Product $product
*
* @return bool
*/
public function isConditionCustom($product)
{
return (bool)$product->getData('ox_custom');
}
/**
* @param Product $product
*
* @return bool
*/
public function isConditionFeatured($product)
{
return (bool)$product->getData('ox_featured') || $product->getData('thm_featured');
}
/**
* @param Product $product
*
* @return bool
* @noinspection PhpUndefinedMethodInspection
*/
public function isConditionNew($product)
{
$productFrom = $product->getNewsFromDate();
$productTo = $product->getNewsToDate();
$productFrom = '0000-00-00 00:00:00' === $productFrom ? '' : $productFrom;
$productTo = '0000-00-00 00:00:00' === $productTo ? '' : $productTo;
if (!empty($productFrom) && !empty($productTo)) {
return ($this->getEndDate() >= $productFrom && $this->getDate() <= $productTo);
} elseif (!empty($productFrom) && empty($productTo)) {
return ($this->getEndDate() >= $productFrom);
} elseif (empty($productFrom) && !empty($productTo)) {
return ($this->getDate() <= $productTo);
}
$productType = $product->getTypeID();
switch ($productType) {
case 'bundle':
case 'grouped':
$childs = $product->getTypeInstance()->getAssociatedProducts($product);
foreach ($childs as $child) {
if ($this->isConditionNew($child)) {
return true;
}
}
break;
case 'configurable':
$childs = $product->getTypeInstance()->getUsedProducts($product);
foreach ($childs as $child) {
if ($this->isConditionNew($child)) {
return true;
}
}
break;
}
return false;
}
/**
* @return string
*/
protected function getEndDate()
{
return $this->getDate('23:59:59');
}
/**
* @param string $time
*
* @return string
*/
protected function getDate($time = '0:0:0')
{
return $this->getDateTime()->date(null, $time);
}
/**
* @return \Magento\Framework\Stdlib\DateTime\DateTime
*/
protected function getDateTime()
{
if (!$this->dateTime) {
$this->dateTime = $this->_loadObject(\Magento\Framework\Stdlib\DateTime\DateTime::class);
}
return $this->dateTime;
}
/**
* @param Product $product
*
* @return bool
*/
public function isConditionSale($product)
{
switch ($product->getTypeID()) {
case 'grouped':
$childs = $product->getTypeInstance()->getAssociatedProducts($product);
foreach ($childs as $child) {
if ($this->isConditionSale($child)) {
return true;
}
}
break;
case 'configurable':
$childs = $product->getTypeInstance()->getUsedProducts($product);
foreach ($childs as $child) {
if ($this->isConditionSale($child)) {
return true;
}
}
break;
default:
$specialPrice = $this->getProductPrice($product,'special');
$price = $this->getProductPrice($product);
if (!empty($specialPrice) && $specialPrice < $price) {
$productFrom = $product->getSpecialFromDate();
$productTo = $product->getSpecialToDate();
$productFrom = '0000-00-00 00:00:00' === $productFrom ? '' : $productFrom;
$productTo = '0000-00-00 00:00:00' === $productTo ? '' : $productTo;
if (!empty($productFrom) && !empty($productTo)) {
return ($this->getEndDate() >= $productFrom && $this->getDate() <= $productTo);
} elseif (!empty($productFrom) && empty($productTo)) {
return ($this->getEndDate() >= $productFrom);
} elseif (empty($productFrom) && !empty($productTo)) {
return ($this->getDate() <= $productTo);
}
}
}
return false;
}
/**
* @param array $style
* @param string $separatorValue
* @param string $separatorAttribute
*
* @return string
*/
public function prepareStyle(array $style, $separatorValue = ': ', $separatorAttribute = ';')
{
$style = array_filter($style);
if (empty($style)) {
return '';
}
foreach ($style as $key => &$value) {
$value = $key . $separatorValue . $value;
}
$style = implode($separatorAttribute, $style);
return $style;
}
/**
* @param string $label
* @param string $attribute
*
* @return mixed
*/
protected function getLabelAttr($label, $attribute = '')
{
return $this->getModuleConfig(sprintf('label/%s_%s', $label, $attribute));
}
/**
* @param string $text
* @param Product $product
*
* @return string|string[]
*/
protected function prepareText($text, $product)
{
$search = [];
$replace = [];
$templates = $this->templateReplace($product);
$index = 0;
if (is_array($templates) && !empty($templates)) {
foreach ($templates as $key => $value) {
$search[$index] = '{{' . $key . '}}';
$replace[$index] = $value;
$index++;
}
}
if (preg_match_all('/{{attribute:([^:}]+)}}/im', $text, $matches, PREG_SET_ORDER)) {
foreach ($matches as $matche) {
$search[$index] = $matche[0];
$replace[$index] = $product->getData($matche[1]);
$index++;
}
}
return str_replace($search, $replace, $text);
}
/**
* @param Product $product
*
* @return array
*/
public function templateReplace($product)
{
$discount = '';
$discount_percent = '';
$special_price = '';
$productType = $product->getTypeID();
switch ($productType) {
case 'grouped':
$childs = $product->getTypeInstance()->getAssociatedProducts($product);
$_discount = [];
$_discount_percent = [];
$_special_price = [];
foreach ($childs as $child) {
$specialPrice = $this->getProductPrice($child, 'special');
if (!empty($specialPrice)) {
$price = $this->getProductPrice($child);
$_special_price[] = $specialPrice;
$_discount[] = $price - $specialPrice;
$_discount_percent[] = round((1 - $specialPrice / $price) * 100);
}
}
if (1 == count($_discount)) {
$discount = array_shift($_discount);
$discount = $this->convertValute($discount);
$discount_percent = array_shift($_discount_percent) . '%';
$special_price = array_shift($_special_price);
} elseif (1 < count($_discount)) {
$minDiscount = min($_discount);
$maxDiscount = max($_discount);
$minDiscount = $this->convertValute($minDiscount);
$maxDiscount = $this->convertValute($maxDiscount);
if ($minDiscount !== $maxDiscount) {
$discount = $minDiscount . '-' . $maxDiscount;
} else {
$discount = $maxDiscount;
}
$minDiscount = min($_discount_percent);
$maxDiscount = max($_discount_percent);
if ($minDiscount !== $maxDiscount) {
$discount_percent = min($_discount_percent) . '%-' . max($_discount_percent) . '%';
} else {
$discount_percent = max($_discount_percent) . '%';
}
$special_price = min($_special_price);
}
break;
case 'configurable':
$childs = $product->getTypeInstance()->getUsedProducts($product);
$_discount = [];
$_discount_percent = [];
$_special_price = [];
foreach ($childs as $child) {
$specialPrice = $this->getProductPrice($child, 'special');
if (!empty($specialPrice)) {
$price = $this->getProductPrice($child);
$_special_price[] = $specialPrice;
$_discount[] = $price - $specialPrice;
$_discount_percent[] = round((1 - $specialPrice / $price) * 100);
}
}
if (1 == count($_discount)) {
$discount = array_shift($_discount);
$discount = $this->convertValute($discount);
$discount_percent = array_shift($_discount_percent) . '%';
$special_price = array_shift($_special_price);
} elseif (1 < count($_discount)) {
$minDiscount = min($_discount);
$maxDiscount = max($_discount);
$minDiscount = $this->convertValute($minDiscount);
$maxDiscount = $this->convertValute($maxDiscount);
if ($minDiscount !== $maxDiscount) {
$discount = $minDiscount . '-' . $maxDiscount;
} else {
$discount = $maxDiscount;
}
$minDiscount = min($_discount_percent);
$maxDiscount = max($_discount_percent);
if ($minDiscount !== $maxDiscount) {
$discount_percent = $minDiscount . '%-' . $maxDiscount . '%';
} else {
$discount_percent = $maxDiscount . '%';
}
$special_price = min($_special_price);
}
break;
case 'bundle':
$specialPrice = $this->getProductPrice($product,'special');
if (!empty($specialPrice)) {
$discount_percent = round(100 - $specialPrice) . '%';
}
break;
case 'simple':
default:
$specialPrice = $this->getProductPrice($product,'special');
if (!empty($specialPrice)) {
$special_price = $specialPrice;
$price = $this->getProductPrice($product);
$discount = $price - $specialPrice;
$discount = $this->convertValute($discount);
if ($price > 0) {
$discount_percent = round((1 - $specialPrice / $price) * 100) . '%';
}
}
}
return [
'discount' => $discount,
'discount_percent' => $discount_percent,
'special_price' => $this->convertValute($special_price),
];
}
/**
* @param \Magento\Catalog\Model\Product $product
* @param string $type
* @return float
*/
protected function getProductPrice($product, $type = '')
{
switch ($type) {
case 'special':
$price = $product->getSpecialPrice();
break;
case 'minimal':
$price = $product->getMinimalPrice();
break;
case 'final':
$price = $product->getFinalPrice();
break;
case 'calculatedFinal':
$price = $product->getCalculatedFinalPrice();
break;
default:
$price = $product->getPrice();
}
return $this->getTaxHelper()->getTaxPrice($product, $price);
}
/**
* @param string $value
*
* @return string
*/
private function convertValute($value)
{
$value = floatval($value);
$value = number_format($value, 2, '.', ',');
return $value;
}
/**
* @return bool|Cache|string
*/
public function showLabelsProduct()
{
$labelsPosition = 'ox-product-labels--' . $this->getModuleConfig('label/label_position_product');
$product = $this->getProduct();
if ($product) {
return $this->showLabels($product, $labelsPosition);
}
return '';
}
/**
* @return Product|null
*/
protected function getProduct()
{
$register = $this->_loadObject(Registry::class);
$product = $register->registry('product');
if ($product) {
return $product;
}
$product = $register->registry('current_product');
if ($product) {
return $product;
}
return null;
}
/**
* @param Product $product
* @param null $labelsPosition
*
* @return bool|Cache|string
*/
public function showLabels($product, $labelsPosition = null)
{
if (!$this->isEnabled()) {
return '';
}
$_labelsPosition = $labelsPosition;
$productId = $product->getId();
$html = $this->getCacheHtml($productId, $_labelsPosition);
if (!empty($html)) {
return $html;
}
$labels = [];
foreach (['new', 'sale', 'featured', 'bestseller', 'custom'] as $label) {
$labels[] = $this->getLabel($product, $label);
}
if (empty($labelsPosition)) {
$labelsPosition = 'ox-product-labels--' . $this->getModuleConfig('label/label_position');
}
$labelsOutput = implode('', $labels);
if ($labelsOutput) {
$labelsOutput = '<div class="ox-product-labels-wrapper ' . $labelsPosition . '">' . $labelsOutput . '</div>';
}
$this->setCacheHtml($labelsOutput, $productId, $_labelsPosition);
return $labelsOutput;
}
/**
* @param int $productId
* @param $labelsPosition
*
* @return bool|Cache|string
*/
protected function getCacheHtml($productId, $labelsPosition)
{
/** @var Cache $cache */
$cache = $this->_loadObject(Cache::class);
$cache = $cache->load($cache->getId('showLabels', [$productId, $labelsPosition, $this->getStoreId()]));
return empty($cache) ? "" : $cache;
}
/**
* @param string $html
* @param int $productId
* @param $labelsPosition
*
* @return bool
*/
protected function setCacheHtml($html, $productId, $labelsPosition)
{
/** @var Cache $cache */
$cache = $this->_loadObject(Cache::class);
return $cache->save(
$html,
$cache->getId('showLabels', [$productId, $labelsPosition, $this->getStoreId()])
);
}
/**
* @return Data
*/
protected function getTaxHelper()
{
return $this->_loadObject(Data::class);
}
/**
* @param string $date
*
* @return DateTime|false
*/
protected function convDate($date)
{
return DateTime::createFromFormat('Y-m-d H:i:s', $date);
}
}
+35
View File
@@ -0,0 +1,35 @@
<?php
namespace Olegnax\ProductLabel\Model\Config;
use Magento\Framework\Option\ArrayInterface;
class Period implements ArrayInterface {
public function toOptionArray()
{
return [
[
'value' => '',
'label' => __('All Time')
],
[
'value' => 'year',
'label' => __('Last Year')
],
[
'value' => 'month',
'label' => __('Last Month')
]
];
}
public function toArray()
{
$array = [];
foreach ($this->toOptionArray() as $item) {
$array[$item['value']] = $item['label'];
}
return $array;
}
}
+39
View File
@@ -0,0 +1,39 @@
<?php
namespace Olegnax\ProductLabel\Model\Config;
use Magento\Framework\Option\ArrayInterface;
class Position implements ArrayInterface {
public function toOptionArray()
{
return [
[
'value' => 'top-left',
'label' => __('Top Left')
],
[
'value' => 'top-right',
'label' => __('Top Right')
],
[
'value' => 'bottom-left',
'label' => __('Bottom Left')
],
[
'value' => 'bottom-right',
'label' => __('Bottom Right')
]
];
}
public function toArray()
{
$array = [];
foreach ($this->toOptionArray() as $item) {
$array[$item['value']] = $item['label'];
}
return $array;
}
}
+107
View File
@@ -0,0 +1,107 @@
<?php
namespace Olegnax\ProductLabel\Setup;
use Magento\Catalog\Model\Product;
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
use Magento\Eav\Model\Entity\Attribute\Source\Boolean;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
class InstallData implements InstallDataInterface
{
private $eavSetupFactory;
/**
* Constructor
*
* @param EavSetupFactory $eavSetupFactory
*/
public function __construct(EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}
/**
* {@inheritdoc}
*/
public function install(
ModuleDataSetupInterface $setup,
ModuleContextInterface $context
) {
$setup->startSetup();
$this->_install($setup);
$setup->endSetup();
}
private function _install(ModuleDataSetupInterface $setup)
{
$eavSetup = $this->eavSetupFactory->create([
'setup' => $setup,
]);
$tablefields = $this->fields();
foreach ($tablefields as $entity => $fields) {
foreach ($fields as $key => $value) {
$eavSetup->addAttribute($entity, $key, $value);
}
}
}
private function fields()
{
return [
Product::ENTITY => [
'ox_featured' => [
'group' => 'Product Details',
'type' => 'int',
'backend' => '',
'frontend' => '',
'label' => 'Featured Product',
'input' => 'boolean',
'class' => '',
'source' => Boolean::class,
'sort_order' => 3,
'global' => ScopedAttributeInterface::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '0',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => true,
'unique' => false,
'apply_to' => '',
],
'ox_custom' => [
'group' => 'Product Details',
'type' => 'int',
'backend' => '',
'frontend' => '',
'label' => 'Custom Label',
'input' => 'boolean',
'class' => '',
'source' => Boolean::class,
'sort_order' => 4,
'global' => ScopedAttributeInterface::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '0',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => true,
'unique' => false,
'apply_to' => '',
],
],
];
}
}
@@ -0,0 +1,110 @@
<?php
namespace Olegnax\ProductLabel\Setup\Patch\Data;
use Magento\Catalog\Model\Product;
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
use Magento\Eav\Model\Entity\Attribute\Source\Boolean;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchRevertableInterface;
class AddOxCustomProductAttribute implements DataPatchInterface, PatchRevertableInterface
{
/**
* @var ModuleDataSetupInterface
*/
private $moduleDataSetup;
/**
* @var EavSetupFactory
*/
private $eavSetupFactory;
/**
* Constructor
*
* @param ModuleDataSetupInterface $moduleDataSetup
* @param EavSetupFactory $eavSetupFactory
*/
public function __construct(
ModuleDataSetupInterface $moduleDataSetup,
EavSetupFactory $eavSetupFactory
) {
$this->moduleDataSetup = $moduleDataSetup;
$this->eavSetupFactory = $eavSetupFactory;
}
/**
* {@inheritdoc}
*/
public static function getDependencies()
{
return [
];
}
/**
* {@inheritdoc}
*/
public function apply()
{
$this->moduleDataSetup->getConnection()->startSetup();
/** @var EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
$eavSetup->addAttribute(
Product::ENTITY,
'ox_custom',
[
'apply_to' => '',
'backend' => '',
'class' => '',
'comparable' => false,
'default' => '0',
'filterable' => false,
'frontend' => '',
'global' => ScopedAttributeInterface::SCOPE_GLOBAL,
'group' => 'Product Details',
'input' => 'boolean',
'label' => 'Custom Label',
'required' => false,
'searchable' => false,
'sort_order' => 4,
'source' => Boolean::class,
'type' => 'int',
'unique' => false,
'used_in_product_listing' => true,
'user_defined' => true,
'visible' => true,
'visible_on_front' => false,
]
);
$this->moduleDataSetup->getConnection()->endSetup();
}
/**
* {@inheritdoc}
*/
public function revert()
{
$this->moduleDataSetup->getConnection()->startSetup();
/** @var EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
$eavSetup->removeAttribute(Product::ENTITY, 'ox_custom');
$this->moduleDataSetup->getConnection()->endSetup();
}
/**
* {@inheritdoc}
*/
public function getAliases()
{
return [];
}
}
+96
View File
@@ -0,0 +1,96 @@
<?php
namespace Olegnax\ProductLabel\Setup;
use Magento\Catalog\Model\Product;
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
use Magento\Eav\Model\Entity\Attribute\Source\Boolean;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\UpgradeDataInterface;
class UpgradeData implements UpgradeDataInterface
{
private $eavSetupFactory;
/**
* Constructor
*
* @param EavSetupFactory $eavSetupFactory
*/
public function __construct(EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}
/**
* @param ModuleDataSetupInterface $setup
* @param ModuleContextInterface $context
*/
public function upgrade(
ModuleDataSetupInterface $setup,
ModuleContextInterface $context
) {
$methods = $this->getUpgradeFunctions($context->getVersion());
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
foreach ($methods as $method) {
call_user_func_array([$this, $method], [$setup, $eavSetup]);
}
}
private function getUpgradeFunctions($low_version = '1.0.0')
{
$methods = get_class_methods($this);
foreach ($methods as $key => $method) {
if (preg_match('/^upgrade_(.+)$/i', $method, $matches)) {
if (version_compare($low_version, $matches[1], '<')) {
continue;
}
}
unset($methods[$key]);
}
$methods = array_filter($methods);
$methods = array_unique($methods);
sort($methods);
return $methods;
}
public function upgrade_0_0_11(
ModuleDataSetupInterface $setup,
EavSetup $eavSetup
) {
$eavSetup->addAttribute(
Product::ENTITY,
'ox_custom',
[
'group' => 'Product Details',
'type' => 'int',
'backend' => '',
'frontend' => '',
'label' => 'Custom Label',
'input' => 'boolean',
'class' => '',
'source' => Boolean::class,
'sort_order' => 4,
'global' => ScopedAttributeInterface::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '0',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => true,
'unique' => false,
'apply_to' => '',
]
);
}
}
+22
View File
@@ -0,0 +1,22 @@
{
"name": "olegnax/module-productlabel",
"description": "",
"type": "magento2-module",
"license": "proprietary",
"authors": [
{
"email": "mail@olegnax.com",
"name": "Olegnax"
}
],
"minimum-stability": "dev",
"require": {},
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Olegnax\\ProductLabel\\": ""
}
}
}
+13
View File
@@ -0,0 +1,13 @@
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
<acl>
<resources>
<resource id="Magento_Backend::admin">
<resource id="Olegnax_Core::Olegnax_Core">
<resource id="Olegnax_ProductLabel::productlabel" sortOrder="10" title="Product Label"/>
</resource>
</resource>
</resources>
</acl>
</config>
+7
View File
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
<menu>
<add id="Olegnax_ProductLabel::productlabel" title="Product Label" translate="title" module="Olegnax_ProductLabel" sortOrder="999" parent="Olegnax_Core::Olegnax_Core" resource="Olegnax_ProductLabel::productlabel"/>
<add id="Olegnax_ProductLabel::config" title="Configuration" translate="title" module="Olegnax_ProductLabel" sortOrder="20" action="adminhtml/system_config/edit/section/olegnax_productlabel" parent="Olegnax_ProductLabel::productlabel" resource="Olegnax_ProductLabel::productlabel"/>
</menu>
</config>
+172
View File
@@ -0,0 +1,172 @@
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<tab id="olegnax" sortOrder="999" translate="label">
<label>Olegnax</label>
</tab>
<section id="olegnax_productlabel" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label">
<label>Product Label</label>
<tab>olegnax</tab>
<resource>Olegnax_ProductLabel::productlabel</resource>
<group id="info" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="0" translate="label">
<frontend_model>Olegnax\ProductLabel\Block\Adminhtml\System\Config\Form\Info</frontend_model>
</group>
<group id="general" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label">
<label>General</label>
<field id="enable" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label" type="select">
<label>Enable</label>
<frontend_class>on-off-trigger</frontend_class>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
<group id="label" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label">
<label>Label</label>
<field id="label_position" translate="label comment" type="select" sortOrder="0" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Labels Position on Grid</label>
<source_model>Olegnax\ProductLabel\Model\Config\Position</source_model>
</field>
<field id="label_position_product" translate="label comment" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Labels Position on Product Page</label>
<source_model>Olegnax\ProductLabel\Model\Config\Position</source_model>
</field>
<field id="new" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label" type="select">
<label>Show Label "New"</label>
<frontend_class>on-off-trigger</frontend_class>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="new_text" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="20" translate="label" type="text">
<label>Label "New" Text</label>
<depends>
<field id="new">1</field>
</depends>
</field>
<field id="new_color" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="30" translate="label" type="text">
<label>Label "New" Color</label>
<frontend_class>ox-ss-colorpicker</frontend_class>
<depends>
<field id="new">1</field>
</depends>
</field>
<field id="new_background_color" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="40" translate="label" type="text">
<label>Label "New" Background Color</label>
<frontend_class>ox-ss-colorpicker</frontend_class>
<depends>
<field id="new">1</field>
</depends>
</field>
<field id="sale" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="50" translate="label" type="select">
<label>Show Label "Sale"</label>
<frontend_class>on-off-trigger</frontend_class>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="sale_text" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="60" translate="label" type="text">
<label>Label "Sale" Text</label>
<comment><![CDATA[{{discount}}, {{discount_percent}}, {{special_price}}, {{attribute:sku}}]]></comment>
<depends>
<field id="sale">1</field>
</depends>
</field>
<field id="sale_color" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="70" translate="label" type="text">
<label>Label "Sale" Color</label>
<frontend_class>ox-ss-colorpicker</frontend_class>
<depends>
<field id="sale">1</field>
</depends>
</field>
<field id="sale_background_color" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="80" translate="label" type="text">
<label>Label "Sale" Background Color</label>
<frontend_class>ox-ss-colorpicker</frontend_class>
<depends>
<field id="sale">1</field>
</depends>
</field>
<field id="featured" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="90" translate="label" type="select">
<label>Show Label "Featured"</label>
<frontend_class>on-off-trigger</frontend_class>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="featured_text" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="100" translate="label" type="text">
<label>Label "Featured" Text</label>
<depends>
<field id="featured">1</field>
</depends>
</field>
<field id="featured_color" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="110" translate="label" type="text">
<label>Label "Featured" Color</label>
<frontend_class>ox-ss-colorpicker</frontend_class>
<depends>
<field id="featured">1</field>
</depends>
</field>
<field id="featured_background_color" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="120" translate="label" type="text">
<label>Label "Featured" Background Color</label>
<frontend_class>ox-ss-colorpicker</frontend_class>
<depends>
<field id="featured">1</field>
</depends>
</field>
<field id="bestseller" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="130" translate="label" type="select">
<label>Show Label "Bestseller"</label>
<frontend_class>on-off-trigger</frontend_class>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="bestseller_period" translate="label comment" type="select" sortOrder="133"
showInDefault="1" showInWebsite="1" showInStore="1">
<label>Bestsellers Period</label>
<source_model>Olegnax\ProductLabel\Model\Config\Period</source_model>
</field>
<field id="bestseller_count" translate="label comment" type="text" sortOrder="136" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Max Number of Bestsellers</label>
<comment>This is not the number of bestsellers this is amount of bestsellers requested from database. This value is shared with all store views and not guarantee the exact match of bestseller products.</comment>
</field>
<field id="bestseller_text" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="140" translate="label" type="text">
<label>Label "Bestseller" Text</label>
<depends>
<field id="bestseller">1</field>
</depends>
</field>
<field id="bestseller_color" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="150" translate="label" type="text">
<label>Label "Bestseller" Color</label>
<frontend_class>ox-ss-colorpicker</frontend_class>
<depends>
<field id="bestseller">1</field>
</depends>
</field>
<field id="bestseller_background_color" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="160" translate="label" type="text">
<label>Label "Bestseller" Background Color</label>
<frontend_class>ox-ss-colorpicker</frontend_class>
<depends>
<field id="bestseller">1</field>
</depends>
</field>
<field id="custom" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="170" translate="label" type="select">
<label>Show Label Custom</label>
<frontend_class>on-off-trigger</frontend_class>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="custom_text" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="180" translate="label" type="text">
<label>Label Custom Text</label>
<depends>
<field id="custom">1</field>
</depends>
</field>
<field id="custom_color" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="190" translate="label" type="text">
<label>Label Custom Color</label>
<frontend_class>ox-ss-colorpicker</frontend_class>
<depends>
<field id="custom">1</field>
</depends>
</field>
<field id="custom_background_color" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="200" translate="label" type="text">
<label>Label Custom Background Color</label>
<frontend_class>ox-ss-colorpicker</frontend_class>
<depends>
<field id="custom">1</field>
</depends>
</field>
</group>
</section>
</system>
</config>
+34
View File
@@ -0,0 +1,34 @@
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<olegnax_productlabel>
<general>
<enable>1</enable>
</general>
<label>
<new>1</new>
<new_text>New</new_text>
<new_color/>
<new_background_color/>
<sale>1</sale>
<sale_text>Sale</sale_text>
<sale_color/>
<sale_background_color/>
<featured>1</featured>
<featured_text>Featured</featured_text>
<featured_color/>
<featured_background_color/>
<bestseller>1</bestseller>
<bestseller_period></bestseller_period>
<bestseller_count>200</bestseller_count>
<bestseller_text>Bestseller</bestseller_text>
<bestseller_color/>
<bestseller_background_color/>
<custom>0</custom>
<custom_text></custom_text>
<custom_color/>
<custom_background_color/>
</label>
</olegnax_productlabel>
</default>
</config>
+9
View File
@@ -0,0 +1,9 @@
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Olegnax_ProductLabel" setup_version="0.0.19.1">
<sequence>
<module name="Magento_Catalog"/>
<module name="Olegnax_Core"/>
</sequence>
</module>
</config>
+7
View File
@@ -0,0 +1,7 @@
<?php
use Magento\Framework\Component\ComponentRegistrar;
ComponentRegistrar::register(
ComponentRegistrar::MODULE, 'Olegnax_ProductLabel', __DIR__
);
@@ -0,0 +1,23 @@
<?php
/**
* Olegnax ProductLabel
*
* NOTICE OF LICENSE
*
* This source file is subject to the Olegnax.com license that is
* available through the world-wide-web at this URL:
* https://www.olegnax.com/license
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Olegnax
* @package Olegnax_ProductLabel
* @copyright Copyright (c) 2023 Olegnax (http://www.olegnax.com/)
* @license https://www.olegnax.com/license
*/
?>
@@ -0,0 +1,105 @@
//
// Variables
// _____________________________________________
@ox-product-label__sale--color: #ffffff;
@ox-product-label__new--color: #ffffff;
@ox-product-label__featured--color: #ffffff;
@ox-product-label__bestseller--color: #ffffff;
@ox-product-label__sale--background: #c2e124;
@ox-product-label__new--background: #f94127;
@ox-product-label__featured--background: #00d7e1;
@ox-product-label__bestseller--background: #f94127;
@ox-product-label__margin:3px;
//
// Common
// _____________________________________________
& when (@media-common = true) {
.ox-product-labels-wrapper{
position: absolute;
text-align: left;
pointer-events: none;
top:0;
left:0;
z-index: 2;
opacity:1;
transition: opacity 0.2s ease;
&.ox-product-labels--top-left{
top:0;
left:0;
bottom:auto;
right:auto;
span {
margin-bottom:@ox-product-label__margin;
}
}
&.ox-product-labels--top-right{
top:0;
right:0;
bottom:auto;
left:auto;
span {
margin-bottom:@ox-product-label__margin;
}
}
&.ox-product-labels--bottom-left{
bottom:0;
left:0;
top: auto;
right: auto;
span {
margin-top:@ox-product-label__margin;
}
}
&.ox-product-labels--bottom-right{
bottom:0;
right:0;
top:auto;
left:auto;
span {
margin-top:@ox-product-label__margin;
}
}
}
.ox-product-label-custom,
.ox-product-label-bestseller,
.ox-product-label-featured,
.ox-product-label-new,
.ox-product-label-sale{
padding: 5px 7px;
font-size: 14px;
font-weight: @font-weight__semibold;
line-height: 1;
display: inline-block;
clear: left;
float: left;
}
.ox-product-label-bestseller{
color: @ox-product-label__bestseller--color;
background: @ox-product-label__bestseller--background;
}
.ox-product-label-custom,
.ox-product-label-featured{
color: @ox-product-label__featured--color;
background: @ox-product-label__featured--background;
}
.ox-product-label-new{
color: @ox-product-label__new--color;
background: @ox-product-label__new--background;
}
.ox-product-label-sale{
color: @ox-product-label__sale--color;
background: @ox-product-label__sale--background;
}
.products-grid__layout-2,
.products-grid__layout-default{
&.grid{
.product-item:hover{
.ox-product-labels-wrapper{
opacity:0;
}
}
}
}
}