本文整理汇总了PHP中Magento\Framework\Pricing\PriceCurrencyInterface::format方法的典型用法代码示例。如果您正苦于以下问题:PHP PriceCurrencyInterface::format方法的具体用法?PHP PriceCurrencyInterface::format怎么用?PHP PriceCurrencyInterface::format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Pricing\PriceCurrencyInterface
的用法示例。
在下文中一共展示了PriceCurrencyInterface::format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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);
}
}
}
示例4: 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;
}
示例5: 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;
}
示例6: renderRangeLabel
/**
* Prepare text of range label
*
* @param float|string $fromPrice
* @param float|string $toPrice
* @return float|\Magento\Framework\Phrase
*/
public function renderRangeLabel($fromPrice, $toPrice)
{
$formattedFromPrice = $this->priceCurrency->format($fromPrice);
$priceInterval = $this->scopeConfig->getValue(self::XML_PATH_ONE_PRICE_INTERVAL, ScopeInterface::SCOPE_STORE);
if ($toPrice === '') {
return __('%1 and above', $formattedFromPrice);
} elseif ($fromPrice == $toPrice && $priceInterval) {
return $formattedFromPrice;
} else {
if ($fromPrice != $toPrice) {
$toPrice -= 0.01;
}
return __('%1 - %2', $formattedFromPrice, $this->priceCurrency->format($toPrice));
}
}
示例7: _renderRangeLabel
/**
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*
* {@inheritDoc}
*/
protected function _renderRangeLabel($fromPrice, $toPrice)
{
$formattedPrice = $this->priceCurrency->format($fromPrice);
if ($toPrice === '') {
$formattedPrice = __('%1 and above', $formattedPrice);
} elseif ($fromPrice != $toPrice || !$this->dataProvider->getOnePriceIntervalValue()) {
$formattedPrice = __('%1 - %2', $formattedPrice, $this->priceCurrency->format($toPrice));
}
return $formattedPrice;
}
示例8: formatPrice
/**
* Format price
*
* @param float $price
* @return string
*/
public function formatPrice($price)
{
$item = $this->getItem();
if ($item instanceof QuoteItem) {
return $this->priceCurrency->format($price, true, PriceCurrencyInterface::DEFAULT_PRECISION, $item->getStore());
} elseif ($item instanceof OrderItem) {
return $item->getOrder()->formatPrice($price);
} else {
return $item->getOrderItem()->getOrder()->formatPrice($price);
}
}
示例9: renderRangeLabel
/**
* Prepare text of range label
*
* @param float|string $fromPrice
* @param float|string $toPrice
* @return \Magento\Framework\Phrase
*/
protected function renderRangeLabel($fromPrice, $toPrice)
{
$formattedFromPrice = $this->priceCurrency->format($fromPrice);
if ($toPrice === '') {
return __('%1 and above', $formattedFromPrice);
} else {
if ($fromPrice != $toPrice) {
$toPrice -= 0.01;
}
return __('%1 - %2', $formattedFromPrice, $this->priceCurrency->format($toPrice));
}
}
示例10: _renderRangeLabel
/**
* Prepare text of range label
*
* @param float|string $fromPrice
* @param float|string $toPrice
* @return string
*/
protected function _renderRangeLabel($fromPrice, $toPrice)
{
$formattedFromPrice = $this->priceCurrency->format($fromPrice);
if ($toPrice === '') {
return __('%1 and above', $formattedFromPrice);
} elseif ($fromPrice == $toPrice && $this->_scopeConfig->getValue(self::XML_PATH_ONE_PRICE_INTERVAL, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) {
return $formattedFromPrice;
} else {
if ($fromPrice != $toPrice) {
$toPrice -= 0.01;
}
return __('%1 - %2', $formattedFromPrice, $this->priceCurrency->format($toPrice));
}
}
示例11: getItems
/**
* getItems method
*
* @return array
*/
public function getItems()
{
$result = [];
$query = $this->queryFactory->get()->getQueryText();
$productIds = $this->searchProductsFullText($query);
// Check if products are found
if ($productIds) {
$searchCriteria = $this->searchCriteriaBuilder->addFilter('entity_id', $productIds, 'in')->create();
$products = $this->productRepository->getList($searchCriteria);
foreach ($products->getItems() as $product) {
$image = $this->imageHelper->init($product, 'product_page_image_small')->getUrl();
$resultItem = $this->itemFactory->create(['title' => $product->getName(), 'price' => $this->priceCurrency->format($product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue(), false), 'special_price' => $this->priceCurrency->format($product->getPriceInfo()->getPrice('special_price')->getAmount()->getValue(), false), 'has_special_price' => $product->getSpecialPrice() > 0 ? true : false, 'image' => $image, 'url' => $product->getProductUrl()]);
$result[] = $resultItem;
}
}
return $result;
}
示例12: getItems
/**
* {@inheritdoc}
*/
public function getItems()
{
$result = [];
$query = $this->queryFactory->get()->getQueryText();
$productIds = $this->searchProductsFullText($query);
// Check if products are found
if ($productIds) {
$searchCriteria = $this->searchCriteriaBuilder->addFilter('entity_id', $productIds, 'in')->create();
$products = $this->productRepository->getList($searchCriteria);
$baseUrl = $this->storeManager->getStore()->getBaseUrl();
// Loop through products
foreach ($products->getItems() as $product) {
$resultItem = $this->itemFactory->create(['title' => $product->getName(), 'price' => $this->priceCurrency->format($product->getFinalPrice(), false), 'special_price' => $this->priceCurrency->format($product->getSpecialPrice(), false), 'has_special_price' => $product->getSpecialPrice() > 0 ? true : false, 'image' => str_replace('index.php/', '', $baseUrl) . '/pub/media/catalog/product' . $product->getImage(), 'url' => $product->getProductUrl()]);
$result[] = $resultItem;
}
}
return $result;
}
示例13: getFormatedPrice
/**
* Get formatted by currency product price
*
* @param Product $product
* @return array || float
*/
public function getFormatedPrice($product)
{
return $this->priceCurrency->format($product->getFinalPrice());
}
示例14: formatPrice
/**
* @param float $price
* @return mixed
*
* @codeCoverageIgnore
*/
public function formatPrice($price)
{
return $this->priceCurrency->format($price, true, PriceCurrencyInterface::DEFAULT_PRECISION, $this->getQuote()->getStore());
}
示例15: _renderItemLabel
/**
* Prepare text of item label
*
* @param int $range
* @param float $value
* @return \Magento\Framework\Phrase
*/
protected function _renderItemLabel($range, $value)
{
$from = $this->priceCurrency->format(($value - 1) * $range, false);
$to = $this->priceCurrency->format($value * $range, false);
return __('%1 - %2', $from, $to);
}