Current File : /var/www/vinorea/modules/ipexportimport/classes/import/order/EIATools.php
<?php
/**
 *
 * NOTICE OF LICENSE
 *
 *  @author    SmartPresta <tehran.alishov@gmail.com>
 *  @copyright 2024 SmartPresta
 *  @license   Commercial License
 */

if (!defined('_PS_VERSION_')) {
    exit;
}

class EIATools
{

    public static function debug($data)
    {
        echo '<pre>';
        var_dump($data);
        die;
    }

    public static function isStringSerialized($string)
    {
        return ($string == 'b:0;' || Tools::unSerialize($string) !== false);
    }

    public static function preparePrice($price, $decimal = 6)
    {
        $price = str_replace(',', '.', $price);
        preg_match_all('/\./', $price, $matches);
        $pointNumber = count($matches[0]);
        if ($pointNumber > 1) {
            $priceArray = str_split($price);
            $newPrice = '';
            $i = 1;
            foreach ($priceArray as $number) {
                if ($number == '.') {
                    if ($i == $pointNumber) {
                        $newPrice .= $number;
                    }
                    $i++;
                } else {
                    $newPrice .= $number;
                }
            }
            $price = $newPrice;
        }

        $price = (float) $price;
        return number_format($price, $decimal, '.', '');
    }

}