Skip to main content

How to apply a discount on product variants?

More
9 years 7 months ago #263890 by Jabatec
Hi,
Is it not possible to apply a different discount on product variants?
Is it not possible to assign a product variant to a category? and on this category a discount.
Also, via custom fields it is not possible to work discounts on product variants
I'm looking for some solution without having to go through phpmyadmin but I can not find anything.

Best regards,
Javier

Javier Ballester
The following user(s) said Thank You: MrsIE

Please Log in or Create an account to join the conversation.

More
9 years 7 months ago #263895 by nicolas
Hi,

1. There is no option for now to assign a discount to variants, only to main products.
2. Variants are not displayed on products listings, so they are not linked to any category. They are linked to categories through their products.
PHPMyadmin won't help you. Even if you set the id of a variant in a discount products field, it won't be used by the system.
The only viable solution I see for now is to set the price you want in the variant itself when you edit it under the "variants" tab of the main product.

Please Log in or Create an account to join the conversation.

More
9 years 7 months ago - 9 years 7 months ago #264015 by Jabatec
Hi Nicolas,
I think the way is that, work with price in product variant, but I am looking for a solution as if it were a discount.
When the retail price exists in a variation of product, this price shown next to the official price, ok, fantastic, but could it be show in Crossed out format and with as a percentage of discount on the official price?
Is there any example code to integrate it?
I think this would be a good solution on how to show a discount on a product variation

Attached example image

Thank you
Javier

Javier Ballester
Last edit: 9 years 7 months ago by Jabatec.

Please Log in or Create an account to join the conversation.

More
9 years 7 months ago #264018 by nicolas
Hi,

Well, you can cross the retail price with simple CSS code.
For example:
.hikashop_product_msrp_price .hikashop_product_price{ decoration: line-through; }

You can also use translation overrides to change the text before the prices. And you can use some more CSS to put both prices on the same line.

If you want to go further, then you would have to edit the file "listing_price" of the view "product" and change that block of code which handles the display of the retail price:
Code:
<span class="hikashop_product_msrp_price hikashop_product_price_full"> <span class="hikashop_product_msrp_price_title"><?php echo JText::_('PRODUCT_MSRP_BEFORE'); ?></span> <span class="hikashop_product_price"><?php $mainCurr = $this->currencyHelper->mainCurrency(); $app = JFactory::getApplication(); $currCurrency = $app->getUserState( HIKASHOP_COMPONENT.'.currency_id', $mainCurr ); $msrpCurrencied = $this->currencyHelper->convertUniquePrice($this->row->product_msrp,$mainCurr,$currCurrency); if($msrpCurrencied == $this->row->product_msrp) echo $this->currencyHelper->format($this->row->product_msrp,$mainCurr); else echo $this->currencyHelper->format($msrpCurrencied,$currCurrency).' ('.$this->currencyHelper->format($this->row->product_msrp,$mainCurr).')'; ?></span> </span>

Having discounts on variants is something we want in the future.
The following user(s) said Thank You: Jabatec

Please Log in or Create an account to join the conversation.

More
9 years 7 months ago #264106 by Jabatec
Hi Nicolas, thank you for your reply
I am not programmer, (developer)
I searched but did not find any example code to calculate the % discount result of the product price on the retail price
Can you help me please?

Thank you
Javier

Javier Ballester

Please Log in or Create an account to join the conversation.

More
9 years 7 months ago #264109 by nicolas
Hi,

This is the retail price:
Code:
$this->row->product_msrp
This is the price of the product:
Code:
$this->row->prices[0]->price_value_with_tax
This is to get the discount percentage:
Code:
$discount_amount = ($this->row->prices[0]->price_value_with_tax-$this->row->product_msrp)*100/$this->row->prices[0]->price_value_with_tax;
This is to get the display it:
Code:
echo $this->currencyHelper->format($discount_amount,$this->row->prices[0]->price_currency_id);

Please Log in or Create an account to join the conversation.

More
9 years 7 months ago #264186 by Jabatec
Hi,
I have updated the formula to correctly calculate the value of discount,
I changed;
$discount_amount = ($this->row->prices[0]->price_value_with_tax-$this->row->product_msrp)*100/$this->row->prices[0]->price_value_with_tax;
by;
$discount_amount = ($this->row->prices[0]-> price_value_with_tax/$this->row->product_msrp )*100-100;
But the problem I find is how to round the percentage to 2 decimals and change the "€" symbol by "%"
Attached image
Code:
<span class="hikashop_product_msrp_price hikashop_product_price_full"> <span class="hikashop_product_msrp_price_title"> <?php echo JText::_('PRODUCT_MSRP_BEFORE'); ?> </span> <span class="hikashop_product_price"> <?php $mainCurr = $this->currencyHelper->mainCurrency(); $app = JFactory::getApplication(); $currCurrency = $app->getUserState( HIKASHOP_COMPONENT.'.currency_id', $mainCurr ); $msrpCurrencied = $this->currencyHelper->convertUniquePrice($this->row->product_msrp,$mainCurr,$currCurrency); if($msrpCurrencied == $this->row->product_msrp) echo $this->currencyHelper->format($this->row->product_msrp,$mainCurr); else echo $this->currencyHelper->format($msrpCurrencied,$currCurrency).' ('.$this->currencyHelper->format($this->row->product_msrp,$mainCurr).')'; ?> </span> <span class="hikashop_product_price_percentaje"> <?php $discount_amount = ($this->row->prices[0]-> price_value_with_tax/$this->row->product_msrp )*100-100; if($msrpCurrencied == $this->row->product_msrp) echo $this->currencyHelper->format($discount_amount,$this->row->prices[0]->price_currency_id); else echo $this->currencyHelper->format($msrpCurrencied,$currCurrency).' ('.$this->currencyHelper->format($this->row->product_msrp,$mainCurr).')'; ?> </span> </span>


Thank you very much
Javier

Javier Ballester

Please Log in or Create an account to join the conversation.

More
9 years 7 months ago #264188 by nicolas
Ah yes, I made a mistake. The code:
Code:
echo $this->currencyHelper->format($discount_amount,$this->row->prices[0]->price_currency_id);
is to display a price.
To display a percentage, it's much more easy:
Code:
echo round($discount_amount,2). ' %';

Please Log in or Create an account to join the conversation.

More
7 years 1 month ago - 7 years 1 month ago #310956 by MrsIE
Hi Nicolas,

do you have a development plan to solve this problem? I mean placing the variant of the product in various categories (e.g. discounts, new product or again in stock etc)?

Best regards
Irene.
Last edit: 7 years 1 month ago by MrsIE.

Please Log in or Create an account to join the conversation.

More
7 years 1 month ago #310975 by nicolas
Hi,

We don't plan on changing this any time soon. Variants were never meant to be linked to categories.
Changing that would require a lot of work and testing as there are many many things coded so that the system automatically use the categories of the main product when filtering of categories (for custom fields, for reports, statistics, mass actions, badges, discounts, etc).
Now, if you could tell us what you're trying to do, maybe we could provide an alternative solution ?

Note also that the possibility to select variants for discounts has been added since the creation of this thread ( and this was the main point of this thread ).
The following user(s) said Thank You: MrsIE

Please Log in or Create an account to join the conversation.

More
7 years 1 month ago #311014 by MrsIE
Hi Nicolas,

thank you for reply.

Sure I'll try this way a bit later. I just wanted to know: should i puzzle or just wait a bit ))

Sometimes I need to display in the listing some variants separately from their main products (eg in categories "Action", "New product" or "Again in stock" etc).

This is not urgent, and I'll return to this item later.

Best regards
Irene.

Please Log in or Create an account to join the conversation.

Time to create page: 0.271 seconds
Powered by Kunena Forum