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.ozonexport/lib/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/wbs24.ozonexport/lib/ExtendPriceByFormula.php
<?php
namespace Wbs24\Ozonexport;

class ExtendPriceByFormula extends Price
{
    protected $Formula;
    protected $currentBasePrice = 0;
    protected $priceDiscount;

    public function __construct($param = [], $objects = [])
    {
        parent::__construct($param);

        $this->Formula = $objects['Formula'] ?? new Formula();
    }

    public function getPrice($minPrice, $fullPrice)
    {
        $ignoreSale = $this->param['ignoreSale'] ?? false;
        $basePrice = $ignoreSale ? $fullPrice : $minPrice;
        //$basePrice = $this->getPriceWithPackagingRatio($basePrice);
        $formula = $this->param['formulaPrice'] ?: false;

        $price = $this->calcByFormula($formula, [
            'PRICE' => $basePrice,
        ]);
        // сохранение текущей базовой цены для расчета в других формулах для данного товара
        // (необходимо т.к. через параметры базовая цена в другие формулы не передается)
        $this->setCurrentBasePrice($basePrice);
        $this->setPriceDiscount(round($price));

        return $this->getPriceWithPackagingRatio(round($price));
    }

    protected function setCurrentBasePrice($basePrice)
    {
        $this->currentBasePrice = $basePrice;
    }

    protected function getCurrentBasePrice()
    {
        return $this->currentBasePrice;
    }

    protected function addPriceTypesToMarkValues($markValues)
    {
        $addMarkValues = [];
        $priceFields = preg_grep('/PRICE_\d+/', array_keys($this->currentItem));

        foreach ($priceFields as $code) {
            $addMarkValues[$code] = intval($this->currentItem[$code]);
        }

        return array_merge($markValues, $addMarkValues);
    }

    public function getOldPrice($minPrice, $fullPrice)
    {
        $formulaBefore10k = $this->param['formulaOldPrice'] ?? '';
        $formulaAfter10k = $this->param['formulaOldPrice10k'] ?? '';
        $minPrice = $this->getPriceDiscount();
        $formula = ($minPrice > 10000) ? $formulaAfter10k : $formulaBefore10k;

        $oldPrice = $this->calcByFormula($formula, [
            'PRICE_DISCOUNT' => $minPrice,
            'PRICE' => $this->getCurrentBasePrice(),
        ]);

        if ($minPrice > 10000) {
            if ($minPrice + 500 >= $oldPrice) $oldPrice = 0;
        } else {
            if ($minPrice * 1.05 > $oldPrice) $oldPrice = 0;
        }

        return $this->getPriceWithPackagingRatio(round($oldPrice));
    }

    public function getPremiumPrice($minPrice, $fullPrice)
    {
        $formula = $this->param['formulaPremiumPrice'] ?? '';
        $minPrice = $this->getPriceDiscount();

        $premiumPrice = $this->calcByFormula($formula, [
            'PRICE_DISCOUNT' => $minPrice,
            'PRICE' => $this->getCurrentBasePrice(),
        ]);

        if ($premiumPrice >= $minPrice) $premiumPrice = 0;
        if (!$formula) $premiumPrice = 0;

        return $this->getPriceWithPackagingRatio(round($premiumPrice));
    }

    public function getMinPrice($minPrice, $fullPrice)
    {
        $formula = $this->param['formulaMinPrice'] ?? '';
        $minPrice = $this->getPriceDiscount();
        $markValues = [
            'PRICE_DISCOUNT' => $minPrice,
            'PRICE' => $this->getCurrentBasePrice(),
        ];

        $markValues = $this->addPriceTypesToMarkValues($markValues);
        $newMinPrice = $this->calcByFormula($formula, $markValues);

        if (
            !$this->validateMinPrice($minPrice, round($newMinPrice))
        ) $newMinPrice = 0;

        return $this->getPriceWithPackagingRatio(round($newMinPrice));
    }

    protected function setPriceDiscount($priceDiscount)
    {
        $this->priceDiscount = $priceDiscount;
    }

    protected function getPriceDiscount()
    {
        return $this->priceDiscount;
    }

    protected function calcByFormula($formula, $marks)
    {
        if ($formula) {
            $allowedMarks = array_keys($marks);
            $this->Formula->setMarks($allowedMarks);
            $this->Formula->setFormula($formula);
            $price = $this->Formula->calc($marks);
        } else {
            $price = $marks['PRICE'] ?? 0;
        }

        return $price;
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit