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/Ecombricks/InventoryCatalog/Plugin/Block/Product/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/corals/Ecombricks/InventoryCatalog/Plugin/Block/Product/View.php
<?php
/**
 * Copyright © eComBricks. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Ecombricks\InventoryCatalog\Plugin\Block\Product;

/**
 * View product block plugin
 */
class View
{
    
    /**
     * Source item management
     * 
     * @var \Ecombricks\InventoryInventorySales\Model\SourceItemManagement
     */
    protected $sourceItemManagement;
    
    /**
     * Serializer
     * 
     * @var \Magento\Framework\Serialize\Serializer\Json
     */
    protected $serializer;
    
    /**
     * Constructor
     * 
     * @param \Ecombricks\InventoryInventorySales\Model\SourceItemManagement $sourceItemManagement
     * @param \Magento\Framework\Serialize\Serializer\Json $serializer
     * @return void
     */
    public function __construct(
        \Ecombricks\InventoryInventorySales\Model\SourceItemManagement $sourceItemManagement,
        \Magento\Framework\Serialize\Serializer\Json $serializer
    )
    {
        $this->sourceItemManagement = $sourceItemManagement;
        $this->serializer = $serializer;
    }
    
    /**
     * Set product source code
     * 
     * @param \Magento\Catalog\Model\Product $product
     * @param string $sourceCode
     * @return $this
     */
    protected function setProductSourceCode(\Magento\Catalog\Model\Product $product, $sourceCode)
    {
        $product->getExtensionAttributes()->setSourceCode($sourceCode);
        $product->reloadPriceInfo();
        return $this;
    }
    
    /**
     * Around get JSON configuration
     * 
     * @param \Magento\Catalog\Block\Product\View $subject
     * @param \Closure $proceed
     * @return string
     */
    public function aroundGetJsonConfig(
        \Magento\Catalog\Block\Product\View $subject,
        \Closure $proceed
    )
    {
        $configSerialized = $proceed();
        $product = $subject->getProduct();
        $config = $this->serializer->unserialize($configSerialized);
        $sourcePrices = [];
        $initialSourceCode = $product->getExtensionAttributes()->getSourceCode();
        foreach ($this->sourceItemManagement->getProductCurrentStockSalableSourceCodes($product) as $sourceCode) {
            $this->setProductSourceCode($product, $sourceCode);
            $priceInfo = $product->getPriceInfo();
            $regularPriceAmount = $priceInfo->getPrice('regular_price')->getAmount();
            $finalPriceAmount = $priceInfo->getPrice('final_price')->getAmount();
            $sourcePrices[$sourceCode] = [
                'oldPrice' => ['amount' => $regularPriceAmount->getValue(), 'adjustments' => []],
                'basePrice' => ['amount' => $finalPriceAmount->getBaseAmount(), 'adjustments' => []],
                'finalPrice' => ['amount' => $finalPriceAmount->getValue(), 'adjustments' => []],
            ];
        }
        $this->setProductSourceCode($product, $initialSourceCode);
        $config['sourcePrices'] = $sourcePrices;
        return $this->serializer->serialize($config);
    }
    
}

Spamworldpro Mini