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


PHP Currency::getInstanceByID方法代码示例

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


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

示例1: testCreateAndRetrieve

 public function testCreateAndRetrieve()
 {
     // set up currency
     if (ActiveRecord::objectExists('Currency', 'USD')) {
         $this->usd = Currency::getInstanceByID('USD', Currency::LOAD_DATA);
     } else {
         $this->usd = Currency::getNewInstance('USD');
         $this->usd->setAsDefault();
         $this->usd->save();
     }
     $products = array();
     for ($k = 0; $k <= 2; $k++) {
         $products[$k] = Product::getNewInstance($this->root);
         $products[$k]->setPrice($this->usd, $k + 1);
         $products[$k]->save();
         $bundled = ProductBundle::getNewInstance($this->container, $products[$k]);
         $bundled->save();
     }
     $list = ProductBundle::getBundledProductSet($this->container);
     $this->assertEqual($list->size(), count($products));
     foreach ($list as $index => $item) {
         $this->assertSame($item->relatedProduct->get(), $products[$index]);
     }
     $this->assertEqual(ProductBundle::getTotalBundlePrice($this->container, $this->usd), 6);
 }
开发者ID:saiber,项目名称:livecart,代码行数:25,代码来源:ProductBundleTest.php

示例2: setUpCurrency

 /**
  * !Running tests not involving initOrder() method will not recreate Currency,
  * but setUp() method is wiping all Currecy records,
  *
  * Store frontend is not working without Currency object
  *
  * As workround this method can be called from test suite to recreate Currency
  *
  * @todo: reorganize tests to call DELETE FROM Currency only when setUpCurrency() method is called.
  *
  */
 protected function setUpCurrency()
 {
     if (ActiveRecord::objectExists('Currency', 'USD')) {
         $this->usd = Currency::getInstanceByID('USD', Currency::LOAD_DATA);
     } else {
         $this->usd = Currency::getNewInstance('USD');
         $this->usd->setAsDefault();
         $this->usd->save();
     }
 }
开发者ID:saiber,项目名称:livecart,代码行数:21,代码来源:LiveCartTest.php

示例3: process

 public function process()
 {
     try {
         $usd = Currency::getInstanceByID('USD', true);
     } catch (Exception $e) {
         return;
     }
     if (!$usd->isEnabled->get()) {
         return;
     }
     $app = ActiveRecordModel::getApplication();
     $request = $app->getRequest();
     $request->set('currency', $usd->getID());
     $app->getRouter()->removeAutoAppendVariable('currency');
 }
开发者ID:saiber,项目名称:www,代码行数:15,代码来源:ActivateUSD.php

示例4: getInstance

 protected function getInstance($record, CsvImportProfile $profile)
 {
     $fields = $profile->getSortedFields();
     if (isset($fields['Currency']['ID'])) {
         try {
             $instance = Currency::getInstanceByID($record[$fields['Currency']['ID']], true);
         } catch (ARNotFoundException $e) {
         }
     } else {
         return;
     }
     if (empty($instance)) {
         $instance = Currency::getNewInstance($record[$fields['Currency']['ID']]);
     }
     $this->setLastImportedRecordName($instance->getID());
     return $instance;
 }
开发者ID:saiber,项目名称:livecart,代码行数:17,代码来源:CurrencyImport.php

示例5: createOrder

 private function createOrder()
 {
     $user = User::getNewInstance('google@checkout.test');
     $user->save();
     $currency = Currency::getInstanceByID('USD');
     $product = Product::getNewInstance(Category::getRootNode());
     $product->isEnabled->set(true);
     $product->stockCount->set(100);
     $product->setPrice($currency, 100);
     $product->setValueByLang('name', null, 'Test name');
     $product->setValueByLang('shortDescription', null, 'Really short description');
     $product->save();
     $order = CustomerOrder::getNewInstance($user);
     $order->addProduct($product, 1);
     $order->save();
     return $order;
 }
开发者ID:saiber,项目名称:www,代码行数:17,代码来源:GoogleCheckoutTest.php

示例6: __get

 public function __get($name)
 {
     if ($inst = parent::__get($name)) {
         return $inst;
     }
     switch ($name) {
         case 'order':
             ClassLoader::import('application.model.order.SessionOrder');
             $this->order = SessionOrder::getOrder();
             // check if order currency matches the request currency
             if (!$this->order->currency->get() || $this->order->currency->get()->getID() != $this->getRequestCurrency()) {
                 $this->order->changeCurrency(Currency::getInstanceByID($this->getRequestCurrency()));
             }
             return $this->order;
             break;
         default:
             break;
     }
 }
开发者ID:saiber,项目名称:www,代码行数:19,代码来源:FrontendController.php

示例7: setConfig

 public function setConfig()
 {
     if (!$this->buildConfigValidator()->isValid()) {
         return new ActionRedirectResponse('install', 'config');
     }
     Language::deleteCache();
     // site name
     $this->config->setValueByLang('STORE_NAME', $this->request->get('language'), $this->request->get('name'));
     $this->config->save();
     ClassLoader::import('application.model.Currency');
     // create currency
     if (ActiveRecord::objectExists('Currency', $this->request->get('curr'))) {
         $currency = Currency::getInstanceByID($this->request->get('curr'), Currency::LOAD_DATA);
     } else {
         $currency = ActiveRecord::getNewInstance('Currency');
         $currency->setID($this->request->get('curr'));
         $currency->isEnabled->set(true);
         $currency->isDefault->set(true);
         $currency->save(ActiveRecord::PERFORM_INSERT);
     }
     ClassLoader::import('application.model.system.Language');
     // create language
     if (ActiveRecord::objectExists('Language', $this->request->get('language'))) {
         $language = Language::getInstanceByID($this->request->get('language'), Language::LOAD_DATA);
     } else {
         $language = ActiveRecord::getNewInstance('Language');
         $language->setID($this->request->get('language'));
         $language->save(ActiveRecord::PERFORM_INSERT);
         $language->isEnabled->set(true);
         $language->isDefault->set(true);
         $language->save();
     }
     // set root category name to "LiveCart"
     ClassLoader::import('application.model.category.Category');
     $root = Category::getInstanceById(Category::ROOT_ID, Category::LOAD_DATA);
     $root->setValueByLang('name', $language->getID(), 'LiveCart');
     $root->save();
     // create a default shipping service
     ClassLoader::import('application.model.delivery.DeliveryZone');
     ClassLoader::import('application.model.delivery.ShippingService');
     ClassLoader::import('application.model.delivery.ShippingRate');
     $service = ShippingService::getNewInstance(DeliveryZone::getDefaultZoneInstance(), 'Default Service', ShippingService::SUBTOTAL_BASED);
     $service->save();
     $rate = ShippingRate::getNewInstance($service, 0, 100000);
     $rate->flatCharge->set(10);
     $rate->save();
     // create a couple of blank static pages
     ClassLoader::import('application.model.staticpage.StaticPage');
     $page = StaticPage::getNewInstance();
     $page->setValueByLang('title', $language->getID(), 'Contact Info');
     $page->setValueByLang('text', $language->getID(), 'Enter your contact information here');
     $page->menu->set(array('INFORMATION' => true));
     $page->save();
     $page = StaticPage::getNewInstance();
     $page->setValueByLang('title', $language->getID(), 'Shipping Policy');
     $page->setValueByLang('text', $language->getID(), 'Enter your shipping rate & policy information here');
     $page->menu->set(array('INFORMATION' => true));
     $page->save();
     // create an example site news post
     ClassLoader::import('application.model.sitenews.NewsPost');
     $news = ActiveRecordModel::getNewInstance('NewsPost');
     $news->setValueByLang('title', $language->getID(), 'Our store is open');
     $news->setValueByLang('text', $language->getID(), 'Powered by LiveCart software, we have gone live! Of course, we will have to go to <a href="../backend">the backend area</a> and add some categories and products first...');
     $news->setValueByLang('moreText', $language->getID(), 'Do not forget to delete this post when you actually go live :)');
     $news->isEnabled->set(true);
     $news->save();
     return new ActionRedirectResponse('install', 'finish');
 }
开发者ID:GregerA,项目名称:livecart,代码行数:68,代码来源:InstallController.php

示例8: index

 public function index()
 {
     $this->loadLanguageFile('Category');
     $product = Product::getInstanceByID($this->request->get('id'), Product::LOAD_DATA, array('ProductImage', 'Manufacturer', 'Category'));
     $this->product = $product;
     if (!$product->isEnabled->get() || $product->parent->get()) {
         throw new ARNotFoundException('Product', $product->getID());
     }
     $product->loadPricing();
     $this->category = $product->getCategory();
     $this->categoryID = $product->getCategory()->getID();
     // get category path for breadcrumb
     $path = $product->category->get()->getPathNodeArray();
     include_once ClassLoader::getRealPath('application.helper.smarty') . '/function.categoryUrl.php';
     include_once ClassLoader::getRealPath('application.helper.smarty') . '/function.productUrl.php';
     foreach ($path as $nodeArray) {
         $url = createCategoryUrl(array('data' => $nodeArray), $this->application);
         if ($nodeArray['isEnabled']) {
             $this->addBreadCrumb($nodeArray['name_lang'], $url);
         }
     }
     // add filters to breadcrumb
     CategoryController::getAppliedFilters();
     // for root category products
     if (!isset($nodeArray)) {
         $nodeArray = array();
     }
     $params = array('data' => $nodeArray, 'filters' => array());
     foreach ($this->filters as $filter) {
         $f = $filter->toArray();
         $params['filters'][] = $f;
         $url = createCategoryUrl($params, $this->application);
         $this->addBreadCrumb($f['name_lang'], $url);
     }
     $productArray = $product->toArray();
     $handle = empty($productArray['URL']) ? $productArray['name_lang'] : $productArray['URL'];
     $this->redirect301($this->request->get('producthandle'), createHandleString($handle));
     //ProductSpecification::loadSpecificationForProductArray($productArray);
     // filter empty attributes
     foreach ($productArray['attributes'] as $key => $attr) {
         if (empty($attr['value']) && empty($attr['values']) && empty($attr['value_lang'])) {
             unset($productArray['attributes'][$key]);
         }
     }
     // attribute summary
     $productArray['listAttributes'] = array();
     foreach ($productArray['attributes'] as $key => $attr) {
         if ($attr['SpecField']['isDisplayedInList']) {
             $productArray['listAttributes'][] = $attr;
         }
         if (!$attr['SpecField']['isDisplayed']) {
             unset($productArray['attributes'][$key]);
         }
     }
     // add product title to breacrumb
     $this->addBreadCrumb($productArray['name_lang'], createProductUrl(array('product' => $productArray), $this->application));
     // manufacturer filter
     if ($product->manufacturer->get()) {
         $manFilter = new ManufacturerFilter($product->manufacturer->get()->getID(), $product->manufacturer->get()->name->get());
     }
     // get category page route
     end($this->breadCrumb);
     $last = prev($this->breadCrumb);
     $catRoute = $this->router->getRouteFromUrl($last['url']);
     $response = new ActionResponse();
     $response->set('product', $productArray);
     $response->set('category', $productArray['Category']);
     $response->set('quantity', $this->getQuantities($product));
     $response->set('currency', $this->request->get('currency', $this->application->getDefaultCurrencyCode()));
     $response->set('catRoute', $catRoute);
     // ratings
     if ($this->config->get('ENABLE_RATINGS')) {
         if ($product->ratingCount->get() > 0) {
             // rating summaries
             ClassLoader::import('application.model.product.ProductRatingSummary');
             $response->set('rating', ProductRatingSummary::getProductRatingsArray($product));
         }
         ClassLoader::import('application.model.category.ProductRatingType');
         $ratingTypes = ProductRatingType::getProductRatingTypeArray($product);
         $response->set('ratingTypes', $ratingTypes);
         $response->set('ratingForm', $this->buildRatingForm($ratingTypes, $product));
         $response->set('isRated', $this->isRated($product));
         $response->set('isLoginRequiredToRate', $this->isLoginRequiredToRate());
         $response->set('isPurchaseRequiredToRate', $this->isPurchaseRequiredToRate($product));
     }
     // add to cart form
     $response->set('cartForm', $this->buildAddToCartForm($this->getOptions(), $this->getVariations()));
     // related products
     $related = $this->getRelatedProducts($product);
     // items purchased together
     $together = $product->getProductsPurchasedTogether($this->config->get('NUM_PURCHASED_TOGETHER'), true);
     $spec = array();
     foreach ($related as $key => $group) {
         foreach ($related[$key] as $i => &$prod) {
             $spec[] =& $related[$key][$i];
         }
     }
     foreach ($together as &$prod) {
         $spec[] =& $prod;
     }
//.........这里部分代码省略.........
开发者ID:saiber,项目名称:www,代码行数:101,代码来源:ProductController.php

示例9: save

 /**
  * @role update
  */
 public function save()
 {
     $currency = Currency::getInstanceByID($this->request->get('id'), Currency::LOAD_DATA);
     $currency->loadRequestData($this->request);
     $currency->rounding->set(serialize(json_decode($this->request->get('rounding'), true)));
     $currency->save();
     return new JSONResponse(false, 'success');
 }
开发者ID:saiber,项目名称:livecart,代码行数:11,代码来源:CurrencyController.php

示例10: transformArray

 public static function transformArray($array, ARSchema $schema)
 {
     $array = parent::transformArray($array, $schema);
     try {
         $array['formattedAmount'] = Currency::getInstanceByID($array['Currency']['ID'])->getFormattedPrice($array['amount']);
         $array['formattedRealAmount'] = Currency::getInstanceByID($array['RealCurrency']['ID'])->getFormattedPrice($array['realAmount']);
     } catch (ARNotFoundException $e) {
     }
     $array['methodName'] = self::getApplication()->getLocale()->translator()->translate($array['method']);
     $array['serializedData'] = unserialize($array['serializedData']);
     $array['ccLastDigits'] = self::decrypt($array['ccLastDigits']);
     if (strlen($array['ccCVV']) > 0) {
         $array['ccCVV'] = self::decrypt($array['ccCVV']);
     }
     return $array;
 }
开发者ID:saiber,项目名称:www,代码行数:16,代码来源:Transaction.php

示例11: save

 private function save(RecurringProductPeriod $rpp)
 {
     $request = $this->getRequest();
     $validator = $this->createFormValidator($rpp->toArray());
     if ($validator->isValid()) {
         $rpp->loadRequestData($this->request);
         // null value is not set by loadRequestData()..
         $rebillCount = $this->request->get('rebillCount');
         $rebillCount = floor($rebillCount);
         $rpp->rebillCount->set(is_numeric($rebillCount) && $rebillCount <= 0 ? $rebillCount : NULL);
         $rpp->save();
         $product = $rpp->product->get();
         $currencies = array();
         foreach ($this->application->getCurrencyArray(true) as $currency) {
             if (array_key_exists($currency, $currencies) == false) {
                 $currencies[$currency] = Currency::getInstanceByID($currency);
             }
             foreach (array(ProductPrice::TYPE_SETUP_PRICE => $request->get('ProductPrice_setup_price_' . $currency), ProductPrice::TYPE_PERIOD_PRICE => $request->get('ProductPrice_period_price_' . $currency)) as $type => $value) {
                 $price = ProductPrice::getInstance($product, $currencies[$currency], $rpp, $type);
                 if (strlen($value) == 0 && $price->isExistingRecord()) {
                     $price->delete();
                 } else {
                     $price->price->set($value);
                     $price->save();
                 }
             }
         }
         return new JSONResponse(array('rpp' => $rpp->toArray()), 'success');
     } else {
         return new JSONResponse(array('errors' => $validator->getErrorList()), 'failure', $this->translate('_could_not_save_recurring_product_period_entry'));
     }
 }
开发者ID:saiber,项目名称:livecart,代码行数:32,代码来源:RecurringProductPeriodController.php

示例12: transformArray

 public static function transformArray($array, ARSchema $schema)
 {
     $array = parent::transformArray($array, $schema);
     $currency = Currency::getInstanceByID($array['currencyID']);
     $array['serializedRules'] = unserialize($array['serializedRules']);
     if ($array['serializedRules'] && !is_array($array['serializedRules'])) {
         $array['serializedRules'] = array();
     }
     if ($array['serializedRules'] && is_array($array['serializedRules'])) {
         $ruleController = self::getApplication()->getBusinessRuleController();
         $quantities = array_keys($array['serializedRules']);
         $nextQuant = array();
         foreach ($quantities as $key => $quant) {
             $nextQuant[$quant] = isset($quantities[$key + 1]) ? $quantities[$key + 1] - 1 : null;
         }
         foreach ($array['serializedRules'] as $quantity => $prices) {
             foreach ($prices as $group => $price) {
                 $originalPrice = $currency->roundPrice($price);
                 $product = isset($array['Product']) ? $array['Product'] : Product::getInstanceByID($array['productID']);
                 $price = $ruleController->getProductPrice($product, $originalPrice);
                 $array['quantityPrices'][$group][$quantity] = array('originalPrice' => $originalPrice, 'price' => $price, 'originalFormattedPrice' => $currency->getFormattedPrice($originalPrice), 'formattedPrice' => $currency->getFormattedPrice($price), 'from' => $quantity, 'to' => $nextQuant[$quantity]);
             }
         }
     }
     return $array;
 }
开发者ID:saiber,项目名称:www,代码行数:26,代码来源:ProductPrice.php

示例13: getDiscountPrices

 public function getDiscountPrices(User $user, $currency)
 {
     if (!$currency instanceof Currency) {
         $currency = Currency::getInstanceByID($currency);
     }
     $price = $this->getPrice($currency);
     if (!$price->getPrice()) {
         $price = $this->getPriceByCurrencyCode($this->application->getDefaultCurrencyCode());
     }
     $prices = array();
     foreach ($price->getUserPrices($user) as $quant => $pr) {
         $pr = $currency->convertAmount($price->currency->get(), $pr);
         $pr = $this->application->getDisplayTaxPrice($pr, $this->product);
         $prices[$quant] = array('price' => $pr, 'formattedPrice' => $currency->getFormattedPrice($pr), 'from' => $quant);
     }
     foreach ($prices as $quant => &$price) {
         if (isset($previousPrice)) {
             $previousPrice['to'] = $quant - 1;
         }
         $previousPrice =& $price;
     }
     return $prices;
 }
开发者ID:saiber,项目名称:www,代码行数:23,代码来源:ProductPricing.php

示例14: includeProductPrice

 public static function includeProductPrice(Product $product, &$options)
 {
     $prices = $product->getPricingHandler()->toArray();
     $prices = $prices['calculated'];
     foreach ($options as &$option) {
         if (!empty($option['choices'])) {
             foreach ($option['choices'] as &$choice) {
                 foreach ($prices as $currency => $price) {
                     $instance = Currency::getInstanceByID($currency);
                     $choice['formattedTotalPrice'][$currency] = $instance->getFormattedPrice($price + $instance->convertAmountFromDefaultCurrency($choice['priceDiff']));
                 }
             }
         }
     }
 }
开发者ID:saiber,项目名称:livecart,代码行数:15,代码来源:ProductOption.php

示例15: getPriceDiff

 public function getPriceDiff($currencyCode, $basePrice = false)
 {
     $basePrice = false === $basePrice ? $this->priceDiff->get() : $basePrice;
     return ProductPrice::convertPrice(Currency::getInstanceByID($currencyCode), $basePrice);
 }
开发者ID:saiber,项目名称:www,代码行数:5,代码来源:ProductOptionChoice.php


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