how to change product-card__badge
-
Hello @gayanpriyankara
You can not apply cart rule until the product is not added in the cart but according to your requirement, you can create a catalogue rule for the same ( It is also part of promotion ).
It is applied to the product without any delay and from haveSpecialPrice method of product type, you can get which rule is applied and can show their desired values.
-
@rahul
am sorry my mistake i have asked the question ina wrong way
this is the real problemI 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
-
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"
-
To show percentage of discount inside badge first you have to do some customisation.
- First open the folder which is given below:
$root_folder/packages/Webkul/Product/src/Type - Inside this folder you will find all product type file (7 files like downloadable, virtual, etc..)
- open each file and find getPriceHtml() function.
- Now inside this getPriceHtml() function you will find sale sticker tag like image given below:
- 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
- First open the folder which is given below:
-
@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%) -
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
-
-
@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 greatthanks in advance