classes/XLite/Model/Currency.php line 15

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright (c) 2011-present Qualiteam software Ltd. All rights reserved.
  4.  * See https://www.x-cart.com/license-agreement.html for license details.
  5.  */
  6. namespace XLite\Model;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * Currency
  10.  *
  11.  * @ORM\Entity
  12.  * @ORM\Table (name="currencies",
  13.  *      indexes = {
  14.  *          @ORM\Index (name="code", columns={"code"})
  15.  *      }
  16.  * )
  17.  */
  18. class Currency extends \XLite\Model\Base\I18n
  19. {
  20.     public const ROUNDUP_NONE 'N';
  21.     /**
  22.      * Currency unique id (ISO 4217 number)
  23.      *
  24.      * @var integer
  25.      *
  26.      * @ORM\Id
  27.      * @ORM\Column (type="integer", options={ "unsigned": true })
  28.      */
  29.     protected $currency_id;
  30.     /**
  31.      * Currency code (ISO 4217 alpha-3)
  32.      *
  33.      * @var string
  34.      *
  35.      * @ORM\Column (type="string", options={ "fixed": true }, length=3, unique=true)
  36.      */
  37.     protected $code;
  38.     /**
  39.      * Symbol
  40.      *
  41.      * @var string
  42.      *
  43.      * @ORM\Column (type="string", length=16)
  44.      */
  45.     protected $symbol;
  46.     /**
  47.      * Prefix
  48.      *
  49.      * @var string
  50.      *
  51.      * @ORM\Column (type="string", length=32)
  52.      */
  53.     protected $prefix '';
  54.     /**
  55.      * Suffix
  56.      *
  57.      * @var string
  58.      *
  59.      * @ORM\Column (type="string", length=32)
  60.      */
  61.     protected $suffix '';
  62.     /**
  63.      * Number of digits after the decimal separator.
  64.      *
  65.      * @var integer
  66.      *
  67.      * @ORM\Column (type="smallint")
  68.      */
  69.     protected $e 0;
  70.     /**
  71.      * Decimal part delimiter
  72.      * @var string
  73.      *
  74.      * @ORM\Column (type="string", length=8)
  75.      */
  76.     protected $decimalDelimiter '.';
  77.     /**
  78.      * Thousand delimier
  79.      *
  80.      * @var string
  81.      *
  82.      * @ORM\Column (type="string", length=8)
  83.      */
  84.     protected $thousandDelimiter '';
  85.     /**
  86.      * Orders
  87.      *
  88.      * @var \Doctrine\Common\Collections\Collection
  89.      *
  90.      * @ORM\OneToMany (targetEntity="XLite\Model\Order", mappedBy="currency")
  91.      */
  92.     protected $orders;
  93.     /**
  94.      * Countries
  95.      *
  96.      * @var \Doctrine\Common\Collections\Collection
  97.      *
  98.      * @ORM\OneToMany (targetEntity="XLite\Model\Country", mappedBy="currency", cascade={"all"})
  99.      */
  100.     protected $countries;
  101.     /**
  102.      * RoundUp
  103.      *
  104.      * @var string
  105.      *
  106.      * @ORM\Column (type="string", options={"default" : "N"})
  107.      */
  108.     protected $roundUp self::ROUNDUP_NONE;
  109.     /**
  110.      * @var \Doctrine\Common\Collections\Collection
  111.      *
  112.      * @ORM\OneToMany (targetEntity="XLite\Model\CurrencyTranslation", mappedBy="owner", cascade={"all"})
  113.      */
  114.     protected $translations;
  115.     /**
  116.      * Set currency Id
  117.      *
  118.      * @param integer $value Currency id
  119.      * TODO - Doctrine is not generate setter for identifier. We must reworkt it
  120.      *
  121.      * @return void
  122.      */
  123.     public function setCurrencyId($value)
  124.     {
  125.         $this->currency_id $value;
  126.     }
  127.     /**
  128.      * Get urrency symbol to display in interface
  129.      *
  130.      * @param boolean $strict Flag: true - return only prefix or suffix, false - return code if prefix and suffix isn't specified for currency
  131.      *
  132.      * @return string
  133.      */
  134.     public function getCurrencySymbol($strict true)
  135.     {
  136.         return $this->getPrefix() ?: ($this->getSuffix() ?: (!$strict $this->getCode() : ''));
  137.     }
  138.     /**
  139.      * Round value
  140.      *
  141.      * @param float $value Value
  142.      *
  143.      * @return float
  144.      */
  145.     public function roundValue($value)
  146.     {
  147.         return \XLite\Logic\Math::getInstance()->roundByCurrency($value$this);
  148.     }
  149.     /**
  150.      * Round value as integer
  151.      *
  152.      * @param float $value Value
  153.      *
  154.      * @return integer
  155.      */
  156.     public function roundValueAsInteger($value)
  157.     {
  158.         return intval(round($this->roundValue($value) * pow(10$this->getE()), 0));
  159.     }
  160.     /**
  161.      * Convert integer to float
  162.      *
  163.      * @param integer $value Value
  164.      *
  165.      * @return float
  166.      */
  167.     public function convertIntegerToFloat($value)
  168.     {
  169.         return $value pow(10$this->getE());
  170.     }
  171.     /**
  172.      * Don't use the method to send prices to 3rd-party API where strict(not like '1 234,99') number is expected,
  173.      * consider using roundValue() calls instead
  174.      *
  175.      * @param float $value Value
  176.      *
  177.      * @return string
  178.      */
  179.     public function formatValue($value)
  180.     {
  181.         return \XLite\Logic\Math::getInstance()->formatValue($value$this);
  182.     }
  183.     /**
  184.      * Get minimum value
  185.      *
  186.      * @return float
  187.      */
  188.     public function getMinimumValue()
  189.     {
  190.         return $this->convertIntegerToFloat(1);
  191.     }
  192.     /**
  193.      * Constructor
  194.      *
  195.      * @param array $data Entity properties OPTIONAL
  196.      *
  197.      * @return void
  198.      */
  199.     public function __construct(array $data = [])
  200.     {
  201.         $this->orders    = new \Doctrine\Common\Collections\ArrayCollection();
  202.         $this->countries = new \Doctrine\Common\Collections\ArrayCollection();
  203.         parent::__construct($data);
  204.     }
  205.     /**
  206.      * Format value as parts list
  207.      *
  208.      * @param float $value Value
  209.      *
  210.      * @return array
  211.      */
  212.     public function formatParts($value)
  213.     {
  214.         return \XLite\Logic\Math::getInstance()->formatParts($value$this);
  215.     }
  216.     /**
  217.      * Get currency_id
  218.      *
  219.      * @return integer
  220.      */
  221.     public function getCurrencyId()
  222.     {
  223.         return $this->currency_id;
  224.     }
  225.     /**
  226.      * Set code
  227.      *
  228.      * @param string $code
  229.      * @return Currency
  230.      */
  231.     public function setCode($code)
  232.     {
  233.         $this->code $code;
  234.         return $this;
  235.     }
  236.     /**
  237.      * Get code
  238.      *
  239.      * @return string
  240.      */
  241.     public function getCode()
  242.     {
  243.         return $this->code;
  244.     }
  245.     /**
  246.      * Set symbol
  247.      *
  248.      * @param string $symbol
  249.      * @return Currency
  250.      */
  251.     public function setSymbol($symbol)
  252.     {
  253.         $this->symbol $symbol;
  254.         return $this;
  255.     }
  256.     /**
  257.      * Get symbol
  258.      *
  259.      * @return string
  260.      */
  261.     public function getSymbol()
  262.     {
  263.         return $this->symbol;
  264.     }
  265.     /**
  266.      * Set prefix
  267.      *
  268.      * @param string $prefix
  269.      * @return Currency
  270.      */
  271.     public function setPrefix($prefix)
  272.     {
  273.         $this->prefix $prefix;
  274.         return $this;
  275.     }
  276.     /**
  277.      * Get prefix
  278.      *
  279.      * @return string
  280.      */
  281.     public function getPrefix()
  282.     {
  283.         return $this->prefix;
  284.     }
  285.     /**
  286.      * Set suffix
  287.      *
  288.      * @param string $suffix
  289.      * @return Currency
  290.      */
  291.     public function setSuffix($suffix)
  292.     {
  293.         $this->suffix $suffix;
  294.         return $this;
  295.     }
  296.     /**
  297.      * Get suffix
  298.      *
  299.      * @return string
  300.      */
  301.     public function getSuffix()
  302.     {
  303.         return $this->suffix;
  304.     }
  305.     /**
  306.      * Set e
  307.      *
  308.      * @param smallint $e
  309.      * @return Currency
  310.      */
  311.     public function setE($e)
  312.     {
  313.         $this->$e;
  314.         return $this;
  315.     }
  316.     /**
  317.      * Get e
  318.      *
  319.      * @return smallint
  320.      */
  321.     public function getE()
  322.     {
  323.         return $this->e;
  324.     }
  325.     /**
  326.      * Set decimalDelimiter
  327.      *
  328.      * @param string $decimalDelimiter
  329.      * @return Currency
  330.      */
  331.     public function setDecimalDelimiter($decimalDelimiter)
  332.     {
  333.         $this->decimalDelimiter $decimalDelimiter;
  334.         return $this;
  335.     }
  336.     /**
  337.      * Get decimalDelimiter
  338.      *
  339.      * @return string
  340.      */
  341.     public function getDecimalDelimiter()
  342.     {
  343.         return $this->decimalDelimiter;
  344.     }
  345.     /**
  346.      * Set thousandDelimiter
  347.      *
  348.      * @param string $thousandDelimiter
  349.      * @return Currency
  350.      */
  351.     public function setThousandDelimiter($thousandDelimiter)
  352.     {
  353.         $this->thousandDelimiter $thousandDelimiter;
  354.         return $this;
  355.     }
  356.     /**
  357.      * Get thousandDelimiter
  358.      *
  359.      * @return string
  360.      */
  361.     public function getThousandDelimiter()
  362.     {
  363.         return $this->thousandDelimiter;
  364.     }
  365.     /**
  366.      * Add orders
  367.      *
  368.      * @param \XLite\Model\Order $orders
  369.      * @return Currency
  370.      */
  371.     public function addOrders(\XLite\Model\Order $orders)
  372.     {
  373.         $this->orders[] = $orders;
  374.         return $this;
  375.     }
  376.     /**
  377.      * Get orders
  378.      *
  379.      * @return \Doctrine\Common\Collections\Collection
  380.      */
  381.     public function getOrders()
  382.     {
  383.         return $this->orders;
  384.     }
  385.     /**
  386.      * Add countries
  387.      *
  388.      * @param \XLite\Model\Country $countries
  389.      * @return Currency
  390.      */
  391.     public function addCountries(\XLite\Model\Country $countries)
  392.     {
  393.         $this->countries[] = $countries;
  394.         return $this;
  395.     }
  396.     /**
  397.      * Get countries
  398.      *
  399.      * @return \Doctrine\Common\Collections\Collection
  400.      */
  401.     public function getCountries()
  402.     {
  403.         return $this->countries;
  404.     }
  405.     /**
  406.      * Return RoundUp
  407.      *
  408.      * @return string
  409.      */
  410.     public function getRoundUp()
  411.     {
  412.         return $this->roundUp;
  413.     }
  414.     /**
  415.      * Set RoundUp
  416.      *
  417.      * @param string $roundUp
  418.      *
  419.      * @return $this
  420.      */
  421.     public function setRoundUp($roundUp)
  422.     {
  423.         $this->roundUp $roundUp;
  424.         return $this;
  425.     }
  426. }