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/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

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

use Bitrix\Main\SystemException;

// 14.02.2023
class PackageRatio
{
    use Exception;

    protected const OPTION_PRODUCT_PROPERTY = 'packageProductRatio';
    protected const OPTION_OFFER_PROPERTY = 'packageOfferRatio';

    public function __construct($objects = [])
    {
        try {
            $this->main = $objects['Main'] ?? new Main();
            $this->moduleId = $this->main->getModuleId();
            $this->wrappers = new Wrappers($objects);

            $this->optionPackageProductPropCode = $this->wrappers->Option->get($this->moduleId, self::OPTION_PRODUCT_PROPERTY);
            $this->optionPackageOfferPropCode = $this->wrappers->Option->get($this->moduleId, self::OPTION_OFFER_PROPERTY);
        } catch (SystemException $exception) {
            $this->exceptionHandler($exception);
        }
    }

    public function getPackageRatioProductPropCode()
    {
        $packageProductPropCode = false;
        if ($this->optionPackageProductPropCode != 'nothing') {
            $packageProductPropCode = strtoupper($this->optionPackageProductPropCode);
        }

        return $packageProductPropCode;
    }

    public function getSelectForProduct($select)
    {
        if ($this->optionPackageProductPropCode != 'nothing') {
            $select[] = 'PROPERTY_' . strtoupper($this->optionPackageProductPropCode);
        }

        return $select;
    }

    public function getSelectForOffer($select)
    {
        if ($this->optionPackageOfferPropCode != 'nothing') {
            $select[] = 'PROPERTY_' . strtoupper($this->optionPackageOfferPropCode);
        }

        return $select;
    }

    public function checkToUseProductPacakgePropForOffer()
    {
        $useProductPacakgeProp = false;
        if (
                $this->optionPackageOfferPropCode == 'nothing'
                && $this->optionPackageProductPropCode != 'nothing'
        ) {
            $useProductPacakgeProp = true;
        }

        return $useProductPacakgeProp;
    }

    // Проверка существования свойства
    public function checkPropertyExistsForProduct($response)
    {
        $propertyExists = $this->checkPropertyExists($response, $this->optionPackageProductPropCode);

        return $propertyExists;
    }

    public function checkPropertyExistsForOffer($response)
    {
        $propertyExists = $this->checkPropertyExists($response, $this->optionPackageOfferPropCode);

        return $propertyExists;
    }

    public function checkPropertyExists($response, $propCode)
    {
        $propertyExists = false;

        if (array_key_exists('PROPERTY_' . strtoupper($propCode) . '_VALUE', $response)) {
            $propertyExists = true;
        }

        return $propertyExists;
    }

    // Получение значения свойства
    public function getPropertyValueForProduct($response)
    {
        $propValue = $this->getPropertyValue($response, $this->optionPackageProductPropCode);

        return $propValue;
    }

    public function getPropertyValueForOffer($response)
    {
        $propValue = $this->getPropertyValue($response, $this->optionPackageOfferPropCode);

        return $propValue;
    }

    public function getPropertyValue($response, $propCode)
    {
        $packageRatioPropValue = (int) $response['PROPERTY_' . strtoupper($propCode) . '_VALUE'];

        if (
            !$packageRatioPropValue
            || $packageRatioPropValue < 0
        ) {
            $packageRatioPropValue = 1;
        }

        return $packageRatioPropValue;
    }

    // рассчет цены и кол-ва
    public function calculatePriceAndQuantityWithPackageRatio($detailInfoAboutProduct, $product)
    {
        $packageRatioValue = $detailInfoAboutProduct['package_ratio_value'] ?? false;

        if ($packageRatioValue) {
            $product['price'] = $this->getPriceWithPackagingRatio($product['price'], $packageRatioValue);
            $product['discount_price'] = $this->getPriceWithPackagingRatio($product['discount_price'], $packageRatioValue);
            $product['quantity'] = $this->getStockWithPackagingRatio($product['quantity'], $packageRatioValue);
        }

        return $product;
    }

    public function getPriceWithPackagingRatio($price, $packageRatioValue)
    {
        $finalPrice = $price / $packageRatioValue;

        return $finalPrice;
    }

    public function getStockWithPackagingRatio($quantity, $packageRatioValue)
    {
        $finalStock = $quantity * $packageRatioValue;

        return $finalStock;
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit