How to apply a discount on product variants?

  • Posts: 80
  • Thank you received: 13
  • Hikaserial Standard Hikashop Business
5 years 2 months ago #263890

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
Hikashop Joomla! Magazine in Spanish
Tu tienda Online Joomla! Hikashop
magazine.joomla.org/es/all-issues/februa...enda-online-joomla-3
The following user(s) said Thank You: MrsIE

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

  • Posts: 75475
  • Thank you received: 11742
  • MODERATOR
5 years 2 months ago #263895

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.

  • Posts: 80
  • Thank you received: 13
  • Hikaserial Standard Hikashop Business
5 years 2 months ago #264015

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
Hikashop Joomla! Magazine in Spanish
Tu tienda Online Joomla! Hikashop
magazine.joomla.org/es/all-issues/februa...enda-online-joomla-3
Attachments:
Last edit: 5 years 2 months ago by Jabatec.

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

  • Posts: 75475
  • Thank you received: 11742
  • MODERATOR
5 years 2 months ago #264018

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:

<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.

  • Posts: 80
  • Thank you received: 13
  • Hikaserial Standard Hikashop Business
5 years 2 months ago #264106

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
Hikashop Joomla! Magazine in Spanish
Tu tienda Online Joomla! Hikashop
magazine.joomla.org/es/all-issues/februa...enda-online-joomla-3

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

  • Posts: 75475
  • Thank you received: 11742
  • MODERATOR
5 years 2 months ago #264109

Hi,

This is the retail price:

$this->row->product_msrp
This is the price of the product:
$this->row->prices[0]->price_value_with_tax
This is to get the discount percentage:
$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:
echo $this->currencyHelper->format($discount_amount,$this->row->prices[0]->price_currency_id);

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

  • Posts: 80
  • Thank you received: 13
  • Hikaserial Standard Hikashop Business
5 years 2 months ago #264186

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

<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
Hikashop Joomla! Magazine in Spanish
Tu tienda Online Joomla! Hikashop
magazine.joomla.org/es/all-issues/februa...enda-online-joomla-3
Attachments:

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

  • Posts: 75475
  • Thank you received: 11742
  • MODERATOR
5 years 2 months ago #264188

Ah yes, I made a mistake. The 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:
echo round($discount_amount,2). ' %';

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

  • Posts: 20
  • Thank you received: 0
2 years 8 months ago #310956

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: 2 years 8 months ago by MrsIE.

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

  • Posts: 75475
  • Thank you received: 11742
  • MODERATOR
2 years 8 months ago #310975

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.

  • Posts: 20
  • Thank you received: 0
2 years 8 months ago #311014

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.087 seconds
Powered by Kunena Forum