本文整理汇总了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);
//.........这里部分代码省略.........
示例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);
}
示例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));
}