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


PHP FormatInterface::getNumber方法代码示例

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


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

示例1: filter

 /**
  * Filter value
  *
  * @param float $value
  * @return string
  */
 public function filter($value)
 {
     $value = $this->_localeFormat->getNumber($value);
     $value = $this->priceCurrency->round($this->_rate * $value);
     $value = sprintf("%f", $value);
     return $this->_currency->toCurrency($value);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:13,代码来源:Filter.php

示例2: filter

 /**
  * Filter value
  *
  * @param float $value
  * @return string
  */
 public function filter($value)
 {
     $value = $this->_localeFormat->getNumber($value);
     $value = $this->_storeManager->getStore()->roundPrice($this->_rate * $value);
     $value = sprintf("%f", $value);
     return $this->_currency->toCurrency($value);
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:13,代码来源:Filter.php

示例3: getNumber

 /**
  * @param string|float|int|null $qty
  * @return float|null
  */
 protected function getNumber($qty)
 {
     if (!is_numeric($qty)) {
         $qty = $this->localeFormat->getNumber($qty);
         return $qty;
     }
     return $qty;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:12,代码来源:StockStateProvider.php

示例4: prepareValue

 /**
  * @param string $entityType
  * @param string $value
  * @param AbstractAttribute $attribute
  * @return string
  * @throws \Exception
  */
 protected function prepareValue($entityType, $value, AbstractAttribute $attribute)
 {
     $metadata = $this->metadataPool->getMetadata($entityType);
     $type = $attribute->getBackendType();
     if (($type == 'int' || $type == 'decimal' || $type == 'datetime') && $value === '') {
         $value = null;
     } elseif ($type == 'decimal') {
         $value = $this->localeFormat->getNumber($value);
     }
     $describe = $metadata->getEntityConnection()->describeTable($attribute->getBackendTable());
     return $metadata->getEntityConnection()->prepareColumnValue($describe['value'], $value);
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:19,代码来源:AttributePersistor.php

示例5: formatTxt

 /**
  * @param float $price
  * @param array $options
  * @return string
  */
 public function formatTxt($price, $options = [])
 {
     if (!is_numeric($price)) {
         $price = $this->_localeFormat->getNumber($price);
     }
     /**
      * Fix problem with 12 000 000, 1 200 000
      *
      * %f - the argument is treated as a float, and presented as a floating-point number (locale aware).
      * %F - the argument is treated as a float, and presented as a floating-point number (non-locale aware).
      */
     $price = sprintf("%F", $price);
     return $this->_localeCurrency->getCurrency($this->getCode())->toCurrency($price, $options);
 }
开发者ID:opexsw,项目名称:magento2,代码行数:19,代码来源:Currency.php

示例6: loadArray

 /**
  * Load array
  *
  * @param array $arr
  * @return $this
  */
 public function loadArray($arr)
 {
     $this->setAttribute(isset($arr['attribute']) ? $arr['attribute'] : false);
     $attribute = $this->getAttributeObject();
     $isContainsOperator = !empty($arr['operator']) && in_array($arr['operator'], array('{}', '!{}'));
     if ($attribute && $attribute->getBackendType() == 'decimal' && !$isContainsOperator) {
         if (isset($arr['value'])) {
             if (!empty($arr['operator']) && in_array($arr['operator'], array('!()', '()')) && false !== strpos($arr['value'], ',')) {
                 $tmp = array();
                 foreach (explode(',', $arr['value']) as $value) {
                     $tmp[] = $this->_localeFormat->getNumber($value);
                 }
                 $arr['value'] = implode(',', $tmp);
             } else {
                 $arr['value'] = $this->_localeFormat->getNumber($arr['value']);
             }
         } else {
             $arr['value'] = false;
         }
         $arr['is_value_parsed'] = isset($arr['is_value_parsed']) ? $this->_localeFormat->getNumber($arr['is_value_parsed']) : false;
     }
     return parent::loadArray($arr);
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:29,代码来源:AbstractProduct.php

示例7: _prepareQty

 /**
  * Prepare quantity
  *
  * @param float|int $qty
  * @return int|float
  */
 protected function _prepareQty($qty)
 {
     $qty = $this->_localeFormat->getNumber($qty);
     $qty = $qty > 0 ? $qty : 1;
     return $qty;
 }
开发者ID:uibar,项目名称:lavinia2,代码行数:12,代码来源:Item.php

示例8: _prepareValueForSave

 /**
  * Prepare value for save
  *
  * @param mixed $value
  * @param AbstractAttribute $attribute
  * @return mixed
  */
 protected function _prepareValueForSave($value, AbstractAttribute $attribute)
 {
     $type = $attribute->getBackendType();
     if (($type == 'int' || $type == 'decimal' || $type == 'datetime') && $value === '') {
         $value = null;
     } elseif ($type == 'decimal') {
         $value = $this->_localeFormat->getNumber($value);
     }
     $backendTable = $attribute->getBackendTable();
     if (!isset(self::$_attributeBackendTables[$backendTable])) {
         self::$_attributeBackendTables[$backendTable] = $this->_getReadAdapter()->describeTable($backendTable);
     }
     $describe = self::$_attributeBackendTables[$backendTable];
     return $this->_getReadAdapter()->prepareColumnValue($describe['value'], $value);
 }
开发者ID:aiesh,项目名称:magento2,代码行数:22,代码来源:AbstractEntity.php

示例9: isPositiveOrZero

 /**
  * Returns whether the value is greater than, or equal to, zero
  *
  * @param mixed $value
  * @return bool
  */
 protected function isPositiveOrZero($value)
 {
     $value = $this->localeFormat->getNumber($value);
     $isNegative = $value < 0;
     return !$isNegative;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:12,代码来源:Weight.php

示例10: checkQuoteItemQty

 /**
  * Checking quote item quantity
  *
  * Second parameter of this method specifies quantity of this product in whole shopping cart
  * which should be checked for stock availability
  *
  * @param int|float $qty quantity of this item (item qty x parent item qty)
  * @param int|float $summaryQty quantity of this product
  * @param int|float $origQty original qty of item (not multiplied on parent item qty)
  * @return \Magento\Framework\Object
  */
 public function checkQuoteItemQty($qty, $summaryQty, $origQty = 0)
 {
     $result = new \Magento\Framework\Object();
     $result->setHasError(false);
     if (!is_numeric($qty)) {
         $qty = $this->_localeFormat->getNumber($qty);
     }
     /**
      * Check quantity type
      */
     $result->setItemIsQtyDecimal($this->getIsQtyDecimal());
     if (!$this->getIsQtyDecimal()) {
         $result->setHasQtyOptionUpdate(true);
         $qty = intval($qty);
         /**
          * Adding stock data to quote item
          */
         $result->setItemQty($qty);
         if (!is_numeric($qty)) {
             $qty = $this->_localeFormat->getNumber($qty);
         }
         $origQty = intval($origQty);
         $result->setOrigQty($origQty);
     }
     if ($this->getMinSaleQty() && $qty < $this->getMinSaleQty()) {
         $result->setHasError(true)->setMessage(__('The fewest you may purchase is %1.', $this->getMinSaleQty() * 1))->setErrorCode('qty_min')->setQuoteMessage(__('Please correct the quantity for some products.'))->setQuoteMessageIndex('qty');
         return $result;
     }
     if ($this->getMaxSaleQty() && $qty > $this->getMaxSaleQty()) {
         $result->setHasError(true)->setMessage(__('The most you may purchase is %1.', $this->getMaxSaleQty() * 1))->setErrorCode('qty_max')->setQuoteMessage(__('Please correct the quantity for some products.'))->setQuoteMessageIndex('qty');
         return $result;
     }
     $result->addData($this->checkQtyIncrements($qty)->getData());
     if ($result->getHasError()) {
         return $result;
     }
     if (!$this->getManageStock()) {
         return $result;
     }
     if (!$this->getIsInStock()) {
         $result->setHasError(true)->setMessage(__('This product is out of stock.'))->setQuoteMessage(__('Some of the products are currently out of stock.'))->setQuoteMessageIndex('stock');
         $result->setItemUseOldQty(true);
         return $result;
     }
     if (!$this->checkQty($summaryQty) || !$this->checkQty($qty)) {
         $message = __('We don\'t have as many "%1" as you requested.', $this->getProductName());
         $result->setHasError(true)->setMessage($message)->setQuoteMessage($message)->setQuoteMessageIndex('qty');
         return $result;
     } else {
         if ($this->getQty() - $summaryQty < 0) {
             if ($this->getProductName()) {
                 if ($this->getIsChildItem()) {
                     $backOrderQty = $this->getQty() > 0 ? ($summaryQty - $this->getQty()) * 1 : $qty * 1;
                     if ($backOrderQty > $qty) {
                         $backOrderQty = $qty;
                     }
                     $result->setItemBackorders($backOrderQty);
                 } else {
                     $orderedItems = (int) $this->getOrderedItems();
                     // Available item qty in stock excluding item qty in other quotes
                     $qtyAvailable = ($this->getQty() - ($summaryQty - $qty)) * 1;
                     if ($qtyAvailable > 0) {
                         $backOrderQty = $qty * 1 - $qtyAvailable;
                     } else {
                         $backOrderQty = $qty * 1;
                     }
                     if ($backOrderQty > 0) {
                         $result->setItemBackorders($backOrderQty);
                     }
                     $this->setOrderedItems($orderedItems + $qty);
                 }
                 if ($this->getBackorders() == \Magento\CatalogInventory\Model\Stock::BACKORDERS_YES_NOTIFY) {
                     if (!$this->getIsChildItem()) {
                         $result->setMessage(__('We don\'t have as many "%1" as you requested, but we\'ll back order the remaining %2.', $this->getProductName(), $backOrderQty * 1));
                     } else {
                         $result->setMessage(__('We don\'t have "%1" in the requested quantity, so we\'ll back order the remaining %2.', $this->getProductName(), $backOrderQty * 1));
                     }
                 } elseif ($this->_hasDefaultNotificationMessage()) {
                     $result->setMessage(__('We don\'t have as many "%1" as you requested.', $this->getProductName()));
                 }
             }
         } else {
             if (!$this->getIsChildItem()) {
                 $this->setOrderedItems($qty + (int) $this->getOrderedItems());
             }
         }
     }
     return $result;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:100,代码来源:Item.php

示例11: _parseCgiResponse

 /**
  * Prepare shipping rate result based on response
  *
  * @param string $response
  * @return Result
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function _parseCgiResponse($response)
 {
     $costArr = [];
     $priceArr = [];
     if (strlen(trim($response)) > 0) {
         $rRows = explode("\n", $response);
         $allowedMethods = explode(",", $this->getConfigData('allowed_methods'));
         foreach ($rRows as $rRow) {
             $row = explode('%', $rRow);
             switch (substr($row[0], -1)) {
                 case 3:
                 case 4:
                     if (in_array($row[1], $allowedMethods)) {
                         $responsePrice = $this->_localeFormat->getNumber($row[8]);
                         $costArr[$row[1]] = $responsePrice;
                         $priceArr[$row[1]] = $this->getMethodPrice($responsePrice, $row[1]);
                     }
                     break;
                 case 5:
                     $errorTitle = $row[1];
                     $message = __('Sorry, something went wrong. Please try again or contact us and we\'ll try to help.');
                     $this->_logger->debug($message . ': ' . $errorTitle);
                     break;
                 case 6:
                     if (in_array($row[3], $allowedMethods)) {
                         $responsePrice = $this->_localeFormat->getNumber($row[10]);
                         $costArr[$row[3]] = $responsePrice;
                         $priceArr[$row[3]] = $this->getMethodPrice($responsePrice, $row[3]);
                     }
                     break;
                 default:
                     break;
             }
         }
         asort($priceArr);
     }
     $result = $this->_rateFactory->create();
     if (empty($priceArr)) {
         $error = $this->_rateErrorFactory->create();
         $error->setCarrier('ups');
         $error->setCarrierTitle($this->getConfigData('title'));
         $error->setErrorMessage($this->getConfigData('specificerrmsg'));
         $result->append($error);
     } else {
         foreach ($priceArr as $method => $price) {
             $rate = $this->_rateMethodFactory->create();
             $rate->setCarrier('ups');
             $rate->setCarrierTitle($this->getConfigData('title'));
             $rate->setMethod($method);
             $methodArray = $this->configHelper->getCode('method', $method);
             $rate->setMethodTitle($methodArray);
             $rate->setCost($costArr[$method]);
             $rate->setPrice($price);
             $result->append($rate);
         }
     }
     return $result;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:65,代码来源:Carrier.php

示例12: parseCustomPrice

 /**
  * Return formatted price
  *
  * @param float|int $price
  * @return float|int
  */
 protected function parseCustomPrice($price)
 {
     $price = $this->localeFormat->getNumber($price);
     return $price > 0 ? $price : 0;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:11,代码来源:Updater.php


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