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
+658
View File
@@ -0,0 +1,658 @@
<?php
/**
* Olegnax
*
* 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_ProductSlider
* @copyright Copyright (c) 2023 Olegnax (http://www.olegnax.com/)
* @license https://www.olegnax.com/license
*/
namespace Olegnax\ProductSlider\Block;
use Magento\Catalog\Block\Product\AbstractProduct;
use Magento\Catalog\Block\Product\Widget\Html\Pager;
use Magento\Catalog\Block\ShortcutButtons\InCatalog\PositionAfter;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Visibility;
use Magento\Catalog\Model\ResourceModel\Product\Collection;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\Catalog\Pricing\Price\FinalPrice;
use Magento\CatalogInventory\Helper\Stock;
use Magento\CatalogInventory\Model\Configuration;
use Magento\Framework\App\ActionInterface;
use Magento\Framework\App\Http\Context;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\DataObject\IdentityInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Framework\Pricing\Render;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\Url\Helper\Data;
use Magento\Framework\View\Element\AbstractBlock;
use Magento\Framework\View\Element\RendererList;
use Magento\Framework\View\LayoutFactory;
use Magento\Framework\View\LayoutInterface;
use Magento\Msrp\Block\Popup;
use Magento\Store\Model\ScopeInterface;
use Magento\Widget\Block\BlockInterface;
use Olegnax\Core\Helper\ProductImage;
use Olegnax\ProductSlider\Model\Config\Source\SortOrder;
use Olegnax\ProductSlider\Model\Config\Source\SortOrderCat;
abstract class AbstractShortcode extends AbstractProduct implements BlockInterface, IdentityInterface
{
/**
* @var Context
*/
protected $httpContext;
/**
* Catalog product visibility
*
* @var Visibility
*/
protected $catalogProductVisibility;
/**
* Product collection factory
*
* @var CollectionFactory
*/
protected $productCollectionFactory;
/**
* @var Data
*/
protected $urlHelper;
protected $_atributtes = [
'title' => '',
'title_align' => 'center',
'title_side_line' => false,
'title_tag' => 'strong',
//region Pagination
'products_count' => 6,
'show_pager' => false,
'products_per_page' => 10,
//endregion
'columns_desktop' => 4,
'columns_desktop_small' => 3,
'columns_table' => 2,
'columns_mobile' => 1,
'loop' => false,
'arrows' => false,
'dots' => false,
'nav_position' => 'left-right',
'dots_align' => 'left',
'show_title' => true,
'autoplay' => false,
'autoplay_time' => '5000',
'pause_on_hover' => false,
'show_addtocart' => true,
'show_wishlist' => true,
'show_compare' => true,
'show_review' => true,
'show_desc' => false,
'show_in_stock' => true,
'rewind' => false,
'sort_order' => '',
'quickview_position' => '',
'products_layout_centered' => false,
'show_swatches' => false,
'review_count' => false,
'hide_name' => false,
'hide_price' => false,
'custom_class' => '',
];
/**
* @var \Magento\Framework\View\Element\BlockInterface
*/
protected $pager;
/**
* @var LayoutFactory
*/
private $layoutFactory;
/**
* @var RendererList
*/
private $rendererListBlock;
/**
* @var PriceCurrencyInterface
*/
private $priceCurrency;
/**
* Json Serializer Instance
*
* @var Json
*/
private $json;
/**
* AbstractShortcode constructor.
* @param \Magento\Catalog\Block\Product\Context $context
* @param CollectionFactory $productCollectionFactory
* @param Visibility $catalogProductVisibility
* @param Context $httpContext
* @param Data $urlHelper
* @param array $data
* @param Json|null $json
*/
public function __construct(
\Magento\Catalog\Block\Product\Context $context,
CollectionFactory $productCollectionFactory,
Visibility $catalogProductVisibility,
Context $httpContext,
Data $urlHelper,
array $data = [],
LayoutFactory $layoutFactory = null,
Json $json = null
) {
$this->productCollectionFactory = $productCollectionFactory;
$this->catalogProductVisibility = $catalogProductVisibility;
$this->httpContext = $httpContext;
$this->urlHelper = $urlHelper;
$this->layoutFactory = $layoutFactory ?: ObjectManager::getInstance()->get(LayoutFactory::class);
$this->json = $json ?: ObjectManager::getInstance()->get(Json::class);
parent::__construct($context, $data);
}
/**
* @param array $newval
* @return array
*/
public function getCacheKeyInfo($newval = [])
{
return array_merge([
'OLEGNAX_PRODUCTSLIDER_PRODUCTS_LIST_WIDGET',
$this->getPriceCurrency()->getCurrency()->getCode(),
$this->getStoreId(),
$this->_design->getDesignTheme()->getId(),
$this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_GROUP),
(int)$this->getRequest()->getParam($this->getData('page_var_name'), 1),
$this->getProductsPerPage(),
$this->getProductsCount(),
$this->json->serialize($this->getRequest()->getParams()),
$this->json->serialize($this->getData()),
], $newval);
}
/**
* @return PriceCurrencyInterface|mixed
*/
private function getPriceCurrency()
{
if ($this->priceCurrency === null) {
$this->priceCurrency = ObjectManager::getInstance()
->get(PriceCurrencyInterface::class);
}
return $this->priceCurrency;
}
/**
* @return int
* @throws NoSuchEntityException
*/
public function getStoreId()
{
return $this->_storeManager->getStore()->getId();
}
/**
* Retrieve how many products should be displayed
*
* @return int
*/
public function getProductsPerPage()
{
if (!$this->hasData('products_per_page')) {
$this->setData('products_per_page', $this->_atributtes['products_per_page']);
}
return $this->getData('products_per_page');
}
/**
* Retrieve how many products should be displayed
*
* @return int
*/
public function getProductsCount()
{
if ($this->hasData('products_count')) {
return $this->getData('products_count');
}
if (null === $this->getData('products_count')) {
$this->setData('products_count', $this->_atributtes['products_count']);
}
return $this->getData('products_count');
}
/**
* @param string $method
* @param array $args
* @return mixed
* @throws LocalizedException
*/
public function __call($method, $args)
{
if ('get' === substr($method, 0, 3)) {
$key = $this->_underscore(substr($method, 3));
if (array_key_exists($key, $this->_atributtes)) {
$value = $this->_atributtes[$key];
if ($this->hasData($key)) {
$value = $this->getData($key);
if (is_null($value)) {
$value = '';
}
}
return $value;
}
}
return parent::__call($method, $args);
}
/**
* {@inheritdoc}
*/
// protected function _beforeToHtml()
// {
// $this->setProductCollection($this->createCollection());
// return parent::_beforeToHtml();
// }
/**
* @param Product $product
* @param null $priceType
* @param string $renderZone
* @param array $arguments
* @return string
* @throws LocalizedException
*/
public function getProductPriceHtml(
Product $product,
$priceType = null,
$renderZone = Render::ZONE_ITEM_LIST,
array $arguments = []
) {
if (!isset($arguments['zone'])) {
$arguments['zone'] = $renderZone;
}
$arguments['price_id'] = isset($arguments['price_id']) ? $arguments['price_id'] : 'old-price-' . $product->getId() . '-' . $priceType;
$arguments['include_container'] = isset($arguments['include_container']) ? $arguments['include_container'] : true;
$arguments['display_minimal_price'] = isset($arguments['display_minimal_price']) ? $arguments['display_minimal_price'] : true;
/** @var Render $priceRender */
$priceRender = $this->getLayout()->getBlock('product.price.render.default');
$price = '';
if ($priceRender) {
$price = $priceRender->render(
FinalPrice::PRICE_CODE,
$product,
$arguments
);
}
return $price;
}
/**
* @return array|string[]
*/
public function getIdentities()
{
$identities = [];
if ($this->getProductCollection()) {
foreach ($this->getProductCollection() as $product) {
if ($product instanceof IdentityInterface) {
$identities = array_merge($identities, $product->getIdentities());
}
}
}
return $identities ?: [Product::CACHE_TAG];
}
/**
* @return Collection
*/
public function getProductCollection()
{
$page = (int)$this->getRequest()->getParam($this->getData('page_var_name'), 1);
$collection = $this->initProductCollection()
->setCurPage($page);
$productsSize = $this->getPageSize();
$productsCount = $productsSize * $page;
if ($productsCount > $this->getProductsCount()) {
$productsSize += $this->getProductsCount() - $productsCount;
}
if ($productsSize) {
$collection->setPageSize($productsSize);
}
return $collection;
}
/**
* @return Collection
*/
public function initProductCollection()
{
/** @var $collection Collection */
$visibleProducts = $this->catalogProductVisibility->getVisibleInCatalogIds();
$collection = $this->productCollectionFactory->create()->setVisibility($visibleProducts);
$collection->addMinimalPrice()
->addFinalPrice()
->addTaxPercents()
->addAttributeToSelect('*');
if ($this->_scopeConfig->getValue(
Configuration::XML_PATH_SHOW_OUT_OF_STOCK,
ScopeInterface::SCOPE_STORE
) &&
$this->getShowInStock()) {
$this->addInStockFilterToCollection($collection);
}
return $collection;
}
/**
* @param $collection
*/
public function addInStockFilterToCollection($collection)
{
$this->_loadObject(Stock::class)->addInStockFilterToCollection($collection);
}
protected function _loadObject($object)
{
return ObjectManager::getInstance()->get($object);
}
/**
* Retrieve how many products should be displayed on page
*
* @return int
*/
protected function getPageSize()
{
return $this->showPager() ? $this->getProductsPerPage() : $this->getProductsCount();
}
/**
* Return flag whether pager need to be shown or not
*
* @return bool
*/
public function showPager()
{
if (!$this->hasData('show_pager')) {
$this->setData('show_pager', $this->_atributtes['show_pager']);
}
return (bool)$this->getData('show_pager');
}
/**
* @param Collection $collection
* @param string $order_attribute
* @param string $order_dir
*/
public function addAttributeToSort(
Collection $collection,
$order_attribute = "",
$order_dir = Collection::SORT_ORDER_ASC
) {
$sortOrder = $this->getSortOrder();
switch ($sortOrder) {
case SortOrder::FIELD_PRICE_ASC:
$order_attribute = 'price';
$order_dir = Collection::SORT_ORDER_ASC;
break;
case SortOrder::FIELD_PRICE_DESC:
$order_attribute = 'price';
$order_dir = Collection::SORT_ORDER_DESC;
break;
case SortOrder::FIELD_CREATED:
$order_attribute = $sortOrder;
$order_dir = Collection::SORT_ORDER_DESC;
break;
case SortOrderCat::FIELD_POSITION:
case SortOrder::FIELD_NAME:
$order_attribute = $sortOrder;
$order_dir = Collection::SORT_ORDER_ASC;
break;
}
if (!empty($order_attribute)) {
$collection->addAttributeToSort($order_attribute, $order_dir);
}
}
/**
* @param array $options
* @param bool $json
* @return array|bool|false|string
*/
public function getCarouselOptions($options = [], $json = true)
{
$autoplayTime = (int)$this->getAutoplayTime();
if (!$autoplayTime || $autoplayTime < 500) {
$autoplayTime = 500;
}
$options['itemClass'] = 'product-item';
$options['margin'] = (int)$this->getMargin();
$options['loop'] = (bool)$this->getLoop();
$options['dots'] = (bool)$this->getDots();
$options['nav'] = (bool)$this->getNav();
$options['items'] = (int)$this->getColumnsDesktop();
$options['autoplay'] = (bool)$this->getAutoplay();
$options['autoplayTimeout'] = $autoplayTime;
$options['autoplayHoverPause'] = (bool)$this->getPauseOnHover();
$options['lazyLoad'] = true;
$options['rewind'] = (bool)$this->getRewind();
$options['responsive'] = [
'0' => [
'items' => max(1, (int)$this->getColumnsMobile()),
],
'640' => [
'items' => max(1, (int)$this->getColumnsTablet()),
],
'1025' => [
'items' => max(1, (int)$this->getColumnsDesktopSmall()),
],
'1160' => [
'items' => max(1, (int)$this->getColumnsDesktop()),
],
];
if ($json) {
return $this->json->serialize($options);
}
return $options;
}
/**
* @return string|string[]|null
*/
public function getUnderlineNameInLayout()
{
$name = $this->getNameInLayout();
$name = preg_replace('/[^a-zA-Z0-9_]/i', '_', $name);
$name .= substr(md5(microtime()), -5);
return $name;
}
/**
* @param Product $product
* @return string
*/
public function getMSRPHtml(Product $product)
{
if ($this->isMSRP($product)) {
return $this->getMSRP();
}
return '';
}
/**
* @param Product $product
* @return bool
*/
public function isMSRP(Product $product)
{
$msrp = $product->getData('msrp');
return null !== $msrp;
}
/**
* @return string
* @throws LocalizedException
*/
public function getMSRP()
{
$content = '';
$block = $this->getLayout()->getBlock('product.tooltip');
if (!$block && class_exists('\Magento\Catalog\Block\ShortcutButtons\InCatalog\PositionAfter')) {
$block = $this->getLayout()->createBlock(
Popup::class,
'product.tooltip'
)->setTemplate('Magento_Msrp::popup.phtml');
$_block = $this->getLayout()->createBlock(
PositionAfter::class,
'map.shortcut.buttons'
);
$block->setChild($_block->getNameInLayout(), $_block);
$content = $block->toHtml();
}
return $content;
}
//region Pagination
/**
* @param Product $product
* @return array
*/
public function getAddToCartPostParams(Product $product)
{
$url = $this->getAddToCartUrl($product);
return [
'action' => $url,
'data' => [
'product' => $product->getEntityId(),
ActionInterface::PARAM_NAME_URL_ENCODED => $this->urlHelper->getEncodedUrl($url),
],
];
}
/**
* @param $product
* @param $imageId
* @param array $attributes
* @return mixed
*/
public function getLazyImage($product, $imageId, $attributes = [])
{
return $this->_loadObject(ProductImage::class)->getImage(
$product,
$imageId,
'Olegnax_ProductSlider::product/image_with_borders.phtml',
$attributes
);
}
/**
* Render pagination HTML
*
* @return string
* @throws LocalizedException
*/
public function getPagerHtml()
{
if ($this->showPager() && $this->initProductCollection()->getSize() > $this->getProductsPerPage()) {
if (!$this->pager) {
$this->pager = $this->getLayout()->createBlock(
Pager::class,
$this->getWidgetPagerBlockName()
);
$this->pager->setUseContainer(true)
->setShowAmounts(true)
->setShowPerPage(false)
->setPageVarName($this->getData('page_var_name'))
->setLimit($this->getProductsPerPage())
->setTotalLimit($this->getProductsCount())
->setCollection($this->getProductCollection());
}
if ($this->pager instanceof AbstractBlock) {
return $this->pager->toHtml();
}
}
return '';
}
/**
* Get widget block name
*
* @return string
*/
private function getWidgetPagerBlockName()
{
$namespace = explode('\\', (string)get_class($this));
$class = array_slice($namespace, -2, 1);
$class = strtolower($class[0]);
$pageName = $this->getData('page_var_name');
$pagerBlockName = 'widget.' . $class . '.pager';
if (!$pageName) {
return $pagerBlockName;
}
return $pagerBlockName . '.' . $pageName;
}
/**
* @inheritdoc
*/
protected function getDetailsRendererList()
{
if (empty($this->rendererListBlock)) {
/** @var $layout LayoutInterface */
$layout = $this->layoutFactory->create(['cacheable' => false]);
$layout->getUpdate()->addHandle('catalog_widget_product_list')->load();
$layout->generateXml();
$layout->generateElements();
$this->rendererListBlock = $layout->getBlock('category.product.type.widget.details.renderers');
}
return $this->rendererListBlock;
}
/**
*
*/
protected function _construct()
{
$this->addData([
'cache_lifetime' => 86400,
]);
parent::_construct();
}
//endregion
}
@@ -0,0 +1,109 @@
<?php
/**
* Olegnax
*
* 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_ProductSlider
* @copyright Copyright (c) 2023 Olegnax (http://www.olegnax.com/)
* @license https://www.olegnax.com/license
*/
namespace Olegnax\ProductSlider\Block;
abstract class AbstractShortcodeByIds extends AbstractShortcode
{
protected $_atributtes = [
'title' => '',
'title_align' => 'center',
'title_tag' => 'strong',
'title_side_line' => false,
//region Pagination
'products_count' => 6,
'show_pager' => false,
'products_per_page' => 10,
//endregion
'products_ids' => '',
'columns_desktop' => 4,
'columns_desktop_small' => 3,
'columns_tablet' => 2,
'columns_mobile' => 1,
'loop' => false,
'arrows' => false,
'dots' => false,
'nav_position' => 'left-right',
'dots_align' => 'left',
'show_title' => true,
'autoplay' => false,
'autoplay_time' => '5000',
'pause_on_hover' => false,
'show_addtocart' => true,
'show_wishlist' => true,
'show_compare' => true,
'show_review' => true,
'hide_name' => false,
'hide_price' => false,
'show_desc' => false,
'show_in_stock' => true,
'rewind' => false,
'sort_order' => '',
'quickview_position' => '',
'products_layout_centered' => false,
'show_swatches' => false,
'review_count' => false,
'custom_class' => '',
];
public function initProductCollection()
{
$collection = parent::initProductCollection();
$productIds = array_filter($this->getLoadedProductIds());
$collection->addIdFilter($productIds);
$productsCount = $this->getProductsCount();
if ($productsCount) {
$collection->setPageSize($productsCount);
}
$this->addAttributeToSort($collection);
$collection->distinct(true);
return $collection;
}
public function getLoadedProductIds()
{
$productIds = $this->getProductIds();
if($productIds) {
if (!is_array($productIds) ) {
$productIds = explode(',', (string)$productIds);
}
$productIds = array_map('intval', $productIds);
$productIds = array_map('abs', $productIds);
$productIds = array_filter($productIds);
} else {
$productIds = [];
}
return $productIds;
}
public function getCacheKeyInfo($newval = [])
{
return parent::getCacheKeyInfo([
'OLEGNAX_PRODUCTSLIDER_PRODUCTS_LIST_BY_ID_WIDGET',
$this->getProductIds(),
]);
}
}
@@ -0,0 +1,51 @@
<?php
/**/
namespace Olegnax\ProductSlider\Block\Adminhtml;
use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\Data\Form\Element\Factory;
Class TextField extends Template
{
protected $_elementFactory;
/**
* @param Context $context
* @param Factory $elementFactory
* @param array $data
*/
public function __construct(
Context $context,
Factory $elementFactory,
array $data = []
) {
$this->_elementFactory = $elementFactory;
parent::__construct($context, $data);
}
/**
* Prepare chooser element HTML
*
* @param AbstractElement $element Form Element
* @return AbstractElement
*/
public function prepareElementHtml(AbstractElement $element)
{
$input = $this->_elementFactory->create("textarea", ['data' => $element->getData()]);
$input->setId($element->getId());
$input->setForm($element->getForm());
$input->setClass("widget-option input-textarea admin__control-text");
if ($element->getRequired()) {
$input->addClass('required-entry');
}
$element->setData('after_element_html', $input->getElementHtml());
return $element;
}
}
+210
View File
@@ -0,0 +1,210 @@
<?php
/**
* Olegnax
*
* 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_ProductSlider
* @copyright Copyright (c) 2023 Olegnax (http://www.olegnax.com/)
* @license https://www.olegnax.com/license
*/
namespace Olegnax\ProductSlider\Block;
use DateTime;
use Exception;
use Magento\Catalog\Model\Product\Visibility;
use Magento\Catalog\Model\ProductFactory;
use Magento\CatalogInventory\Model\Configuration;
use Magento\Framework\App\Http\Context;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\Url\Helper\Data;
use Magento\Framework\View\LayoutFactory;
use Magento\Sales\Model\ResourceModel\Report\Bestsellers\Collection;
use Magento\Sales\Model\ResourceModel\Report\Bestsellers\CollectionFactory;
use Magento\Store\Model\ScopeInterface;
class BestSellerProducts extends ProductsByIds
{
/**
* @var ProductFactory
*/
protected $product;
/**
* BestSellerProducts constructor.
* @param \Magento\Catalog\Block\Product\Context $context
* @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
* @param Visibility $catalogProductVisibility
* @param Context $httpContext
* @param Data $urlHelper
* @param ProductFactory $product
* @param array $data
* @param LayoutFactory|null $layoutFactory
* @param Json|null $json
*/
public function __construct(
\Magento\Catalog\Block\Product\Context $context,
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
Visibility $catalogProductVisibility,
Context $httpContext,
Data $urlHelper,
ProductFactory $product,
array $data = [],
LayoutFactory $layoutFactory = null,
Json $json = null
) {
$this->product = $product;
parent::__construct($context, $productCollectionFactory, $catalogProductVisibility, $httpContext, $urlHelper,
$data, $layoutFactory, $json);
}
/**
* @return array
* @throws NoSuchEntityException
*/
public function getLoadedProductIds()
{
$productIds = [];
/** @var Collection $collection */
$collection = $this->_loadObject(CollectionFactory::class)->create();
$period = $this->getData('period');
if ($period) {
$collection
->addFieldToFilter(
'period',
[
'date' => true,
'from' => $this->getDateAgo($period),
]
);
if (in_array($period, ['month', 'year'])) {
$collection->setPeriod($period);
}
}
if (method_exists($collection, 'addStoreRestrictions')) {
$collection->addStoreRestrictions([0, $this->getStoreId()]);
}
$bestsellers = $collection
->setOrder('MIN(rating_pos)', \Magento\Framework\Data\Collection::SORT_ORDER_ASC)
->setPageSize(200);
$productsCount = $this->getProductsCount();
foreach ($bestsellers as $_product) {
$id = $_product->getProductId();
if (!in_array($id, $productIds) && $this->categoryStatus($id) && $this->stockStatus($id)) {
$productIds[] = $id;
}
if ($productsCount && count($productIds) >= $productsCount) {
break;
}
}
return $productIds;
}
/**
* @param string $period
* @param int $countPeriod
* @return int
*/
protected function getDateAgo($period = 'year', $countPeriod = 1)
{
if (!in_array($period, ['year', 'month', 'day'])) {
$period = 'year';
}
return (new DateTime())
->modify('-' . $countPeriod . ' ' . $period)
->setTime(0, 0)
->getTimestamp();
}
/**
* @param $id
* @return bool
*/
protected function categoryStatus($id)
{
$categoryIds = $this->getCategoryIds();
if (!empty($categoryIds)) {
try {
$productCategoryIds = $this->product->create()->load($id)->getCategoryIds();
return 0 < count(array_intersect($categoryIds, $productCategoryIds));
} catch (Exception $exception) {
return false;
}
}
return true;
}
/**
* @return array|mixed|null
*/
protected function getCategoryIds()
{
$categoryIds = $this->getData('category_ids');
if (!is_array($categoryIds)) {
if ($categoryIds) {
$categoryIds = is_array($categoryIds) ? $categoryIds : explode(',', (string)$categoryIds);
$categoryIds = array_map('intval', $categoryIds);
$categoryIds = array_filter($categoryIds);
$categoryIds = array_unique($categoryIds);
} else {
$categoryIds = [];
}
$this->setData('category_ids', $categoryIds);
}
return $this->getData('category_ids');
}
/**
* @param $id
* @return bool|int
*/
protected function stockStatus($id)
{
if ($this->_scopeConfig->getValue(
Configuration::XML_PATH_SHOW_OUT_OF_STOCK,
ScopeInterface::SCOPE_STORE
) &&
$this->getShowInStock()) {
try {
return $this->stockRegistry->getProductStockStatus($id);
} catch (Exception $exception) {
return false;
}
}
return true;
}
/**
* @param array $newval
* @return array
*/
public function getCacheKeyInfo($newval = [])
{
return parent::getCacheKeyInfo([
'OLEGNAX_PRODUCTSLIDER_BESTSELLER_PRODUCTS_LIST_WIDGET',
implode(',', $this->getCategoryIds()),
$this->getData('period'),
]);
}
}
+54
View File
@@ -0,0 +1,54 @@
<?php
/**
* Olegnax
*
* 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_ProductSlider
* @copyright Copyright (c) 2023 Olegnax (http://www.olegnax.com/)
* @license https://www.olegnax.com/license
*/
namespace Olegnax\ProductSlider\Block;
use Magento\Catalog\Model\ResourceModel\Product\Collection;
class FeaturedProducts extends AbstractShortcode
{
/**
* Prepare and return product collection
*
* @return Collection
*/
public function initProductCollection()
{
$collection = parent::initProductCollection();
$collection->addStoreFilter()
->setPageSize($this->getProductsCount())
->addAttributeToFilter('ox_featured', '1');
$collection->distinct(true);
$this->addAttributeToSort($collection);
return $collection;
}
public function getCacheKeyInfo($newval = [])
{
return parent::getCacheKeyInfo(['OLEGNAX_PRODUCTSLIDER_FEATURED_PRODUCTS_LIST_WIDGET']);
}
}
@@ -0,0 +1,68 @@
<?php
/**
* Olegnax
*
* 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_ProductSlider
* @copyright Copyright (c) 2023 Olegnax (http://www.olegnax.com/)
* @license https://www.olegnax.com/license
*/
namespace Olegnax\ProductSlider\Block;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;
use Olegnax\ProductSlider\Model\ResourceModel\Report\Product\CollectionFactory;
class MostViewedProducts extends ProductsByIds
{
const FLAT_CATALOG_PATH = 'catalog/frontend/flat_catalog_product';
public function initProductCollection()
{
$storeId = $this->getStoreId();
$collection = $this->_loadObject(CollectionFactory::class)->create();
$collection->addAttributeToSelect('*')
->setStoreId($storeId)
->addStoreFilter($storeId)
->addViewsCount()
->setPageSize($this->getProductsCount());
$flatCatalogProduct = $this->_loadObject(ScopeConfigInterface::class)
->getValue(static::FLAT_CATALOG_PATH, ScopeInterface::SCOPE_STORE);
if ($flatCatalogProduct) {
$collection->getSelect()->joinLeft(
['flat' => 'catalog_product_flat_' . $storeId],
"(e.entity_id = flat.entity_id ) ",
[
'flat.name AS name',
'flat.small_image AS small_image',
'flat.img_hover AS img_hover',
'flat.ox_featured AS ox_featured',
'flat.price AS price',
'flat.special_price as special_price',
'flat.special_from_date AS special_from_date',
'flat.special_to_date AS special_to_date'
]
);
}
return $collection;
}
public function getCacheKeyInfo($newval = [])
{
return parent::getCacheKeyInfo(['OLEGNAX_PRODUCTSLIDER_MOSTVIEWED_PRODUCTS_LIST_WIDGET']);
}
}
+61
View File
@@ -0,0 +1,61 @@
<?php
/**
* Olegnax
*
* 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_ProductSlider
* @copyright Copyright (c) 2023 Olegnax (http://www.olegnax.com/)
* @license https://www.olegnax.com/license
*/
namespace Olegnax\ProductSlider\Block;
use Magento\Framework\Stdlib\DateTime\DateTime;
use Zend_Db_Expr;
class NewProducts extends AbstractShortcode
{
public function initProductCollection()
{
$collection = parent::initProductCollection();
$collection->addStoreFilter($this->getStoreId())
->addAttributeToFilter('news_from_date', ['date' => true, 'to' => $this->getDate('23:59:59')], 'left')
->addAttributeToFilter(
'news_to_date', [
'or' => [
0 => ['date' => true, 'from' => $this->getDate()],
1 => ['is' => new Zend_Db_Expr('null')],
]
], 'left')
->setPageSize($this->getProductsCount())
->distinct(true);
$this->addAttributeToSort($collection, 'news_from_date', 'desc');
return $collection;
}
public function getDate($time = '0:0:0')
{
return $this->_loadObject(DateTime::class)->date(null, $time);
}
public function getCacheKeyInfo($newval = [])
{
return parent::getCacheKeyInfo(['OLEGNAX_PRODUCTSLIDER_NEW_PRODUCTS_LIST_WIDGET']);
}
}
+59
View File
@@ -0,0 +1,59 @@
<?php
/**
* Olegnax
*
* 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_ProductSlider
* @copyright Copyright (c) 2023 Olegnax (http://www.olegnax.com/)
* @license https://www.olegnax.com/license
*/
namespace Olegnax\ProductSlider\Block;
use Magento\Framework\Stdlib\DateTime\DateTime;
use Zend_Db_Expr;
class OnSaleProducts extends AbstractShortcode
{
public function initProductCollection()
{
$collection = parent::initProductCollection();
$collection->addStoreFilter($this->getStoreId())
->addAttributeToFilter('special_from_date', ['date' => true, 'to' => $this->getDate('23:59:59')], 'left')
->addAttributeToFilter(
'special_to_date', [
'or' => [
0 => ['date' => true, 'from' => $this->getDate()],
1 => ['is' => new Zend_Db_Expr('null')],
]
], 'left')
->setPageSize($this->getProductsCount())
->distinct(true);
$this->addAttributeToSort($collection, 'special_from_date', 'desc');
return $collection;
}
public function getDate($time = '0:0:0')
{
return $this->_loadObject(DateTime::class)->date(null, $time);
}
public function getCacheKeyInfo($newval = [])
{
return parent::getCacheKeyInfo(['OLEGNAX_PRODUCTSLIDER_ONSALE_PRODUCTS_LIST_WIDGET']);
}
}
+118
View File
@@ -0,0 +1,118 @@
<?php
/**
* Olegnax
*
* 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_ProductSlider
* @copyright Copyright (c) 2023 Olegnax (http://www.olegnax.com/)
* @license https://www.olegnax.com/license
*/
namespace Olegnax\ProductSlider\Block;
use Magento\Catalog\Model\CategoryFactory;
class ProductsByCategory extends AbstractShortcode
{
protected $_atributtes = [
'title' => '',
'title_align' => 'center',
'title_tag' => 'strong',
'title_side_line' => false,
//region Pagination
'products_count' => 6,
'show_pager' => false,
'products_per_page' => 10,
//endregion
'category_ids' => '',
'columns_desktop' => 4,
'columns_desktop_small' => 3,
'columns_tablet' => 2,
'columns_mobile' => 1,
'loop' => false,
'arrows' => false,
'dots' => false,
'nav_position' => 'left-right',
'dots_align' => 'left',
'show_title' => true,
'autoplay' => false,
'autoplay_time' => '5000',
'pause_on_hover' => false,
'show_addtocart' => true,
'show_wishlist' => true,
'show_compare' => true,
'show_review' => true,
'show_desc' => false,
'show_in_stock' => true,
'rewind' => false,
'sort_order' => '',
'quickview_position' => '',
'products_layout_centered' => false,
'show_swatches' => false,
'review_count' => false,
'hide_name' => false,
'hide_price' => false,
'custom_class' => '',
];
public function initProductCollection()
{
$categoryIds = $this->getCategoryIds();
$collection = parent::initProductCollection();
if (1 == count($categoryIds)) {
$categoryId = array_shift($categoryIds);
$category = $this->_loadObject(CategoryFactory::class)->create()->load($categoryId);
$collection->addCategoryFilter($category);
} else {
$collection->addCategoriesFilter(['eq' => $categoryIds]);
}
$productsCount = $this->getProductsCount();
if ($productsCount) {
$collection->setPageSize($productsCount);
}
$this->addAttributeToSort($collection);
$collection->distinct(true);
return $collection;
}
protected function getCategoryIds(){
$categoryIds = $this->getData('category_ids');
if (!is_array($categoryIds)) {
if ($categoryIds) {
$categoryIds = is_array($categoryIds) ? $categoryIds : explode(',', (string)$categoryIds);
$categoryIds = array_map('intval', $categoryIds);
$categoryIds = array_filter($categoryIds);
$categoryIds = array_unique($categoryIds);
} else {
$categoryIds = [];
}
$this->setData('category_ids', $categoryIds);
}
return $this->getData('category_ids');
}
public function getCacheKeyInfo($newval = [])
{
return parent::getCacheKeyInfo([
'OLEGNAX_PRODUCTSLIDER_CATEGORY_PRODUCTS_LIST_WIDGET',
implode(',', $this->getCategoryIds())
]);
}
}
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace Olegnax\ProductSlider\Block;
use Magento\Catalog\Model\ResourceModel\Product\Collection;
class ProductsByIds extends AbstractShortcodeByIds
{
public function addAttributeToSort(
Collection $collection,
$order_attribute = "",
$order_dir = Collection::SORT_ORDER_ASC
) {
$sortOrder = $this->getSortOrder();
if (empty($sortOrder)) {
$collection->getSelect()->order(
'FIELD(e.entity_id, ' . implode(
",",
array_filter($this->getLoadedProductIds())
) . ')'
);
} else {
parent::addAttributeToSort($collection, $order_attribute, $order_dir);
}
}
}
+79
View File
@@ -0,0 +1,79 @@
<?php
/*
* @author Olegnax
* @package Olegnax_ProductSlider
* @copyright Copyright (c) 2023 Olegnax (http://olegnax.com/). All rights reserved.
* See COPYING.txt for license details.
*/
namespace Olegnax\ProductSlider\Block;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\View\Element\Template;
use Magento\Ui\Block\Wrapper;
use Magento\Ui\Model\UiComponentGenerator;
use Magento\Widget\Block\BlockInterface;
class RecentlyViewed extends Wrapper implements BlockInterface
{
/**
* @var Json
*/
protected $json;
public function __construct(
Template\Context $context,
UiComponentGenerator $uiComponentGenerator,
Json $json = null,
array $data = []
) {
parent::__construct($context, $uiComponentGenerator, $data);
$this->json = $json ?: ObjectManager::getInstance()->get(Json::class);
}
/**
* @param array $options
* @param bool $json
*
* @return array|bool|false|string
*/
public function getCarouselOptions($options = [], $json = true)
{
$autoplayTime = (int)$this->getAutoplayTime();
if (!$autoplayTime || $autoplayTime < 500) {
$autoplayTime = 500;
}
$options['itemClass'] = 'product-item';
$options['margin'] = (int)$this->getMargin();
$options['loop'] = (bool)$this->getLoop();
$options['dots'] = (bool)$this->getDots();
$options['nav'] = (bool)$this->getNav();
$options['items'] = (int)$this->getColumnsDesktop();
$options['autoplay'] = (bool)$this->getAutoplay();
$options['autoplayTimeout'] = $autoplayTime;
$options['autoplayHoverPause'] = (bool)$this->getPauseOnHover();
$options['lazyLoad'] = true;
$options['rewind'] = (bool)$this->getRewind();
$options['responsive'] = [
'0' => [
'items' => max(1, (int)$this->getColumnsMobile()),
],
'640' => [
'items' => max(1, (int)$this->getColumnsTablet()),
],
'1025' => [
'items' => max(1, (int)$this->getColumnsDesktopSmall()),
],
'1160' => [
'items' => max(1, (int)$this->getColumnsDesktop()),
],
];
if ($json) {
return $this->json->serialize(['OXowlCarousel' => $options]);
}
return $options;
}
}
+41
View File
@@ -0,0 +1,41 @@
<?php
/**
* Olegnax
*
* 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_ProductSlider
* @copyright Copyright (c) 2023 Olegnax (http://www.olegnax.com/)
* @license https://www.olegnax.com/license
*/
namespace Olegnax\ProductSlider\Block;
use Magento\Reports\Block\Product\Viewed;
class ViewedProducts extends AbstractShortcode
{
public function initProductCollection()
{
$collection = $this->_loadObject(Viewed::class)
->getItemsCollection()
->setPageSize($this->getProductsCount());
$collection->distinct(true);
return $collection;
}
}
+46
View File
@@ -0,0 +1,46 @@
<?php
/**
* Olegnax
*
* 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_ProductSlider
* @copyright Copyright (c) 2023 Olegnax (http://www.olegnax.com/)
* @license https://www.olegnax.com/license
*/
namespace Olegnax\ProductSlider\Block;
use Magento\Customer\Model\Session;
use Magento\Wishlist\Model\ResourceModel\Item\CollectionFactory;
class WishlistProducts extends ProductsByIds
{
public function getLoadedProductIds()
{
$productIds = [];
$customerSession = $this->_loadObject(Session::class);
if ($customerSession->isLoggedIn()) {
$_productCollection = $this->_loadObject(CollectionFactory::class)->create()
->addCustomerIdFilter($customerSession->getCustomerId());
foreach ($_productCollection as $_product) {
$productIds[] = $_product->getEntityId();
}
}
return $productIds;
}
}