How to create a product with a NEGATIVE price

  • Posts: 329
  • Thank you received: 94
7 years 9 months ago #275073

-- HikaShop version -- : 2.6.4 AND 3.1.1
-- Joomla version -- : 3.7.4
-- PHP version -- : 5.6.31

Reposting this as our comment in an old thread was not answered. ( www.hikashop.com/support/forum/product-c...ce-value/275022.html )

We need to know how to do this under two different versions of HikaShop. Our client's highly customized site is currently running 2.6.4 today, and we'll be updating it by end of Q3 to HikaShop v3 series. Therefore, we want to understand how to handle this in each, in order to code most effectively for the future upgrade.

Here is the end goal. We've built an admin checkout so an admin can dynamically create/assign orders to users so the admin can take phone orders as if they are the customer. We want to dynamically create an order discount PRODUCT on the fly with explanation that an admin can apply as they are on the phone. One solution we came up with would be to create a couple of order custom fields then dynamically add an admin only product to the cart during checkout with the explanation as one custom field on the item and using the custom price plugin to add a negative product price (or positive if they want to charge extra for something like extra fast processing, etc). They can't use coupons for this as they want to have this ability on top of coupons.

We need to know how this can be handled in both versions, please.


~ Deb Cinkus, CEO

Polished Geek: more with monday․com
eCommerce Business Process Automation Experts

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

  • Posts: 83799
  • Thank you received: 13571
  • MODERATOR
7 years 9 months ago #275112

Hi,

Your solution to have a custom order field on the checkout so that the admin and enter the value he wants sounds good.
I would then have a custom plugin add a product to the cart dynamically with the trigger onAfterCartProductsLoad, pushing the price you want from the custom order field data.

Whether the price is positive or negative is not a problem. The only restriction that HikaShop enforces is that the total of the order must be >= to zero.

The main difference you'll have between HikaShop 2.6.4 and HikaShop 3 with this is that with HikaShop 3, the custom order field data is stored in $cart->cart_fields, while in HikaShop 2.6.4, the custom order field data is stored in $app->getUserState(HIKASHOP_COMPONENT.'.checkout_fields')

I would recommend to push the data directly in $cart in your onAfterCartProductsLoad and recalculate the total manually. That way, you won't have to deal with the cart cache and the product update/save functions of the cart which add the products to the cart in the database and have to also deal with a custom price override plugin.

The following user(s) said Thank You: PolishedGeek

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

Time to create page: 0.052 seconds
Powered by Kunena Forum