当前位置: 首页>>代码示例>>PHP>>正文


PHP Currency::getInstanceById方法代码示例

本文整理汇总了PHP中Currency::getInstanceById方法的典型用法代码示例。如果您正苦于以下问题:PHP Currency::getInstanceById方法的具体用法?PHP Currency::getInstanceById怎么用?PHP Currency::getInstanceById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Currency的用法示例。


在下文中一共展示了Currency::getInstanceById方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 public function __construct(Product $product, $prices = null, LiveCart $application)
 {
     $this->product = $product;
     $this->application = $application;
     if (is_null($prices) && $product->getID()) {
         $prices = $product->getRelatedRecordSet("ProductPrice", new ARSelectFilter());
     }
     if ($prices instanceof ARSet) {
         foreach ($prices as $price) {
             $this->setPrice($price);
         }
     } else {
         if (is_array($prices)) {
             foreach ($prices as $id => $price) {
                 if (array_key_exists('ID', $price)) {
                     $this->prices[$id] = ProductPrice::getInstance($product, Currency::getInstanceById($id));
                 } else {
                     $this->prices[$id] = ProductPrice::getNewInstance($product, Currency::getInstanceById($id));
                 }
                 $this->prices[$id]->price->set($price['price']);
                 $this->prices[$id]->listPrice->set($price['listPrice']);
                 $this->prices[$id]->serializedRules->set(serialize($price['serializedRules']));
                 $this->prices[$id]->resetModifiedStatus();
             }
         }
     }
 }
开发者ID:saiber,项目名称:www,代码行数:27,代码来源:ProductPricing.php

示例2: applyToOrder

 public function applyToOrder(CustomerOrder $order)
 {
     $currencyID = $this->getFieldValue('currency', '');
     if ($currencyID) {
         $currency = Currency::getInstanceById($currencyID);
         $order->changeCurrency($currency);
         ActiveRecordModel::getApplication()->getRequest()->set('currency', $currencyID);
     }
 }
开发者ID:saiber,项目名称:livecart,代码行数:9,代码来源:RuleActionChangeCurrency.php

示例3: process

 public function process()
 {
     $source = CurrencyRateSource::getInstance($this->application);
     foreach ($source->getAllCurrencyCodes() as $currencyCode) {
         $rate = $source->getRate($currencyCode);
         if ($rate != null) {
             $currency = Currency::getInstanceById($currencyCode);
             $currency->rate->set($rate);
             $currency->lastUpdated->set(date('Y-m-d H:i:s', time()));
             $currency->save();
         }
     }
     $this->application->getCache()->set('currencyRateUpdateTs', time());
 }
开发者ID:saiber,项目名称:livecart,代码行数:14,代码来源:CurrencyRates.php

示例4: __construct

 function __construct($filterID, LiveCart $application)
 {
     $this->filterID = $filterID;
     $this->application = $application;
     $c = $this->application->getConfig();
     for ($definedFilterCount = 1; $definedFilterCount <= self::MAX_FILTER_COUNT; $definedFilterCount++) {
         if (!$c->get('PRICE_FILTER_FROM_' . $definedFilterCount) && !$c->get('PRICE_FILTER_TO_' . $definedFilterCount)) {
             break;
         }
     }
     $definedFilterCount--;
     $this->name = $c->get('PRICE_FILTER_NAME_' . $filterID);
     $setCustomName = !strlen(trim($this->name));
     $this->priceFrom = $c->get('PRICE_FILTER_FROM_' . $filterID);
     $this->priceTo = $c->get('PRICE_FILTER_TO_' . $filterID);
     $requestCurrencyID = $this->application->controllerInstance->getRequestCurrency();
     $defaultCurrency = $this->application->getDefaultCurrency();
     if ($defaultCurrency->getID() != $requestCurrencyID) {
         $setCustomName = true;
         $requestCurrency = Currency::getInstanceById($requestCurrencyID);
         foreach (array('priceFrom', 'priceTo') as $price) {
             $this->{$price} = $requestCurrency->convertAmount($defaultCurrency, $this->{$price});
             if ($this->{$price} != 0) {
                 $this->{$price} = $requestCurrency->round($this->{$price});
             }
         }
     }
     if ($setCustomName) {
         if ($this->priceFrom == 0) {
             $this->name = $this->application->maketext('_to [_1]', $this->priceTo);
         } else {
             if ($definedFilterCount == $filterID && $this->priceFrom * 2 < $this->priceTo) {
                 $this->name = $this->application->maketext('_more_than [_1]', $this->priceFrom);
             } else {
                 $this->name = $this->application->maketext('[_1] - [_2]', array($this->priceFrom, $this->priceTo));
             }
         }
     }
 }
开发者ID:saiber,项目名称:livecart,代码行数:39,代码来源:PriceFilter.php

示例5: getNewInstance

 public static function getNewInstance(CustomerOrder $order, TransactionResult $result)
 {
     $instance = parent::getNewInstance(__CLASS__);
     $instance->order->set($order);
     $instance->gatewayTransactionID->set($result->gatewayTransactionID->get());
     // determine currency
     if ($result->currency->get()) {
         $instance->realCurrency->set(Currency::getInstanceById($result->currency->get()));
     } else {
         $instance->realCurrency->set($order->currency->get());
     }
     // amount
     $instance->realAmount->set($result->amount->get());
     // different currency than initial order currency?
     if ($order->currency->get()->getID() != $result->currency->get()) {
         $instance->amount->set($order->currency->get()->convertAmount($instance->realCurrency->get(), $instance->realAmount->get()));
         $instance->currency->set($order->currency->get());
         // test if some amount is not missing due to currency conversion rounding (a difference of 0.01, etc)
         $total = $order->totalAmount->get();
         if ($instance->amount->get() < $total) {
             $largerAmount = $order->currency->get()->convertAmount($instance->realCurrency->get(), 0.01 + $instance->realAmount->get());
             if ($largerAmount >= $total) {
                 $instance->amount->set($total);
             }
         }
     }
     // transaction type
     $instance->type->set($result->getTransactionType());
     if ($instance->type->get() != self::TYPE_AUTH) {
         $instance->isCompleted->set(true);
     }
     if ($result->details->get()) {
         $instance->comment->set($result->details->get());
     }
     return $instance;
 }
开发者ID:saiber,项目名称:www,代码行数:36,代码来源:Transaction.php

示例6: getNextCustomerOrder

 public function getNextCustomerOrder()
 {
     if (!($data = $this->loadRecord('SELECT ' . $this->getTablePrefix() . 'orders.*, ' . $this->getTablePrefix() . 'customers.email AS userEmail FROM ' . $this->getTablePrefix() . 'orders LEFT JOIN ' . $this->getTablePrefix() . 'customers ON ' . $this->getTablePrefix() . 'orders.login=' . $this->getTablePrefix() . 'customers.login'))) {
         return null;
     }
     if (!($user = User::getInstanceByEmail($data['userEmail']))) {
         return $this->getNextCustomerOrder();
     }
     $order = CustomerOrder::getNewInstance($user);
     $order->currency->set(Currency::getInstanceById($this->getDefaultCurrency()));
     $order->dateCompleted->set($data['date']);
     // products
     foreach ($this->getDataBySql('SELECT * FROM ' . $this->getTablePrefix() . 'order_details WHERE orderid=' . $data['orderid']) as $prod) {
         try {
             $product = Product::getInstanceById($this->getRealId('Product', $prod['productid']), true);
             $order->addProduct($product, $prod['amount'], true);
             $item = array_shift($order->getItemsByProduct($product));
             $item->price->set($prod['price']);
         } catch (ARNotFoundException $e) {
             // the product no longer exists
         }
     }
     // addresses
     $order->shippingAddress->set($this->getUserAddress($data, 's_'));
     $order->billingAddress->set($this->getUserAddress($data, 'b_'));
     // assume that all orders are paid and shipped
     $order->status->set(CustomerOrder::STATUS_SHIPPED);
     $order->isPaid->set(true);
     $order->rawData = $data;
     return $order;
 }
开发者ID:saiber,项目名称:livecart,代码行数:31,代码来源:XCartImport.php

示例7: getNextCustomerOrder

    public function getNextCustomerOrder()
    {
        if (!($data = $this->loadRecord('SELECT *, ' . $this->getTablePrefix() . 'orders.orders_id AS id, ' . $this->getTablePrefix() . 'orders_total.value FROM ' . $this->getTablePrefix() . 'orders
												LEFT JOIN ' . $this->getTablePrefix() . 'orders_total ON (' . $this->getTablePrefix() . 'orders.orders_id=' . $this->getTablePrefix() . 'orders_total.orders_id AND class="ot_shipping")
												LEFT JOIN ' . $this->getTablePrefix() . 'customers ON (' . $this->getTablePrefix() . 'orders.customers_id=' . $this->getTablePrefix() . 'customers.customers_id)
												WHERE ' . $this->getTablePrefix() . 'customers.customers_id IS NOT NULL'))) {
            return null;
        }
        $order = CustomerOrder::getNewInstance(User::getInstanceById($this->getRealId('User', $data['customers_id'])));
        $order->currency->set(Currency::getInstanceById($data['currency']));
        $order->dateCompleted->set($data['date_purchased']);
        // products
        $tax = 0;
        foreach ($this->getDataBySql('SELECT *, ' . $this->getTablePrefix() . 'orders_products.products_quantity AS quant FROM ' . $this->getTablePrefix() . 'orders_products LEFT JOIN ' . $this->getTablePrefix() . 'products ON (' . $this->getTablePrefix() . 'orders_products.products_id=' . $this->getTablePrefix() . 'products.products_id) WHERE ' . $this->getTablePrefix() . 'orders_id=' . $data['id'] . ' AND ' . $this->getTablePrefix() . 'products.products_id IS NOT NULL') as $prod) {
            $product = Product::getInstanceById($this->getRealId('Product', $prod['products_id']));
            if (!$prod['quant']) {
                continue;
            }
            $item = $order->addProduct($product, $prod['quant'], true);
            $item->price->set($prod['products_price']);
            $tax += $prod['products_tax'];
        }
        // addresses
        $order->shippingAddress->set($this->getUserAddress($data, 'delivery_'));
        $order->billingAddress->set($this->getUserAddress($data, 'billing_'));
        // assume that all orders are paid and shipped
        $order->status->set(CustomerOrder::STATUS_SHIPPED);
        $order->isPaid->set(true);
        $data['taxAmount'] = $tax;
        $order->rawData = $data;
        return $order;
    }
开发者ID:saiber,项目名称:livecart,代码行数:32,代码来源:OsCommerceImport.php

示例8: setDefault

 /**
  * Sets default currency.
  * @role status
  * @return ActionRedirectResponse
  */
 public function setDefault()
 {
     try {
         $r = ActiveRecord::getInstanceByID('Currency', $this->request->get('id'), true);
     } catch (ARNotFoundException $e) {
         return new ActionRedirectResponse('backend.currency', 'index');
     }
     ActiveRecord::beginTransaction();
     $update = new ARUpdateFilter();
     $update->addModifier('isDefault', 0);
     ActiveRecord::updateRecordSet('Currency', $update);
     $r->setAsDefault(true);
     $r->save();
     $config = $this->getApplication()->getConfig();
     if ($config->get('CURRENCY_RATE_UPDATE')) {
         $source = CurrencyRateSource::getInstance($this->application, $r->getID());
         foreach ($source->getAllCurrencyCodes() as $currencyCode) {
             $rate = $source->getRate($currencyCode);
             if ($rate != null) {
                 $currency = Currency::getInstanceById($currencyCode);
                 $currency->rate->set($rate);
                 $currency->lastUpdated->set(date('Y-m-d H:i:s', time()));
                 $currency->save();
             }
         }
     }
     ActiveRecord::commit();
     return new ActionRedirectResponse('backend.currency', 'index');
 }
开发者ID:saiber,项目名称:livecart,代码行数:34,代码来源:CurrencyController.php

示例9: getPaymentHandler

 public function getPaymentHandler($className, LiveCartTransaction $details = null)
 {
     if (!class_exists($className, false)) {
         if ('OfflineTransactionHandler' == $className) {
             ClassLoader::import('application.model.order.OfflineTransactionHandler');
         } else {
             ClassLoader::importNow('library.payment.method.*');
             ClassLoader::importNow('library.payment.method.cc.*');
             ClassLoader::importNow('library.payment.method.express.*');
         }
     }
     if (is_null($details)) {
         $details = new TransactionDetails();
     }
     $inst = new $className($details);
     if ($details instanceof LiveCartTransaction) {
         $inst->setOrder($details->getOrder());
     }
     $c = $this->config->getSection('payment/' . $className);
     foreach ($c as $key => $value) {
         $value = $this->config->get($key);
         $key = substr($key, strlen($className) + 1);
         $inst->setConfigValue($key, $value);
     }
     // check if the currency is supported by the payment handler
     $currency = $inst->getValidCurrency($details->currency->get());
     if ($details->currency->get() != $currency && !is_null($details->currency->get())) {
         $newAmount = Currency::getInstanceById($currency, Currency::LOAD_DATA)->convertAmount(Currency::getInstanceById($details->currency->get(), Currency::LOAD_DATA), $details->amount->get());
         $details->currency->set($currency);
         $details->amount->set(round($newAmount, 2));
     }
     $inst->setApplication($this);
     return $inst;
 }
开发者ID:GregerA,项目名称:livecart,代码行数:34,代码来源:LiveCart.php

示例10: toArray

 public function toArray($amount = null)
 {
     $array = parent::toArray();
     if (!is_null($amount)) {
         $array['costAmount'] = $amount;
     }
     if (!$this->application) {
         $this->application = ActiveRecordModel::getApplication();
     }
     $amountCurrency = Currency::getInstanceById($array['costCurrency']);
     $currencies = $this->application->getCurrencySet();
     // get and format prices
     $prices = $formattedPrices = $taxPrices = $unformattedTaxPrices = array();
     foreach ($currencies as $id => $currency) {
         $prices[$id] = $currency->convertAmount($amountCurrency, $array['costAmount']);
         $formattedPrices[$id] = $currency->getFormattedPrice($prices[$id]);
         $unformattedTaxPrices[$id] = $currency->convertAmount($amountCurrency, $this->amountWithTax);
         $taxPrices[$id] = $currency->getFormattedPrice($unformattedTaxPrices[$id]);
         $withoutTaxPrices[$id] = $currency->convertAmount($amountCurrency, $this->amountWithoutTax);
         $formattedWithoutTaxPrices[$id] = $currency->getFormattedPrice($withoutTaxPrices[$id]);
     }
     $array['price'] = $prices;
     $array['priceWithTax'] = $unformattedTaxPrices;
     $array['formattedPrice'] = $formattedPrices;
     $array['taxPrice'] = $taxPrices;
     $array['priceWithoutTax'] = $withoutTaxPrices;
     $array['formattedPriceWithoutTax'] = $formattedWithoutTaxPrices;
     // shipping service name
     $id = $this->getServiceID();
     if (is_numeric($id)) {
         try {
             $service = ShippingService::getInstanceById($id, ShippingService::LOAD_DATA);
             $array['ShippingService'] = $service->toArray();
         } catch (ARNotFoundException $e) {
             return array();
         }
     } else {
         $array['ShippingService'] = array('name_lang' => $this->getServiceName(), 'provider' => $this->getProviderName());
     }
     return $array;
 }
开发者ID:saiber,项目名称:www,代码行数:41,代码来源:ShipmentDeliveryRate.php

示例11: toArray_CustomerOrder

 private function toArray_CustomerOrder($records)
 {
     foreach ($records as &$order) {
         $currency = Currency::getInstanceById($order['currencyID']);
         $order['formattedTotalAmount'] = $currency->getFormattedPrice($order['totalAmount']);
     }
 }
开发者ID:GregerA,项目名称:livecart,代码行数:7,代码来源:QuickSearchController.php

示例12: toArray

 public function toArray()
 {
     $array = parent::toArray();
     $currency = $this->getCurrency();
     $id = $currency->getID();
     // ordered items
     $items = array();
     foreach ($this->items as $item) {
         $items[] = $item->toArray();
     }
     $array['items'] = $items;
     // subtotal
     $currencies = self::getApplication()->getCurrencySet();
     $array['subTotal'][$id] = $this->getSubTotal();
     // total amount
     $array['totalAmount'] = $this->getTotal();
     $array['formatted_totalAmount'] = $this->order->get()->currency->get()->getFormattedPrice($array['totalAmount']);
     $array['formatted_amount'] = $this->order->get()->currency->get()->getFormattedPrice($array['amount']);
     // formatted subtotal
     $array['formattedSubTotal'] = $array['formattedSubTotalBeforeTax'] = array();
     $array['formattedSubTotal'][$id] = $currency->getFormattedPrice($array['subTotal'][$id]);
     $array['formattedSubTotalBeforeTax'][$id] = $currency->getFormattedPrice($array['subTotal'][$id] - $this->getTaxAmount());
     // selected shipping rate
     if ($selected = $this->getSelectedRate()) {
         $array['selectedRate'] = $selected->toArray($this->applyTaxesToShippingAmount($selected->getCostAmount()));
         if (!$array['selectedRate']) {
             unset($array['selectedRate']);
         } else {
             $array['ShippingService'] = $array['selectedRate']['ShippingService'];
         }
     }
     // shipping rate for a saved shipment
     if (!isset($array['selectedRate']) && isset($array['shippingAmount'])) {
         $array['shippingAmountWithoutTax'] = $array['shippingAmount'];
         $array['shippingAmount'] = $this->applyTaxesToShippingAmount($array['shippingAmount']);
         $orderCurrency = $this->order->get()->currency->get();
         $array['selectedRate']['formattedPrice'] = array();
         foreach ($currencies as $id => $currency) {
             $rate = $currency->convertAmount($orderCurrency, $array['shippingAmount']);
             $array['selectedRate']['formattedPrice'][$id] = Currency::getInstanceById($id)->getFormattedPrice($rate);
             $array['selectedRate']['formattedPriceWithoutTax'][$id] = Currency::getInstanceById($id)->getFormattedPrice($array['shippingAmountWithoutTax']);
         }
     }
     // taxes
     $taxes = array();
     foreach ($this->getTaxes() as $tax) {
         if ($tax->taxRate->get()) {
             $taxes[$tax->taxRate->get()->tax->get()->getID()][] = $tax;
         }
     }
     foreach ($taxes as $taxType) {
         $amount = 0;
         foreach ($taxType as $tax) {
             $amount += $tax->amount->get();
         }
         if ($amount > 0) {
             $array['taxes'][] = $tax->toArray($amount);
         }
     }
     // consists of downloadable files only?
     $array['isShippable'] = $this->isShippable();
     // Statuses
     $array['isReturned'] = (int) $this->isReturned();
     $array['isShipped'] = (int) $this->isShipped();
     $array['isAwaitingShipment'] = (int) $this->isAwaitingShipment();
     $array['isProcessing'] = (int) $this->isProcessing();
     $array['isDelivered'] = (int) $this->isDelivered();
     $array['isLost'] = (int) $this->isLost();
     $array['AmountCurrency'] =& $array['Order']['Currency'];
     return $array;
 }
开发者ID:saiber,项目名称:livecart,代码行数:71,代码来源:Shipment.php

示例13: getCurrency

 public function getCurrency()
 {
     return Currency::getInstanceById($this->currency);
 }
开发者ID:saiber,项目名称:livecart,代码行数:4,代码来源:RuleOrderContainer.php

示例14: updatePrice

 private function updatePrice($replaceQuantityPrices)
 {
     $request = $this->getApplication()->getRequest();
     $sku = $request->get('sku');
     $product = Product::getInstanceBySku($sku, array('ProductPrice'));
     if ($product == null) {
         throw new Exception('Product not found');
     }
     $currency = $request->get('currency');
     if ($currency == '') {
         $currency = $this->getApplication()->getDefaultCurrency()->getID();
     }
     $price = $request->get('definedPrice');
     if (is_numeric($price)) {
         $product->setPrice($currency, $price, false);
     }
     $price = $request->get('definedListPrice');
     if (is_numeric($price)) {
         $product->setPrice($currency, $price, true);
     }
     $quantityPrices = $request->get('quantityPrices');
     $groupedQuantityPrices = array();
     foreach ($quantityPrices as $item) {
         if ($item['currency'] == '') {
             $item['currency'] = $currency;
         }
         if ($item['group'] == '') {
             $item['group'] = 0;
         }
         $groupedQuantityPrices[$item['currency']][$item['quantity']][$item['group']] = $item['price'];
     }
     foreach ($product->getRelatedRecordSet('ProductPrice', new ARSelectFilter()) as $productPrice) {
         if ($replaceQuantityPrices == true) {
             $productPrice->serializedRules->set(serialize(array()));
         }
         $currencyID = $productPrice->currency->get()->getID();
         if (array_key_exists($currencyID, $groupedQuantityPrices)) {
             foreach ($groupedQuantityPrices[$currencyID] as $quanty => $qItem) {
                 foreach ($qItem as $group => $price) {
                     $group = !$group ? null : UserGroup::getInstanceByID($group);
                     $productPrice->setPriceRule($quanty, $group, $price);
                 }
             }
             $productPrice->save();
             unset($groupedQuantityPrices[$currencyID]);
             // for this currency saved
         }
     }
     if (count($groupedQuantityPrices) > 0) {
         // there is missing ProductPrice for some currencies,
         // will try to save as  new ProductPrice items
         foreach ($groupedQuantityPrices as $currency => $rules) {
             $productPrice = ProductPrice::getNewInstance($product, Currency::getInstanceById($currency));
             $productPrice->serializedRules->set(serialize($rules));
             $productPrice->save();
         }
     }
     $product->save();
     return $this->statusResponse($sku, 'updated');
 }
开发者ID:saiber,项目名称:livecart,代码行数:60,代码来源:ProductPriceApi.php


注:本文中的Currency::getInstanceById方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。