Decimal in Product Quantity (inventory/stock)

  • Posts: 201
  • Thank you received: 13
  • Hikashop Business
4 months 2 weeks ago #364919

-- HikaShop version -- : 5.1.2
-- Joomla version -- : 5.2.2
-- PHP version -- : 8.2.14
-- Browser(s) name and version -- : n/a
-- Error-message(debug-mod must be tuned on) -- : n/a

My client sells flooring - carpet, hardwood, etc - by the square foot. I've installed the Custom Quantity plugin to allow a customer to purchase a quantity with a decimal, but is there a way for me to set an inventory quantity in the product to include a decimal? And, then to maintain the remaining inventory to the decimal when the client purchases to the decimal?


3by400, Inc.
3by400.com
Websites that Work, Marketing that Matters

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

  • Posts: 83674
  • Thank you received: 13545
  • MODERATOR
4 months 2 weeks ago #364922

Hi,

The inventory quantity can only be an integer, so no decimals.
I'm afraid you won't be able to do what you want.

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

  • Posts: 1090
  • Thank you received: 12
  • Hikashop Business
1 month 1 week ago #366311

Hi,
On behalf of our client we run a daily csv import of product quantities from his ERP.
The client uses decimal quantities and as the stock quantities on hikashop are a whole number, the client asks us to implement a floor function.
What would be the quickest way to do this? Which file would we need to modify etc?
Thank you!

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

  • Posts: 83674
  • Thank you received: 13545
  • MODERATOR
1 month 1 week ago #366313

Hi,

Supposing that you're using the auto update products cron plugin for the import, before the line:

foreach($this->fields as $field){
in the file administrator/components/com_hikashop/helpers/import.php, you could add:
if(isset($product->product_quantity)) $product->product_quantity = (int)floor($product->product_quantity);
Ideally, instead of modifying the core file of HikaShop, you would create an override as per www.hikashop.com/support/documentation/6...ntation.html#classes
That way, you wouldn't have to redo the change after each update of HikaShop.

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

  • Posts: 1090
  • Thank you received: 12
  • Hikashop Business
2 weeks 19 hours ago #366689

Hi, Nicolas.
Following up on the topic, a good client of ours has expressed a strong interest in having decimal quantities for his eshop products for both backend stock and frontend order placement.
We would like to find a solution so that he can continue to use Joomla.
Would it be possible with a plugin to meet his requirements and how many hikashop files would they need to be changed?
Thank you!

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

  • Posts: 83674
  • Thank you received: 13545
  • MODERATOR
2 weeks 15 hours ago #366694

Hi,

Well, the simplest would be to leave the quantity as unlimited and then:
1. create a custom product field to store the stock with decimals.
2. create a custom item field to allow the customer to enter a quantity with decimals on the frontend
3. create a HikaShop plugin and implement different events to update the value, change the price, etc:
- with the onAfterProductQuantityCheck event, you can check that the requested quantity in the custom item field is smaller than the available stock in the custom product field:
www.hikashop.com/support/documentation/6...ProductQuantityCheck
- with the onBeforeCalculateProductPriceForQuantity or onAfterCalculateProductPriceForQuantity event, you can change the price of the product in the cart based on the value entered in the custom item field:
www.hikashop.com/support/documentation/6...ductPriceForQuantity
- with the onAfterOrderCreate and / or onAfterOrderUpdate events, you can update the value of the custom product field based on the value entered by the customer in the custom item field:
www.hikashop.com/support/documentation/6...l#onAfterOrderCreate

The main drawback of this solution is that you don't actually use the quantity system of HikaShop. So the quantity column in the cart / order will always be "1". It's possible to hide it (same with the normal quantity input field). Also, the "out of stock" or "waitlist" plugins won't take your custom product field into account.

However, the advantage is that you don't need to modify any core files of HikaShop. Just a plugin with 100 to 200 lines of code and 2 custom fields (and maybe some CSS to hide the quantity to 1 here and there ) should be enough.

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

Time to create page: 0.082 seconds
Powered by Kunena Forum