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/amasty/shopby-seo/Model/SeoOptionsModifier/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/amasty/shopby-seo/Model/SeoOptionsModifier/YesNoAliases.php
<?php

declare(strict_types=1);

/**
 * @author Amasty Team
 * @copyright Copyright (c) Amasty (https://www.amasty.com)
 * @package Shop by Seo for Magento 2 (System)
 */

namespace Amasty\ShopbySeo\Model\SeoOptionsModifier;

use Amasty\ShopbySeo\Helper\Data;
use Magento\Eav\Model\ResourceModel\Entity\Attribute\CollectionFactory;

class YesNoAliases implements SeoModifierInterface
{
    public const ATTRIBUTE_TYPE_BOOLEAN = 'boolean';

    public const VALUE_YES = 1;
    public const VALUE_NO = 0;
    public const LABEL_YES = 'yes';
    public const LABEL_NO = 'no';

    /**
     * @var Data
     */
    private $seoHelper;

    /**
     * @var CollectionFactory
     */
    private $attributeCollectionFactory;

    /**
     * @var array
     */
    private $optionValues = [];

    public function __construct(
        Data $seoHelper,
        CollectionFactory $attributeCollectionFactory,
        array $optionValues = []
    ) {
        $this->seoHelper = $seoHelper;
        $this->attributeCollectionFactory = $attributeCollectionFactory;
        $this->optionValues = $optionValues;
    }

    /**
     * Method modifies seo attributes options data
     *
     * @param array $optionsSeoData
     * @param int $storeId
     * @param array $attributeIds
     */
    public function modify(array &$optionsSeoData, int $storeId, array &$attributeIds = []): void
    {
        if ($this->isValid()) {
            foreach ($this->getAttributesCollection() as $attribute) {
                $attributeCode = (string)$attribute->getAttributeCode();
                if (!array_key_exists($attribute->getAttributeId(), $attributeIds)) {
                    $attributeIds[$attribute->getAttributeId()] = $attributeCode;
                }

                foreach ($this->getOptionValues() as $optionValue => $optionLabel) {
                    $optionsSeoData[$storeId][$attributeCode][$optionValue] = $optionLabel;
                }
            }
        }
    }

    private function getAttributesCollection(): array
    {
        $seoAttributeCodes = $this->seoHelper->getSeoSignificantAttributeCodes();

        $collection = $this->attributeCollectionFactory->create()
            ->setCodeFilter($seoAttributeCodes)
            ->setFrontendInputTypeFilter(self::ATTRIBUTE_TYPE_BOOLEAN);

        return $collection->getItems();
    }

    private function isValid(): bool
    {
        return $this->seoHelper->isModuleEnabled() && $this->seoHelper->isIncludeAttributeName();
    }

    private function getOptionValues(): array
    {
        if (empty($this->optionValues)) {
            $this->optionValues = [self::VALUE_NO => self::LABEL_NO, self::VALUE_YES => self::LABEL_YES];
        }

        return $this->optionValues;
    }
}

Spamworldpro Mini