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/cartforge.co/app/code/Webkul/PrivateShop/Model/Plugin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/cartforge.co/app/code/Webkul/PrivateShop/Model/Plugin/ProductDataProvider.php
<?php
/**
 * Webkul Software
 *
 * @category  Webkul
 * @package   Webkul_PrivateShop
 * @author    Webkul Software Private Limited
 * @copyright Webkul Software Private Limited (https://webkul.com)
 * @license   https://store.webkul.com/license.html
 */

namespace Webkul\PrivateShop\Model\Plugin;

use Magento\Catalog\Ui\DataProvider\Product\Form\ProductDataProvider as DataProvider;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\Exception\NoSuchEntityException;

/**
 * Class ProductDataProvider
 * Webkul\PrivateShop\Model\Plugin
 */
class ProductDataProvider
{
    /**
     * @var ProductRepositoryInterface
     */
    protected $productRepository;

    /**
     * @var \Magento\Framework\Serialize\Serializer\Json
     */
    protected $jsonSerializer;
    
    /**
     * @var PrivateGroupInterfaceFactory
     */
    protected $privateGroupFactory;
    /**
     * @param ProductRepositoryInterface $productRepository
     * @param \Webkul\PrivateShop\Api\Data\PrivateGroupInterfaceFactory $privateGroupFactory
     * @param \Magento\Framework\Serialize\Serializer\Json $jsonSerializer
     */
    public function __construct(
        ProductRepositoryInterface $productRepository,
        \Webkul\PrivateShop\Api\Data\PrivateGroupInterfaceFactory $privateGroupFactory,
        \Magento\Framework\Serialize\Serializer\Json $jsonSerializer
    ) {
        $this->productRepository = $productRepository;
        $this->privateGroupFactory = $privateGroupFactory;
        $this->jsonSerializer = $jsonSerializer;
    }

    /**
     * Add grops to the Customer Form
     *
     * @param DataProvider $subject
     * @param array $results
     * @see DataProvider::getData()
     * @return array
     */
    public function afterGetData(DataProvider $subject, $results)
    {
        if ($results) {
            $productId = array_keys($results)[0];
            if (!$productId) {
                return $results;
            }
            $storeId = isset($results[$productId]['product']['current_store_id']) ?
                        $results[$productId]['product']['current_store_id'] :(
                        isset($results[$productId]['store_id']) ? $results[$productId]['store_id'] : 0);
            
            try {
                $product = $this->productRepository->getById($productId, false, $storeId);
                if ($product->getData('product_private_group')) {
                    $groups = $this->jsonSerializer->unserialize(
                        $product->getData('product_private_group')
                    );
                    $collection = $this->privateGroupFactory->create()
                        ->getCollection()
                        ->addFieldToFilter('entity_id', ['in' => $groups]);
                    
                    $availableIds = [];
                    foreach ($collection as $group) {
                        $availableIds[] = $group->getId();
                    }
                    $results[$productId]['product']['product_private_group'] = $availableIds;
                }
            } catch (\NoSuchEntityException $e) {
                throw new \NoSuchEntityException(__("Error:", $e->getMessage()));
            }
        }
        return $results;
    }
}

Spamworldpro Mini