/**
  * Return the amount for this tax rate for displaying in the {@link CheckoutForm}
  * 
  * @return String
  */
 public function Description()
 {
     return $this->amount->Nice();
 }
 public function testToCurrency()
 {
     $USD = new Money();
     $USD->setCurrency('USD');
     $USD->setLocale('en_US');
     $EGP = new Money();
     $EGP->setCurrency('EGP');
     $EGP->setLocale('ar_EG');
     $USD->setAmount(53292.18);
     $this->assertSame('$53,292.18', $USD->Nice());
     $USD->setAmount(53292.18);
     $this->assertSame('$٥٣,٢٩٢.١٨', $USD->Nice(array('script' => 'Arab')));
     $USD->setAmount(53292.18);
     $this->assertSame('$ ٥٣.٢٩٢,١٨', $USD->Nice(array('script' => 'Arab', 'format' => 'de_AT')));
     $USD->setAmount(53292.18);
     $this->assertSame('$ 53.292,18', $USD->Nice(array('format' => 'de_AT')));
     $EGP->setAmount(53292.18);
     $this->assertSame('ج.م.‏ 53٬292٫18', $EGP->Nice());
     $EGP->setAmount(53292.18);
     $this->assertSame('ج.م.‏ ٥٣٬٢٩٢٫١٨', $EGP->Nice(array('script' => 'Arab')));
     $EGP->setAmount(53292.18);
     $this->assertSame('ج.م.‏ ٥٣.٢٩٢,١٨', $EGP->Nice(array('script' => 'Arab', 'format' => 'de_AT')));
     $EGP->setAmount(53292.18);
     $this->assertSame('ج.م.‏ 53.292,18', $EGP->Nice(array('format' => 'de_AT')));
     $USD = new Money();
     $USD->setLocale('en_US');
     $USD->setAmount(53292.18);
     $this->assertSame('$53,292.18', $USD->Nice());
     /*
     try {
     	$this->assertSame('$ 53,292.18', $USD->Nice('nocontent'));
     	$this->fail("No currency expected");
     } catch (Exception $e) {
     	$this->assertContains("has to be numeric", $e->getMessage());
     }
     */
     $INR = new Money();
     $INR->setLocale('de_AT');
     $INR->setCurrency('INR');
     $INR->setAmount(1.2);
     $this->assertSame('Rs. 1,20', $INR->Nice());
     $INR->setAmount(1);
     $this->assertSame('Re. 1,00', $INR->Nice());
     $INR->setAmount(0);
     $this->assertSame('Rs. 0,00', $INR->Nice());
     $INR->setAmount(-3);
     $this->assertSame('-Rs. 3,00', $INR->Nice());
 }
Exemplo n.º 3
0
 /**
  * Returns the Order Positions as a string.
  * 
  * @param bool $asHtmlString    Set to true to use HTML inside the string.
  * @param bool $withAmountTotal Set to true add the orders total amount.
  * 
  * @return string
  */
 public function getPositionsAsString($asHtmlString = false, $withAmountTotal = false)
 {
     if ($asHtmlString) {
         $seperator = '<br/>';
     } else {
         $seperator = PHP_EOL;
     }
     $positionsStrings = array();
     foreach ($this->SilvercartOrderPositions() as $position) {
         $positionsString = $position->getTypeSafeQuantity() . 'x #' . $position->ProductNumber . ' "' . $position->Title . '" ' . $position->getPriceTotalNice();
         $positionsStrings[] = $positionsString;
     }
     $positionsAsString = implode($seperator . '------------------------' . $seperator, $positionsStrings);
     if ($withAmountTotal) {
         $shipmentAndPayment = new Money();
         $shipmentAndPayment->setAmount($this->HandlingCostPayment->getAmount() + $this->HandlingCostShipment->getAmount());
         $shipmentAndPayment->setCurrency($this->HandlingCostPayment->getCurrency());
         $positionsAsString .= $seperator . '------------------------' . $seperator;
         $positionsAsString .= $this->fieldLabel('HandlingCost') . ': ' . $shipmentAndPayment->Nice() . $seperator;
         $positionsAsString .= '________________________' . $seperator . $seperator;
         $positionsAsString .= $this->fieldLabel('AmountTotal') . ': ' . $this->AmountTotal->Nice();
     }
     return $positionsAsString;
 }
Exemplo n.º 4
0
 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')));
 }
 /**
  * Returns the Price formatted by locale.
  *
  * @return string
  *
  * @author Sascha Koehler <*****@*****.**>
  * @since 31.01.2011
  */
 public function PriceFormatted()
 {
     $priceObj = new Money();
     $priceObj->setAmount($this->getPriceAmount());
     $priceObj->setCurrency($this->price->getCurrency());
     return $priceObj->Nice();
 }
 /**
  * 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);
 }
 /**
  * Returns the Price formatted by locale.
  * 
  * @param bool $plain Set to true to load the price amount without any manipulation
  *
  * @return string
  *
  * @author Sascha Koehler <*****@*****.**>, Sebastian Diel <*****@*****.**>
  * @since 04.04.2012
  */
 public function PriceFormatted($plain = false)
 {
     $priceFormatted = '';
     if ($this->PostPricing) {
         $priceFormatted = '---';
     } else {
         $priceObj = new Money();
         $priceObj->setAmount($this->getPriceAmount($plain));
         $priceObj->setCurrency($this->getPriceCurrency());
         $priceFormatted = $priceObj->Nice();
     }
     return $priceFormatted;
 }
 /**
  * Returns the minimum order value.
  *
  * @return mixed Money
  *
  * @author Sascha Koehler <*****@*****.**>
  * @since 09.06.2011
  */
 public function MinimumOrderValue()
 {
     $minimumOrderValue = new Money();
     if (SilvercartConfig::UseMinimumOrderValue() && SilvercartConfig::MinimumOrderValue()) {
         $minimumOrderValue->setAmount(SilvercartConfig::MinimumOrderValue()->getAmount());
         $minimumOrderValue->setCurrency(SilvercartConfig::MinimumOrderValue()->getCurrency());
     }
     return $minimumOrderValue->Nice();
 }