本文整理汇总了PHP中Magento\Catalog\Helper\Data::getTaxPrice方法的典型用法代码示例。如果您正苦于以下问题:PHP Data::getTaxPrice方法的具体用法?PHP Data::getTaxPrice怎么用?PHP Data::getTaxPrice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Helper\Data
的用法示例。
在下文中一共展示了Data::getTaxPrice方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getItems
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function getItems()
{
Profiler::start(__METHOD__);
$items = [];
/** @var \Magento\Catalog\Model\Product $product */
foreach ($this->collection as $product) {
$item = ['sku' => $product->getSku(), 'name' => $product->getName(), 'url' => $product->getProductUrl(), 'description' => null, 'image' => null, 'price' => null, 'rating' => null];
if ($this->config->isShowShortDescription()) {
$item['description'] = html_entity_decode(strip_tags($product->getDataUsingMethod('description')));
}
$image = false;
if ($product->getImage() && $product->getImage() != 'no_selection') {
$image = $product->getImage();
} elseif ($product->getSmallImage() && $product->getSmallImage() != 'no_selection') {
$image = $product->getSmallImage();
}
if ($this->config->isShowImage() && $image) {
$item['image'] = $this->imageHelper->init($product, false)->setImageFile($image)->resize(65 * 2, 80 * 2)->getUrl();
}
if ($this->config->isShowPrice()) {
$item['price'] = $this->catalogHelper->getTaxPrice($product, $product->getFinalPrice());
$item['price'] = $this->pricingHelper->currency($item['price'], false, false);
}
if ($this->config->isShowRating()) {
$item['rating'] = $this->reviewRenderer->getReviewsSummaryHtml($product, ReviewRendererInterface::SHORT_VIEW);
}
$items[] = $item;
}
Profiler::stop(__METHOD__);
return $items;
}
示例2: getPrice
/**
* Get price with including/excluding tax
*
* @param float $price
* @param bool $includingTax
* @return float
*/
public function getPrice($price, $includingTax = null)
{
if ($includingTax !== null) {
$price = $this->_catalogHelper->getTaxPrice($this->getProduct(), $price, true);
} else {
$price = $this->_catalogHelper->getTaxPrice($this->getProduct(), $price);
}
return $price;
}
示例3: _getPriceConfiguration
/**
* Get price configuration
*
* @param \Magento\Catalog\Model\Product\Option\Value|\Magento\Catalog\Model\Product\Option $option
* @return array
*/
protected function _getPriceConfiguration($option)
{
$data = array();
$data['price'] = $this->_coreData->currency($option->getPrice(true), false, false);
$data['oldPrice'] = $this->_coreData->currency($option->getPrice(false), false, false);
$data['priceValue'] = $option->getPrice(false);
$data['type'] = $option->getPriceType();
$data['exclTaxPrice'] = $price = $this->_catalogData->getTaxPrice($option->getProduct(), $data['price'], false);
$data['inclTaxPrice'] = $price = $this->_catalogData->getTaxPrice($option->getProduct(), $data['price'], true);
return $data;
}
示例4: testGetTaxPrice
/**
* @param \Magento\Framework\Object $input
* @param float $expectOutputPrice
* @param string[] $configs
* @param string $productClassName
*
* @magentoDataFixture Magento/Catalog/_files/products.php
* @magentoDataFixture Magento/Customer/_files/customer.php
* @magentoDataFixture Magento/Customer/_files/customer_address.php
* @magentoDbIsolation enabled
* @dataProvider getTaxPriceDataProvider
*/
public function testGetTaxPrice($input, $expectOutputPrice, $configs = [], $productClassName = 'DefaultProductClass')
{
$this->setUpDefaultRules();
$fixtureProductId = 1;
/** @var \Magento\Catalog\Model\Product $product */
$product = $this->objectManager->create('Magento\\Catalog\\Model\\Product')->load($fixtureProductId);
$product->setTaxClassId($this->taxClasses[$productClassName]);
$shippingAddress = $this->getCustomerAddress();
$billingAddress = $shippingAddress;
foreach ($configs as $config) {
$this->scopeConfig->setValue($config['path'], $config['value'], ScopeInterface::SCOPE_STORE, 'default');
}
$price = $this->helper->getTaxPrice($product, $input->getPrice(), $input->getIncludingTax(), $shippingAddress, $billingAddress, $this->taxClasses['DefaultCustomerClass'], $input->getStore(), $input->getPriceIncludesTax(), $input->getRoundPrice());
$this->assertEquals($expectOutputPrice, $price);
}
示例5: _getFinalPrice
/**
* Calculate final price
*
* @param Product $product
* @param \Magento\Store\Model\Store $store
* @param bool $inclTax
* @param bool $isSalePriceAllowed
* @return float|null
*/
private function _getFinalPrice($product, $store, $inclTax, $isSalePriceAllowed)
{
// calculate sale_price attribute value
$salePriceAttribute = $this->getGroupAttributeSalePrice();
$salePriceMapValue = null;
$finalPrice = null;
if (!is_null($salePriceAttribute)) {
$salePriceMapValue = $salePriceAttribute->getProductAttributeValue($product);
}
if (!is_null($salePriceMapValue) && floatval($salePriceMapValue) > 0.0001) {
$finalPrice = $salePriceMapValue;
} else {
if ($isSalePriceAllowed) {
$finalPrice = $this->catalogPrice->getCatalogPrice($product, $store, $inclTax);
}
}
if ($product->getTypeId() != Product\Type::TYPE_BUNDLE) {
$finalPrice = $this->_catalogData->getTaxPrice($product, $finalPrice, $inclTax, null, null, null, $product->getStoreId());
}
return $finalPrice;
}
示例6: _getPriceConfiguration
/**
* Get price configuration
*
* @param \Magento\Catalog\Model\Product\Option\Value|\Magento\Catalog\Model\Product\Option $option
* @return array
*/
protected function _getPriceConfiguration($option)
{
$optionPrice = $this->pricingHelper->currency($option->getPrice(true), false, false);
$data = ['prices' => ['oldPrice' => ['amount' => $this->pricingHelper->currency($option->getRegularPrice(), false, false), 'adjustments' => []], 'basePrice' => ['amount' => $this->_catalogData->getTaxPrice($option->getProduct(), $optionPrice, false, null, null, null, null, null, false)], 'finalPrice' => ['amount' => $this->_catalogData->getTaxPrice($option->getProduct(), $optionPrice, true, null, null, null, null, null, false)]], 'type' => $option->getPriceType(), 'name' => $option->getTitle()];
return $data;
}
示例7: getItemBaseOriginalPrice
/**
* Return item base original price
*
* @param AbstractItem $item
* @return float
*/
public function getItemBaseOriginalPrice($item)
{
return $this->_catalogData->getTaxPrice($item, $item->getBaseOriginalPrice(), true);
}
示例8: getTotalPrices
/**
* Retrieve Price considering tier price
*
* @param \Magento\Catalog\Model\Product $product
* @param string|null $which
* @param bool|null $includeTax
* @param bool $takeTierPrice
* @return float|array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function getTotalPrices($product, $which = null, $includeTax = null, $takeTierPrice = true)
{
// check calculated price index
if ($product->getData('min_price') && $product->getData('max_price')) {
$minimalPrice = $this->_catalogData->getTaxPrice($product, $product->getData('min_price'), $includeTax);
$maximalPrice = $this->_catalogData->getTaxPrice($product, $product->getData('max_price'), $includeTax);
$this->_isPricesCalculatedByIndex = true;
} else {
/**
* Check if product price is fixed
*/
$finalPrice = $product->getFinalPrice();
if ($product->getPriceType() == self::PRICE_TYPE_FIXED) {
$minimalPrice = $maximalPrice = $this->_catalogData->getTaxPrice($product, $finalPrice, $includeTax);
} else {
// PRICE_TYPE_DYNAMIC
$minimalPrice = $maximalPrice = 0;
}
$options = $this->getOptions($product);
$minPriceFounded = false;
if ($options) {
foreach ($options as $option) {
/* @var $option \Magento\Bundle\Model\Option */
$selections = $option->getSelections();
if ($selections) {
$selectionMinimalPrices = [];
$selectionMaximalPrices = [];
foreach ($option->getSelections() as $selection) {
/* @var $selection \Magento\Bundle\Model\Selection */
if (!$selection->isSalable()) {
/**
* @todo CatalogInventory Show out of stock Products
*/
continue;
}
$qty = $selection->getSelectionQty();
$item = $product->getPriceType() == self::PRICE_TYPE_FIXED ? $product : $selection;
$selectionMinimalPrices[] = $this->_catalogData->getTaxPrice($item, $this->getSelectionFinalTotalPrice($product, $selection, 1, $qty, true, $takeTierPrice), $includeTax);
$selectionMaximalPrices[] = $this->_catalogData->getTaxPrice($item, $this->getSelectionFinalTotalPrice($product, $selection, 1, null, true, $takeTierPrice), $includeTax);
}
if (count($selectionMinimalPrices)) {
$selMinPrice = min($selectionMinimalPrices);
if ($option->getRequired()) {
$minimalPrice += $selMinPrice;
$minPriceFounded = true;
} elseif (true !== $minPriceFounded) {
$selMinPrice += $minimalPrice;
$minPriceFounded = false === $minPriceFounded ? $selMinPrice : min($minPriceFounded, $selMinPrice);
}
if ($option->isMultiSelection()) {
$maximalPrice += array_sum($selectionMaximalPrices);
} else {
$maximalPrice += max($selectionMaximalPrices);
}
}
}
}
}
// condition is TRUE when all product options are NOT required
if (!is_bool($minPriceFounded)) {
$minimalPrice = $minPriceFounded;
}
$customOptions = $product->getOptions();
if ($product->getPriceType() == self::PRICE_TYPE_FIXED && $customOptions) {
foreach ($customOptions as $customOption) {
/* @var $customOption \Magento\Catalog\Model\Product\Option */
$values = $customOption->getValues();
if ($values) {
$prices = [];
foreach ($values as $value) {
/* @var $value \Magento\Catalog\Model\Product\Option\Value */
$valuePrice = $value->getPrice(true);
$prices[] = $valuePrice;
}
if (count($prices)) {
if ($customOption->getIsRequire()) {
$minimalPrice += $this->_catalogData->getTaxPrice($product, min($prices), $includeTax);
}
$multiTypes = [\Magento\Catalog\Model\Product\Option::OPTION_TYPE_CHECKBOX, \Magento\Catalog\Model\Product\Option::OPTION_TYPE_MULTIPLE];
if (in_array($customOption->getType(), $multiTypes)) {
$maximalValue = array_sum($prices);
} else {
$maximalValue = max($prices);
}
$maximalPrice += $this->_catalogData->getTaxPrice($product, $maximalValue, $includeTax);
}
} else {
$valuePrice = $customOption->getPrice(true);
//.........这里部分代码省略.........
示例9: _processPrice
/**
* Process price emails
*
* @param \Magento\ProductAlert\Model\Email $email
* @return $this
*/
protected function _processPrice(\Magento\ProductAlert\Model\Email $email)
{
$email->setType('price');
foreach ($this->_getWebsites() as $website) {
/* @var $website \Magento\Store\Model\Website */
if (!$website->getDefaultGroup() || !$website->getDefaultGroup()->getDefaultStore()) {
continue;
}
if (!$this->_scopeConfig->getValue(self::XML_PATH_PRICE_ALLOW, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $website->getDefaultGroup()->getDefaultStore()->getId())) {
continue;
}
try {
$collection = $this->_priceColFactory->create()->addWebsiteFilter($website->getId())->setCustomerOrder();
} catch (\Exception $e) {
$this->_errors[] = $e->getMessage();
return $this;
}
$previousCustomer = null;
$email->setWebsite($website);
foreach ($collection as $alert) {
try {
if (!$previousCustomer || $previousCustomer->getId() != $alert->getCustomerId()) {
$customer = $this->_customerAccountService->getCustomer($alert->getCustomerId());
if ($previousCustomer) {
$email->send();
}
if (!$customer) {
continue;
}
$previousCustomer = $customer;
$email->clean();
$email->setCustomerData($customer);
} else {
$customer = $previousCustomer;
}
/** @var \Magento\Catalog\Model\Product $product */
$product = $this->_productFactory->create()->setStoreId($website->getDefaultStore()->getId())->load($alert->getProductId());
if (!$product) {
continue;
}
$product->setCustomerGroupId($customer->getGroupId());
if ($alert->getPrice() > $product->getFinalPrice()) {
$productPrice = $product->getFinalPrice();
$product->setFinalPrice($this->_catalogData->getTaxPrice($product, $productPrice));
$product->setPrice($this->_catalogData->getTaxPrice($product, $product->getPrice()));
$email->addPriceProduct($product);
$alert->setPrice($productPrice);
$alert->setLastSendDate($this->_dateFactory->create()->gmtDate());
$alert->setSendCount($alert->getSendCount() + 1);
$alert->setStatus(1);
$alert->save();
}
} catch (\Exception $e) {
$this->_errors[] = $e->getMessage();
}
}
if ($previousCustomer) {
try {
$email->send();
} catch (\Exception $e) {
$this->_errors[] = $e->getMessage();
}
}
}
return $this;
}