<commit_before><?php

namespace DotPlant\Store\models\price;

use DotPlant\Currencies\helpers\CurrencyHelper;
use DotPlant\Store\exceptions\PriceException;
use DotPlant\Store\interfaces\PriceInterface;
use DotPlant\Store\models\goods\Goods;
use DotPlant\Store\models\warehouse\Warehouse;
use Yii;
use yii\helpers\ArrayHelper;

abstract class Price implements PriceInterface
{
    protected $_calculatorClass = null;

    protected $_goods = null;

    protected $_warehouseId = null;

    protected $_priceType = null;

    protected $_extendedPrice = null;

    protected $_convert_iso_code = false;

    /**
     * @var bool
     */
    protected $_withDiscount = true;

    private static $_priceMap = [];


    protected static $_price = [];

    /**
     * @inheritdoc
     */
    public static function create(Goods $goods)
    {
        /** @var Price | string $priceClass */
        $priceClass = get_called_class();
        if (false === is_subclass_of($priceClass, Price::class)) {
            throw new PriceException(
                Yii::t('dotplant.store', 'Attempting to get unknown price type')
            );
        }
        if (false === isset(self::$_priceMap[$priceClass])) {
            if (false === $goods->getIsNewRecord()) {
                $price = new $priceClass;
            } else {
                $price = new DummyPrice();
            }
            self::$_priceMap[$priceClass] = $price;
        } else {
            $price = self::$_priceMap[$priceClass];
        }

        /* @var $price Price */
        $price->_goods = $goods;
        return $price;
    }


    public static function convert($price, $to)
    {

        $price['originalCurrencyIsoCode'] = $price['isoCode'];
        $price['originalValue'] = $price['value'];
        $price['isoCode'] = $to;
        $price['value'] = CurrencyHelper::convertCurrencies(
            $price['value'],
            CurrencyHelper::findCurrencyByIso($price['originalCurrencyIsoCode']),
            CurrencyHelper::findCurrencyByIso($to)
        );

        if (isset($price['valueWithoutDiscount'])) {
            $price['valueWithoutDiscount'] = CurrencyHelper::convertCurrencies(
                $price['valueWithoutDiscount'],
                CurrencyHelper::findCurrencyByIso($price['originalCurrencyIsoCode']),
                CurrencyHelper::findCurrencyByIso($to)
            );
        }
<commit_msg>Price bug on listing page<commit_after><?php

namespace DotPlant\Store\models\price;

use DotPlant\Currencies\helpers\CurrencyHelper;
use DotPlant\Store\exceptions\PriceException;
use DotPlant\Store\interfaces\PriceInterface;
use DotPlant\Store\models\goods\Goods;
use DotPlant\Store\models\warehouse\Warehouse;
use Yii;
use yii\helpers\ArrayHelper;

abstract class Price implements PriceInterface
{
    protected $_calculatorClass = null;

    protected $_goods = null;

    protected $_warehouseId = null;

    protected $_priceType = null;

    protected $_extendedPrice = null;

    protected $_convert_iso_code = false;

    /**
     * @var bool
     */
    protected $_withDiscount = true;

    private static $_priceMap = [];


    protected static $_price = [];

    /**
     * @inheritdoc
     */
    public static function create(Goods $goods)
    {
        /** @var Price | string $priceClass */
        $priceClass = get_called_class();
        if (false === is_subclass_of($priceClass, Price::class)) {
            throw new PriceException(
                Yii::t('dotplant.store', 'Attempting to get unknown price type')
            );
        }
        if (false === isset(self::$_priceMap[$priceClass])) {
            if (false === $goods->getIsNewRecord()) {
                $price = new $priceClass;
            } else {
                $price = new DummyPrice();
            }
            self::$_priceMap[$priceClass] = $price;
        } else {
            $price = clone self::$_priceMap[$priceClass];
        }

        /* @var $price Price */
        $price->_goods = $goods;
        return $price;
    }


    public static function convert($price, $to)
    {

        $price['originalCurrencyIsoCode'] = $price['isoCode'];
        $price['originalValue'] = $price['value'];
        $price['isoCode'] = $to;
        $price['value'] = CurrencyHelper::convertCurrencies(
            $price['value'],
            CurrencyHelper::findCurrencyByIso($price['originalCurrencyIsoCode']),
            CurrencyHelper::findCurrencyByIso($to)
        );

        if (isset($price['valueWithoutDiscount'])) {
            $price['valueWithoutDiscount'] = CurrencyHelper::convertCurrencies(
                $price['valueWithoutDiscount'],
                CurrencyHelper::findCurrencyByIso($price['originalCurrencyIsoCode']),
                CurrencyHelper::findCurrencyByIso($to)
            );
        }

{'fraction_non_alphanumeric': 0.1288981288981289, 'fraction_numerical': 0.0, 'mean_word_length': 2.4661383285302594, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6509446', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1353, 'n_words': 255}