Custom price/discount calculation across products

  • Posts: 14
  • Thank you received: 0
12 years 10 months ago #41965

Hi People,

I have a load of seperate products in a category and have to calculate a discount based on the total number of all these products in the order, e.g 1-4 products is full price, 5-9 is £1 discount per product, 10-14 is £2 less etc.

I'm doing the processing in my custom hikashop plugin in the function onBeforeOrderCreate(), but I'm unsure what data I will need to adjust: I was going to simply adjust the product prices and total but there are a lot of places where the price and tax are shown, e.g. order_full_price, cart->products->order_product_price, total->prices->price_value/price_value_with_tax, it seems to be to be playing with all these fields is just going to create a lot of bugs.

So I'm wondering what is the best way to proceed, it looks like it might be easiest to create discount coupons in advance and apply one to the total order as it is created, but I would need to trigger the price calculation again before the order is created in the DB and I'm not sure how to do this.

Any help of advice you can give me would be most welcome.

Thanks,

Jerry

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

  • Posts: 14
  • Thank you received: 0
12 years 10 months ago #42082

Sorry for the bump but I would really like an answer as it is holding up development of this site.

All I really want to know is what callback or hook should I define to do a discount calculation on the entire order that will still allow me to have the tax and final price calculations done by Hikashop, and display the total discount to the user.

Thanks.

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

  • Posts: 83103
  • Thank you received: 13416
  • MODERATOR
12 years 10 months ago #42119

Hi,

One solution could be to create a quantity price calculation override plugin as explained there:
www.hikashop.com/en/support/documentatio...tation.html#override

Another one would be to create autoloaded coupons (commercial edition of HikaShop) with a restriction on the category and the number of products and the option "Coupon percentage applies to product only" turned on. You should then be able to have a coupon loaded with the correct discount on the checkout without one line of code.
However, that process has a bug in the current release which will be fixed in next. If you want to go that road, you can use our contact form to request a preversion of next release with that bug fixed (please also specify your version, essential or business):
www.hikashop.com/en/contact-us.html

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

  • Posts: 14
  • Thank you received: 0
12 years 10 months ago #42289

Thanks Nicolas, we are using the business edition.

This is the first time I've built a Joomla plugin, my hikashop plugin works just fine, but I did try to create the quantity price system plugin, and I couldn't get the hikashop_product_price_for_quantity_in_order() function to be called. The constructor was called, confirmed using J!dump plugin, also tried changing the plugin loading order.

Should I be including "if(!@include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')){ return false; }", extending a Hikashop class or using joomla.plugin to load hikashop code somewhere? I imagine this is probably the issue.

Could you paste an example system plugin snippet that invokes this function and also confirm where it should be in the filesystem, that would really help me.

I think this is my only option, as calculation is not a simple percentage (it's actually £1 discount per product before tax for every 5 products bought up to 40 products), and it also has to span several categories.

I see that the function is passed a reference to a product, it's no problem to apply the discount to each product for the current formula, but if the client needed a formula that would apply the discount to the total order, would that still be possible from this function?

Thanks for your time,

Jerry

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

  • Posts: 83103
  • Thank you received: 13416
  • MODERATOR
12 years 10 months ago #42447

The functions should be outside of the JPlugin class in your plugin. Here is an example:
www.hikashop.com/en/forum/2-general-talk...w-feature.html#24390

These functions are only for changing the prices of the products in the order/cart.
If you want that the formula add automatically a coupon to the cart, then you should not use these overrides but instead edit the file "cart" of the view "checkout" via the menu Display->Views and loop through the products array for your formula and then create a coupon in the database and load it into the cart (that can be done easily by adding the coupon code to the cart in the hikashop_cart table of the database and refreshing the current page.

The following user(s) said Thank You: Density5

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

  • Posts: 14
  • Thank you received: 0
12 years 10 months ago #42548

Thanks, Nicolas, the example really helps, I had defined the functions as methods of the plugin class. I will see if I can implement it this way now.

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

Time to create page: 0.068 seconds
Powered by Kunena Forum