/** * @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; }
/** * 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; }
/** * 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); } } }
/** * 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; }
/** * 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; }
/** * 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)); } }
/** * @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; }
/** * 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); } }
/** * 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)); } }
/** * 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)); } }
/** * 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; }
/** * {@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; }
/** * Get formatted by currency product price * * @param Product $product * @return array || float */ public function getFormatedPrice($product) { return $this->priceCurrency->format($product->getFinalPrice()); }
/** * @param float $price * @return mixed * * @codeCoverageIgnore */ public function formatPrice($price) { return $this->priceCurrency->format($price, true, PriceCurrencyInterface::DEFAULT_PRECISION, $this->getQuote()->getStore()); }
/** * 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); }
/** * Retrieve formatted price * * @param float $value * @return string */ public function formatPrice($value) { $store = $this->_storeManager->getStore($this->_getRecurringPayment()->getStore()); return $this->priceCurrency->format($value, true, PriceCurrencyInterface::DEFAULT_PRECISION, $store); }
/** * Format price value * * @param float $amount * @param bool $includeContainer * @param int $precision * @return float */ public function formatCurrency($amount, $includeContainer = true, $precision = PriceCurrencyInterface::DEFAULT_PRECISION) { return $this->priceCurrency->format($amount, $includeContainer, $precision); }
/** * Formats price * * @param float $price * @param bool $includeContainer * @return string */ public function formatPrice($price, $includeContainer = true) { return $this->_priceCurrency->format($price, $includeContainer); }