Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/vendor/mageworx/module-seoxtemplates/Model/Observer/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/mageworx/module-seoxtemplates/Model/Observer/ProductNameToSeoName.php
<?php
/**
 * Copyright © 2016 MageWorx. All rights reserved.
 * See LICENSE.txt for license details.
 */

namespace MageWorx\SeoXTemplates\Model\Observer;

use MageWorx\SeoXTemplates\Helper\Data as HelperData;
use Magento\Framework\App\RequestInterface;

/**
 * Observer class for product seo name
 */
class ProductNameToSeoName implements \Magento\Framework\Event\ObserverInterface
{
    /**
     * @var \MageWorx\SeoXTemplates\Helper\Data
     */
    protected $helperData;

    /**
     * Request object
     *
     * @var \Magento\Framework\App\RequestInterface
     */
    protected $request;

    /**
     *
     * @param HelperData $helperData
     * @param RequestInterface $request
     */
    public function __construct(
        HelperData $helperData,
        RequestInterface $request
    ) {
        $this->request    = $request;
        $this->helperData = $helperData;
    }

    /**
     * Product Name to Product SEO Name for frontend
     *
     * @param Varien_Event_Observer $observer
     * @return void
     */
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        //catalog_product_load_after
        $product = $observer->getData('product');

        if ($this->_out($product)) {
            return;
        }

        $product->setName($product->getProductSeoName());
    }

    /**
     * Check if go out
     *
     * @param $product
     * @return boolean
     */
    protected function _out($product)
    {
        if (!$this->helperData->isUseProductSeoName()) {
            return true;
        }

        if (!is_object($product)) {
            return true;
        }

        if (!in_array($this->request->getFullActionName(), $this->_getAvailableActions())) {
            return true;
        }

        if ($product->getId() != $this->request->getParam('id')) {
            return true;
        }

        if (!$product->getProductSeoName()) {
            return true;
        }
        return false;
    }

    /**
     * Retrieve list of available actions
     *
     * @return array
     */
    protected function _getAvailableActions()
    {
        return ['catalog_product_view'];
    }
}

Spamworldpro Mini