public function getCurrencyPrice()
 {
     if ($currentCurrency = Session::get('Currency')) {
         $currencyRate = ExchangeRate::get()->filter(array("Currency" => $currentCurrency))->first();
         if ($currencyRate && $currencyRate->exists()) {
             $convertedPrice = $this->owner->getField('BasePrice') * $currencyRate->Rate;
             return $convertedPrice;
         }
     }
     // no currency other than base
     return false;
 }
예제 #2
0
 public function beforeSave()
 {
     if ($this->pk()) {
         $cur = ExchangeRate::get($this->pk());
         if ($cur->rate != $this->rate) {
             $history = new ExchangeRate\History();
             $history->currency_exchangerate_id = $this->pk();
             $history->old = $cur->rate;
             $history->new = $this->rate;
             $history->save();
         }
     }
 }
 public function doChangeCurrency($data, Form $form)
 {
     // validate here again
     $currencyIsValid = ExchangeRate::get()->filter(array("ID" => $data['Currency'], "Status" => 1))->first();
     if ($currencyIsValid && $currencyIsValid->exists()) {
         // clear it just incase
         Session::clear('Currency');
         // trigger set currenct function
         $this->setCurrentCurrency($currencyIsValid->Currency);
     }
     // return the user to where they were
     return Controller::curr()->redirectBack();
 }
 public function updatePrice($amount)
 {
     //If the order is processed and the currency saved, use that
     //If the order is processed and no currency saved, do nothing
     //If the order is not processed and the currency in Session, use that
     $order = $this->owner->Order();
     if ($order->Status != 'Cart') {
         if ($order->Currency && $order->ExchangeRate) {
             $amount->setAmount($amount->getAmount() * $order->ExchangeRate);
             $amount->setCurrency($order->Currency);
             $amount->setSymbol($order->CurrencySymbol);
         }
     } else {
         if ($currency = Session::get('SWS.Currency')) {
             //Get the exchange rate, alter the amount
             $rate = ExchangeRate::get()->where("\"Currency\" = '{$currency}'")->limit(1)->first();
             if ($rate && $rate->exists()) {
                 $amount->setAmount($amount->getAmount() * $rate->Rate);
                 $amount->setCurrency($rate->Currency);
                 $amount->setSymbol($rate->CurrencySymbol);
             }
         }
     }
 }