本文整理汇总了PHP中Magento\Framework\Pricing\PriceCurrencyInterface类的典型用法代码示例。如果您正苦于以下问题:PHP PriceCurrencyInterface类的具体用法?PHP PriceCurrencyInterface怎么用?PHP PriceCurrencyInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PriceCurrencyInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: currencyByStore
/**
* Convert and format price value for specified store
*
* @param float $value
* @param int|\Magento\Store\Model\Store $store
* @param bool $format
* @param bool $includeContainer
* @return float|string
*/
public function currencyByStore($value, $store = null, $format = true, $includeContainer = true)
{
if ($format) {
$value = $this->priceCurrency->convertAndFormat($value, $includeContainer, PriceCurrencyInterface::DEFAULT_PRECISION, $store);
} else {
$value = $this->priceCurrency->convert($value, $store);
}
return $value;
}
示例2: testCurrencyByStore
/**
* @param string $amount
* @param string $store
* @param bool $format
* @param bool $includeContainer
* @param string $result
* @dataProvider currencyByStoreDataProvider
*/
public function testCurrencyByStore($amount, $store, $format, $includeContainer, $result)
{
if ($format) {
$this->priceCurrencyMock->expects($this->once())->method('convertAndFormat')->with($amount, $includeContainer, PriceCurrencyInterface::DEFAULT_PRECISION, $store)->will($this->returnValue($result));
} else {
$this->priceCurrencyMock->expects($this->once())->method('convert')->with($amount, $store)->will($this->returnValue($result));
}
$helper = $this->getHelper(['priceCurrency' => $this->priceCurrencyMock]);
$this->assertEquals($result, $helper->currencyByStore($amount, $store, $format, $includeContainer));
}
示例3: setUp
public function setUp()
{
$objectManager = new ObjectManager($this);
$this->coreRegistry = $this->getMockBuilder('\\Magento\\Framework\\Registry')->disableOriginalConstructor()->setMethods(['registry'])->getMock();
$this->orderTaxService = $this->getMockBuilder('\\Magento\\Tax\\Service\\V1\\OrderTaxService')->disableOriginalConstructor()->setMethods(['getOrderTaxDetails'])->getMock();
$this->priceCurrency = $this->getMockBuilder('Magento\\Framework\\Pricing\\PriceCurrencyInterface')->getMock();
$this->priceCurrency->expects($this->any())->method('round')->will($this->returnCallback(function ($argument) {
return round($argument, 2);
}));
$this->taxHelper = $objectManager->getObject('Magento\\Tax\\Helper\\Data', ['coreRegistry' => $this->coreRegistry, 'orderTaxService' => $this->orderTaxService, 'priceCurrency' => $this->priceCurrency]);
$this->orderTaxDetailsBuilder = $objectManager->getObject('Magento\\Tax\\Service\\V1\\Data\\OrderTaxDetailsBuilder');
}
示例4: displayPrices
/**
* Get "double" prices html (block with base and place currency)
*
* @param \Magento\Framework\Object $dataObject
* @param float $basePrice
* @param float $price
* @param bool $strong
* @param string $separator
* @return string
*/
public function displayPrices($dataObject, $basePrice, $price, $strong = false, $separator = '<br/>')
{
$order = false;
if ($dataObject instanceof \Magento\Sales\Model\Order) {
$order = $dataObject;
} else {
$order = $dataObject->getOrder();
}
if ($order && $order->isCurrencyDifferent()) {
$res = '<strong>';
$res .= $order->formatBasePrice($basePrice);
$res .= '</strong>' . $separator;
$res .= '[' . $order->formatPrice($price) . ']';
} elseif ($order) {
$res = $order->formatPrice($price);
if ($strong) {
$res = '<strong>' . $res . '</strong>';
}
} else {
$res = $this->priceCurrency->format($price);
if ($strong) {
$res = '<strong>' . $res . '</strong>';
}
}
return $res;
}
示例5: 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());
}
示例6: 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;
}
示例7: getListValues
/**
* @param $products
* @return array
*/
public function getListValues($ids)
{
$values = [];
$searchCriteria = $this->_criteriaBuilder->addFilter('entity_id', $ids, 'in')->create();
$products = $this->_productRepository->getList($searchCriteria);
foreach ($products->getItems() as $product) {
$image = $this->_imageHelper->init($product, 'product_page_image_small')->getUrl();
$price = $product->getFinalPrice();
if ($price == 0 && $product->getTypeId() == 'grouped') {
$children = $product->getTypeInstance()->getAssociatedProducts($product);
foreach ($children as $child) {
if ($child->getPrice() < $price || $price == 0) {
$price = $child->getPrice();
}
}
}
$value = array();
$value['escape_name'] = $this->escapeHtml($product->getName());
$value['name'] = $product->getName();
$value['url'] = $product->getProductUrl();
$value['price'] = $this->_priceCurrency->format($price, false);
$value['image'] = $image;
$values[] = $value;
}
return $values;
}
示例8: 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);
}
示例9: prepareDataSource
/**
* Prepare Data Source
*
* @param array $dataSource
* @return void
*/
public function prepareDataSource(array &$dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as &$item) {
$item[$this->getData('name')] = $this->priceFormatter->format($item[$this->getData('name')], false);
}
}
}
示例10: prepareDataSource
/**
* Prepare Data Source
*
* @param array $dataSource
* @return array
*/
public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as &$item) {
$currencyCode = isset($item['base_currency_code']) ? $item['base_currency_code'] : null;
$item[$this->getData('name')] = $this->priceFormatter->format($item[$this->getData('name')], false, null, null, $currencyCode);
}
}
return $dataSource;
}
示例11: testGetCustomAmount
public function testGetCustomAmount()
{
$exclude = false;
$amount = 21.0;
$convertedValue = 30.25;
$customAmount = 42.0;
$this->priceCurrencyMock->expects($this->any())->method('convertAndRound')->with($amount)->will($this->returnValue($convertedValue));
$this->calculatorMock->expects($this->once())->method('getAmount')->with($convertedValue, $this->saleableItemMock, $exclude)->will($this->returnValue($customAmount));
$this->assertEquals($customAmount, $this->price->getCustomAmount($amount, $exclude));
}
示例12: 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;
}
示例13: testGetValue
/**
* @param bool $isValidInterval
* @param float $specialPrice
* @param float|bool $specialPriceValue
*
* @dataProvider specialPriceDataProvider
*/
public function testGetValue($isValidInterval, $specialPrice, $specialPriceValue)
{
$expected = 56.34;
$specialPriceModel = $this->objectManager->getObject('Magento\\Catalog\\Pricing\\Price\\SpecialPrice', ['saleableItem' => $this->prepareSaleableItem($specialPrice), 'localeDate' => $this->prepareLocaleDate($isValidInterval), 'priceCurrency' => $this->priceCurrencyMock]);
if ($isValidInterval) {
$this->priceCurrencyMock->expects($this->once())->method('convertAndRound')->with($specialPriceValue)->will($this->returnValue($expected));
} else {
$expected = $specialPriceValue;
}
$this->assertSame($expected, $specialPriceModel->getValue());
}
示例14: getAssociatedProducts
/**
* Retrieve grouped products
*
* @return array
*/
public function getAssociatedProducts()
{
/** @var $product \Magento\Catalog\Model\Product */
$product = $this->_registry->registry('current_product');
$associatedProducts = $product->getTypeInstance()->getAssociatedProducts($product);
$products = [];
foreach ($associatedProducts as $product) {
$products[] = ['id' => $product->getId(), 'sku' => $product->getSku(), 'name' => $product->getName(), 'price' => $this->priceCurrency->format($product->getPrice(), false), 'qty' => $product->getQty(), 'position' => $product->getPosition()];
}
return $products;
}
示例15: testGetLinkAmount
public function testGetLinkAmount()
{
$amount = 100;
$convertedAmount = 50;
$this->linkMock->expects($this->once())->method('getPrice')->will($this->returnValue($amount));
$this->linkMock->expects($this->once())->method('getProduct')->will($this->returnValue($this->saleableItemMock));
$this->priceCurrencyMock->expects($this->once())->method('convertAndRound')->with($amount)->will($this->returnValue($convertedAmount));
$this->calculatorMock->expects($this->once())->method('getAmount')->with($convertedAmount, $this->equalTo($this->saleableItemMock))->will($this->returnValue($convertedAmount));
$result = $this->linkPrice->getLinkAmount($this->linkMock);
$this->assertEquals($convertedAmount, $result);
}