Hello. I want to know if there is a function in magento that create a table that display number of products (quantity) and it's price.
For example, object "a" costs 13,59€. 100 "a" costs 11,92€ and 1000 "a" costs 10€.
So, in the product page, under description i want to display a table that has 1-99 qty -> 13,59€, 100-999 qty's -> 11,92€ excetera.
How can i do? Else, can i display the price for qty's selected? Example if i want 150 "a", it will cost 11,92€ * 100 + 13,59€ * 50.
Thanks.
Solved! Go to Solution.
Where do you want to show it? On a product page in the webshop itself? Or somewhere else?
If you want to show it on the product page, you have to modify app/design/frontend/base/default/template/catalog/product/view/tierprices.phtml. Copy that file to your custom theme and check the contents. In this file, the block containing all the tier prices for the product are added. By default, it's an unordered list, with a new line for every tier price option. It should be rather easy to change the HTML and show this in a table with a row for every tier price option.
@gregilmejo yes magento provide tier prices option.
Ok, but, how can i display this in a table? Maybe under "add to chart" button?
Where do you want to show it? On a product page in the webshop itself? Or somewhere else?
If you want to show it on the product page, you have to modify app/design/frontend/base/default/template/catalog/product/view/tierprices.phtml. Copy that file to your custom theme and check the contents. In this file, the block containing all the tier prices for the product are added. By default, it's an unordered list, with a new line for every tier price option. It should be rather easy to change the HTML and show this in a table with a row for every tier price option.
Fantastic. I've created a table in this section and it works correctly.
The code in my tier price file is
<?php /** * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ // @codingStandardsIgnoreFile ?> <?php /** @var \Magento\Catalog\Pricing\Render\PriceBox $block */ /** @var \Magento\Catalog\Pricing\Price\TierPrice $tierPriceModel */ $tierPriceModel = $block->getPrice(); $tierPrices = $tierPriceModel->getTierPriceList(); $msrpShowOnGesture = $block->getPriceType('msrp_price')->isShowPriceOnGesture(); $product = $block->getSaleableItem(); ?> <?php if (count($tierPrices)) : ?> <table style="width: 100%; background-color: #eeeeee; margin:15px 0 15px 0;" border="0" cellspacing="0" cellpadding="0" > <tbody> <tr> <table style="width: 100%; background-color: #eeeeee; margin-left: auto; margin-right: auto;" border="0" cellspacing="0" cellpadding="0"> <thead > <tr> <th style="text-align: right;" width="25%"> Pcs<br/> <strong></strong> </th> <th width="40%"> </th> <th style="text-align:left;" width="25%"> <strong>EUR/Pcs</strong> </th> </tr> </thead> <tbody> <ul class="<?php /* @escapeNotVerified */ echo($block->hasListClass() ? $block->getListClass() : 'prices-tier items'); ?>"> <?php foreach ($tierPrices as $index => $price) : ?> <?php $productId = $product->getId(); $isSaleable = $product->isSaleable(); $popupId = 'msrp-popup-' . $productId . $block->getRandomString(20); if ($msrpShowOnGesture && $price['price']->getValue() < $product->getMsrp()): $addToCartUrl = ''; if ($isSaleable) { $addToCartUrl = $this->helper('\Magento\Checkout\Helper\Cart') ->getAddUrl($product, ['qty' => $price['price_qty']]); } $tierPriceData = [ 'addToCartUrl' => $addToCartUrl, 'name' => $product->getName(), 'realPrice' => $block->renderAmount( $price['price'], [ 'price_id' => $index, 'id_suffix' => '-' . $index, 'include_container' => true ] ), 'msrpPrice' => $block->renderAmount( $block->getPriceType('msrp_price')->getAmount(), [ 'price_id' => $index, 'id_suffix' => '-' . $index, 'include_container' => true ] ), ]; if ($block->getCanDisplayQty($product)) { $tierPriceData['qty'] = $price['price_qty']; } ?> <?php /* @escapeNotVerified */ echo __('Buy %1 for: ', $price['price_qty']); ?> <a href="javascript:void(0);" id="<?php /* @escapeNotVerified */ echo($popupId);?>" data-tier-price="<?php echo $block->escapeHtml($block->jsonEncode($tierPriceData)); ?>"> <?php /* @escapeNotVerified */ echo __('Click for price'); ?></a> <?php else: $priceAmountBlock = $block->renderAmount( $price['price'], [ 'price_id' => $index, 'id_suffix' => '-' . $index, 'include_container' => true, 'zone' => \Magento\Framework\Pricing\Render::ZONE_ITEM_OPTION ] ); ?> <?php endif; ?> <tr style="border-bottom: 2px solid #ffffff;" > <td style="text-align: right; border-bottom: 1px solid #ffffff;"> <?php echo $price['price_qty']; ?><?php echo "+" ; ?> </td> <td> </td> <td style="text-align:left;"> <?php echo $price['price']; ?> </td> </tr> <?php endforeach; ?> </ul> <tr> <td style="text-align: center;" colspan="3"> <p><span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque arcu enim, convallis quis sollicitudin ac, eleifend nec dui. Nam imperdiet ornare urna, at pretium magna ornare a. </span></p> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <?php if ($msrpShowOnGesture):?> <script type="text/x-magento-init"> { ".product-info-main": { "addToCart": { "origin": "tier", "addToCartButton": "#product_addtocart_form [type=submit]", "inputQty": "#qty", "attr": "[data-tier-price]", "productForm": "#product_addtocart_form", "productId": "<?php /* @escapeNotVerified */ echo $productId; ?>", "productIdInput": "input[type=hidden][name=product]", "isSaleable": "<?php /* @escapeNotVerified */ echo $isSaleable; ?>" } } } </script> <?php endif;?> <?php endif; ?>
Now it show quantities of product major than one, configured in the advanced pricing correctly.
I need now to see also price for 1 quantity product, indicated in the img.
The problem is that i think the final price has another file and another class. I can't link these file, but nothing is impossible, considering i'm a noob with magento 2...
At last, in the row in which now is located the "Lorem ipsium..." i need to see a product attributes that refers to the packages of that product.
Please help me, and sorry for my english.
Thanks to all!