Recent Topics

how to change product-card__badge



  • @rahul
    am sorry my mistake i have asked the question ina wrong way
    this is the real problem

    I was trying to show the cart rule percentage or the name on the product badge so that the coustomer can see the given promotion to the product but I couldn't



  • Hi @gayanpriyankara

    You can get the applied cart rule from 'applied_cart_rule_ids' in the cart and cart_items table and can show the desired data (like name, percentage or price for discount) on product badge.



  • @rahul
    can you please assist me hot show the percentage of the discount in the product badge
    as shown in the image i want to show the percentage of the discount instead of "new"
    img1.JPG



  • Hi @gayanpriyankara

    To show percentage of discount inside badge first you have to do some customisation.

    1. First open the folder which is given below:
      $root_folder/packages/Webkul/Product/src/Type
    2. Inside this folder you will find all product type file (7 files like downloadable, virtual, etc..)
    3. open each file and find getPriceHtml() function.
    4. Now inside this getPriceHtml() function you will find sale sticker tag like image given below:ea58c254-4b46-47e8-89a2-48760fbc6e6d-image.png
    5. Now inside this function first you have to calculate discount percentage using special price and add that percentage inside sticker sale div.

    Now whenever you set special price of product your logic inside getPriceHtml() function calculate discount percentage using special price and set that percentage inside sticker sale div so in front-end you will see discount percentage inside badge.

    Note: Kindly take backup of project before performing above steps.

    Thanks



  • @vishalK thank you very much for the help
    but what i need is i want to show the percentage discount when we apply a promotion in cart-rule
    the discount amount (20%)



  • Hi @gayanpriyankara

    Open the AbstractType.php file inside the Product package and replace the below code in getPriceHtml() method.

    if ($this->haveSpecialPrice()) {
                $per = (($this->product->price - $this->getSpecialPrice()) * 100)/$this->product->price;
                
                $html = '<div class="sticker sale">' . $per .'%'. '</div>'
                    . '<span class="regular-price">' . core()->currency($this->product->price) . '</span>'
                    . '<span class="special-price">' . core()->currency($this->getSpecialPrice()) . '</span>';
            } else {
                $html = '<span>' . core()->currency($this->product->price) . '</span>';
            }
    
            return $html;
    

    Thanks
    Rahul Shukla



  • @rahul thank a lot bro it helped to get the % to the sale items



  • @rahul hi can you show me how to do this too



  • Hi @gayanpriyankara

    I don't get what are you asking, please explain more.

    Thanks



  • @rahul
    ok lets say ,
    we are giving a discount (20%) to a certain Category so when we search for a product in the web the sticker should be 20% like "new" so the customer will know that this product has 20 discount if he buy it
    if we can get the cart-rule name or the percentage of the discount to the sticker that will be great

    thanks in advance


Log in to reply