Discounts exclude from existing discount

  • Posts: 1177
  • Thank you received: 13
  • Hikashop Business
3 days 21 hours ago #372589

-- HikaShop version -- : 6.5.1
-- Joomla version -- : 6.1.2

Hi!

I have many different discounts for many products, and now i want to add a 20% discount to the whole eshop except the ones that already have a dicsount.
I cannot find an easy way to do that though.

Thank you

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

  • Posts: 273
  • Thank you received: 40
  • Hikamarket Multivendor Hikashop Business
3 days 20 hours ago #372591

Use coupon instead, there you can set the coupon to "Auto load in cart if possible" and "Ignore discounted products".



The issue with this approch is that the user can't use another coupon from you if he has one, but you can fix that with this plugin: Multi Coupon Checkout

Attachments:
The following user(s) said Thank You: verzevoul

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

  • Posts: 1177
  • Thank you received: 13
  • Hikashop Business
3 days 20 hours ago #372592

Hi,

Thanks for your help but this doesn't work for me!
It would be easier if the discounts had the option "Ignore discounted products".

So there is no other way? Cause it sounds like a big trouble, there are a lot of products.

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

  • Posts: 273
  • Thank you received: 40
  • Hikamarket Multivendor Hikashop Business
3 days 19 hours ago #372593

No, for the moment there is no other way around this.
I know for sure that this question was asked before and until now (from my knowledge) you can't use discount with "Ignore discounted products".
But wait for an official answer from nicolas.

The following user(s) said Thank You: verzevoul

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

  • Posts: 85884
  • Thank you received: 14124
  • MODERATOR
3 days 15 hours ago #372597

Hi,

You can actually do this with a normal discount, no coupon needed, thanks to the way discounts are prioritized.

For a given product, only one automatic discount applies, and HikaShop keeps the most specific one: a discount set on that product wins over a discount set on its category, which itself wins over a discount that applies to the whole shop.

So all you have to do is create one discount with:

- Value: 20 %
- No product restriction
- No category restriction (so it applies to the whole shop)

On the products that already have their own discount (set per product or per category), that more specific discount keeps winning, so your 20 % is not applied there. On all the other products, which have no discount, the 20 % is the only one available, so it applies. That is exactly the "20 % on everything except the products that are already discounted" behavior you are looking for, and it stays automatic.

The only thing to keep in mind is that this relies on your existing discounts being set on the products or on their categories, which is the case for you. Leave the new 20 % one with no product and no category so that it stays the lowest priority and only fills the gaps.

The following user(s) said Thank You: verzevoul, oxido

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

  • Posts: 1177
  • Thank you received: 13
  • Hikashop Business
3 days 15 hours ago #372598

Hi,

great i tried it and it does work like you said.
Problem is that i need to exclude one category from the whole website discount, this category's products will not have a discount at all.
So what do i do?

Thank you

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

  • Posts: 85884
  • Thank you received: 14124
  • MODERATOR
3 days 11 hours ago #372600

Hi,

For that last part there is no built-in "exclude this category" option on discounts, so the clean way is a small system plugin (group "hikashop") that reacts to the onSelectDiscount event. That event runs right before HikaShop picks the discount for each product, so you can remove the whole-shop discount for the products of the category you want to leave out, and those products then get no discount at all (no fake 0% or 0.001% discount, nothing shown on the front end).

Here is the method to put in your plugin, just set your category id at the top:

public function onSelectDiscount(&$product, &$discountsSelected, &$discounts, $zone_id, &$parent)
{
	// Category to keep out of the whole-shop discount
	$excludedCategoryId = 42;

	// The whole-shop discount is the least specific one, stored under key 20.
	// If it was not selected for this product, there is nothing to remove.
	if(empty($discountsSelected[20]))
		return;

	// Use the parent product id for variants
	$productId = (int)$product->product_id;
	if(!empty($product->product_parent_id))
		$productId = (int)$product->product_parent_id;

	$db = \Joomla\CMS\Factory::getDBO();

	// Bounds of the excluded category so its sub-categories are covered too
	$db->setQuery('SELECT category_left, category_right FROM '.hikashop_table('category').
		' WHERE category_id = '.(int)$excludedCategoryId);
	$cat = $db->loadObject();
	if(empty($cat))
		return;

	// Is the product linked to the excluded category or one of its children?
	$db->setQuery(
		'SELECT COUNT(*) FROM '.hikashop_table('product_category').' AS pc'.
		' JOIN '.hikashop_table('category').' AS c ON pc.category_id = c.category_id'.
		' WHERE pc.product_id = '.$productId.
		' AND c.category_left >= '.(int)$cat->category_left.
		' AND c.category_right <= '.(int)$cat->category_right
	);

	if($db->loadResult() > 0) {
		// Remove the whole-shop discount: this category gets no discount at all
		unset($discountsSelected[20]);
	}
}

Your existing per-product and per-category discounts are not touched, they are stored under more specific keys and keep winning as before. Only the whole-shop 20% is removed, and only for the products of that one category.

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

  • Posts: 1177
  • Thank you received: 13
  • Hikashop Business
2 days 21 hours ago #372612

Hi,

You mean i have to create a custom plugin or is there an existing one?

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

  • Posts: 273
  • Thank you received: 40
  • Hikamarket Multivendor Hikashop Business
2 days 20 hours ago #372617

You need to create one using the method nicolas gave, fi you don't know how, I will try to take some time to make one and I will post it here.

The following user(s) said Thank You: verzevoul

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

  • Posts: 85884
  • Thank you received: 14124
  • MODERATOR
2 days 17 hours ago #372618

We'll look into adding extra options for this in HikaShop for its next version in August / September.

The following user(s) said Thank You: verzevoul

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

Time to create page: 0.218 seconds
Powered by Kunena Forum