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


PHP Currency::Nice方法代码示例

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


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

示例1: testNiceFormatting

	function testNiceFormatting() {
		// Test a bunch of different data values and results in Nice() and Whole()
		$tests = array(
			// Test basic operation
			'$50.00' => array('$50.00', '$50'),
			
			// Test removal of junk text
			'this is -50.29 dollars' => array('($50.29)', '($50)'),
			'this is -50.79 dollars' => array('($50.79)', '($51)'),
			'this is 50.79 dollars' => array('$50.79', '$51'),
			
			// Test negative numbers
			'-1000' => array('($1,000.00)','($1,000)'),
			'-$2,000' => array('($2,000.00)', '($2,000)'),
			
			// Test thousands comma
			'5000' => array('$5,000.00', '$5,000'),
			
			// Test scientific notation
			'5.68434188608E-14' => array('$0.00', '$0'),
			'5.68434188608E7' => array('$56,843,418.86', '$56,843,419'),
			"Sometimes Es are still bad: 51 dollars, even though they\'re used in scientific notation" => array('$51.00', '$51'),
			"What about 5.68434188608E7 in the middle of a string" => array('$56,843,418.86', '$56,843,419'),
		);
		
		foreach($tests as $value => $niceValues) {
			$c = new Currency('MyField');
			$c->setValue($value);
			$this->assertEquals($niceValues[0], $c->Nice());
			$this->assertEquals($niceValues[1], $c->Whole());
		}
	}	
开发者ID:redema,项目名称:sapphire,代码行数:32,代码来源:CurrencyTest.php

示例2: Nice

 public function Nice()
 {
     if ($this->value == 0) {
         return _t("ShopCurrency.Free", "<span class=\"free\">FREE</span>");
     }
     return parent::Nice();
 }
开发者ID:burnbright,项目名称:silverstripe-shop,代码行数:7,代码来源:CanBeFreeCurrency.php

示例3: __construct

 public function __construct($controller, $name = "PostagePaymentForm")
 {
     // Get delivery data and postage areas from session
     $delivery_data = Session::get("Commerce.DeliveryDetailsForm.data");
     $country = $delivery_data['DeliveryCountry'];
     $postcode = $delivery_data['DeliveryPostCode'];
     $postage_areas = $controller->getPostageAreas($country, $postcode);
     // Loop through all postage areas and generate a new list
     $postage_array = array();
     foreach ($postage_areas as $area) {
         $area_currency = new Currency("Cost");
         $area_currency->setValue($area->Cost);
         $postage_array[$area->ID] = $area->Title . " (" . $area_currency->Nice() . ")";
     }
     $postage_id = Session::get('Commerce.PostageID') ? Session::get('Commerce.PostageID') : 0;
     // Setup postage fields
     $postage_field = CompositeField::create(HeaderField::create("PostageHeader", _t('Commerce.Postage', "Postage")), OptionsetField::create("PostageID", _t('Commerce.PostageSelection', 'Please select your prefered postage'), $postage_array)->setValue($postage_id))->setName("PostageFields")->addExtraClass("unit")->addExtraClass("size1of2")->addExtraClass("unit-50");
     // Get available payment methods and setup payment
     $payment_methods = SiteConfig::current_site_config()->PaymentMethods();
     // Deal with payment methods
     if ($payment_methods->exists()) {
         $payment_map = $payment_methods->map('ID', 'Label');
         $payment_value = $payment_methods->filter('Default', 1)->first()->ID;
     } else {
         $payment_map = array();
         $payment_value = 0;
     }
     $payment_field = CompositeField::create(HeaderField::create('PaymentHeading', _t('Commerce.Payment', 'Payment'), 2), OptionsetField::create('PaymentMethodID', _t('Commerce.PaymentSelection', 'Please choose how you would like to pay'), $payment_map, $payment_value))->setName("PaymentFields")->addExtraClass("unit")->addExtraClass("size1of2")->addExtraClass("unit-50");
     $fields = FieldList::create(CompositeField::create($postage_field, $payment_field)->setName("PostagePaymentFields")->addExtraClass("units-row")->addExtraClass("line"));
     $back_url = $controller->Link("billing");
     $actions = FieldList::create(LiteralField::create('BackButton', '<a href="' . $back_url . '" class="btn btn-red commerce-action-back">' . _t('Commerce.Back', 'Back') . '</a>'), FormAction::create('doContinue', _t('Commerce.PaymentDetails', 'Enter Payment Details'))->addExtraClass('btn')->addExtraClass('commerce-action-next')->addExtraClass('btn-green'));
     $validator = RequiredFields::create(array("PostageID", "PaymentMethod"));
     parent::__construct($controller, $name, $fields, $actions, $validator);
 }
开发者ID:helpfulrobot,项目名称:i-lateral-silverstripe-commerce,代码行数:34,代码来源:PostagePaymentForm.php

示例4: PostageForm

 /**
  * Form responsible for estimating shipping based on location and
  * postal code
  *
  * @return Form
  */
 public function PostageForm()
 {
     $available_postage = Session::get("Commerce.AvailablePostage");
     // Setup default postage fields
     $country_select = CompositeField::create(CountryDropdownField::create('Country', _t('Commerce.Country', 'Country'))->setAttribute("class", 'countrydropdown dropdown btn'), TextField::create("ZipCode", _t('Commerce.ZipCode', "Zip/Postal Code")))->addExtraClass("size1of2")->addExtraClass("unit")->addExtraClass("unit-50");
     // If we have stipulated a search, then see if we have any results
     // otherwise load empty fieldsets
     if ($available_postage) {
         $search_text = _t('Commerce.Update', "Update");
         // Loop through all postage areas and generate a new list
         $postage_array = array();
         foreach ($available_postage as $area) {
             $area_currency = new Currency("Cost");
             $area_currency->setValue($area->Cost);
             $postage_array[$area->ID] = $area->Title . " (" . $area_currency->Nice() . ")";
         }
         $postage_select = CompositeField::create(OptionsetField::create("PostageID", _t('Commerce.SelectPostage', "Select Postage"), $postage_array))->addExtraClass("size1of2")->addExtraClass("unit")->addExtraClass("unit-50");
         $confirm_action = CompositeField::create(FormAction::create("doSavePostage", _t('Commerce.Confirm', "Confirm"))->addExtraClass('btn')->addExtraClass('btn-green'))->addExtraClass("size1of2")->addExtraClass("unit")->addExtraClass("unit-50");
     } else {
         $search_text = _t('Commerce.Search', "Search");
         $postage_select = CompositeField::create()->addExtraClass("size1of2")->addExtraClass("unit")->addExtraClass("unit-50");
         $confirm_action = CompositeField::create()->addExtraClass("size1of2")->addExtraClass("unit")->addExtraClass("unit-50");
     }
     // Set search field
     $search_action = CompositeField::create(FormAction::create("doGetPostage", $search_text)->addExtraClass('btn'))->addExtraClass("size1of2")->addExtraClass("unit")->addExtraClass("unit-50");
     // Setup fields and actions
     $fields = new FieldList(CompositeField::create($country_select, $postage_select)->addExtraClass("line")->addExtraClass("units-row-end"));
     $actions = new FieldList(CompositeField::create($search_action, $confirm_action)->addExtraClass("line")->addExtraClass("units-row-end"));
     $required = RequiredFields::create(array("Country", "ZipCode"));
     $form = Form::create($this, 'PostageForm', $fields, $actions, $required)->addExtraClass('forms')->addExtraClass('forms-columnar');
     // Check if the form has been re-posted and load data
     $data = Session::get("Form.{$form->FormName()}.data");
     if (is_array($data)) {
         $form->loadDataFrom($data);
     }
     // Check if the postage area has been set, if so, Set Postage ID
     $data = array();
     $data["PostageID"] = Session::get("Commerce.PostageID");
     if (is_array($data)) {
         $form->loadDataFrom($data);
     }
     // Extension call
     $this->extend("updatePostageForm", $form);
     return $form;
 }
开发者ID:helpfulrobot,项目名称:i-lateral-silverstripe-commerce,代码行数:51,代码来源:ShoppingCart.php

示例5: parseFloat

 protected function parseFloat($floatString)
 {
     //hack to clean up currency symbols, etc....
     $LocaleInfo = localeconv();
     $floatString = str_replace($LocaleInfo["mon_decimal_point"], ".", $floatString);
     $titleDescriptor = new Currency("titleDescriptor");
     $titleDescriptor->setValue(1111111);
     $titleDescriptorString = $titleDescriptor->Nice();
     $titleDescriptorString = str_replace("1", "", $titleDescriptorString);
     //HACK!
     $titleDescriptorString = str_replace(".00", "", $titleDescriptorString);
     for ($i = 0; $i < strlen($titleDescriptorString); $i++) {
         $char = substr($titleDescriptorString, $i, 1);
         if ($char != $LocaleInfo["mon_decimal_point"]) {
             $floatString = str_replace($char, "", $floatString);
         }
     }
     return round(floatval($floatString - 0), 2);
 }
开发者ID:helpfulrobot,项目名称:sunnysideup-ecommerce-anypriceproduct,代码行数:19,代码来源:AnyPriceProductPage.php

示例6: PostageForm

 /**
  * Form responsible for estimating shipping based on location and
  * postal code
  *
  * @return Form
  */
 public function PostageForm()
 {
     if (!Checkout::config()->simple_checkout) {
         $available_postage = Session::get("Checkout.AvailablePostage");
         // Setup form
         $form = Form::create($this, 'PostageForm', $fields = new FieldList(CountryDropdownField::create('Country', _t('Checkout.Country', 'Country')), TextField::create("ZipCode", _t('Checkout.ZipCode', "Zip/Postal Code"))), $actions = new FieldList(FormAction::create("doSetPostage", _t('Checkout.Search', "Search"))->addExtraClass('btn')->addExtraClass('btn btn-green btn-success')), $required = RequiredFields::create(array("Country", "ZipCode")))->addExtraClass('forms')->addExtraClass('forms-inline')->setLegend(_t("Checkout.EstimateShipping", "Estimate Shipping"));
         // If we have stipulated a search, then see if we have any results
         // otherwise load empty fieldsets
         if ($available_postage && $available_postage->exists()) {
             // Loop through all postage areas and generate a new list
             $postage_array = array();
             foreach ($available_postage as $area) {
                 $area_currency = new Currency("Cost");
                 $area_currency->setValue($area->Cost);
                 $postage_array[$area->ID] = $area->Title . " (" . $area_currency->Nice() . ")";
             }
             $fields->add(OptionsetField::create("PostageID", _t('Checkout.SelectPostage', "Select Postage"), $postage_array));
             $actions->dataFieldByName("action_doSetPostage")->setTitle(_t('Checkout.Update', "Update"));
         }
         // Check if the form has been re-posted and load data
         $data = Session::get("Form.{$form->FormName()}.data");
         if (is_array($data)) {
             $form->loadDataFrom($data);
         }
         // Check if the postage area has been set, if so, Set Postage ID
         $data = array();
         $data["PostageID"] = Session::get("Checkout.PostageID");
         if (is_array($data)) {
             $form->loadDataFrom($data);
         }
         // Extension call
         $this->extend("updatePostageForm", $form);
         return $form;
     }
 }
开发者ID:i-lateral,项目名称:silverstripe-checkout,代码行数:41,代码来源:ShoppingCart.php

示例7: __construct

 public function __construct($controller, $name = "PostagePaymentForm")
 {
     if (!Checkout::config()->simple_checkout && !ShoppingCart::get()->isCollection()) {
         // Get delivery data and postage areas from session
         $delivery_data = Session::get("Checkout.DeliveryDetailsForm.data");
         $country = $delivery_data['DeliveryCountry'];
         $postcode = $delivery_data['DeliveryPostCode'];
         $cart = ShoppingCart::get();
         $postage_areas = new ShippingCalculator($postcode, $country);
         $postage_areas->setCost($cart->SubTotalCost)->setWeight($cart->TotalWeight)->setItems($cart->TotalItems);
         $postage_areas = $postage_areas->getPostageAreas();
         // Loop through all postage areas and generate a new list
         $postage_array = array();
         foreach ($postage_areas as $area) {
             $area_currency = new Currency("Cost");
             $area_currency->setValue($area->Cost);
             $postage_array[$area->ID] = $area->Title . " (" . $area_currency->Nice() . ")";
         }
         if (Session::get('Checkout.PostageID')) {
             $postage_id = Session::get('Checkout.PostageID');
         } elseif ($postage_areas->exists()) {
             $postage_id = $postage_areas->first()->ID;
         } else {
             $postage_id = 0;
         }
         if (count($postage_array)) {
             $select_postage_field = OptionsetField::create("PostageID", _t('Checkout.PostageSelection', 'Please select your preferred postage'), $postage_array)->setValue($postage_id);
         } else {
             $select_postage_field = ReadonlyField::create("NoPostage", "", _t('Checkout.NoPostageSelection', 'Unfortunately we cannot deliver to your address'))->addExtraClass("label")->addExtraClass("label-red");
         }
         // Setup postage fields
         $postage_field = CompositeField::create(HeaderField::create("PostageHeader", _t('Checkout.Postage', "Postage")), $select_postage_field)->setName("PostageFields")->addExtraClass("unit")->addExtraClass("size1of2")->addExtraClass("unit-50");
     } elseif (ShoppingCart::get()->isCollection()) {
         $postage_field = CompositeField::create(HeaderField::create("PostageHeader", _t('Checkout.CollectionOnly', "Collection Only")), ReadonlyField::create("CollectionText", "", _t("Checkout.ItemsReservedInstore", "Your items will be held instore until you collect them")))->setName("CollectionFields")->addExtraClass("unit")->addExtraClass("size1of2")->addExtraClass("unit-50");
     } else {
         $postage_field = null;
     }
     // Get available payment methods and setup payment
     $payment_methods = ArrayList::create();
     foreach (SiteConfig::current_site_config()->PaymentMethods() as $payment_method) {
         if ($payment_method->canView()) {
             $payment_methods->add($payment_method);
         }
     }
     // Deal with payment methods
     if ($payment_methods->exists()) {
         $payment_field = OptionsetField::create('PaymentMethodID', _t('Checkout.PaymentSelection', 'Please choose how you would like to pay'), $payment_methods->map('ID', 'Label'), $payment_methods->filter('Default', 1)->first()->ID);
     } else {
         $payment_field = ReadonlyField::create("PaymentMethodID", _t('Checkout.PaymentSelection', 'Please choose how you would like to pay'), _t('Checkout.NoPaymentMethods', 'You cannot pay at this time, if you feel there has been an error please contact us.'));
     }
     $payment_field = CompositeField::create(HeaderField::create('PaymentHeading', _t('Checkout.Payment', 'Payment'), 2), $payment_field)->setName("PaymentFields")->addExtraClass("unit")->addExtraClass("size1of2")->addExtraClass("unit-50");
     $fields = FieldList::create(CompositeField::create($postage_field, $payment_field)->setName("PostagePaymentFields")->addExtraClass("units-row")->addExtraClass("line"));
     $back_url = $controller->Link("billing");
     if ($payment_methods->exists()) {
         $actions = FieldList::create(LiteralField::create('BackButton', '<a href="' . $back_url . '" class="btn btn-red checkout-action-back">' . _t('Checkout.Back', 'Back') . '</a>'), FormAction::create('doContinue', _t('Checkout.PaymentDetails', 'Enter Payment Details'))->addExtraClass('btn')->addExtraClass('checkout-action-next')->addExtraClass('btn-green'));
     } else {
         $actions = FieldList::create();
     }
     $validator = RequiredFields::create(array("PostageID", "PaymentMethod"));
     parent::__construct($controller, $name, $fields, $actions, $validator);
 }
开发者ID:helpfulrobot,项目名称:i-lateral-silverstripe-checkout,代码行数:61,代码来源:PostagePaymentForm.php


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