예제 #1
0
 /**
  * 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);
 }
예제 #2
0
 /**
  * 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);
 }
 /**
  * @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;
 }
예제 #4
0
 /**
  * @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);
 }
예제 #5
0
 /**
  * @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);
 }
예제 #6
0
 /**
  * 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);
 }
예제 #7
0
파일: Item.php 프로젝트: uibar/lavinia2
 /**
  * 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;
 }
예제 #8
0
 /**
  * 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);
 }
예제 #9
0
 /**
  * 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;
 }
예제 #10
0
파일: Item.php 프로젝트: aiesh/magento2
 /**
  * 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;
 }
예제 #11
0
 /**
  * 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;
 }
예제 #12
0
파일: Updater.php 프로젝트: aiesh/magento2
 /**
  * Return formatted price
  *
  * @param float|int $price
  * @return float|int
  */
 protected function parseCustomPrice($price)
 {
     $price = $this->localeFormat->getNumber($price);
     return $price > 0 ? $price : 0;
 }