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-seobase/Model/ResourceModel/Catalog/Product/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/mageworx/module-seobase/Model/ResourceModel/Catalog/Product/Associated.php
<?php
/**
 * Copyright © 2015 MageWorx. All rights reserved.
 * See LICENSE.txt for license details.
 */

namespace MageWorx\SeoBase\Model\ResourceModel\Catalog\Product;

use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator;

class Associated extends \MageWorx\SeoBase\Model\ResourceModel\Catalog\Product
{
    /**
     * @var \MageWorx\SeoBase\Helper\Data
     */
    protected $helperData;

    /**
     * @var \Magento\Store\Model\StoreManagerInterface
     */
    protected $storeManager;

    /**
     * @var \Magento\Catalog\Model\Product\Visibility
     */
    protected $productVisibility;

    /**
     * @var \Magento\Catalog\Model\Product\Attribute\Source\Status
     */
    protected $productStatus;

    /**
     * @var \Magento\Eav\Model\ConfigFactory
     */
    protected $eavConfigFactory;

    /**
     * @var \Magento\Store\Model\StoreManagerInterface
     */
    protected $helperStoreUrl;

    /**
     * @var \Magento\Framework\DataObject\Factory
     */
    protected $objectFactory;

    /**
     * @var \MageWorx\SeoBase\Model\ResourceModel\Catalog\Product\FlexibleCanonical
     */
    protected $flexibleCanonicalResource;

    /**
     * Associated constructor.
     *
     * @param \Magento\Framework\Model\ResourceModel\Db\Context $context
     * @param \MageWorx\SeoBase\Helper\Data $helperData
     * @param \Magento\Catalog\Model\ResourceModel\Product $productResource
     * @param \Magento\Store\Model\StoreManagerInterface $storeManager
     * @param \Magento\Catalog\Model\Product\Visibility $productVisibility
     * @param \Magento\Catalog\Model\Product\Attribute\Source\Status $productStatus
     * @param \Magento\Eav\Model\ConfigFactory $eavConfigFactory
     * @param \MageWorx\SeoBase\Helper\StoreUrl $helperStoreUrl
     * @param \Magento\Framework\DataObject\Factory $objectFactory
     * @param \MageWorx\SeoAll\Helper\LinkFieldResolver $linkFieldResolver
     * @param FlexibleCanonical $flexibleCanonical
     * @param null $resourcePrefix
     */
    public function __construct(
        \Magento\Framework\Model\ResourceModel\Db\Context $context,
        \MageWorx\SeoBase\Helper\Data $helperData,
        \Magento\Catalog\Model\ResourceModel\Product $productResource,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Magento\Catalog\Model\Product\Visibility $productVisibility,
        \Magento\Catalog\Model\Product\Attribute\Source\Status $productStatus,
        \Magento\Eav\Model\ConfigFactory $eavConfigFactory,
        \MageWorx\SeoBase\Helper\StoreUrl $helperStoreUrl,
        \Magento\Framework\DataObject\Factory $objectFactory,
        \MageWorx\SeoAll\Helper\LinkFieldResolver $linkFieldResolver,
        \MageWorx\SeoBase\Model\ResourceModel\Catalog\Product\FlexibleCanonical $flexibleCanonical,
        $resourcePrefix = null
    ) {
        $this->storeManager              = $storeManager;
        $this->productVisibility         = $productVisibility;
        $this->productStatus             = $productStatus;
        $this->eavConfigFactory          = $eavConfigFactory;
        $this->helperData                = $helperData;
        $this->helperStoreUrl            = $helperStoreUrl;
        $this->objectFactory             = $objectFactory;
        $this->flexibleCanonicalResource = $flexibleCanonical;

        parent::__construct($context, $productResource, $linkFieldResolver, $resourcePrefix);
    }

    /**
     * @return void
     */
    protected function _construct()
    {
        $this->_init('catalog_product_entity', 'entity_id');
    }

    /**
     * Get associated product data
     *
     * @param null|string|bool|int|\Magento\Store\Model\Store $storeId
     * @return \Magento\Framework\Object|null|false
     */
    public function getAssociatedData($productId, array $associatedProductTypes, $storeId = null)
    {
        /* @var $store \Magento\Store\Model\Store */
        $store = $this->storeManager->getStore($storeId);

        if (!$store || empty($associatedProductTypes)) {
            return false;
        }

        $adapter = $this->getConnection();

        $this->select = $adapter->select();
        $this->select
            ->from(
                ['e' => $this->getMainTable()],
                [$this->getIdFieldName()]
            )
            ->joinInner(
                ['w' => $this->getTable('catalog_product_website')],
                'e.entity_id = w.product_id',
                []
            )
            ->joinLeft(
                ['url_rewrite' => $this->getTable('url_rewrite')],
                'e.entity_id = url_rewrite.entity_id AND url_rewrite.is_autogenerated = 1'
                . $adapter->quoteInto(' AND url_rewrite.store_id = ?', $store->getId())
                . $adapter->quoteInto(
                    ' AND url_rewrite.entity_type = ?',
                    ProductUrlRewriteGenerator::ENTITY_TYPE
                ),
                ['url' => 'request_path']
            )
            ->joinLeft(
                ['catalog_url_rewrite' => $this->getTable('catalog_url_rewrite_product_category')],
                'url_rewrite.url_rewrite_id = catalog_url_rewrite.url_rewrite_id',
                []
            )
            ->where(
                'e.entity_id IN(?)', $this->getProductRelationQuery($productId)
            )
            ->where(
                'e.type_id IN(?)',
                $associatedProductTypes
            )
            ->where(
                'w.website_id = ?',
                $store->getWebsiteId()
            )
            ->order(['e.entity_id'], \Magento\Framework\DB\Select::SQL_DESC);

        $this->flexibleCanonicalResource->addFlexibleConditions($this->select, $storeId);

        $this->addFilter($store->getId(), 'visibility', $this->productVisibility->getVisibleInSiteIds(), 'in');
        $this->addFilter($store->getId(), 'status', $this->productStatus->getVisibleStatusIds(), 'in');


        $query = $adapter->query($this->select);
        $row   = $query->fetch();

        if (!is_array($row)) {
            return false;
        }

        return $this->prepareProduct($row, $store->getId());
    }

    /**
     * @param int $productId
     * @return \Magento\Framework\DB\Select
     */
    protected function getProductRelationQuery($productId)
    {
        $adapter = $this->getConnection();
        $select = $adapter->select();
        $select
            ->from(
                [$this->getTable('catalog_product_relation')],
                ['parent_id']
            )
            ->where('child_id = ?', (int)$productId);

        return $select;
    }

    /**
     * Prepare and convert associated data to object
     *
     * @param array $productRow
     * @param int $storeId
     * @return \Magento\Framework\Object
     */
    protected function prepareProduct(array $productRow, $storeId)
    {
        $product = $this->objectFactory->create();
        $product->addData($productRow);
        $product['id'] = $productRow[$this->getIdFieldName()];

        if (empty($productRow['url'])) {
            return null;
        }
        $product->setUrl($this->helperStoreUrl->getUrl($productRow['url'], $storeId, true));

        return $product;
    }
}

Spamworldpro Mini