/** * 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; }
/** * 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; }
/** * $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; }
/** * @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(); }
/** * @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]; }
/** * 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()); }
/** * 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; }
/** * @param float $price * @param bool $format * @return float */ public function convertPrice($price, $format = true) { return $format ? $this->priceCurrency->convertAndFormat($price) : $this->priceCurrency->convert($price); }
/** * 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); }
/** * Get Shipping Price * * @return float */ public function getShippingPrice() { return $this->priceCurrency->convertAndFormat($this->shippingRate->getPrice()); }
/** * @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()); }
/** * 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()); }
/** * 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); }
/** * 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()); }
/** * 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); }
/** * Convert price from default currency to current currency * * @param float $price * @param boolean $format Format price to currency format * @param boolean $includeContainer Enclose into <span class="price"><span> * @return float */ public function formatPrice($price, $format = true, $includeContainer = true) { return $format ? $this->priceCurrency->convertAndFormat($price, $includeContainer) : $this->priceCurrency->convert($price); }
/** * Convert price * * @param float $value * @param bool $format * @return float */ public function convertPrice($value, $format = true) { return $format ? $this->priceCurrency->convertAndFormat($value, true, PriceCurrencyInterface::DEFAULT_PRECISION, $this->getStore()) : $this->priceCurrency->convert($value, $this->getStore()); }