Skip to main content

Applying discount via plugin

More
11 years 2 months ago - 11 years 2 months ago #209739 by designbuilder
-- HikaShop version -- : 2.5.0

I have a plugin which processes a coupon against certain rules. I have a requirement that when product A is added to the cart, and the coupon matches a rule, product B is added to the cart. Product B should be discounted by 100%.

Using the function onAfterCouponCheck I add product B when required:

$product_id = 'B';
$quantity = '10';
$cartClass = hikashop_get('class.cart');
$cartClass->update($product_id,$quantity);

Is there a way that I can apply a discount to product B when it is added to the cart so that it is a no cost addition to the cart.

Many thanks
Last edit: 11 years 2 months ago by designbuilder. Reason: Typo

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

More
11 years 2 months ago #209747 by Jerome
Replied by Jerome on topic Applying discount via plugin
Hi,

There is no easy way to add a discounted product in the cart.
But you can override the product price or access to some cart elements (like "additional") using triggers.

www.hikashop.com/support/support/documen...mentation.html#other
www.hikashop.com/support/support/documen...fterCartProductsLoad

The modification of the product price or the usage of "order additional" will allow you to create something near the discount.

Regards,

Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
The following user(s) said Thank You: designbuilder

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

More
11 years 2 months ago #209861 by designbuilder
Thank you for your response. I can achieve the discount by modifying the product price as you suggested. The unit price and total price for Product B are correct in the cart, however the subtotal is not correct. The Subtotal/Total pricing etc does not appear to be calculated using the modified prices.

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

More
11 years 2 months ago #209863 by Jerome
Replied by Jerome on topic Applying discount via plugin
Hi,

If you modified the prices using the trigger "onAfterCartProductsLoad" that's logical.
That trigger is useful for the order additional but the cart total price is processed before the trigger is called.
(so if you want to change the product prices, you need to also recalculate the order full price ; but you might have an issue with the order creation...).

If not ; please indicate what you have done ; because you didn't share that information and if we do not know what you have done ; it will be more than difficult for us to help you.

Regards,

Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

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

Time to create page: 0.150 seconds
Powered by Kunena Forum