當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Money::subtract方法代碼示例

本文整理匯總了PHP中Money::subtract方法的典型用法代碼示例。如果您正苦於以下問題:PHP Money::subtract方法的具體用法?PHP Money::subtract怎麽用?PHP Money::subtract使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Money的用法示例。


在下文中一共展示了Money::subtract方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getShippingTotal

 /** Calculate shipping cost (Also set free shipping)
  * @param Money $totalSubtotal
  * @param $orderItems
  * @return array
  * @internal param Money $credits
  */
 public function getShippingTotal(Money $totalSubtotal, $orderItems, $zipCode = null)
 {
     $hasFreeShipping = FALSE;
     $shipping = [];
     $market_check = Configure::read('market_id');
     if (!empty($market_check)) {
         $market_id = Configure::read('market_id');
     } else {
         $market_id = $this->getMarketId();
     }
     //shipping tiers
     // market touch point
     $trait = ClassRegistry::init('TraitCountry');
     $defaultShipping = Money::fromFloat($trait->getTrait($market_id, 'default_shipping'));
     $midTierShipping = Money::fromFloat($trait->getTrait($market_id, 'mid_shipping_tier'));
     $marketShippingTierMid = Money::fromFloat($trait->getTrait($market_id, 'market_shipping_mid_tier'));
     $marketShippingTierFree = Money::fromFloat($trait->getTrait($market_id, 'market_shipping_free_tier'));
     $total_weight = 0.0;
     $no_expedite_reason = array();
     $backordered_items = false;
     $items = 0;
     $backorder_num = 0;
     $expedite = true;
     if (Configure::read('market_id') != MARKET::MARKET_USA) {
         $expedite = false;
         $no_expedite_reason[] = 1;
         //Currently none expeditable market
     }
     $expedite_check = $this->getExpeditedShipCount();
     if (!$expedite_check) {
         $expedite = false;
         $no_expedite_reason[] = 2;
         //Limit exceeded for expedited shipping requests
     }
     foreach ($orderItems as $key => $item) {
         $items++;
         if ($item['backordered'] == true) {
             $backordered_items = true;
             $this->orderObject->backOrderCount += (int) $item['qty'];
             //backorder
         }
         if ($item['childBackordered'] == true) {
             $backordered_items = true;
         }
         if ($item['sku'] == 'US-12001-01') {
             $expedite = false;
             $no_expedite_reason[] = 4;
             //hazmat
         }
         if ($item['hazmat'] == TRUE) {
             $expedite = false;
             $no_expedite_reason[] = 4;
             //hazmat
         }
         if (!empty($item['weight'])) {
             $total_weight += $item['weight'];
         } else {
             $total_weight += 0.35;
         }
         $shipping[$key] = $defaultShipping;
         // Convention tickets have free shipping + Presenter Kits
         if (in_array($item['item_type_id'], [Item::TYPE_CONVENTION_TICKET])) {
             $hasFreeShipping = TRUE;
         }
         // Items with free shipping (guest passes)
         if (in_array($item['sku'], ProductGlobal::freeShipping())) {
             $hasFreeShipping = TRUE;
         }
         // Remove business supplies from subtotal
         if ($item['item_type_id'] == Item::TYPE_SUPPLIES || $item['item_type_id'] == Item::TYPE_SUPPLIES_SETS) {
             $totalSubtotal->subtract($item['subtotal']);
         }
         // Remove presenter kits from subtotal
         if ($item['item_type_id'] == Item::TYPE_PRESENTER_KIT) {
             $totalSubtotal->subtract($item['subtotal']);
         }
     }
     if (CakeSession::read('market_id') != $market_id) {
         $this->orderObject->backOrderCount = 0;
         $wid = WarehouseUtil::idByMarket($market_id);
         Configure::write('ns_warehouse_id', $wid);
         $locale = CakeSession::read('Config');
         $locale = $locale['language'];
         /**
          * Get Cart
          */
         $results = ['backordered' => [], 'unavailable' => []];
         /**
          * Get availability for cart items
          */
         $this->Item = ClassRegistry::init('Item');
         $this->NsWarehouse = ClassRegistry::init('NsWarehouse');
         foreach ($orderItems as $key => $item) {
             $itemCheck = $this->Item->detailsBySku($item['sku'], $locale, true);
//.........這裏部分代碼省略.........
開發者ID:kameshwariv,項目名稱:testexample,代碼行數:101,代碼來源:Order.php

示例2: testExceptionIsRaisedWhenMoneyObjectWithDifferentCurrencyIsSubtracted

 /**
  * @covers            \SebastianBergmann\Money\Money::subtract
  * @covers            \SebastianBergmann\Money\Money::assertSameCurrency
  * @uses              \SebastianBergmann\Money\Money::__construct
  * @uses              \SebastianBergmann\Money\Money::handleCurrencyArgument
  * @uses              \SebastianBergmann\Money\Money::getAmount
  * @uses              \SebastianBergmann\Money\Money::getCurrency
  * @uses              \SebastianBergmann\Money\Currency
  * @expectedException \SebastianBergmann\Money\CurrencyMismatchException
  */
 public function testExceptionIsRaisedWhenMoneyObjectWithDifferentCurrencyIsSubtracted()
 {
     $a = new Money(1, new Currency('EUR'));
     $b = new Money(2, new Currency('USD'));
     $b->subtract($a);
 }
開發者ID:erictho,項目名稱:money,代碼行數:16,代碼來源:MoneyTest.php

示例3: subtractMoney

 /**
  * subtractMoney
  * 
  * Adds two instances of Money together, returning a new instance in the
  * same currency as the first instance.
  * 
  * @param Money $first
  * @param Money $second
  * @return type
  */
 public function subtractMoney(Money $first, Money $second)
 {
     return $first->subtract($this->normalizeMoneyValue($first, $second));
 }
開發者ID:mcordingley,項目名稱:money,代碼行數:14,代碼來源:Broker.php


注:本文中的Money::subtract方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。