How should I show the pre-sale price for grouped or configurable products in category view?
By default, the pre-sale price and sale branding are shown for simple products that are on sale, but for grouped products for which one associated product is on sale, only the sale price is shown, without any indication that it is a sale price.
magento2
add a comment |
By default, the pre-sale price and sale branding are shown for simple products that are on sale, but for grouped products for which one associated product is on sale, only the sale price is shown, without any indication that it is a sale price.
magento2
add a comment |
By default, the pre-sale price and sale branding are shown for simple products that are on sale, but for grouped products for which one associated product is on sale, only the sale price is shown, without any indication that it is a sale price.
magento2
By default, the pre-sale price and sale branding are shown for simple products that are on sale, but for grouped products for which one associated product is on sale, only the sale price is shown, without any indication that it is a sale price.
magento2
magento2
asked 2 mins ago
James Edward Lewis IIJames Edward Lewis II
1013
1013
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I have already done something that seems to work, but the logic of the one for grouped products is a little suspect: It will show the current price of the associated product with the lowest current price, and then it will show sale branding dependent on whether that product is on sale, even if its regular price happens to not be the minimum regular price among the associated products.
Each of these paths is relative to your theme; whether you purchased a theme or just started with Luma, you should be sure to make a child theme with all changes:
Magento_ConfigurableProduct/Templates/product/price/final_price.phtml
<?php
/** @var MagentoConfigurableProductPricingRenderFinalPriceBox$block */
/** @var MagentoFrameworkPricingPricePriceInterface $priceModel */
$priceModel = $block->getPriceType('regular_price');
/** @var MagentoFrameworkPricingPricePriceInterface $finalPriceModel */
$finalPriceModel = $block->getPriceType('final_price');
$idSuffix = $block->getIdSuffix();
$idSuffix = $idSuffix ? $idSuffix : '';
$schema = $block->getZone() == 'item_view';
$hasSpecial = $block->hasSpecialPrice();
?>
<span class="<?= $hasSpecial ? 'special' : 'normal' ?>-price">
<?= /* @noEscape */ $block->renderAmount($finalPriceModel->getAmount(), [
'display_label' => __('As low as'),
'price_id' => $block->getPriceId('product-price-' . $idSuffix),
'price_type' => 'finalPrice',
'include_container' => true,
'schema' => $schema
]) ?>
</span>
<?php if ($hasSpecial): ?>
<span class="old-price no-display">
<?= /* @escapeNotVerified */ $block->renderAmount($priceModel->getAmount(), [
'display_label' => __('Regular Price'),
'price_id' => $block->getPriceId('old-price-' . $idSuffix),
'price_type' => 'oldPrice',
'include_container' => true,
'skip_adjustments' => true
]) ?>
</span>
<?php endif; ?>
<?php if ($block->showMinimalPrice()): ?>
<?php if ($block->getUseLinkForAsLowAs()):?>
<a href="<?= /* @escapeNotVerified */ $block->getSaleableItem()->getProductUrl() ?>" class="minimal-price-link">
<?= /* @escapeNotVerified */ $block->renderAmountMinimal() ?>
</a>
<?php else: ?>
<span class="minimal-price-link">
<?= /* @escapeNotVerified */ $block->renderAmountMinimal() ?>
</span>
<?php endif?>
<?php endif; ?>
Magento_GroupedProduct/Templates/product/price/final_price.phtml
<?php
$hasSpecial = false;
$minProduct = $block->getSaleableItem()
->getPriceInfo()
->getPrice(MagentoCatalogPricingPriceFinalPrice::PRICE_CODE)
->getMinProduct();
if ($minProduct) {
$finalPrice = $minProduct->getPriceInfo()->getPrice('final_price');
$finalAmount = $finalPrice->getAmount();
$regularPrice = $minProduct->getPriceInfo()->getPrice('regular_price');
$regularAmount = $regularPrice->getAmount();
$hasSpecial = $finalAmount < $regularAmount;
$amountRender = $block->getRendererPool()
->createAmountRender(
$finalAmount,
$minProduct,
$finalPrice,
['include_container' => true]
);
}
?>
<div class="price-box" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<?php if ($minProduct && MagentoFrameworkPricingRender::ZONE_ITEM_VIEW != $block->getZone()): ?>
<?php $groupedLabel = 'Starting at'; ?>
<?php if ($hasSpecial) { ?>
<span class="price-label"><?= /* @escapeNotVerified */ __($groupedLabel) ?></span><span class="special-price"><?= $amountRender->toHtml() ?></span>
<span class="old-price"><?= $block->getRendererPool()
->createAmountRender(
$regularAmount,
$minProduct,
$regularPrice,
['include_container' => true]
)->toHtml() ?></span>
<?php } else { ?>
<p class="minimal-price">
<span class="price-label"><?= /* @escapeNotVerified */ __($groupedLabel) ?></span><?= $amountRender->toHtml() ?>
</p>
<?php } ?>
<?php endif; ?>
</div>
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f264120%2fhow-should-i-show-the-pre-sale-price-for-grouped-or-configurable-products-in-cat%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I have already done something that seems to work, but the logic of the one for grouped products is a little suspect: It will show the current price of the associated product with the lowest current price, and then it will show sale branding dependent on whether that product is on sale, even if its regular price happens to not be the minimum regular price among the associated products.
Each of these paths is relative to your theme; whether you purchased a theme or just started with Luma, you should be sure to make a child theme with all changes:
Magento_ConfigurableProduct/Templates/product/price/final_price.phtml
<?php
/** @var MagentoConfigurableProductPricingRenderFinalPriceBox$block */
/** @var MagentoFrameworkPricingPricePriceInterface $priceModel */
$priceModel = $block->getPriceType('regular_price');
/** @var MagentoFrameworkPricingPricePriceInterface $finalPriceModel */
$finalPriceModel = $block->getPriceType('final_price');
$idSuffix = $block->getIdSuffix();
$idSuffix = $idSuffix ? $idSuffix : '';
$schema = $block->getZone() == 'item_view';
$hasSpecial = $block->hasSpecialPrice();
?>
<span class="<?= $hasSpecial ? 'special' : 'normal' ?>-price">
<?= /* @noEscape */ $block->renderAmount($finalPriceModel->getAmount(), [
'display_label' => __('As low as'),
'price_id' => $block->getPriceId('product-price-' . $idSuffix),
'price_type' => 'finalPrice',
'include_container' => true,
'schema' => $schema
]) ?>
</span>
<?php if ($hasSpecial): ?>
<span class="old-price no-display">
<?= /* @escapeNotVerified */ $block->renderAmount($priceModel->getAmount(), [
'display_label' => __('Regular Price'),
'price_id' => $block->getPriceId('old-price-' . $idSuffix),
'price_type' => 'oldPrice',
'include_container' => true,
'skip_adjustments' => true
]) ?>
</span>
<?php endif; ?>
<?php if ($block->showMinimalPrice()): ?>
<?php if ($block->getUseLinkForAsLowAs()):?>
<a href="<?= /* @escapeNotVerified */ $block->getSaleableItem()->getProductUrl() ?>" class="minimal-price-link">
<?= /* @escapeNotVerified */ $block->renderAmountMinimal() ?>
</a>
<?php else: ?>
<span class="minimal-price-link">
<?= /* @escapeNotVerified */ $block->renderAmountMinimal() ?>
</span>
<?php endif?>
<?php endif; ?>
Magento_GroupedProduct/Templates/product/price/final_price.phtml
<?php
$hasSpecial = false;
$minProduct = $block->getSaleableItem()
->getPriceInfo()
->getPrice(MagentoCatalogPricingPriceFinalPrice::PRICE_CODE)
->getMinProduct();
if ($minProduct) {
$finalPrice = $minProduct->getPriceInfo()->getPrice('final_price');
$finalAmount = $finalPrice->getAmount();
$regularPrice = $minProduct->getPriceInfo()->getPrice('regular_price');
$regularAmount = $regularPrice->getAmount();
$hasSpecial = $finalAmount < $regularAmount;
$amountRender = $block->getRendererPool()
->createAmountRender(
$finalAmount,
$minProduct,
$finalPrice,
['include_container' => true]
);
}
?>
<div class="price-box" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<?php if ($minProduct && MagentoFrameworkPricingRender::ZONE_ITEM_VIEW != $block->getZone()): ?>
<?php $groupedLabel = 'Starting at'; ?>
<?php if ($hasSpecial) { ?>
<span class="price-label"><?= /* @escapeNotVerified */ __($groupedLabel) ?></span><span class="special-price"><?= $amountRender->toHtml() ?></span>
<span class="old-price"><?= $block->getRendererPool()
->createAmountRender(
$regularAmount,
$minProduct,
$regularPrice,
['include_container' => true]
)->toHtml() ?></span>
<?php } else { ?>
<p class="minimal-price">
<span class="price-label"><?= /* @escapeNotVerified */ __($groupedLabel) ?></span><?= $amountRender->toHtml() ?>
</p>
<?php } ?>
<?php endif; ?>
</div>
add a comment |
I have already done something that seems to work, but the logic of the one for grouped products is a little suspect: It will show the current price of the associated product with the lowest current price, and then it will show sale branding dependent on whether that product is on sale, even if its regular price happens to not be the minimum regular price among the associated products.
Each of these paths is relative to your theme; whether you purchased a theme or just started with Luma, you should be sure to make a child theme with all changes:
Magento_ConfigurableProduct/Templates/product/price/final_price.phtml
<?php
/** @var MagentoConfigurableProductPricingRenderFinalPriceBox$block */
/** @var MagentoFrameworkPricingPricePriceInterface $priceModel */
$priceModel = $block->getPriceType('regular_price');
/** @var MagentoFrameworkPricingPricePriceInterface $finalPriceModel */
$finalPriceModel = $block->getPriceType('final_price');
$idSuffix = $block->getIdSuffix();
$idSuffix = $idSuffix ? $idSuffix : '';
$schema = $block->getZone() == 'item_view';
$hasSpecial = $block->hasSpecialPrice();
?>
<span class="<?= $hasSpecial ? 'special' : 'normal' ?>-price">
<?= /* @noEscape */ $block->renderAmount($finalPriceModel->getAmount(), [
'display_label' => __('As low as'),
'price_id' => $block->getPriceId('product-price-' . $idSuffix),
'price_type' => 'finalPrice',
'include_container' => true,
'schema' => $schema
]) ?>
</span>
<?php if ($hasSpecial): ?>
<span class="old-price no-display">
<?= /* @escapeNotVerified */ $block->renderAmount($priceModel->getAmount(), [
'display_label' => __('Regular Price'),
'price_id' => $block->getPriceId('old-price-' . $idSuffix),
'price_type' => 'oldPrice',
'include_container' => true,
'skip_adjustments' => true
]) ?>
</span>
<?php endif; ?>
<?php if ($block->showMinimalPrice()): ?>
<?php if ($block->getUseLinkForAsLowAs()):?>
<a href="<?= /* @escapeNotVerified */ $block->getSaleableItem()->getProductUrl() ?>" class="minimal-price-link">
<?= /* @escapeNotVerified */ $block->renderAmountMinimal() ?>
</a>
<?php else: ?>
<span class="minimal-price-link">
<?= /* @escapeNotVerified */ $block->renderAmountMinimal() ?>
</span>
<?php endif?>
<?php endif; ?>
Magento_GroupedProduct/Templates/product/price/final_price.phtml
<?php
$hasSpecial = false;
$minProduct = $block->getSaleableItem()
->getPriceInfo()
->getPrice(MagentoCatalogPricingPriceFinalPrice::PRICE_CODE)
->getMinProduct();
if ($minProduct) {
$finalPrice = $minProduct->getPriceInfo()->getPrice('final_price');
$finalAmount = $finalPrice->getAmount();
$regularPrice = $minProduct->getPriceInfo()->getPrice('regular_price');
$regularAmount = $regularPrice->getAmount();
$hasSpecial = $finalAmount < $regularAmount;
$amountRender = $block->getRendererPool()
->createAmountRender(
$finalAmount,
$minProduct,
$finalPrice,
['include_container' => true]
);
}
?>
<div class="price-box" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<?php if ($minProduct && MagentoFrameworkPricingRender::ZONE_ITEM_VIEW != $block->getZone()): ?>
<?php $groupedLabel = 'Starting at'; ?>
<?php if ($hasSpecial) { ?>
<span class="price-label"><?= /* @escapeNotVerified */ __($groupedLabel) ?></span><span class="special-price"><?= $amountRender->toHtml() ?></span>
<span class="old-price"><?= $block->getRendererPool()
->createAmountRender(
$regularAmount,
$minProduct,
$regularPrice,
['include_container' => true]
)->toHtml() ?></span>
<?php } else { ?>
<p class="minimal-price">
<span class="price-label"><?= /* @escapeNotVerified */ __($groupedLabel) ?></span><?= $amountRender->toHtml() ?>
</p>
<?php } ?>
<?php endif; ?>
</div>
add a comment |
I have already done something that seems to work, but the logic of the one for grouped products is a little suspect: It will show the current price of the associated product with the lowest current price, and then it will show sale branding dependent on whether that product is on sale, even if its regular price happens to not be the minimum regular price among the associated products.
Each of these paths is relative to your theme; whether you purchased a theme or just started with Luma, you should be sure to make a child theme with all changes:
Magento_ConfigurableProduct/Templates/product/price/final_price.phtml
<?php
/** @var MagentoConfigurableProductPricingRenderFinalPriceBox$block */
/** @var MagentoFrameworkPricingPricePriceInterface $priceModel */
$priceModel = $block->getPriceType('regular_price');
/** @var MagentoFrameworkPricingPricePriceInterface $finalPriceModel */
$finalPriceModel = $block->getPriceType('final_price');
$idSuffix = $block->getIdSuffix();
$idSuffix = $idSuffix ? $idSuffix : '';
$schema = $block->getZone() == 'item_view';
$hasSpecial = $block->hasSpecialPrice();
?>
<span class="<?= $hasSpecial ? 'special' : 'normal' ?>-price">
<?= /* @noEscape */ $block->renderAmount($finalPriceModel->getAmount(), [
'display_label' => __('As low as'),
'price_id' => $block->getPriceId('product-price-' . $idSuffix),
'price_type' => 'finalPrice',
'include_container' => true,
'schema' => $schema
]) ?>
</span>
<?php if ($hasSpecial): ?>
<span class="old-price no-display">
<?= /* @escapeNotVerified */ $block->renderAmount($priceModel->getAmount(), [
'display_label' => __('Regular Price'),
'price_id' => $block->getPriceId('old-price-' . $idSuffix),
'price_type' => 'oldPrice',
'include_container' => true,
'skip_adjustments' => true
]) ?>
</span>
<?php endif; ?>
<?php if ($block->showMinimalPrice()): ?>
<?php if ($block->getUseLinkForAsLowAs()):?>
<a href="<?= /* @escapeNotVerified */ $block->getSaleableItem()->getProductUrl() ?>" class="minimal-price-link">
<?= /* @escapeNotVerified */ $block->renderAmountMinimal() ?>
</a>
<?php else: ?>
<span class="minimal-price-link">
<?= /* @escapeNotVerified */ $block->renderAmountMinimal() ?>
</span>
<?php endif?>
<?php endif; ?>
Magento_GroupedProduct/Templates/product/price/final_price.phtml
<?php
$hasSpecial = false;
$minProduct = $block->getSaleableItem()
->getPriceInfo()
->getPrice(MagentoCatalogPricingPriceFinalPrice::PRICE_CODE)
->getMinProduct();
if ($minProduct) {
$finalPrice = $minProduct->getPriceInfo()->getPrice('final_price');
$finalAmount = $finalPrice->getAmount();
$regularPrice = $minProduct->getPriceInfo()->getPrice('regular_price');
$regularAmount = $regularPrice->getAmount();
$hasSpecial = $finalAmount < $regularAmount;
$amountRender = $block->getRendererPool()
->createAmountRender(
$finalAmount,
$minProduct,
$finalPrice,
['include_container' => true]
);
}
?>
<div class="price-box" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<?php if ($minProduct && MagentoFrameworkPricingRender::ZONE_ITEM_VIEW != $block->getZone()): ?>
<?php $groupedLabel = 'Starting at'; ?>
<?php if ($hasSpecial) { ?>
<span class="price-label"><?= /* @escapeNotVerified */ __($groupedLabel) ?></span><span class="special-price"><?= $amountRender->toHtml() ?></span>
<span class="old-price"><?= $block->getRendererPool()
->createAmountRender(
$regularAmount,
$minProduct,
$regularPrice,
['include_container' => true]
)->toHtml() ?></span>
<?php } else { ?>
<p class="minimal-price">
<span class="price-label"><?= /* @escapeNotVerified */ __($groupedLabel) ?></span><?= $amountRender->toHtml() ?>
</p>
<?php } ?>
<?php endif; ?>
</div>
I have already done something that seems to work, but the logic of the one for grouped products is a little suspect: It will show the current price of the associated product with the lowest current price, and then it will show sale branding dependent on whether that product is on sale, even if its regular price happens to not be the minimum regular price among the associated products.
Each of these paths is relative to your theme; whether you purchased a theme or just started with Luma, you should be sure to make a child theme with all changes:
Magento_ConfigurableProduct/Templates/product/price/final_price.phtml
<?php
/** @var MagentoConfigurableProductPricingRenderFinalPriceBox$block */
/** @var MagentoFrameworkPricingPricePriceInterface $priceModel */
$priceModel = $block->getPriceType('regular_price');
/** @var MagentoFrameworkPricingPricePriceInterface $finalPriceModel */
$finalPriceModel = $block->getPriceType('final_price');
$idSuffix = $block->getIdSuffix();
$idSuffix = $idSuffix ? $idSuffix : '';
$schema = $block->getZone() == 'item_view';
$hasSpecial = $block->hasSpecialPrice();
?>
<span class="<?= $hasSpecial ? 'special' : 'normal' ?>-price">
<?= /* @noEscape */ $block->renderAmount($finalPriceModel->getAmount(), [
'display_label' => __('As low as'),
'price_id' => $block->getPriceId('product-price-' . $idSuffix),
'price_type' => 'finalPrice',
'include_container' => true,
'schema' => $schema
]) ?>
</span>
<?php if ($hasSpecial): ?>
<span class="old-price no-display">
<?= /* @escapeNotVerified */ $block->renderAmount($priceModel->getAmount(), [
'display_label' => __('Regular Price'),
'price_id' => $block->getPriceId('old-price-' . $idSuffix),
'price_type' => 'oldPrice',
'include_container' => true,
'skip_adjustments' => true
]) ?>
</span>
<?php endif; ?>
<?php if ($block->showMinimalPrice()): ?>
<?php if ($block->getUseLinkForAsLowAs()):?>
<a href="<?= /* @escapeNotVerified */ $block->getSaleableItem()->getProductUrl() ?>" class="minimal-price-link">
<?= /* @escapeNotVerified */ $block->renderAmountMinimal() ?>
</a>
<?php else: ?>
<span class="minimal-price-link">
<?= /* @escapeNotVerified */ $block->renderAmountMinimal() ?>
</span>
<?php endif?>
<?php endif; ?>
Magento_GroupedProduct/Templates/product/price/final_price.phtml
<?php
$hasSpecial = false;
$minProduct = $block->getSaleableItem()
->getPriceInfo()
->getPrice(MagentoCatalogPricingPriceFinalPrice::PRICE_CODE)
->getMinProduct();
if ($minProduct) {
$finalPrice = $minProduct->getPriceInfo()->getPrice('final_price');
$finalAmount = $finalPrice->getAmount();
$regularPrice = $minProduct->getPriceInfo()->getPrice('regular_price');
$regularAmount = $regularPrice->getAmount();
$hasSpecial = $finalAmount < $regularAmount;
$amountRender = $block->getRendererPool()
->createAmountRender(
$finalAmount,
$minProduct,
$finalPrice,
['include_container' => true]
);
}
?>
<div class="price-box" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<?php if ($minProduct && MagentoFrameworkPricingRender::ZONE_ITEM_VIEW != $block->getZone()): ?>
<?php $groupedLabel = 'Starting at'; ?>
<?php if ($hasSpecial) { ?>
<span class="price-label"><?= /* @escapeNotVerified */ __($groupedLabel) ?></span><span class="special-price"><?= $amountRender->toHtml() ?></span>
<span class="old-price"><?= $block->getRendererPool()
->createAmountRender(
$regularAmount,
$minProduct,
$regularPrice,
['include_container' => true]
)->toHtml() ?></span>
<?php } else { ?>
<p class="minimal-price">
<span class="price-label"><?= /* @escapeNotVerified */ __($groupedLabel) ?></span><?= $amountRender->toHtml() ?>
</p>
<?php } ?>
<?php endif; ?>
</div>
answered 2 mins ago
James Edward Lewis IIJames Edward Lewis II
1013
1013
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f264120%2fhow-should-i-show-the-pre-sale-price-for-grouped-or-configurable-products-in-cat%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown