本文整理匯總了PHP中Money::setAmount方法的典型用法代碼示例。如果您正苦於以下問題:PHP Money::setAmount方法的具體用法?PHP Money::setAmount怎麽用?PHP Money::setAmount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Money
的用法示例。
在下文中一共展示了Money::setAmount方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: price_for_display
public static function price_for_display($price)
{
$currency = ShopConfig::get_site_currency();
$field = new Money("Price");
$field->setAmount($price);
$field->setCurrency($currency);
return $field;
}
示例2: testCanSetAmount
public function testCanSetAmount()
{
// Arrange
$a = new Money(1);
// Act
$a->setAmount(123);
// Assert
$this->assertEquals(123, $a->getAmount());
}
示例3: testSetValueAsMoney
public function testSetValueAsMoney()
{
$o = new MoneyFieldTest_Object();
$f = new MoneyField('MyMoney', 'MyMoney');
$m = new Money();
$m->setAmount(123456.78);
$m->setCurrency('EUR');
$f->setValue($m);
$f->saveInto($o);
$this->assertEquals(123456.78, $o->MyMoney->getAmount());
$this->assertEquals('EUR', $o->MyMoney->getCurrency());
}
示例4: testAddCompositedExtraFields
public function testAddCompositedExtraFields()
{
$obj = new ManyManyListTest_ExtraFields();
$obj->write();
$money = new Money();
$money->setAmount(100);
$money->setCurrency('USD');
// the actual test is that this does not generate an error in the sql.
$obj->Clients()->add($obj, array('Worth' => $money, 'Reference' => 'Foo'));
$check = $obj->Clients()->First();
$this->assertEquals('Foo', $check->Reference, 'Basic scalar fields should exist');
$this->assertInstanceOf('Money', $check->Worth, 'Composite fields should exist on the record');
$this->assertEquals(100, $check->Worth->getAmount());
}
示例5: variationprice
/**
* Calculate the {@link Variation} price difference based on current request.
* Current seleted options are passed in POST vars, if a matching Variation can
* be found, the price difference of that Variation is returned for display on the Product
* page.
*
* TODO return the total here as well
*
* @param SS_HTTPRequest $request
* @return String JSON encoded string of price difference
*/
function variationprice(SS_HTTPRequest $request)
{
$data = array();
$product = $this->data();
$variations = $product->Variations();
$attributeOptions = $request->postVar('Options');
//Filter variations to match attribute ID and option ID
$variationOptions = array();
if ($variations && $variations->exists()) {
foreach ($variations as $variation) {
$options = $variation->Options();
if ($options) {
foreach ($options as $option) {
$variationOptions[$variation->ID][$option->AttributeID] = $option->ID;
}
}
}
}
$variation = null;
foreach ($variationOptions as $variationID => $options) {
if ($options == $attributeOptions) {
$variation = $variations->find('ID', $variationID);
break;
}
}
$data['totalPrice'] = $product->Amount->Nice();
if ($variation) {
if ($variation->Amount->getAmount() == 0) {
$data['priceDifference'] = 0;
} else {
if ($variation->Amount->getAmount() > 0) {
$data['priceDifference'] = '(+' . $variation->Amount->Nice() . ')';
$newTotal = new Money();
$newTotal->setCurrency($product->Amount->getCurrency());
$newTotal->setAmount($product->Amount->getAmount() + $variation->Amount->getAmount());
$data['totalPrice'] = $newTotal->Nice();
} else {
//Variations have been changed so only positive values, so this is unnecessary
//$data['priceDifference'] = '(' . $variation->Amount->Nice() . ')';
}
}
}
return json_encode($data);
}
示例6: getCalculatedPrice
/**
* Returns the price for this shipping fee.
*
* @return Money
*
* @author Sascha Koehler <skoehler@pixeltricks.de>
* @since 13.03.2012
*/
public function getCalculatedPrice()
{
$priceObj = new Money();
$priceObj->setAmount($this->getPriceAmount());
$priceObj->setCurrency($this->getPriceCurrency());
return $priceObj;
}
示例7: PromoSavings
/**
* @return Money
*/
public function PromoSavings()
{
$currency = method_exists('ShopConfig', 'get_site_currency') ? ShopConfig::get_site_currency() : Payment::site_currency();
$field = new Money("PromoSavings");
$field->setAmount($this->calculatePromoSavings());
$field->setCurrency($currency);
return $field;
}
示例8: NormalPrice
function NormalPrice()
{
$normalPrice = new Money();
$normalPrice->setAmount((int) $this->owner->Price);
return $normalPrice;
}
示例9: testToCurrency
public function testToCurrency()
{
$USD = new Money();
$USD->setLocale('en_US');
$USD->setAmount(53292.18);
$this->assertSame('$53,292.18', $USD->Nice());
$this->assertSame('$ 53.292,18', $USD->Nice(array('format' => 'de_AT')));
}
示例10: Amount
/**
* Get Amount for this modifier so that it can be saved into an {@link Order} {@link Modification}.
* Get the FlatFeeTaxRate and multiply the rate by the Order subtotal.
*
* @see Modification
* @param Order $order
* @param Int $value ID for a {@link FlatFeeShippingRate}
* @return Money
*/
public function Amount($order, $value)
{
$currency = Modification::currency();
$amount = new Money();
$amount->setCurrency($currency);
$taxRate = DataObject::get_by_id('FlatFeeTaxRate', $value);
if ($taxRate && $taxRate->exists()) {
$amount->setAmount($order->SubTotal->getAmount() * ($taxRate->Rate / 100));
} else {
user_error("Cannot find flat tax rate for that ID.", E_USER_WARNING);
//TODO return meaningful error to browser in case error not shown
return;
}
return $amount;
}
示例11: getChargesAndDiscountsForTotal
/**
* Returns the charges and discounts for the shopping cart total for
* this payment method.
*
* @param SilvercartShoppingCart $silvercartShoppingCart The shopping cart object
* @param string $priceType 'gross' or 'net'
*
* @return mixed boolean|DataObject
*
* @author Sascha Koehler <skoehler@pixeltricks.de>,
* Sebastian Diel <sdiel@pixeltricks.de>
* @since 16.11.2013
*/
public function getChargesAndDiscountsForTotal(SilvercartShoppingCart $silvercartShoppingCart, $priceType = false)
{
$handlingCosts = new Money();
$handlingCosts->setAmount(0);
$handlingCosts->setCurrency(SilvercartConfig::DefaultCurrency());
if ($priceType === false) {
$priceType = SilvercartConfig::PriceType();
}
if ($this->useSumModification && $this->sumModificationImpact == 'totalValue') {
$excludedPositions = array();
switch ($this->sumModificationValueType) {
case 'percent':
$amount = $silvercartShoppingCart->getAmountTotal(array(), false, true);
$modificationValue = $amount->getAmount() / 100 * $this->sumModificationValue;
$index = 1;
foreach ($silvercartShoppingCart->SilvercartShoppingCartPositions() as $position) {
if ($position->SilvercartProductID > 0 && $position->SilvercartProduct() instanceof SilvercartProduct && $position->SilvercartProduct()->ExcludeFromPaymentDiscounts) {
$modificationValue -= $position->getPrice()->getAmount() / 100 * $this->sumModificationValue;
$excludedPositions[] = $index;
}
$index++;
}
break;
case 'absolute':
default:
$modificationValue = $this->sumModificationValue;
}
if (count($excludedPositions) > 0) {
if (count($excludedPositions) == 1) {
$this->sumModificationLabel .= ' (' . sprintf(_t('SilvercartPaymentMethod.ExcludedPosition'), implode(', ', $excludedPositions)) . ')';
} else {
$this->sumModificationLabel .= ' (' . sprintf(_t('SilvercartPaymentMethod.ExcludedPositions'), implode(', ', $excludedPositions)) . ')';
}
}
if ($this->sumModificationImpactType == 'charge') {
$handlingCostAmount = $modificationValue;
} else {
$handlingCostAmount = "-" . $modificationValue;
}
if (SilvercartConfig::PriceType() == 'gross') {
$shoppingCartTotal = $silvercartShoppingCart->getAmountTotal(array(), false, true);
} else {
$shoppingCartTotal = $silvercartShoppingCart->getAmountTotalNetWithoutVat(array(), false, true);
$taxRate = $silvercartShoppingCart->getMostValuableTaxRate();
$handlingCostAmount = round($handlingCostAmount / (100 + $taxRate->Rate) * 100, 4);
}
if ($handlingCostAmount < 0 && $shoppingCartTotal->getAmount() < $handlingCostAmount * -1) {
$handlingCostAmount = $shoppingCartTotal->getAmount() * -1;
}
$handlingCosts->setAmount($handlingCostAmount);
}
$this->extend('updateChargesAndDiscountsForTotal', $handlingCosts);
if ($handlingCosts->getAmount() == 0) {
$handlingCosts = false;
}
return $handlingCosts;
}
示例12: Amount
/**
* Get Amount for this modifier so that it can be saved into an {@link Order} {@link Modification}.
*
* @see Modification
* @param Order $order
* @param Int $value ID for a {@link FlatFeeShippingRate}
* @return Money
*/
public function Amount($order, $value)
{
$optionID = $value;
$amount = new Money();
$currency = Modification::currency();
$amount->setCurrency($currency);
$flatFeeShippingRates = DataObject::get('FlatFeeShippingRate');
if ($flatFeeShippingRates && $flatFeeShippingRates->exists()) {
$shippingRate = $flatFeeShippingRates->find('ID', $optionID);
if ($shippingRate) {
$amount->setAmount($shippingRate->Amount->getAmount());
} else {
user_error("Cannot find flat fee rate for that ID.", E_USER_WARNING);
//TODO return meaningful error to browser in case error not shown
return;
}
}
return $amount;
}
示例13: getMoney
/**
* Package the amcount and currency into a Money object.
* @return Money
*/
protected function getMoney()
{
$money = new Money("Amount");
$money->setAmount($this->amount);
$money->setCurrency($this->currency);
return $money;
}
示例14: TotalPaid
/**
* Calculate the total paid for this order, only 'Success' payments
* are considered.
*
* @return Money With value and currency of total paid
*/
function TotalPaid()
{
$paid = 0;
if ($this->Payments()) {
foreach ($this->Payments() as $payment) {
if ($payment->Status == 'Success') {
$paid += $payment->Amount->getAmount();
}
}
}
$totalPaid = new Money();
$totalPaid->setAmount($paid);
$totalPaid->setCurrency($this->Total->getCurrency());
return $totalPaid;
}
示例15: testAddProductToCartChangePrice
/**
* Change product price after it is in the cart, check that price has not changed in cart
*/
function testAddProductToCartChangePrice()
{
$productA = $this->objFromFixture('Product', 'productA');
$this->logInAs('admin');
$productA->doPublish();
$this->logOut();
$productALink = $productA->Link();
$this->get(Director::makeRelative($productALink));
$this->submitForm('AddToCartForm_AddToCartForm', null, array('Quantity' => 1));
$order = CartControllerExtension::get_current_order();
$items = $order->Items();
$firstItem = $items->First();
$firstProduct = clone $productA;
$this->assertEquals(1, $order->Items()->Count());
$this->assertEquals($productA->Amount->getAmount(), $firstItem->Amount->getAmount());
$this->assertEquals($productA->Amount->getCurrency(), $firstItem->Amount->getCurrency());
$newAmount = new Money();
$newAmount->setAmount(72.34);
$newAmount->setCurrency('NZD');
$this->logInAs('admin');
$productA->Amount->setValue($newAmount);
$productA->doPublish();
$this->logOut();
$productALink = $productA->Link();
$this->get(Director::makeRelative($productALink));
$this->submitForm('AddToCartForm_AddToCartForm', null, array('Quantity' => 1));
$order = CartControllerExtension::get_current_order();
$items = $order->Items();
$firstItem = $items->First();
$secondItem = $items->Last();
$this->assertEquals(2, $order->Items()->Count());
$this->assertEquals($firstProduct->Amount->getAmount(), $firstItem->Amount->getAmount());
$this->assertEquals($firstProduct->Amount->getCurrency(), $firstItem->Amount->getCurrency());
$this->assertEquals($newAmount->getAmount(), $secondItem->Amount->getAmount());
$this->assertEquals($newAmount->getCurrency(), $secondItem->Amount->getCurrency());
}