ltsecurityinc安防产品在线商城代码
This commit is contained in:
+149
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
namespace Olegnax\Athlete2\Observer;
|
||||
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Framework\Event\Observer;
|
||||
use Magento\Framework\Event\ObserverInterface;
|
||||
use Magento\Framework\View\Page\Config;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Olegnax\Athlete2\Helper\Helper;
|
||||
|
||||
class AddBodyClass implements ObserverInterface
|
||||
{
|
||||
/**
|
||||
* @var \Olegnax\Athlete2\Helper\Helper
|
||||
*/
|
||||
protected $athleteHelper;
|
||||
protected $config;
|
||||
protected $scopeConfig;
|
||||
|
||||
public function __construct(
|
||||
Config $config,
|
||||
Helper $helper,
|
||||
ScopeConfigInterface $scopeConfig
|
||||
) {
|
||||
$this->config = $config;
|
||||
$this->athleteHelper = $helper;
|
||||
$this->scopeConfig = $scopeConfig;
|
||||
}
|
||||
|
||||
public function execute(Observer $observer)
|
||||
{
|
||||
if (!$this->getConfig(Helper::XML_ENABLED)) {
|
||||
return;
|
||||
}
|
||||
$class = [];
|
||||
if (1 == $this->getConfig('athlete2_design/appearance_toolbar/toolbar_nobg')) {
|
||||
$class[] = 'toolbar-nobg';
|
||||
}
|
||||
if (1 == $this->getConfig('athlete2_design/appearance_sidebar/sidebar_nobg')) {
|
||||
$class[] = 'sidebar-nobg';
|
||||
}
|
||||
if (1 == $this->getConfig('athlete2_settings/product/gallery_zoom_cursor')) {
|
||||
$class[] = 'custom-gallery-cursor';
|
||||
}
|
||||
if (1 == $this->athleteHelper->isLazyLoadEnabled()) {
|
||||
$class[] = 'ox-lazy';
|
||||
}
|
||||
if (1 == $this->getConfig('athlete2_settings/general/messages_fixed')) {
|
||||
$class[] = 'ox-messages-fixed';
|
||||
}
|
||||
if ('2' == $this->getConfig('athlete2_settings/product/actions_position')){
|
||||
$count = 0;
|
||||
if( 1 == $this->getConfig('athlete2_settings/product/compare_disable')){
|
||||
$count++;
|
||||
}
|
||||
if(1 == $this->getConfig('athlete2_settings/product/wishlist_disable')){
|
||||
$count++;
|
||||
}
|
||||
if($count == 1){
|
||||
$class[] = 'ox-quickview-sa';
|
||||
}
|
||||
}
|
||||
$class[] = $this->getConfig('athlete2_settings/header/menu_hover_style');
|
||||
$class[] = 'menu--align-' . $this->getConfig('athlete2_settings/header/menu_align');
|
||||
if(!empty($this->getConfig('athlete2_settings/header/menu_align_sticky'))) {
|
||||
$class[] = 'menu--align-sticky-' . $this->getConfig('athlete2_settings/header/menu_align_sticky');
|
||||
}
|
||||
$class[] = 'minicart--style-' . $this->getConfig('athlete2_settings/header/minicart_style');
|
||||
$class[] = 'mobile-header--layout-' . $this->getConfig('athlete2_settings/mobile_header/mobile_header_layout');
|
||||
$class[] = 'footer--layout-' . $this->getConfig('athlete2_settings/footer/footer_layout');
|
||||
$header_layout = $this->getConfig('athlete2_settings/header/header_layout');
|
||||
$class[] = 'header--layout-' . $header_layout[-1];
|
||||
|
||||
if (1 == $this->getConfig('athlete2_settings/contacts_page/contacts_page_fullwidth')) {
|
||||
$class[] = 'contacts-fullwidth';
|
||||
}
|
||||
if (1 == $this->getConfig('athlete2_settings/products_listing/grid_fullwidth')) {
|
||||
$class[] = 'categories--fullwidth';
|
||||
}
|
||||
if (1 == $this->getConfig('athlete2_settings/product/product_fullwidth')) {
|
||||
$class[] = 'product-page--fullwidth';
|
||||
}
|
||||
if ( $this->getConfig('athlete2_settings/product/product_tabs_style')) {
|
||||
$class[] = 'tabs-style--' . $this->getConfig('athlete2_settings/product/product_tabs_style');
|
||||
}
|
||||
if (2 == $this->getConfig('athlete2_settings/header/menu_position')) {
|
||||
$class[] = 'menu-position--below';
|
||||
}
|
||||
if (1 == $this->getConfig('athlete2_settings/header/minicart_btn_minimal')) {
|
||||
$class[] = 'minicart-btn--minimal';
|
||||
}
|
||||
if (1 == $this->getConfig('athlete2_settings/header/minicart_counter_mobile')) {
|
||||
$class[] = 'minicart--show-counter-mobile';
|
||||
}
|
||||
if (1 == $this->getConfig('athlete2_settings/header/minicart_btn_hide_icon') && !$this->getConfig('athlete2_settings/header/minicart_btn_minimal')) {
|
||||
$class[] = 'minicart-btn__icon--hide';
|
||||
}
|
||||
if ('main' != $this->getConfig('athlete2_settings/mobile_header/wishlist_mobile_position') && '' != $this->getConfig('athlete2_settings/mobile_header/wishlist_mobile_position')) {
|
||||
$class[] = 'mobile-header__wishlist--hide';
|
||||
}
|
||||
if ('main' != $this->getConfig('athlete2_settings/mobile_header/compare_mobile_position') && '' != $this->getConfig('athlete2_settings/mobile_header/compare_mobile_position')) {
|
||||
$class[] = 'mobile-header__compare--hide';
|
||||
}
|
||||
if ($this->getConfig('athlete2_settings/header/sticky_header') && $this->getConfig('athlete2_settings/header/sticky_header_smart')) {
|
||||
$class[] = 'sticky-smart';
|
||||
} else {
|
||||
$class[] = 'sticky-simple';
|
||||
}
|
||||
if ($this->getConfig('athlete2_settings/header/sticky_header') && $this->getConfig('athlete2_settings/header/sticky_header_minimized')) {
|
||||
$class[] = 'sticky-minimized';
|
||||
}
|
||||
if ($this->getConfig('athlete2_design/appearance_general/inputs_underlined')) {
|
||||
$class[] = 'inputs-style--underlined';
|
||||
}
|
||||
if ($this->getConfig('athlete2_settings/products_listing/quickview_mobile')) {
|
||||
$class[] = 'quickview-mobile--hide';
|
||||
}
|
||||
|
||||
foreach ($class as $_class) {
|
||||
$this->addBodyClass($_class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getConfig($path, $storeCode = null)
|
||||
{
|
||||
$value = $this->scopeConfig->getValue($path, ScopeInterface::SCOPE_STORE, $storeCode);
|
||||
if (is_null($value)) {
|
||||
$value = '';
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function addBodyClass($className)
|
||||
{
|
||||
$className = strtolower($className);
|
||||
$bodyClasses = $this->config->getElementAttribute(Config::ELEMENT_TYPE_BODY, Config::BODY_ATTRIBUTE_CLASS);
|
||||
$bodyClasses = $bodyClasses ? explode(' ', $bodyClasses) : [];
|
||||
$bodyClasses[] = $className;
|
||||
$bodyClasses = array_unique($bodyClasses);
|
||||
$this->config->setElementAttribute(
|
||||
Config::ELEMENT_TYPE_BODY,
|
||||
Config::BODY_ATTRIBUTE_CLASS,
|
||||
implode(' ', $bodyClasses)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace Olegnax\Athlete2\Observer;
|
||||
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Magento\Framework\Event\Observer;
|
||||
use Magento\Framework\Event\ObserverInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Serialize\Serializer\Json;
|
||||
use Magento\Framework\View\Element\AbstractBlock;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Olegnax\Athlete2\Block\Product\View;
|
||||
use Olegnax\Athlete2\Helper\Helper;
|
||||
|
||||
class BeforeLoadBlock implements ObserverInterface
|
||||
{
|
||||
const OPTION_CUSTOMTABS_BY_BLOCK = 'athlete2_settings/product/customtabs_by_block';
|
||||
const OPTION_CUSTOMTABS_BY_ATTRIBUTE = 'athlete2_settings/product/customtabs_by_attribute';
|
||||
const OPTION_CUSTOMTABS_ENABLED = 'athlete2_settings/product/customtabs_enable';
|
||||
|
||||
const CHILD_TEMPLATE = View::class;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var ScopeConfigInterface
|
||||
*/
|
||||
protected $scopeConfig;
|
||||
|
||||
/**
|
||||
* @var Json
|
||||
*/
|
||||
private $serializer;
|
||||
|
||||
/**
|
||||
* BeforeLoadBlock constructor.
|
||||
* @param ScopeConfigInterface $scopeConfig
|
||||
* @param Json|null $serializer
|
||||
*/
|
||||
public function __construct(
|
||||
ScopeConfigInterface $scopeConfig,
|
||||
Json $serializer = null
|
||||
) {
|
||||
$this->scopeConfig = $scopeConfig;
|
||||
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Observer $observer
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function execute(Observer $observer)
|
||||
{
|
||||
if (!$this->getConfig(Helper::XML_ENABLED) || !$this->getConfig(static::OPTION_CUSTOMTABS_ENABLED)) {
|
||||
return;
|
||||
}
|
||||
/** @var AbstractBlock $block */
|
||||
$block = $observer->getData('block');
|
||||
$current_name = $block->getNameInLayout();
|
||||
|
||||
if (in_array($current_name, ['product.info.details'])) {
|
||||
$tabs_by_block = $this->getConfig(static::OPTION_CUSTOMTABS_BY_BLOCK);
|
||||
$tabs_by_attr = $this->getConfig(static::OPTION_CUSTOMTABS_BY_ATTRIBUTE);
|
||||
$tabs_by_block = empty($tabs_by_block) ? false : $this->serializer->unserialize($tabs_by_block);
|
||||
$tabs_by_attr = empty($tabs_by_attr) ? false : $this->serializer->unserialize($tabs_by_attr);
|
||||
$tabs = [];
|
||||
if (is_array($tabs_by_attr)) {
|
||||
$tabs = array_merge($tabs, $tabs_by_attr);
|
||||
}
|
||||
if (is_array($tabs_by_block)) {
|
||||
$tabs = array_merge($tabs, $tabs_by_block);
|
||||
}
|
||||
$index = 40;
|
||||
foreach ($tabs as $key => $value) {
|
||||
if (!isset($value['sort_order']) || empty($value['sort_order'])) {
|
||||
$tabs[$key]['sort_order'] = $index;
|
||||
$index++;
|
||||
}
|
||||
}
|
||||
|
||||
uasort($tabs, [$this, 'sorter']);
|
||||
|
||||
foreach ($tabs as $key => $value) {
|
||||
/** @var View $_block */
|
||||
$_block = $block->getLayout()->createBlock(
|
||||
static::CHILD_TEMPLATE,
|
||||
$current_name . '.custom' . $key,
|
||||
['data' => $value]
|
||||
);
|
||||
$_block_name = $_block->getNameInLayout();
|
||||
$block->setChild('custom' . $key, $_block);
|
||||
$block->getLayout()->addToParentGroup($_block_name, 'detailed_info');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getConfig($path)
|
||||
{
|
||||
$value = $this->scopeConfig->getValue(
|
||||
$path,
|
||||
ScopeInterface::SCOPE_STORE
|
||||
);
|
||||
if (is_null($value)) {
|
||||
$value = '';
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function sorter($first, $next)
|
||||
{
|
||||
$a = isset($first['sort_order']) ? (int)$first['sort_order'] : 10;
|
||||
$b = isset($next['sort_order']) ? (int)$next['sort_order'] : 10;
|
||||
if ($a == $b) {
|
||||
return 0;
|
||||
}
|
||||
return ($a < $b) ? -1 : 1;
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Set layout for blog pages
|
||||
*
|
||||
* @category Olegnax
|
||||
* @package Olegnax_Athlete2
|
||||
* @copyright Copyright (c) 2023 Olegnax (http://www.olegnax.com/)
|
||||
* @license https://www.olegnax.com/license
|
||||
*/
|
||||
|
||||
namespace Olegnax\Athlete2\Observer;
|
||||
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Framework\Event\Observer;
|
||||
use Magento\Framework\Event\ObserverInterface;
|
||||
use Magento\Framework\View\Page\Config;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Olegnax\Athlete2\Helper\Helper;
|
||||
|
||||
class ChangeBlogLayout implements ObserverInterface
|
||||
{
|
||||
|
||||
protected $config;
|
||||
protected $scopeConfig;
|
||||
|
||||
public function __construct(
|
||||
Config $config,
|
||||
ScopeConfigInterface $scopeConfig
|
||||
) {
|
||||
$this->config = $config;
|
||||
$this->scopeConfig = $scopeConfig;
|
||||
}
|
||||
|
||||
public function execute(Observer $observer)
|
||||
{
|
||||
$variable = $this->getConfig('athlete2_settings/blog/blog_list_page_layout');
|
||||
if ($this->getConfig(Helper::XML_ENABLED) && !empty($variable)) {
|
||||
$this->config->setPageLayout($variable);
|
||||
}
|
||||
}
|
||||
|
||||
public function getConfig($path, $storeCode = null)
|
||||
{
|
||||
$value = $this->scopeConfig->getValue($path, ScopeInterface::SCOPE_STORE, $storeCode);
|
||||
if (is_null($value)) {
|
||||
$value = '';
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
||||
+174
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
/**
|
||||
* Set layout
|
||||
*
|
||||
* @category Olegnax
|
||||
* @package Olegnax_Athlete2
|
||||
* @copyright Copyright (c) 2023 Olegnax (http://www.olegnax.com/)
|
||||
* @license https://www.olegnax.com/license
|
||||
*/
|
||||
|
||||
namespace Olegnax\Athlete2\Observer;
|
||||
|
||||
use Magento\Catalog\Model\Category;
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Cms\Api\Data\PageInterface;
|
||||
use Magento\Cms\Api\PageRepositoryInterface;
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use Magento\Framework\Event\Observer;
|
||||
use Magento\Framework\Event\ObserverInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Framework\View\Page\Config;
|
||||
use Olegnax\Athlete2\Helper\Helper;
|
||||
|
||||
class ChangeLayout implements ObserverInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
protected $config;
|
||||
/**
|
||||
* @var RequestInterface
|
||||
*/
|
||||
private $_request;
|
||||
/**
|
||||
* @var Helper
|
||||
*/
|
||||
private $_helper;
|
||||
/**
|
||||
* @var Registry
|
||||
*/
|
||||
private $_registry;
|
||||
/**
|
||||
* @var PageRepositoryInterface
|
||||
*/
|
||||
private $_pageRepository;
|
||||
|
||||
/**
|
||||
* ChangeLayout constructor.
|
||||
* @param Config $config
|
||||
* @param RequestInterface $request
|
||||
* @param Registry $registry
|
||||
* @param PageRepositoryInterface $pageRepository
|
||||
* @param Helper $helper
|
||||
*/
|
||||
public function __construct(
|
||||
Config $config,
|
||||
RequestInterface $request,
|
||||
Registry $registry,
|
||||
PageRepositoryInterface $pageRepository,
|
||||
Helper $helper
|
||||
) {
|
||||
$this->config = $config;
|
||||
$this->_request = $request;
|
||||
$this->_registry = $registry;
|
||||
$this->_pageRepository = $pageRepository;
|
||||
$this->_helper = $helper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Observer $observer
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function execute(Observer $observer)
|
||||
{
|
||||
if (!$this->_helper->getSystemValue(Helper::XML_ENABLED)) {
|
||||
return;
|
||||
}
|
||||
$variable = '';
|
||||
$actionName = $this->_request->getFullActionName();
|
||||
switch ($actionName) {
|
||||
case 'catalog_category_view':
|
||||
$category = $this->getCurrentCategory();
|
||||
if ($category) {
|
||||
$variable = $category->getData('page_layout');
|
||||
}
|
||||
|
||||
if (($category
|
||||
&& !$category->getData('custom_use_parent_settings')
|
||||
&& empty($variable)
|
||||
)
|
||||
|| !$category
|
||||
) {
|
||||
$variable = $this->getModuleConfig('products_listing/catalog_page_layout');
|
||||
}
|
||||
break;
|
||||
case 'cms_page_view':
|
||||
$page = $this->getCurrentPage();
|
||||
if ($page) {
|
||||
$variable = $page->getData('page_layout');
|
||||
}
|
||||
|
||||
if (empty($variable) || 'empty' !== $variable) {
|
||||
$variable = $this->getModuleConfig('cms_pages/cms_page_layout');
|
||||
}
|
||||
break;
|
||||
case 'catalogsearch_result_index':
|
||||
$variable = $this->getModuleConfig('products_listing/search_results_layout');
|
||||
break;
|
||||
case 'catalog_product_view':
|
||||
$product = $this->getCurrentProduct();
|
||||
if ($product) {
|
||||
$variable = $product->getData('page_layout');
|
||||
}
|
||||
|
||||
if (empty($variable)) {
|
||||
$variable = $this->getModuleConfig('product/product_page_layout');
|
||||
}
|
||||
break;
|
||||
case 'blog_index_index':
|
||||
case 'blog_search_index':
|
||||
case 'blog_archive_view':
|
||||
$variable = $this->getModuleConfig('blog/blog_list_page_layout');
|
||||
break;
|
||||
}
|
||||
|
||||
if (!empty($variable)) {
|
||||
$this->config->setPageLayout($variable);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Category
|
||||
*/
|
||||
protected function getCurrentCategory()
|
||||
{
|
||||
return $this->_registry->registry('current_category') ?: $this->_registry->registry('category');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getModuleConfig($path = '')
|
||||
{
|
||||
return $this->_helper->getModuleConfig($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PageInterface
|
||||
*/
|
||||
protected function getCurrentPage()
|
||||
{
|
||||
try {
|
||||
$pageId = $this->_request->getParam('page_id', $this->_request->getParam('id', false));
|
||||
if ($pageId) {
|
||||
return $this->_pageRepository->getById($pageId);
|
||||
}
|
||||
} catch (LocalizedException $e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Product
|
||||
*/
|
||||
public function getCurrentProduct()
|
||||
{
|
||||
return $this->_registry->registry('current_product') ?: $this->_registry->registry('product');
|
||||
}
|
||||
}
|
||||
+388
@@ -0,0 +1,388 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_DeferJS
|
||||
* @copyright Copyright (c) 2023 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*
|
||||
* @noinspection PhpUndefinedClassInspection
|
||||
*/
|
||||
|
||||
namespace Olegnax\Athlete2\Observer;
|
||||
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use Magento\Framework\App\Cache;
|
||||
use Magento\Framework\App\Cache\State;
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use Magento\Framework\App\Response\Http as ResponseHttp;
|
||||
use Magento\Framework\Event\Observer;
|
||||
use Magento\Framework\Event\ObserverInterface;
|
||||
use Magento\Framework\Serialize\Serializer\Json;
|
||||
use Magento\PageCache\Model\Cache\Type;
|
||||
use Olegnax\Athlete2\Helper\Helper;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Class for modifying js elements in the page source
|
||||
*/
|
||||
class DeferJS implements ObserverInterface
|
||||
{
|
||||
const DEFERJS = 'general/deferjs';
|
||||
const DEFERJS_USE_CACHE = 'general/deferjs_use_cache';
|
||||
const DEFERJS_COMBINE_INLINE = 'general/deferjs_combine_inline';
|
||||
const DEFERJS_COMBINE_MAGENTOINIT = 'general/deferjs_combine_magentoinit';
|
||||
const DEFERJS_EXCLUDE_HOMEPAGE = 'general/deferjs_exclude_homepage';
|
||||
const DEFERJS_EXCLUDE_ACTION = 'general/deferjs_exclude_action';
|
||||
const DEFERJS_EXCLUDE_PATH = 'general/deferjs_exclude_path';
|
||||
const DEFERJS_SHOW_ACTION_PATH = 'general/deferjs_show_action_path';
|
||||
|
||||
const CACHE_KEY_PREFIX = 'OX_DEFERJS_';
|
||||
const TYPE_IDENTIFIER = Type::TYPE_IDENTIFIER;
|
||||
const CACHE_TAG = Type::CACHE_TAG;
|
||||
/**
|
||||
* @var Helper
|
||||
*/
|
||||
protected $helper;
|
||||
/**
|
||||
* @var RequestInterface
|
||||
*/
|
||||
protected $request;
|
||||
/**
|
||||
* @var Json
|
||||
*/
|
||||
protected $serializer;
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
protected $logger;
|
||||
/**
|
||||
* @var Cache
|
||||
*/
|
||||
protected $_cache;
|
||||
/**
|
||||
* @var State
|
||||
*/
|
||||
protected $_cacheState;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $_useCache;
|
||||
|
||||
/**
|
||||
* FrontSendResponseBefore constructor.
|
||||
*
|
||||
* @param Helper $helper
|
||||
* @param RequestInterface $request
|
||||
* @param LoggerInterface $logger
|
||||
* @param State $cacheState
|
||||
* @param Type $cache
|
||||
* @param Json|null $serializer
|
||||
*/
|
||||
public function __construct(
|
||||
Helper $helper,
|
||||
RequestInterface $request,
|
||||
LoggerInterface $logger,
|
||||
State $cacheState,
|
||||
Type $cache,
|
||||
Json $serializer = null
|
||||
) {
|
||||
$this->helper = $helper;
|
||||
$this->request = $request;
|
||||
$this->logger = $logger;
|
||||
$this->_cacheState = $cacheState;
|
||||
$this->_cache = $cache ?: $helper->_loadObject(Type::class);
|
||||
$this->serializer = $serializer ?: $helper->_loadObject(Json::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $value
|
||||
* @return string
|
||||
*/
|
||||
public function mapCondition($value)
|
||||
{
|
||||
if (is_array($value) && array_key_exists('condition', $value)) {
|
||||
$value = $value['condition'];
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function useCache() {
|
||||
if (!is_bool($this->_useCache)) {
|
||||
//$this->_useCache = (bool) $this->helper->getModuleConfig(static::DEFERJS_USE_CACHE);
|
||||
$this->_useCache = false;
|
||||
}
|
||||
return (bool)$this->_useCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Observer $observer
|
||||
*/
|
||||
public function execute(Observer $observer)
|
||||
{
|
||||
if (!$this->allowedDefer()) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var ResponseHttp $response */
|
||||
$response = $observer->getEvent()->getData('response');
|
||||
if (!$response) {
|
||||
return;
|
||||
}
|
||||
$html = $response->getBody();
|
||||
if (empty($html)) {
|
||||
return;
|
||||
}
|
||||
if ($this->useCache()) {
|
||||
$_html = $this->_loadCache();
|
||||
if (!empty($_html)) {
|
||||
$response->setBody($html);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$html = $this->defer($html);
|
||||
$html = $this->showActionPath($html);
|
||||
|
||||
if ($this->useCache()) {
|
||||
$this->_saveCache($html, $response);
|
||||
}
|
||||
$response->setBody($html);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function allowedDefer()
|
||||
{
|
||||
if (!$this->helper->isEnabled()
|
||||
|| !$this->getConfig(static::DEFERJS)
|
||||
|| $this->request->isXmlHttpRequest()
|
||||
|| (
|
||||
$this->getConfig(static::DEFERJS_EXCLUDE_HOMEPAGE)
|
||||
&& $this->helper->isHomePage()
|
||||
)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$exclude_action = $this->getConfig(static::DEFERJS_EXCLUDE_ACTION);
|
||||
$exclude_path = $this->getConfig(static::DEFERJS_EXCLUDE_PATH);
|
||||
try {
|
||||
$exclude_action = empty($exclude_action) ? [] : $this->serializer->unserialize($exclude_action);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$exclude_action = [];
|
||||
}
|
||||
$exclude_action = array_map([$this, 'mapCondition'], $exclude_action);
|
||||
|
||||
try {
|
||||
$exclude_path = empty($exclude_path) ? [] : $this->serializer->unserialize($exclude_path);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$exclude_path = [];
|
||||
}
|
||||
$exclude_path = array_map([$this, 'mapCondition'], $exclude_path);
|
||||
|
||||
$action = $this->request->getFullActionName();
|
||||
$path = $this->request->getPathInfo();
|
||||
$org_path = $this->request->getOriginalPathInfo();
|
||||
if (in_array($action, $exclude_action)
|
||||
|| in_array($path, $exclude_path)
|
||||
|| in_array($org_path, $exclude_path)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getConfig($path = '')
|
||||
{
|
||||
return $this->helper->getModuleConfig($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load response from cache storage
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _loadCache()
|
||||
{
|
||||
$cacheKey = $this->getCacheKey();
|
||||
$html = $this->_cache->load($cacheKey);
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Key for caching block content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCacheKey()
|
||||
{
|
||||
$data = [
|
||||
$this->request->isSecure(),
|
||||
$this->request->getUriString(),
|
||||
$this->request->get(ResponseHttp::COOKIE_VARY_STRING),
|
||||
];
|
||||
|
||||
$key = sha1($this->serializer->serialize($data));
|
||||
|
||||
return static::CACHE_KEY_PREFIX . $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $html
|
||||
* @return string
|
||||
*/
|
||||
protected function defer($html)
|
||||
{
|
||||
$pattern = '@<script([^<>]*+(?<!text/x-magento-template.| nodefer))>(.*?)</script>@ims';
|
||||
if (preg_match_all($pattern, $html, $_matches)) {
|
||||
$html_js = implode('', $_matches[0]);
|
||||
|
||||
// Combine magento init scripts
|
||||
if ($this->getConfig(static::DEFERJS_COMBINE_MAGENTOINIT)) {
|
||||
$html_js = $this->replaceMagentoInit($html_js);
|
||||
}
|
||||
// Combine inline scripts
|
||||
if ($this->getConfig(static::DEFERJS_COMBINE_INLINE)) {
|
||||
$html_js = $this->implodeScript($html_js);
|
||||
}
|
||||
$html = preg_replace($pattern, '', $html);
|
||||
if (preg_match('@</body>@i', $html)) {
|
||||
$html = preg_replace('@</body>@i', '</body>', $html);
|
||||
$html = str_replace('</body>', $html_js . '</body>', $html);
|
||||
} else {
|
||||
$html .= $html_js;
|
||||
}
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $html
|
||||
* @return string
|
||||
*/
|
||||
protected function replaceMagentoInit($html)
|
||||
{
|
||||
$pattern = '@<script[^<>]*type="text/x-magento-init"[^<>]*>(.+)</script>@msU';
|
||||
if (preg_match_all($pattern, $html, $matches)) {
|
||||
foreach ($matches[1] as $key => $value) {
|
||||
try {
|
||||
$_value = $this->serializer->unserialize($value);
|
||||
$matches[1][$key] = is_array($_value) ? $_value : [];
|
||||
$html = str_replace($matches[0][$key], '', $html);
|
||||
} catch (Exception $exception) {
|
||||
$this->logger->error(__('Wrong Json structure: ' . $value));
|
||||
unset($matches[1][$key]);
|
||||
}
|
||||
}
|
||||
/** @var array $matches */
|
||||
$matches = call_user_func_array('array_replace_recursive', $matches[1]);
|
||||
$js = '<script type="text/x-magento-init">' . $this->serializer->serialize($matches) . '</script>';
|
||||
$html .= $js;
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $html
|
||||
* @return string
|
||||
*/
|
||||
protected function implodeScript($html)
|
||||
{
|
||||
$pattern = '@(<script[^<>]*>)(.*)</script>@msU';
|
||||
if (preg_match_all($pattern, $html, $matches, PREG_SET_ORDER)) {
|
||||
|
||||
$new_html = [];
|
||||
$script = [];
|
||||
foreach ($matches as $match) {
|
||||
if (preg_match('@src="@i', $match[1])) {
|
||||
if (!empty($script)) {
|
||||
$script[1] = preg_replace('@^\s+@', '', $script[1]);
|
||||
$script[1] = preg_replace('@\s+$@', '', $script[1]);
|
||||
$new_html[] = $script[0] . $script[1] . '</script>';
|
||||
$script = [];
|
||||
}
|
||||
$new_html[] = $match[0];
|
||||
continue;
|
||||
}
|
||||
if (preg_match('@type="(text|application)/javascript"@i', $match[1]) ||
|
||||
!preg_match('@type="([^"]+)"@i', $match[1])
|
||||
) {
|
||||
if (empty($script)) {
|
||||
$script[0] = $match[1];
|
||||
$script[1] = '';
|
||||
}
|
||||
$script[1] .= rtrim(trim($match[2]), ';') . ";\n";
|
||||
} else {
|
||||
$new_html[] = $match[0];
|
||||
}
|
||||
}
|
||||
if (!empty($script)) {
|
||||
$new_html[] = $script[0] . $script[1] . '</script>';
|
||||
}
|
||||
$html = implode('', $new_html);
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $html
|
||||
* @return string
|
||||
*/
|
||||
protected function showActionPath($html)
|
||||
{
|
||||
if ($this->getConfig(static::DEFERJS_SHOW_ACTION_PATH)) {
|
||||
$new_html = '<table>
|
||||
<tr><td>' . __('Action') . '</td><td>' . $this->request->getFullActionName() . '</td></tr>
|
||||
<tr><td>' . __('Path') . '</td><td>' . $this->request->getPathInfo() . '</td></tr>
|
||||
<tr><td>' . __('Original Path') . '</td><td>' . $this->request->getOriginalPathInfo() . '</td></tr>
|
||||
</table>';
|
||||
if (preg_match('@</body>@i', $html)) {
|
||||
$html = preg_replace('@</body>@i', $new_html . '</body>', $html);
|
||||
} else {
|
||||
$html .= $new_html;
|
||||
}
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save response content to cache storage
|
||||
*
|
||||
* @param string $html
|
||||
* @param ResponseHttp $response
|
||||
* @return void
|
||||
*/
|
||||
protected function _saveCache($html, ResponseHttp $response)
|
||||
{
|
||||
if ($this->_cacheState->isEnabled(self::TYPE_IDENTIFIER)
|
||||
&& (
|
||||
$response->getHttpResponseCode() == 200
|
||||
|| $response->getHttpResponseCode() == 404
|
||||
)
|
||||
&& (
|
||||
$this->request->isGet()
|
||||
|| $this->request->isHead()
|
||||
)
|
||||
) {
|
||||
$tagsHeader = $response->getHeader('X-Magento-Tags');
|
||||
$tags = $tagsHeader ? explode(',', $tagsHeader->getFieldValue()) : [];
|
||||
|
||||
$cacheKey = $this->getCacheKey();
|
||||
$tags[] = self::CACHE_TAG;
|
||||
$this->_cache->save($html, $cacheKey, array_unique($tags));
|
||||
}
|
||||
}
|
||||
}
|
||||
+191
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_Athlete2
|
||||
* @copyright Copyright (c) 2023 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Olegnax\Athlete2\Observer;
|
||||
|
||||
use Magento\Framework\App\Cache\State;
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use Magento\Framework\App\Response\Http as ResponseHttp;
|
||||
use Magento\Framework\Event\Observer;
|
||||
use Magento\Framework\Event\ObserverInterface;
|
||||
use Magento\Framework\Serialize\Serializer\Json;
|
||||
use Magento\PageCache\Model\Cache\Type;
|
||||
use Olegnax\Athlete2\Helper\Helper;
|
||||
use Olegnax\Athlete2\Helper\LazyLoad as HelperLazyLoad;
|
||||
|
||||
class LazyLoad implements ObserverInterface
|
||||
{
|
||||
const CACHE_KEY_PREFIX = 'OX_LazyLoad_';
|
||||
const TYPE_IDENTIFIER = Type::TYPE_IDENTIFIER;
|
||||
const CACHE_TAG = Type::CACHE_TAG;
|
||||
const LAZY_USE_CACHE = 'general/lazy_use_cache';
|
||||
/**
|
||||
* @var Helper
|
||||
*/
|
||||
protected $helper;
|
||||
/**
|
||||
* @var State
|
||||
*/
|
||||
protected $_cacheState;
|
||||
/**
|
||||
* @var Type
|
||||
*/
|
||||
protected $_cache;
|
||||
/**
|
||||
* @var Json|null
|
||||
*/
|
||||
protected $serializer;
|
||||
/**
|
||||
* @var RequestInterface
|
||||
*/
|
||||
protected $request;
|
||||
/**
|
||||
* @var Helper
|
||||
*/
|
||||
protected $lazyLoad;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $_useCache;
|
||||
|
||||
/**
|
||||
* FrontSendResponseBefore constructor.
|
||||
*
|
||||
* @param Helper $helper
|
||||
* @param HelperLazyLoad $LazyLoad
|
||||
* @param RequestInterface $request
|
||||
* @param State $cacheState
|
||||
* @param Type $cache
|
||||
* @param Json|null $serializer
|
||||
*/
|
||||
public function __construct(
|
||||
Helper $helper,
|
||||
HelperLazyLoad $LazyLoad,
|
||||
RequestInterface $request,
|
||||
State $cacheState,
|
||||
Type $cache,
|
||||
Json $serializer = null
|
||||
) {
|
||||
$this->helper = $helper;
|
||||
$this->lazyLoad = $LazyLoad;
|
||||
$this->request = $request;
|
||||
$this->_cacheState = $cacheState;
|
||||
$this->_cache = $cache ?: $helper->_loadObject(Type::class);
|
||||
$this->serializer = $serializer ?: $helper->_loadObject(Json::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function useCache() {
|
||||
if (!is_bool($this->_useCache)) {
|
||||
// $this->_useCache = (bool) $this->helper->getModuleConfig(static::LAZY_USE_CACHE);
|
||||
$this->_useCache = false;
|
||||
}
|
||||
return $this->_useCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Observer $observer
|
||||
* @return void
|
||||
*/
|
||||
public function execute(Observer $observer)
|
||||
{
|
||||
if (!$this->lazyLoad->isEnabled()
|
||||
||
|
||||
(
|
||||
$this->request->isXmlHttpRequest() &&
|
||||
$this->request->isAjax()
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var ResponseHttp $response */
|
||||
$response = $observer->getEvent()->getData('response');
|
||||
if (!$response) {
|
||||
return;
|
||||
}
|
||||
$html = $response->getBody();
|
||||
if (empty($html)) {
|
||||
return;
|
||||
}
|
||||
if ($this->useCache()) {
|
||||
$_html = $this->_loadCache();
|
||||
if (!empty($_html)) {
|
||||
$response->setBody($_html);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$html = $this->lazyLoad->replaceImageToLazy($html);
|
||||
|
||||
if ($this->useCache()) {
|
||||
$this->_saveCache($html, $response);
|
||||
}
|
||||
$response->setBody($html);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load response from cache storage
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _loadCache()
|
||||
{
|
||||
$cacheKey = $this->getCacheKey();
|
||||
$html = $this->_cache->load($cacheKey);
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Key for caching block content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCacheKey()
|
||||
{
|
||||
$data = [
|
||||
$this->request->isSecure(),
|
||||
$this->request->getUriString(),
|
||||
$this->request->get(ResponseHttp::COOKIE_VARY_STRING),
|
||||
];
|
||||
|
||||
$key = sha1($this->serializer->serialize($data));
|
||||
|
||||
return static::CACHE_KEY_PREFIX . $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save response content to cache storage
|
||||
*
|
||||
* @param string $html
|
||||
* @param ResponseHttp $response
|
||||
* @return void
|
||||
*/
|
||||
protected function _saveCache($html, ResponseHttp $response)
|
||||
{
|
||||
if ($this->_cacheState->isEnabled(self::TYPE_IDENTIFIER)
|
||||
&& (
|
||||
$response->getHttpResponseCode() == 200
|
||||
|| $response->getHttpResponseCode() == 404
|
||||
)
|
||||
&& (
|
||||
$this->request->isGet()
|
||||
|| $this->request->isHead()
|
||||
)
|
||||
) {
|
||||
$tagsHeader = $response->getHeader('X-Magento-Tags');
|
||||
$tags = $tagsHeader ? explode(',', $tagsHeader->getFieldValue()) : [];
|
||||
|
||||
$cacheKey = $this->getCacheKey();
|
||||
$tags[] = self::CACHE_TAG;
|
||||
$this->_cache->save($html, $cacheKey, array_unique($tags));
|
||||
}
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* Remove Title and Breadcrumbs from blog page
|
||||
*
|
||||
* @category Olegnax
|
||||
* @package Olegnax_Athlete2
|
||||
* @copyright Copyright (c) 2023 Olegnax (http://www.olegnax.com/)
|
||||
* @license https://www.olegnax.com/license
|
||||
*/
|
||||
namespace Olegnax\Athlete2\Observer;
|
||||
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Framework\Event\ObserverInterface;
|
||||
use Magento\Framework\Event\Observer;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Olegnax\Athlete2\Helper\Helper;
|
||||
|
||||
class ModifyBlogLayout implements ObserverInterface {
|
||||
|
||||
protected $config;
|
||||
protected $scopeConfig;
|
||||
|
||||
public function __construct(
|
||||
ScopeConfigInterface $scopeConfig
|
||||
) {
|
||||
$this->scopeConfig = $scopeConfig;
|
||||
}
|
||||
|
||||
public function getConfig( $path, $storeCode = null ) {
|
||||
$value = $this->scopeConfig->getValue( $path, ScopeInterface::SCOPE_STORE, $storeCode );
|
||||
if (is_null($value)) {
|
||||
$value = '';
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function execute( Observer $observer ) {
|
||||
if (!$this->getConfig(Helper::XML_ENABLED)) {
|
||||
return;
|
||||
}
|
||||
$layout = $observer->getLayout();
|
||||
$full_action_name = $observer->getFullActionName();
|
||||
if ( in_array( $full_action_name, [ 'blog_index_index' ] ) ) {
|
||||
$valueBreadcrumbs = $this->getConfig( 'athlete2_settings/blog/hide_breadcrumbs' );
|
||||
$valueTitle = $this->getConfig( 'athlete2_settings/blog/hide_title' );
|
||||
|
||||
if ( $valueBreadcrumbs ) {
|
||||
$this->removeBlock( 'breadcrumbs', $layout );
|
||||
}
|
||||
if ( $valueTitle ) {
|
||||
$this->removeBlock( 'page.main.title', $layout );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function removeBlock( $name, $layout ) {
|
||||
$block = $layout->getBlock( $name );
|
||||
if ( $block ) {
|
||||
$layout->unsetElement( $name );
|
||||
$layout->removeOutputElement( $name );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+166
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
namespace Olegnax\Athlete2\Observer;
|
||||
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Framework\Event\Observer;
|
||||
use Magento\Framework\Event\ObserverInterface;
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Olegnax\Athlete2\Helper\Helper;
|
||||
|
||||
class Move implements ObserverInterface
|
||||
{
|
||||
protected $scopeConfig;
|
||||
/**
|
||||
*
|
||||
* @var ObjectManager
|
||||
*/
|
||||
public $objectManager;
|
||||
/**
|
||||
* @var Helper
|
||||
*/
|
||||
private $helper;
|
||||
public function __construct(
|
||||
Helper $helper,
|
||||
ScopeConfigInterface $scopeConfig
|
||||
)
|
||||
{
|
||||
$this->objectManager = ObjectManager::getInstance();
|
||||
$this->scopeConfig = $scopeConfig;
|
||||
$this->helper = $helper;
|
||||
}
|
||||
|
||||
public function execute(Observer $observer)
|
||||
{
|
||||
if (!$this->getConfig(Helper::XML_ENABLED)) {
|
||||
return;
|
||||
}
|
||||
$layout = $observer->getData('layout');
|
||||
/* move minicart in header 1*/
|
||||
$headerLayout = $this->getConfig('athlete2_settings/header/header_layout');
|
||||
if($headerLayout == 'header_1'){
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_header_move_minicart');
|
||||
}
|
||||
$fullActionName = $observer->getData('full_action_name');
|
||||
|
||||
$account_action_drop = $this->getConfig('athlete2_settings/header/account_action');
|
||||
if($account_action_drop == 'login' && $fullActionName !='customer_account_login' && $fullActionName !='multishipping_checkout_login'){
|
||||
if( version_compare($this->helper->getVersion(), '2.4.0', '>' ) ){
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_login_recaptcha');
|
||||
} elseif (version_compare($this->helper->getVersion(), '2.3.1', '=')) {
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_login_recaptcha_msp_231');
|
||||
} else {
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_login_recaptcha_msp');
|
||||
}
|
||||
}
|
||||
if( version_compare($this->helper->getVersion(), '2.3.6', '>' ) && version_compare($this->helper->getVersion(), '2.4.0', '!=' ) ){
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_header_search_args');
|
||||
}
|
||||
|
||||
if ($fullActionName == 'catalog_category_view' || $fullActionName == 'catalogsearch_result_index' ) {
|
||||
if($this->getConfig('athlete2_settings/products_listing/move_cat_title')){
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_category_move_title');
|
||||
}
|
||||
if($this->getConfig('athlete2_settings/products_listing/move_cat_cms_block')){
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_category_move_cms_block');
|
||||
}
|
||||
/*
|
||||
if($this->getConfig('athlete2_settings/products_listing/move_breadrumbs')){
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_category_move_breadcrumbs');
|
||||
}
|
||||
if($this->getConfig('athlete2_settings/products_listing/move_image')){
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_category_move_image');
|
||||
}
|
||||
if($this->getConfig('athlete2_settings/products_listing/move_desc')){
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_category_move_desc');
|
||||
}*/
|
||||
}
|
||||
if ($fullActionName == 'sales_order_print' ) {
|
||||
$layout->getUpdate()->addHandle('olegnax_remove_newsletter');
|
||||
}
|
||||
if (!in_array($fullActionName, ['catalog_product_view', 'ox_quickview_catalog_product_view'])) {
|
||||
return $this;
|
||||
}
|
||||
/* move reviews */
|
||||
$reviewsInTab = $this->getConfig('athlete2_settings/product/reviews_position');
|
||||
if ($reviewsInTab) {
|
||||
if($reviewsInTab == 'oxbottom'){
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_catalog_product_view_review_oxbottom');
|
||||
} elseif($reviewsInTab == 'bottom'){
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_catalog_product_view_review_bottom');
|
||||
} elseif($reviewsInTab == 'gallery'){
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_catalog_product_view_review_gallery');
|
||||
}
|
||||
} else{
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_catalog_product_view_move_review');
|
||||
}
|
||||
|
||||
$tabsInInfo = $this->getConfig('athlete2_settings/product/product_tabs_position');
|
||||
/*if($fullActionName == 'ox_quickview_catalog_product_view' && $tabsInInfo == 'info'){
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_catalog_product_tabs_remove');
|
||||
}*/
|
||||
|
||||
|
||||
if ($tabsInInfo == 'info') {
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_catalog_product_tabs_right');
|
||||
}
|
||||
if($tabsInInfo == 'oxbottom'){
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_catalog_product_tabs_oxbottom');
|
||||
}
|
||||
if($tabsInInfo == 'bottom'){
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_catalog_product_tabs_bottom');
|
||||
}
|
||||
if($tabsInInfo == 'gallery'){
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_catalog_product_tabs_gallery');
|
||||
}
|
||||
/* move related */
|
||||
$moveRelated = $this->getConfig('athlete2_settings/product/related_positon');
|
||||
$moveUpsell = $this->getConfig('athlete2_settings/product/upsell_positon');
|
||||
if ($moveRelated == 'oxbottom') {
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_catalog_product_related_oxbottom');
|
||||
} elseif($moveRelated == 'bottom'){
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_catalog_product_related_bottom');
|
||||
} elseif($moveRelated == 'gallery'){
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_catalog_product_related_gallery');
|
||||
}
|
||||
if ($moveUpsell == 'oxbottom') {
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_catalog_product_upsell_oxbottom');
|
||||
} elseif($moveUpsell == 'bottom'){
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_catalog_product_upsell_bottom');
|
||||
} elseif($moveUpsell == 'gallery'){
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_catalog_product_upsell_gallery');
|
||||
}
|
||||
/* sticky product, move elements in sticky wrapper */
|
||||
$galleryLayout = $this->getConfig('athlete2_settings/product/gallery_layout');
|
||||
$stickyDesc = $this->getConfig('athlete2_settings/product/gallery_sticky');
|
||||
$infoWrapper = $this->getConfig('athlete2_settings/product/gallery_wrapper');
|
||||
if(($stickyDesc && ($galleryLayout == '1col' || $galleryLayout == '2cols')) || $infoWrapper){
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_catalog_product_info_wrapper');
|
||||
}
|
||||
/* replace fotorama with css only gallery for mobile theme */
|
||||
if( $this->getConfig('athlete2_settings/product/css_only_gallery')){
|
||||
if($this->objectManager->get( 'Olegnax\Core\Helper\Helper' )->isMobileTheme()){
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_css_only_gallery');
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_remove_fotorama_video');
|
||||
}
|
||||
}
|
||||
|
||||
if($fullActionName == 'catalog_product_view' && ( $galleryLayout == '1col' || $galleryLayout == '2cols')){
|
||||
/* remove fotorama video if fotorama disabled */
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_remove_fotorama_video');
|
||||
/* set product gallery layout */
|
||||
$layout->getUpdate()->addHandle('olegnax_athlete2_product_gallery_layout');
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getConfig($path, $storeCode = null)
|
||||
{
|
||||
$value = $this->scopeConfig->getValue($path, ScopeInterface::SCOPE_STORE, $storeCode);
|
||||
if (is_null($value)) {
|
||||
$value = '';
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
/* renamed to Move.php in 1.5 */
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Save Athlete2 Settings interface
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Olegnax\Athlete2\Observer;
|
||||
|
||||
use Exception;
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Framework\Event\Observer;
|
||||
use Magento\Framework\Event\ObserverInterface;
|
||||
use Magento\Framework\Message\ManagerInterface;
|
||||
use Olegnax\Athlete2\Helper\Helper;
|
||||
use Olegnax\Athlete2\Model\DynamicStyle\Generator;
|
||||
|
||||
class SaveAthlete2License implements ObserverInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var ManagerInterface
|
||||
*/
|
||||
protected $_messageManager;
|
||||
|
||||
/**
|
||||
* @var Helper
|
||||
*/
|
||||
protected $_helper;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Generator $generator
|
||||
*/
|
||||
public function __construct(
|
||||
ManagerInterface $messageManager,
|
||||
Helper $helper
|
||||
) {
|
||||
$this->_messageManager = $messageManager;
|
||||
$this->_helper = $helper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Observer $observer
|
||||
* @return void
|
||||
*/
|
||||
public function execute(Observer $observer)
|
||||
{
|
||||
$this->_messageManager->getMessages(true);
|
||||
$code = trim((string)$this->_helper->getSystemDefaultValue('athlete2_license/general/code'));
|
||||
|
||||
try {
|
||||
$license = $this->_helper->get();
|
||||
|
||||
if ((empty($license) || !isset($license->data->the_key)) && !empty($code)) {
|
||||
$this->activate($code);
|
||||
} elseif (!empty($license) && isset($license->data->the_key)) {
|
||||
if ($license->data->the_key == $code) {
|
||||
$this->validate();
|
||||
} elseif (!empty($code)) {
|
||||
$this->reactivate($code);
|
||||
} else {
|
||||
$this->deactivate();
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->_messageManager->addErrorMessage(__($e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
private function activate($code, $showMessages = true)
|
||||
{
|
||||
$result = $this->_helper->activate($code);
|
||||
if (!$result) {
|
||||
$this->_messageManager->addErrorMessage(__("Incorrect response from server"));
|
||||
return false;
|
||||
}
|
||||
if ($showMessages) {
|
||||
$this->messages($result);
|
||||
}
|
||||
if (isset($result->error) && $result->error) {
|
||||
$this->_helper->setSystemValue(
|
||||
'athlete2_license/general/code',
|
||||
'',
|
||||
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
|
||||
0
|
||||
);
|
||||
}
|
||||
return !$result->error;
|
||||
}
|
||||
|
||||
private function messages($result)
|
||||
{
|
||||
if (!$result->error) {
|
||||
$this->_messageManager->addSuccessMessage(__($result->message));
|
||||
if (isset($result->notices)) {
|
||||
foreach ($result->notices as $noticeGroup) {
|
||||
$this->_messageManager->addNoticeMessage(__(implode(' ', $noticeGroup)));
|
||||
}
|
||||
}
|
||||
} elseif (isset($result->errors)) {
|
||||
foreach ($result->errors as $errorsGroup) {
|
||||
$this->_messageManager->addErrorMessage(__(implode(' ', $errorsGroup)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function validate()
|
||||
{
|
||||
$this->_helper->validate(true);
|
||||
}
|
||||
|
||||
private function reactivate($code)
|
||||
{
|
||||
if ($this->deactivate(false)) {
|
||||
return $this->activate($code);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function deactivate($showMessages = true)
|
||||
{
|
||||
$result = $this->_helper->deactivate();
|
||||
if (!$result) {
|
||||
$this->_messageManager->addErrorMessage(__("Incorrect response from server"));
|
||||
return false;
|
||||
}
|
||||
if ($showMessages) {
|
||||
$this->messages($result);
|
||||
}
|
||||
return !$result->error;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Save Athlete2 Settings interface
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Olegnax\Athlete2\Observer;
|
||||
|
||||
use Exception;
|
||||
use Magento\Framework\Event\Observer;
|
||||
use Magento\Framework\Event\ObserverInterface;
|
||||
use Magento\Framework\Message\ManagerInterface;
|
||||
use Olegnax\Athlete2\Helper\Helper;
|
||||
use Olegnax\Athlete2\Model\DynamicStyle\Generator as DynamicStyleGenerator;
|
||||
|
||||
class SaveAthlete2Settings implements ObserverInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Dynamic Style generator
|
||||
*
|
||||
* @var DynamicStyleGenerator
|
||||
*/
|
||||
protected $_DynamicStyleGenerator;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @var Helper
|
||||
*/
|
||||
protected $_helper;
|
||||
/**
|
||||
* @var ManagerInterface
|
||||
*/
|
||||
private $_messageManager;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param DynamicStyleGenerator $generator
|
||||
*/
|
||||
public function __construct(
|
||||
ManagerInterface $messageManager,
|
||||
DynamicStyleGenerator $generator,
|
||||
Helper $helper
|
||||
) {
|
||||
$this->_messageManager = $messageManager;
|
||||
$this->_DynamicStyleGenerator = $generator;
|
||||
$this->_helper = $helper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Observer $observer
|
||||
* @return void
|
||||
*/
|
||||
public function execute(Observer $observer)
|
||||
{
|
||||
try {
|
||||
$this->_helper->validate();
|
||||
} catch (Exception $e) {
|
||||
$this->_messageManager->addErrorMessage(__($e->getMessage()));
|
||||
}
|
||||
$this->_DynamicStyleGenerator->generate('settings', $observer->getData('website'), $observer->getData('store'));
|
||||
$this->_helper->validate();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user