0

Magento frontend product view page i need to set custom final price,

how to set? I tried Magento\Catalog\Model\Product\Type\Price.php in this file getFinalprice function but not working with plugin

can anyone give suggestion

  • what you want when customer trying to add product to cart then during this a custom price should be set? – Charul Tyagi Oct 3 '18 at 11:30
  • no, when i open product need to display my custom price i am calculating price with some extra amount if min sale qty is less than 5 i need to display my custom price like price * my extra fee – Pawankumar Oct 3 '18 at 11:45
0

The class you're looking for is Magento\Catalog\Pricing\Price\FinalPrice

The below code will double the final price as an example:

etc/frontend/di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Catalog\Pricing\Price\FinalPrice">
        <plugin name="vendorname_modulename_catalog_pricing_price_finalprice" type="VendorName\ModuleName\Plugin\FinalPrice" />
    </type>
</config>

Plugin/FinalPrice.php

<?php

namespace VendorName\ModuleName\Plugin;

class FinalPrice
{
    /**
     * @param \Magento\Catalog\Pricing\Price\FinalPrice $subject
     * @param float $result
     * @return float
     */
    public function afterGetValue(\Magento\Catalog\Pricing\Price\FinalPrice $subject, $result)
    {
        return $result * 2;
    }
}
  • here the problem is i am unable to get product data – Pawankumar Oct 3 '18 at 12:27
  • You can do $subject->getProduct() to get the product data – Media Lounge Oct 3 '18 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.