Dynamic display of discounts

  • Posts: 1058
  • Thank you received: 11
  • Hikashop Business
4 months 4 weeks ago #362174

-- HikaShop version -- : 5.0.4
-- Joomla version -- : 3.10.12
-- PHP version -- : 7.4

Hi!
We are interested to make a dynamic display of price discounts.
Depending on the customer (after logging in) a call will be made first to a web service to get the customer’s discount.
Then the discount should be applied to all product views.
Which way would you recommend as the fastest and easiest way to achieve that? (avoiding any db changes)
Thank you

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

  • Posts: 83007
  • Thank you received: 13398
  • MODERATOR
4 months 4 weeks ago #362178

Hi,

You want to implement the event onAfterLoadProductPriceDiscount(&$discounts, &$rows, $filters, $trigger_options) in a plugin of the group "hikashop"
$discounts contains an array of the discounts loaded from the database
$rows contains a product object or an array of product objects for which the discounts are being loaded
$filters contains an array of MySQL conditions which were used to load the discounts
$trigger_options contains some options like the user_id, the zone_id, the currency_id, the ids of the products, the ids of the variants
So you want to set your own discount objects in $discounts. You need to make sure that in each discount, you have a discount_product_id which matches with the corresponding product / variant.
HikaShop will then automatically apply the discounts to the products / variants.

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

  • Posts: 1058
  • Thank you received: 11
  • Hikashop Business
3 months 3 weeks ago #362786

Hi!
Your suggestion is working. Just to ask about the structure of $rows variable.
It returns an array in both cases of category view and cart view.
I am testing three variable products and one simple product in checkout view
rows[0] returns the simple product
rows[1-3] returns three times the parent product object but every time only one instance would contain the variants?
(in order to get the variant product ids and load their discount)
Thank you

Last edit: 3 months 3 weeks ago by verzevoul.

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

  • Posts: 83007
  • Thank you received: 13398
  • MODERATOR
3 months 3 weeks ago #362792

Hi,

You also need to handle the case where $rows is a product object.

When rows is an array, you should have one entry per product and one per variant.
So you want to take into account the product_id of each element in the array.

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

Time to create page: 0.069 seconds
Powered by Kunena Forum