Applying discount via plugin

  • Posts: 9
  • Thank you received: 0
  • Hikashop Business
9 years 3 months ago #209739

-- 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: 9 years 3 months ago by designbuilder. Reason: Typo

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
9 years 3 months ago #209747

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.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
The following user(s) said Thank You: designbuilder

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

  • Posts: 9
  • Thank you received: 0
  • Hikashop Business
9 years 3 months ago #209861

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.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
9 years 3 months ago #209863

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.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

Time to create page: 0.059 seconds
Powered by Kunena Forum