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


PHP Currency::getNewInstance方法代码示例

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


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

 function testTransactionCurrencyConverting()
 {
     $eur = Currency::getNewInstance('EUR');
     $eur->rate->set('3.4528');
     $eur->save();
     $this->products[0]->setPrice($this->usd, '9.99');
     $this->order->addProduct($this->products[0], 1);
     $this->order->save();
     $this->order->changeCurrency($this->usd);
     //$this->order->finalize();
     ActiveRecord::clearPool();
     $order = CustomerOrder::getInstanceByID($this->order->getID(), true);
     $order->loadAll();
     $details = new LiveCartTransaction($order, $eur);
     ActiveRecord::clearPool();
     $order = CustomerOrder::getInstanceByID($this->order->getID(), true);
     $order->loadAll();
     $this->assertEquals($details->amount->get(), '2.89');
     $result = new TransactionResult();
     $result->amount->set($details->amount->get());
     $result->currency->set($details->currency->get());
     $transaction = Transaction::getNewInstance($order, $result);
     $transaction->type->set(Transaction::TYPE_SALE);
     $this->assertEquals($transaction->amount->get(), '9.99');
     $this->assertEquals($transaction->realAmount->get(), '2.89');
     $transaction->save();
     $this->assertFalse((bool) $order->isFinalized->get());
     $order->finalize();
     $this->assertTrue((bool) $order->isFinalized->get());
     $this->assertEquals($order->getPaidAmount(), '9.99');
     $this->assertEquals($order->totalAmount->get(), '9.99');
     $this->assertTrue((bool) $order->isPaid->get());
 }
开发者ID:saiber,项目名称:livecart,代码行数:33,代码来源:TransactionTest.php

示例3: 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

示例4: setUp

 public function setUp()
 {
     parent::setUp();
     // create a product without attributes
     $this->product = Product::getNewInstance($this->category, 'test');
     $this->product->setValueByLang("name", "en", "TEST_PRODUCT");
     $this->product->save();
     $this->productAutoIncrementNumber = $this->product->getID();
     for ($k = 1; $k < 4; $k++) {
         $currency = Currency::getNewInstance($k . 'zz');
         $currency->save();
     }
 }
开发者ID:saiber,项目名称:livecart,代码行数:13,代码来源:ProductPricingTest.php

示例5: ztestModelPlugins

 public function ztestModelPlugins()
 {
     $this->getApplication()->registerPluginDirectory(ClassLoader::getRealPath('test.fixture.plugin'));
     $currency = Currency::getNewInstance('ZZZ');
     $currency->save();
     $this->assertEquals($currency->rate->get(), 0.5);
     $this->assertFalse((bool) $currency->isEnabled->get());
     $currency->rate->set(0.6);
     $currency->save();
     $this->assertTrue((bool) $currency->isEnabled->get());
     $array = $currency->toArray();
     $this->assertTrue($array['testValue']);
     $this->getApplication()->unregisterPluginDirectory(ClassLoader::getRealPath('test.fixture.plugin'));
 }
开发者ID:saiber,项目名称:livecart,代码行数:14,代码来源:LiveCartApplicationTest.php

示例6: 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

示例7: getNextCustomerOrder

 public function getNextCustomerOrder()
 {
     if (!($data = $this->loadRecord('SELECT * FROM ' . $this->getTablePrefix() . 'orders WHERE customerID > 0'))) {
         return null;
     }
     $user = ActiveRecordModel::getInstanceByIDIfExists('User', $this->getRealId('User', $data['customerID'], false));
     if (!$user || !$user->isExistingRecord()) {
         return $this->getNextCustomerOrder();
     }
     $currCode = $data['currency_code'];
     if (!($currency = ActiveRecordModel::getInstanceByIDIfExists('Currency', $currCode, false))) {
         $currency = Currency::getNewInstance($currCode);
         $currency->save();
     }
     $order = CustomerOrder::getNewInstance($user);
     $order->currency->set($currency);
     $order->dateCompleted->set($data['order_time']);
     // products
     foreach ($this->getDataBySql('SELECT * FROM ' . $this->getTablePrefix() . 'ordered_carts WHERE orderID=' . $data['orderID']) as $item) {
         $product = null;
         // try to identify product by SKU
         preg_match('/\\[(.*)\\]/', $item['name'], $sku);
         if (isset($sku[1])) {
             $product = Product::getInstanceBySKU($sku[1]);
         }
         // if that doesn't work, then try to match the exact name
         if (!$product) {
             $productData = array_shift($this->getDataBySQL('SELECT productID FROM ' . $this->getTablePrefix() . 'products WHERE name="' . addslashes($item['name']) . '"'));
             if ($productData && is_array($productData)) {
                 $product = Product::getInstanceByID($this->getRealId('Product', $productData['productID']), Product::LOAD_DATA);
             }
         }
         if ($product) {
             $order->addProduct($product, $item['Quantity'], true);
             $orderedItem = array_shift($order->getItemsByProduct($product));
             $orderedItem->price->set($item['Price']);
         }
     }
     // addresses
     $order->shippingAddress->set($this->getUserAddress($data, 'shipping_'));
     $order->billingAddress->set($this->getUserAddress($data, 'billing_'));
     $order->status->set($this->getOrderStatus($data['statusID']));
     if ($order->status->get() == CustomerOrder::STATUS_SHIPPED) {
         $order->isPaid->set(true);
     }
     $order->rawData = $data;
     return $order;
 }
开发者ID:saiber,项目名称:www,代码行数:48,代码来源:ShopScriptImport.php

示例8: testMustHavePurchasedToRate

 public function testMustHavePurchasedToRate()
 {
     $user = User::getNewInstance('i-want-to-rate@example.com');
     $user->save();
     self::getApplication()->getConfig()->set('ENABLE_REVIEWS', true);
     self::getApplication()->getConfig()->set('ENABLE_ANONYMOUS_RATINGS', false);
     self::getApplication()->getConfig()->set('REQUIRE_PURCHASE_TO_RATE', true);
     $this->request->set('rating_', 4);
     $this->request->set('ajax', 'true');
     $this->assertRatingError();
     $this->controller->setUser($user);
     // login not enough - should still fail
     $this->assertRatingError();
     ActiveRecordModel::executeUpdate('DELETE FROM Currency');
     $usd = Currency::getNewInstance('USD');
     $usd->save();
     $order = CustomerOrder::getNewInstance($user);
     $order->addProduct($this->product);
     $order->save();
     // order not completed - should still fail
     $this->assertRatingError();
     // order finalized - now works
     $order->finalize();
     $id = $this->product->getID();
     $this->setUp();
     $this->controller->setUser($user);
     $this->request->set('id', $id);
     $this->assertRatingError(false);
 }
开发者ID:saiber,项目名称:livecart,代码行数:29,代码来源:ProductControllerTest.php

示例9: testOrderTotalsWithRoundedPrices

 public function testOrderTotalsWithRoundedPrices()
 {
     $currency = Currency::getNewInstance('RON');
     $currency->setRoundingRule(0, Currency::TRIM, 0.09);
     $currency->save();
     $product = Product::getNewInstance(Category::getRootNode());
     $product->isEnabled->set(true);
     $product->setPrice($currency, 1.26);
     $product->save();
     $order = CustomerOrder::getNewInstance(SessionUser::getAnonymousUser());
     $order->addProduct($product);
     $order->save(true);
     $item = array_shift($order->getItemsByProduct($product));
     $this->assertEquals($product->getPrice($currency), 1.29);
     $this->assertEquals($item->getSubTotal(), 1.29);
     $item->count->set(2);
     $this->assertEquals($item->getSubTotal(), 2.58);
     $this->assertEquals($order->getTotal(true), 2.58);
     // add another currency to mix - no rounding rules
     $bgn = Currency::getNewInstance('BGN');
     $bgn->rate->set(2);
     $bgn->save();
     $item->count->set(2);
     $order->changeCurrency($bgn);
     $this->assertEquals($product->getPrice($bgn), 0.63);
     $this->assertEquals($item->getPrice(), 0.63);
     $this->assertSame($item->getCurrency(), $bgn);
     $this->assertEquals($item->getSubTotal(), 1.26);
     $this->assertEquals($order->getTotal(true), 1.26);
     // add rounding rules
     $bgn->clearRoundingRules();
     $bgn->setRoundingRule(0, Currency::TRIM, 0.07000000000000001);
     $order->changeCurrency($bgn);
     $this->assertEquals($product->getPrice($bgn), 0.67);
     $this->assertEquals($item->getSubTotal(), 1.34);
     $this->assertEquals($order->getTotal(true), 1.34);
 }
开发者ID:saiber,项目名称:livecart,代码行数:37,代码来源:CurrencyTest.php


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