Custom Price Based On Contents of Cart

  • Posts: 8
  • Thank you received: 1
11 years 2 weeks ago #169161

-- HikaShop version -- : 2.3.2
-- Joomla version -- : 3.3.3
-- PHP version -- : 5.4.31

I need Hikashop to display certain price levels (as assigned in the admin area) based on the presence of a particular item in the shopping cart. There is a 'membership fee' to get special (lower) prices on the products in this website I'm working on. I could, of course, handle this with ACLs in the admin area... but that doesn't help with newly arrived customers who don't even have an account yet... Basically, the idea here is if the cart does not contain item 'X' then they see price A (retail)... if the cart DOES contain item 'X' then they see price B (wholesale).

I've been hacking away at the custom price plugin... It gets me CLOSE to what I want... but I'm having some challenges. It would be perfect if I could hack that plugin to do the following:
A: Each time it's fired I cycle through the cart and check for X
B: If I find X then tell hikashop to use price B otherwise use default

As written the plugin brute-forces a price into the product object... I'd rather tell it to relax it's ACL filters as if the guest user had group Y membership. If this is not possible (or practical) then I could brute-force it - but I still need a way to access the shopping cart from inside the hikashop_product_price_for_quantity_in_cart() function.

Any suggestions?

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

  • Posts: 26274
  • Thank you received: 4045
  • MODERATOR
11 years 2 weeks ago #169240

Hi,

Like that I would recommend you to use the plugin "group after purchase" so the user group can change by buying a special product in your store.
But this feature won't work on the same order, because the user group will change after the order ; it will provide you the same feature but in two steps (two orders).

If you want to load the full cart, you can use

$cartClass = hikashop_get('class.cart');
$cart = $cartClass->loadFullCart();

Instead of the function "hikashop_product_price_for_quantity_in_cart" you can use a classical HikaShop plugin and the trigger "onBeforeCalculateProductPriceForQuantity".
The function give you the product object with his prices and you can modify it like you want.

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.057 seconds
Powered by Kunena Forum