本文整理汇总了PHP中Magento\Framework\Pricing\PriceCurrencyInterface::round方法的典型用法代码示例。如果您正苦于以下问题:PHP PriceCurrencyInterface::round方法的具体用法?PHP PriceCurrencyInterface::round怎么用?PHP PriceCurrencyInterface::round使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Pricing\PriceCurrencyInterface
的用法示例。
在下文中一共展示了PriceCurrencyInterface::round方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepareOrder
/**
* Prepare order data for refund
*
* @param \Magento\Sales\Model\Order\Creditmemo $creditmemo
* @return void
*/
protected function prepareOrder(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
{
$order = $creditmemo->getOrder();
$baseOrderRefund = $this->priceCurrency->round($order->getBaseTotalRefunded() + $creditmemo->getBaseGrandTotal());
$orderRefund = $this->priceCurrency->round($order->getTotalRefunded() + $creditmemo->getGrandTotal());
$order->setBaseTotalRefunded($baseOrderRefund);
$order->setTotalRefunded($orderRefund);
$order->setBaseSubtotalRefunded($order->getBaseSubtotalRefunded() + $creditmemo->getBaseSubtotal());
$order->setSubtotalRefunded($order->getSubtotalRefunded() + $creditmemo->getSubtotal());
$order->setBaseTaxRefunded($order->getBaseTaxRefunded() + $creditmemo->getBaseTaxAmount());
$order->setTaxRefunded($order->getTaxRefunded() + $creditmemo->getTaxAmount());
$order->setBaseDiscountTaxCompensationRefunded($order->getBaseDiscountTaxCompensationRefunded() + $creditmemo->getBaseDiscountTaxCompensationAmount());
$order->setDiscountTaxCompensationRefunded($order->getDiscountTaxCompensationRefunded() + $creditmemo->getDiscountTaxCompensationAmount());
$order->setBaseShippingRefunded($order->getBaseShippingRefunded() + $creditmemo->getBaseShippingAmount());
$order->setShippingRefunded($order->getShippingRefunded() + $creditmemo->getShippingAmount());
$order->setBaseShippingTaxRefunded($order->getBaseShippingTaxRefunded() + $creditmemo->getBaseShippingTaxAmount());
$order->setShippingTaxRefunded($order->getShippingTaxRefunded() + $creditmemo->getShippingTaxAmount());
$order->setAdjustmentPositive($order->getAdjustmentPositive() + $creditmemo->getAdjustmentPositive());
$order->setBaseAdjustmentPositive($order->getBaseAdjustmentPositive() + $creditmemo->getBaseAdjustmentPositive());
$order->setAdjustmentNegative($order->getAdjustmentNegative() + $creditmemo->getAdjustmentNegative());
$order->setBaseAdjustmentNegative($order->getBaseAdjustmentNegative() + $creditmemo->getBaseAdjustmentNegative());
$order->setDiscountRefunded($order->getDiscountRefunded() + $creditmemo->getDiscountAmount());
$order->setBaseDiscountRefunded($order->getBaseDiscountRefunded() + $creditmemo->getBaseDiscountAmount());
if ($creditmemo->getDoTransaction()) {
$order->setTotalOnlineRefunded($order->getTotalOnlineRefunded() + $creditmemo->getGrandTotal());
$order->setBaseTotalOnlineRefunded($order->getBaseTotalOnlineRefunded() + $creditmemo->getBaseGrandTotal());
} else {
$order->setTotalOfflineRefunded($order->getTotalOfflineRefunded() + $creditmemo->getGrandTotal());
$order->setBaseTotalOfflineRefunded($order->getBaseTotalOfflineRefunded() + $creditmemo->getBaseGrandTotal());
}
$order->setBaseTotalInvoicedCost($order->getBaseTotalInvoicedCost() - $creditmemo->getBaseCost());
}
示例2: 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);
}
示例3: aroundGet
/**
* MOBI-486: Add partial payment data to totals are requested with REST API.
* MOBI-489: Add partial payment configuration to totals extension attributes.
*
* @param \Magento\Quote\Model\Cart\CartTotalRepository $subject
* @param \Closure $proceed
* @param $cartId
* @return \Magento\Quote\Api\Data\TotalsInterface
*/
public function aroundGet(\Magento\Quote\Model\Cart\CartTotalRepository $subject, \Closure $proceed, $cartId)
{
/** @var \Magento\Quote\Model\Cart\Totals $result */
$result = $proceed($cartId);
/* Get partial method configuration */
$isPartialEnabled = $this->_hlpCfg->getWalletPartialEnabled();
if ($isPartialEnabled) {
// $partialMaxPercent = $this->_hlpCfg->getWalletPartialPercent();
// /** @var \Magento\Quote\Api\Data\TotalExtensionInterface $exts */
// $exts = $this->_factTotalExt->create();
// /** @var \Praxigento\Wallet\Api\Data\Config\Payment\Method $extData */
// $extData = new \Praxigento\Wallet\Api\Data\Config\Payment\Method();
// $extData->setPartialMaxPercent($partialMaxPercent);
// $extData->setIsPartialEnabled($isPartialEnabled);
// $exts->setPraxigentoWalletPaymentConfig($extData);
// $result->setExtensionAttributes($exts);
/* get partial data from repository */
/** @var \Praxigento\Wallet\Data\Entity\Partial\Quote $found */
$found = $this->_repoPartialQuote->getById($cartId);
if ($found) {
$basePartial = $found->getBasePartialAmount();
$basePartial = $this->_hlpPriceCurrency->round($basePartial);
/* add current partial total to segment */
$segments = $result->getTotalSegments();
/** @var \Magento\Quote\Api\Data\TotalSegmentInterface $seg */
$seg = $this->_manObj->create(\Magento\Quote\Api\Data\TotalSegmentInterface::class);
$seg->setCode(self::TOTAL_SEGMENT);
$seg->setValue($basePartial);
$segments[self::TOTAL_SEGMENT] = $seg;
$result->setTotalSegments($segments);
}
}
return $result;
}
示例4: getShippingAmount
/**
* Get credit memo shipping amount depend on configuration settings
*
* @return float
*/
public function getShippingAmount()
{
$source = $this->getSource();
if ($this->_taxConfig->displaySalesShippingInclTax($source->getOrder()->getStoreId())) {
$shipping = $source->getBaseShippingInclTax();
} else {
$shipping = $source->getBaseShippingAmount();
}
return $this->priceCurrency->round($shipping) * 1;
}
示例5: collect
/**
* @param \Magento\Sales\Model\Order\Creditmemo $creditmemo
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
{
$order = $creditmemo->getOrder();
$allowedAmount = $order->getShippingAmount() - $order->getShippingRefunded();
$baseAllowedAmount = $order->getBaseShippingAmount() - $order->getBaseShippingRefunded();
$orderShippingAmount = $order->getShippingAmount();
$orderBaseShippingAmount = $order->getBaseShippingAmount();
$orderShippingInclTax = $order->getShippingInclTax();
$orderBaseShippingInclTax = $order->getBaseShippingInclTax();
$shippingAmount = $baseShippingAmount = $shippingInclTax = $baseShippingInclTax = 0;
/**
* Check if shipping amount was specified (from invoice or another source).
* Using has magic method to allow setting 0 as shipping amount.
*/
if ($creditmemo->hasBaseShippingAmount()) {
$baseShippingAmount = $this->priceCurrency->round($creditmemo->getBaseShippingAmount());
/*
* Rounded allowed shipping refund amount is the highest acceptable shipping refund amount.
* Shipping refund amount shouldn't cause errors, if it doesn't exceed that limit.
* Note: ($x < $y + 0.0001) means ($x <= $y) for floats
*/
if ($baseShippingAmount < $this->priceCurrency->round($baseAllowedAmount) + 0.0001) {
$ratio = 0;
if ($orderBaseShippingAmount > 0) {
$ratio = $baseShippingAmount / $orderBaseShippingAmount;
}
/*
* Shipping refund amount should be equated to allowed refund amount,
* if it exceeds that limit.
* Note: ($x > $y - 0.0001) means ($x >= $y) for floats
*/
if ($baseShippingAmount > $baseAllowedAmount - 0.0001) {
$shippingAmount = $allowedAmount;
$baseShippingAmount = $baseAllowedAmount;
} else {
$shippingAmount = $this->priceCurrency->round($orderShippingAmount * $ratio);
}
$shippingInclTax = $this->priceCurrency->round($orderShippingInclTax * $ratio);
$baseShippingInclTax = $this->priceCurrency->round($orderBaseShippingInclTax * $ratio);
} else {
$baseAllowedAmount = $order->getBaseCurrency()->format($baseAllowedAmount, null, false);
throw new \Magento\Framework\Exception\LocalizedException(__('Maximum shipping amount allowed to refund is: %1', $baseAllowedAmount));
}
} else {
$shippingAmount = $allowedAmount;
$baseShippingAmount = $baseAllowedAmount;
$allowedTaxAmount = $order->getShippingTaxAmount() - $order->getShippingTaxRefunded();
$baseAllowedTaxAmount = $order->getBaseShippingTaxAmount() - $order->getBaseShippingTaxRefunded();
$shippingInclTax = $this->priceCurrency->round($allowedAmount + $allowedTaxAmount);
$baseShippingInclTax = $this->priceCurrency->round($baseAllowedAmount + $baseAllowedTaxAmount);
}
$creditmemo->setShippingAmount($shippingAmount);
$creditmemo->setBaseShippingAmount($baseShippingAmount);
$creditmemo->setShippingInclTax($shippingInclTax);
$creditmemo->setBaseShippingInclTax($baseShippingInclTax);
$creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $shippingAmount);
$creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseShippingAmount);
return $this;
}
示例6: getBasePriceInclTax
/**
* @param AbstractItem $item
* @return float
*/
public function getBasePriceInclTax($item)
{
$qty = $item->getQty() ? $item->getQty() : ($item->getQtyOrdered() ? $item->getQtyOrdered() : 1);
$taxAmount = $item->getBaseTaxAmount() + $item->getBaseDiscountTaxCompensation();
$price = floatval($qty) ? ($item->getBaseRowTotal() + $taxAmount) / $qty : 0;
return $this->priceCurrency->round($price);
}
示例7: distributeDiscount
/**
* Distribute discount at parent item to children items
*
* @param \Magento\Quote\Model\Quote\Item\AbstractItem $item
* @return $this
*/
protected function distributeDiscount(\Magento\Quote\Model\Quote\Item\AbstractItem $item)
{
$parentBaseRowTotal = $item->getBaseRowTotal();
$keys = ['discount_amount', 'base_discount_amount', 'original_discount_amount', 'base_original_discount_amount'];
$roundingDelta = [];
foreach ($keys as $key) {
//Initialize the rounding delta to a tiny number to avoid floating point precision problem
$roundingDelta[$key] = 1.0E-7;
}
foreach ($item->getChildren() as $child) {
$ratio = $child->getBaseRowTotal() / $parentBaseRowTotal;
foreach ($keys as $key) {
if (!$item->hasData($key)) {
continue;
}
$value = $item->getData($key) * $ratio;
$roundedValue = $this->priceCurrency->round($value + $roundingDelta[$key]);
$roundingDelta[$key] += $value - $roundedValue;
$child->setData($key, $roundedValue);
}
}
foreach ($keys as $key) {
$item->setData($key, 0);
}
return $this;
}
示例8: _prepareOrder
/**
* Prepare order based on quote address
*
* @param \Magento\Quote\Model\Quote\Address $address
* @return \Magento\Sales\Model\Order
* @throws \Magento\Checkout\Exception
*/
protected function _prepareOrder(\Magento\Quote\Model\Quote\Address $address)
{
$quote = $this->getQuote();
$quote->unsReservedOrderId();
$quote->reserveOrderId();
$quote->collectTotals();
$order = $this->quoteAddressToOrder->convert($address);
$order->setQuote($quote);
$order->setBillingAddress($this->quoteAddressToOrderAddress->convert($quote->getBillingAddress()));
if ($address->getAddressType() == 'billing') {
$order->setIsVirtual(1);
} else {
$order->setShippingAddress($this->quoteAddressToOrderAddress->convert($address));
}
$order->setPayment($this->quotePaymentToOrderPayment->convert($quote->getPayment()));
if ($this->priceCurrency->round($address->getGrandTotal()) == 0) {
$order->getPayment()->setMethod('free');
}
foreach ($address->getAllItems() as $item) {
$_quoteItem = $item->getQuoteItem();
if (!$_quoteItem) {
throw new \Magento\Checkout\Exception(__('Item not found or already ordered'));
}
$item->setProductType($_quoteItem->getProductType())->setProductOptions($_quoteItem->getProduct()->getTypeInstance()->getOrderOptions($_quoteItem->getProduct()));
$orderItem = $this->quoteItemToOrderItem->convert($item);
if ($item->getParentItem()) {
$orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId()));
}
$order->addItem($orderItem);
}
return $order;
}
示例9: deltaRound
/**
* Round price considering delta
*
* @param float $price
* @param bool $negative Indicates if we perform addition (true) or subtraction (false) of rounded value
* @return float
*/
public function deltaRound($price, $negative = false)
{
$roundedPrice = $price;
if ($roundedPrice) {
if ($negative) {
$this->_delta = -$this->_delta;
}
$price += $this->_delta;
$roundedPrice = $this->priceCurrency->round($price);
$this->_delta = $price - $roundedPrice;
if ($negative) {
$this->_delta = -$this->_delta;
}
}
return $roundedPrice;
}
示例10: calcRuleProductPrice
/**
* @param array $ruleData
* @param null $productData
* @return float
*/
protected function calcRuleProductPrice($ruleData, $productData = null)
{
if ($productData !== null && isset($productData['rule_price'])) {
$productPrice = $productData['rule_price'];
} else {
$productPrice = $ruleData['default_price'];
}
switch ($ruleData['action_operator']) {
case 'to_fixed':
$productPrice = min($ruleData['action_amount'], $productPrice);
break;
case 'to_percent':
$productPrice = $productPrice * $ruleData['action_amount'] / 100;
break;
case 'by_fixed':
$productPrice = max(0, $productPrice - $ruleData['action_amount']);
break;
case 'by_percent':
$productPrice = $productPrice * (1 - $ruleData['action_amount'] / 100);
break;
default:
$productPrice = 0;
}
return $this->priceCurrency->round($productPrice);
}
示例11: calculateDynamicBundleAmount
/**
* Calculate amount for dynamic bundle product
*
* @param float $basePriceValue
* @param Product $bundleProduct
* @param \Magento\Bundle\Pricing\Price\BundleSelectionPrice[] $selectionPriceList
* @param null|string $exclude
* @return \Magento\Framework\Pricing\Amount\AmountInterface
*/
protected function calculateDynamicBundleAmount($basePriceValue, $bundleProduct, $selectionPriceList, $exclude)
{
$fullAmount = 0.0;
$adjustments = [];
$amountList = [$this->calculator->getAmount($basePriceValue, $bundleProduct, $exclude)];
/** @var $option \Magento\Bundle\Model\Option */
foreach ($selectionPriceList as $selectionPrice) {
$amountList[] = $selectionPrice->getAmount();
}
/** @var Store $store */
$store = $bundleProduct->getStore();
$roundingMethod = $this->taxHelper->getCalculationAgorithm($store);
/** @var \Magento\Framework\Pricing\Amount\AmountInterface $itemAmount */
foreach ($amountList as $itemAmount) {
if ($roundingMethod != TaxCalculationServiceInterface::CALC_TOTAL_BASE) {
//We need to round the individual selection first
$fullAmount += $this->priceCurrency->round($itemAmount->getValue());
foreach ($itemAmount->getAdjustmentAmounts() as $code => $adjustment) {
$adjustment = $this->priceCurrency->round($adjustment);
$adjustments[$code] = isset($adjustments[$code]) ? $adjustments[$code] + $adjustment : $adjustment;
}
} else {
$fullAmount += $itemAmount->getValue();
foreach ($itemAmount->getAdjustmentAmounts() as $code => $adjustment) {
$adjustments[$code] = isset($adjustments[$code]) ? $adjustments[$code] + $adjustment : $adjustment;
}
}
}
if ($exclude && isset($adjustments[$exclude])) {
$fullAmount -= $adjustments[$exclude];
unset($adjustments[$exclude]);
}
return $this->amountFactory->create($fullAmount, $adjustments);
}
示例12: calcRowTotal
/**
* Calculate item row total price
*
* @return $this
*/
public function calcRowTotal()
{
$qty = $this->getTotalQty();
// Round unit price before multiplying to prevent losing 1 cent on subtotal
$total = $this->priceCurrency->round($this->getCalculationPriceOriginal()) * $qty;
$baseTotal = $this->priceCurrency->round($this->getBaseCalculationPriceOriginal()) * $qty;
$this->setRowTotal($this->priceCurrency->round($total));
$this->setBaseRowTotal($this->priceCurrency->round($baseTotal));
return $this;
}
示例13: _convertPrice
/**
* Convert price from default currency to current currency
*
* @param float $price
* @param bool $round
* @return float
*/
protected function _convertPrice($price, $round = false)
{
if (empty($price)) {
return 0;
}
$price = $this->priceCurrency->convert($price);
if ($round) {
$price = $this->priceCurrency->round($price);
}
return $price;
}
示例14: processTotalAmount
/**
* Process row amount based on FPT total amount configuration setting
*
* @param \Magento\Quote\Model\Quote\Address\Total $total
* @param float $rowValueExclTax
* @param float $baseRowValueExclTax
* @param float $rowValueInclTax
* @param float $baseRowValueInclTax
* @return $this
*/
protected function processTotalAmount($total, $rowValueExclTax, $baseRowValueExclTax, $rowValueInclTax, $baseRowValueInclTax)
{
if (!$this->weeeData->isTaxable($this->_store)) {
//Accumulate the values. Will be used later in the 'weee tax' collector
$this->weeeTotalExclTax += $this->priceCurrency->round($rowValueExclTax);
$this->weeeBaseTotalExclTax += $this->priceCurrency->round($baseRowValueExclTax);
}
//This value is used to calculate shipping cost; it will be overridden by tax collector
$total->setSubtotalInclTax($total->getSubtotalInclTax() + $this->priceCurrency->round($rowValueInclTax));
$total->setBaseSubtotalInclTax($total->getBaseSubtotalInclTax() + $this->priceCurrency->round($baseRowValueInclTax));
return $this;
}
示例15: validateForRefund
/**
* @param \Magento\Sales\Api\Data\CreditmemoInterface $creditmemo
* @return bool
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function validateForRefund(\Magento\Sales\Api\Data\CreditmemoInterface $creditmemo)
{
if ($creditmemo->getId()) {
throw new \Magento\Framework\Exception\LocalizedException(__('We cannot register an existing credit memo.'));
}
$baseOrderRefund = $this->priceCurrency->round($creditmemo->getOrder()->getBaseTotalRefunded() + $creditmemo->getBaseGrandTotal());
if ($baseOrderRefund > $this->priceCurrency->round($creditmemo->getOrder()->getBaseTotalPaid())) {
$baseAvailableRefund = $creditmemo->getOrder()->getBaseTotalPaid() - $creditmemo->getOrder()->getBaseTotalRefunded();
throw new \Magento\Framework\Exception\LocalizedException(__('The most money available to refund is %1.', $creditmemo->getOrder()->formatBasePrice($baseAvailableRefund)));
}
return true;
}