本文整理匯總了PHP中Magento\Framework\Pricing\PriceCurrencyInterface::convertAndFormat方法的典型用法代碼示例。如果您正苦於以下問題:PHP PriceCurrencyInterface::convertAndFormat方法的具體用法?PHP PriceCurrencyInterface::convertAndFormat怎麽用?PHP PriceCurrencyInterface::convertAndFormat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\Framework\Pricing\PriceCurrencyInterface
的用法示例。
在下文中一共展示了PriceCurrencyInterface::convertAndFormat方法的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: getFormatedTierPrice
/**
* Get formatted by currency tier price
*
* @param float $qty
* @param Product $product
* @return array|float
* @deprecated
*/
public function getFormatedTierPrice($qty, $product)
{
$price = $product->getTierPrice($qty);
if (is_array($price)) {
foreach (array_keys($price) as $index) {
$price[$index]['formated_price'] = $this->priceCurrency->convertAndFormat($price[$index]['website_price']);
}
} else {
$price = $this->priceCurrency->format($price);
}
return $price;
}
示例3: getAdditionalData
/**
* $excludeAttr is optional array of attribute codes to
* exclude them from additional data array
*
* @param array $excludeAttr
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function getAdditionalData(array $excludeAttr = [])
{
$data = [];
$product = $this->getProduct();
$attributes = $product->getAttributes();
foreach ($attributes as $attribute) {
if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), $excludeAttr)) {
$value = $attribute->getFrontend()->getValue($product);
if (!$product->hasData($attribute->getAttributeCode())) {
$value = __('N/A');
} elseif ((string) $value == '') {
$value = __('No');
} elseif ($attribute->getFrontendInput() == 'price' && is_string($value)) {
$value = $this->priceCurrency->convertAndFormat($value);
}
if (is_string($value) && strlen($value)) {
$data[$attribute->getAttributeCode()] = ['label' => $attribute->getStoreLabel(), 'value' => $value, 'code' => $attribute->getAttributeCode()];
}
}
}
return $data;
}
示例4: _toHtml
/**
* @return string
*/
protected function _toHtml()
{
//store id is store view id
$storeId = $this->_getStoreId();
$websiteId = $this->_storeManager->getStore($storeId)->getWebsiteId();
//customer group id
$customerGroupId = $this->_getCustomerGroupId();
/** @var $product \Magento\Catalog\Model\Product */
$product = $this->_productFactory->create();
$product->setStoreId($storeId);
$specials = $product->getResourceCollection()->addPriceDataFieldFilter('%s < %s', array('final_price', 'price'))->addPriceData($customerGroupId, $websiteId)->addAttributeToSelect(array('name', 'short_description', 'description', 'price', 'thumbnail', 'special_price', 'special_to_date', 'msrp_enabled', 'msrp_display_actual_price_type', 'msrp'), 'left')->addAttributeToSort('name', 'asc');
$newUrl = $this->_urlBuilder->getUrl('rss/catalog/special/store_id/' . $storeId);
$title = __('%1 - Special Products', $this->_storeManager->getStore()->getFrontendName());
$lang = $this->_scopeConfig->getValue('general/locale/code', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
/** @var $rssObj \Magento\Rss\Model\Rss */
$rssObj = $this->_rssFactory->create();
$rssObj->_addHeader(array('title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8', 'language' => $lang));
$results = array();
/*
using resource iterator to load the data one by one
instead of loading all at the same time. loading all data at the same time can cause the big memory allocation.
*/
$this->_resourceIterator->walk($specials->getSelect(), array(array($this, 'addSpecialXmlCallback')), array('rssObj' => $rssObj, 'results' => &$results));
if (sizeof($results) > 0) {
foreach ($results as $result) {
// render a row for RSS feed
$product->setData($result);
$html = sprintf('<table><tr>' . '<td><a href="%s"><img src="%s" alt="" border="0" align="left" height="75" width="75" /></a></td>' . '<td style="text-decoration:none;">%s', $product->getProductUrl(), $this->_imageHelper->init($product, 'thumbnail')->resize(75, 75), $this->_outputHelper->productAttribute($product, $product->getDescription(), 'description'));
// add price data if needed
if ($product->getAllowedPriceInRss()) {
if ($this->_catalogData->canApplyMsrp($product)) {
$html .= '<br/><a href="' . $product->getProductUrl() . '">' . __('Click for price') . '</a>';
} else {
$special = '';
if ($result['use_special']) {
$special = '<br />' . __('Special Expires On: %1', $this->formatDate($result['special_to_date'], \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM));
}
$html .= sprintf('<p>%s %s%s</p>', __('Price: %1', $this->_priceCurrency->convertAndFormat($result['price'])), __('Special Price: %1', $this->_priceCurrency->convertAndFormat($result['final_price'])), $special);
}
}
$html .= '</td></tr></table>';
$rssObj->_addEntry(array('title' => $product->getName(), 'link' => $product->getProductUrl(), 'description' => $html));
}
}
return $rssObj->createRssXml();
}
示例5: getEntryData
/**
* @param \Magento\Catalog\Model\Product $item
* @return array
*/
protected function getEntryData(\Magento\Catalog\Model\Product $item)
{
$description = '
<table><tr>
<td><a href="%s"><img src="%s" alt="" border="0" align="left" height="75" width="75" /></a></td>
<td style="text-decoration:none;">%s %s</td>
</tr></table>
';
$specialPrice = '';
if ($item->getAllowedPriceInRss()) {
if ($this->msrpHelper->canApplyMsrp($item)) {
$specialPrice = '<br/><a href="' . $item->getProductUrl() . '">' . __('Click for price') . '</a>';
} else {
$special = '';
if ($item->getUseSpecial()) {
$special = '<br />' . __('Special Expires On: %1', $this->formatDate($item->getSpecialToDate(), \IntlDateFormatter::MEDIUM));
}
$specialPrice = sprintf('<p>%s %s%s</p>', __('Price: %1', $this->priceCurrency->convertAndFormat($item->getPrice())), __('Special Price: %1', $this->priceCurrency->convertAndFormat($item->getFinalPrice())), $special);
}
}
$description = sprintf($description, $item->getProductUrl(), $this->imageHelper->init($item, 'rss_thumbnail')->getUrl(), $this->outputHelper->productAttribute($item, $item->getDescription(), 'description'), $specialPrice);
return ['title' => $item->getName(), 'link' => $item->getProductUrl(), 'description' => $description];
}
示例6: _formatPrice
/**
* Format price base on store convert price method
*
* @param float $price
* @return string
*/
protected function _formatPrice($price)
{
return $this->priceCurrency->convertAndFormat($price, true, PriceCurrencyInterface::DEFAULT_PRECISION, $this->_quote->getStore());
}
示例7: getProductPrice
/**
* Get product price including store convertion rate
*
* @param \Magento\Catalog\Model\Product $product
* @param null|string $format
* @return float|string
* @deprecated
*/
public function getProductPrice($product, $format = null)
{
try {
$value = $product->getPrice();
$value = $format ? $this->priceCurrency->convertAndFormat($value) : $this->priceCurrency->convert($value);
} catch (\Exception $e) {
$value = $e->getMessage();
}
return $value;
}
示例8: convertPrice
/**
* @param float $price
* @param bool $format
* @return float
*/
public function convertPrice($price, $format = true)
{
return $format ? $this->priceCurrency->convertAndFormat($price) : $this->priceCurrency->convert($price);
}
示例9: convertPrice
/**
* Convert prices for template
*
* @param float $amount
* @param bool $format
* @return float
*/
public function convertPrice($amount, $format = false)
{
return $format ? $this->priceCurrency->convertAndFormat($amount) : $this->priceCurrency->convert($amount);
}
示例10: getShippingPrice
/**
* Get Shipping Price
*
* @return float
*/
public function getShippingPrice()
{
return $this->priceCurrency->convertAndFormat($this->shippingRate->getPrice());
}
示例11: getShippingPrice
/**
* @param Address $address
* @param float $price
* @param bool $flag
* @return float
*/
public function getShippingPrice($address, $price, $flag)
{
return $this->priceCurrency->convertAndFormat($this->_taxHelper->getShippingPrice($price, $flag, $address), true, PriceCurrencyInterface::DEFAULT_PRECISION, $address->getQuote()->getStore());
}
示例12: getShippingPrice
/**
* Get shipping price
*
* @param float $price
* @param bool $flag
* @return float
*/
public function getShippingPrice($price, $flag)
{
return $this->priceCurrency->convertAndFormat($this->_taxData->getShippingPrice($price, $flag, $this->getAddress(), null, $this->getAddress()->getQuote()->getStore()), true, PriceCurrencyInterface::DEFAULT_PRECISION, $this->getQuote()->getStore());
}
示例13: convertAndFormatCurrency
/**
* Convert and format price value
*
* @param float $amount
* @param bool $includeContainer
* @param int $precision
* @return string
*/
public function convertAndFormatCurrency($amount, $includeContainer = true, $precision = PriceCurrencyInterface::DEFAULT_PRECISION)
{
return $this->priceCurrency->convertAndFormat($amount, $includeContainer, $precision);
}
示例14: formatPrice
/**
* Convert price from default currency to current currency
*
* @param float $price
* @return float
*/
public function formatPrice($price)
{
return $this->priceCurrency->convertAndFormat($price, true, PriceCurrencyInterface::DEFAULT_PRECISION, $this->getQuote()->getStore());
}
示例15: formatCurrency
/**
* Format and convert currency using current store option
*
* @param float $value
* @param bool $includeContainer
* @return string
*/
public function formatCurrency($value, $includeContainer = true)
{
return $this->_priceCurrency->convertAndFormat($value, $includeContainer);
}