Calculate quantity (not price) with plugin

  • Posts: 14
  • Thank you received: 0
10 years 1 month ago #210494

-- HikaShop version -- : 2.5.0
-- Joomla version -- : 3.4.3
-- PHP version -- : 5.4.40
-- Browser(s) name and version -- : Firefox 39

Hi,

I'm currently working on a site where products (floors) are priced per m2 (square meter) but are sold per package.
The contents per package is variable per product.

I added a custom field (inhoud_pak) which contains the number of m2 in the package.

Customers need to be able to enter the lengt and width of the floor. Based on that length and width I want the quantity to change.

I dowloaded and installed the custom_quantity_width_length plugin and changed the calculation to

if(!empty($product->inhoud_pak)) $quantity = ceil(($quantity*$product->length*$product->width)/$product->inhoud_pak);

This is working for the price. The price in the cart is showing the price of (x * packageprice) but the quantity is still showing 1. So the quantity is linked to the calculated price (adding 1 to the quantity will double the calculated price).

Is it possible to not calculate the price but the quantity (number of packages needed) and automatically change the quantity to the number of packages needed?

The cart would then be showing:

Name Product: name
Unit price: price per package
Quantity: calculated quantity
Total: Unit price * Quantity

Adding 1 to the quantity will then add 1 packageprice to the total.

Kind regards,
Eric Beernink

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

  • Posts: 84305
  • Thank you received: 13700
  • MODERATOR
10 years 1 month ago #210501

Hi,

Yes, that's possible.
As you can see in the code of the plugin, $quantity is a copy of $product->cart_product_quantity ( or $product->order_product_quantity ) which is where the quantity of the product in the cart ( or order ) is stored.
So on top of changing $quantity, change $product->cart_product_quantity and that should do it.

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

  • Posts: 14
  • Thank you received: 0
10 years 1 month ago #210560

Hi Nicolas,

Thank you for your answer. Changing $product->cart_product_quantity works, but changing the quantity in the cart still returns wrong values:

After

if(!empty($product->inhoud_pak)) $quantity = ceil(($quantity*$product->length*$product->width)/$product->inhoud_pak);
I added
$product->cart_product_quantity = $quantity;
Now the cart is showing the right price and quantity.

Changing the quantity still goes wrong. For example, length = 9 and width = 2 would need 4 packages.
In the cart this is showing allright; quantity = 4 and the price is 4 * package price. But changing the quantity (if a clients wants 1 package extra) in the cart to 5 (and refresh) shows quantity = 18 and the price to 18 * package price.

How can this be corrected?

Kind regards,
Eric

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

  • Posts: 846
  • Thank you received: 92
10 years 1 month ago #210565

where is plug in
for reader , have a look also to this post .
what is strange is that this post speak about hikashop custom quantity plugin and when i go to plugin manager to search it i don't have any ?
Where is locate the plug in ?
which is the name of the php file to edit ? ( if unique then i could search it's location on my OS filesystem )




the logic for choose quantity not by product quantity but other fields
-Does this kind of logic can be implemented in a general way by hikashop team ?
-people don't buy the quantities they need but higher quantities if they do some mistakes !!
-Does product package are unique for one type of model ( square red) or many size package ?
if model exist in many package size , people should be able to mix product pakage of the same model. in a way variant can be package of same model but compute has to be compute refer to variant product not stand alone product !!
variant that support price could be quantity name and value filed in "m2" . Does varient value can be use to compute quantity of variant name the end user need ?



logic use in this post
What is the logic in this post to manage compute/"calculate " Quantity .
The dev add to hks product a custom field and use it for create different product that share in common the same motif1 . so motif1 is available in product1 and product2 and so don't go/use variant way !


regard's

Attachments:
Last edit: 10 years 1 month ago by lionel75.

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

  • Posts: 26274
  • Thank you received: 4045
  • MODERATOR
10 years 1 month ago #210566

Hi,

@insitevision
If you base your algorithm to calculate the quantity using the quantity ; you will have for sure an exponential increment.

@lionel75
pasteboard.co/2s4HwiIQ.png

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