[Skip to main content](#vessel-content)

#   Calculate quantity (not price) with plugin

##

- **[insitevision](/forum/user/35045-insitevision "View insitevision's Profile")**
- [![insitevision's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/35045-insitevision "View insitevision's Profile") Topic Author
- [ Offline](/forum/user/35045-insitevision)

Less More

- Posts: 14
- Thank you received: 0
-
-

11 years 2 months ago [\#210494](#210494) by [insitevision](/forum/user/35045-insitevision "View insitevision's Profile")  *[Calculate quantity (not price) with plugin](/forum/26-product-category-display/878559-calculate-quantity-not-price-with-plugin#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&#95;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&#95;quantity&#95;width&#95;length plugin and changed the calculation to  This is working for the price. The price in the cart is showing the price of (x &#42; 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 &#42; Quantity  Adding 1 to the quantity will then add 1 packageprice to the total.  Kind regards, Eric Beernink")* was created by *[insitevision](/forum/user/35045-insitevision "View insitevision's Profile")*

-- 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
Code:

if(!empty($product-&gt;inhoud_pak)) $quantity = ceil(($quantity*$product-&gt;length*$product-&gt;width)/$product-&gt;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](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84Nzg1NTktY2FsY3VsYXRlLXF1YW50aXR5LW5vdC1wcmljZS13aXRoLXBsdWdpbj90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86290
- Thank you received: 14268
-
-

11 years 2 months ago [\#210501](#210501) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Calculate quantity (not price) with plugin](/forum/26-product-category-display/878559-calculate-quantity-not-price-with-plugin#210501 "-- 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&#95;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&#95;quantity&#95;width&#95;length plugin and changed the calculation to  This is working for the price. The price in the cart is showing the price of (x &#42; 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 &#42; Quantity  Adding 1 to the quantity will then add 1 packageprice to the total.  Kind regards, Eric Beernink")*

Hi,

Yes, that's possible.
As you can see in the code of the plugin, $quantity is a copy of $product-&gt;cart_product_quantity ( or $product-&gt;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-&gt;cart_product_quantity and that should do it.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84Nzg1NTktY2FsY3VsYXRlLXF1YW50aXR5LW5vdC1wcmljZS13aXRoLXBsdWdpbj90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[insitevision](/forum/user/35045-insitevision "View insitevision's Profile")**
- [![insitevision's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/35045-insitevision "View insitevision's Profile") Topic Author
- [ Offline](/forum/user/35045-insitevision)

Less More

- Posts: 14
- Thank you received: 0
-
-

11 years 2 months ago [\#210560](#210560) by [insitevision](/forum/user/35045-insitevision "View insitevision's Profile")  Replied by *[insitevision](/forum/user/35045-insitevision "View insitevision's Profile")* on topic *[Calculate quantity (not price) with plugin](/forum/26-product-category-display/878559-calculate-quantity-not-price-with-plugin#210560 "-- 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&#95;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&#95;quantity&#95;width&#95;length plugin and changed the calculation to  This is working for the price. The price in the cart is showing the price of (x &#42; 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 &#42; Quantity  Adding 1 to the quantity will then add 1 packageprice to the total.  Kind regards, Eric Beernink")*

Hi Nicolas,

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

After Code:

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

I added Code:

$product-&gt;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](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84Nzg1NTktY2FsY3VsYXRlLXF1YW50aXR5LW5vdC1wcmljZS13aXRoLXBsdWdpbj90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[lionel75](/forum/user/11856-lionel75 "View lionel75's Profile")**
- [![lionel75's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/11856-lionel75 "View lionel75's Profile")
- [ Offline](/forum/user/11856-lionel75)

Less More

- Posts: 846
- Thank you received: 92
-
-

11 years 2 months ago -  11 years 2 months ago [\#210565](#210565) by [lionel75](/forum/user/11856-lionel75 "View lionel75's Profile")  Replied by *[lionel75](/forum/user/11856-lionel75 "View lionel75's Profile")* on topic *[Calculate quantity (not price) with plugin](/forum/26-product-category-display/878559-calculate-quantity-not-price-with-plugin#210565 "-- 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&#95;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&#95;quantity&#95;width&#95;length plugin and changed the calculation to  This is working for the price. The price in the cart is showing the price of (x &#42; 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 &#42; Quantity  Adding 1 to the quantity will then add 1 packageprice to the total.  Kind regards, Eric Beernink")*

**where is plug in**
for reader , have a look also to this [ post](http://www.hikashop.com/forum/content-creation/866537-diff-prices-of-several-height-width-combinations.html) .
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 )

####  Attachment not found

**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 ?

####  Attachment not found

**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

Last edit: 11 years 2 months ago by [lionel75](/forum/user/11856-lionel75 "View lionel75's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84Nzg1NTktY2FsY3VsYXRlLXF1YW50aXR5LW5vdC1wcmljZS13aXRoLXBsdWdpbj90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Jerome](/forum/user/80-jerome "View Jerome's Profile")**
- [![Jerome's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar80.png)](/forum/user/80-jerome "View Jerome's Profile")
- [ Offline](/forum/user/80-jerome)
- HikaShop core developer

Less More

- Posts: 26394
- Thank you received: 4078
-
- [](http://obsi.dev)
-

11 years 2 months ago [\#210566](#210566) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[Calculate quantity (not price) with plugin](/forum/26-product-category-display/878559-calculate-quantity-not-price-with-plugin#210566 "-- 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&#95;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&#95;quantity&#95;width&#95;length plugin and changed the calculation to  This is working for the price. The price in the cart is showing the price of (x &#42; 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 &#42; Quantity  Adding 1 to the quantity will then add 1 packageprice to the total.  Kind regards, Eric Beernink")*

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](http://pasteboard.co/2s4HwiIQ.png)

Regards,

---

Jerome - Obsidev.com
HikaMarket &amp; HikaSerial developer / HikaShop core dev team.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84Nzg1NTktY2FsY3VsYXRlLXF1YW50aXR5LW5vdC1wcmljZS13aXRoLXBsdWdpbj90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop- Install &amp; Update- Product &amp; Category Display- Content Creation- Sales and Orders- - Orders management- - Reports &amp; Statistics- Customers- Checkout- Payment Methods- Shipping Methods- Import &amp; Export (CSV, XLS…)- Specific Features- - Affilation- - Taxes- - Wishlist- - Vote- - Carousel &amp; Slider- - Mass Actions- - Filters &amp; Search- - Discount &amp; Coupon- - Feature Request- Integrations- Showcase- General Talk about HikaShop- Development- - HikaShop 3.0 Beta- Translation- Commercial Jobs HikaShop Components- HikaMarket- - Market: Feature requests- - Market: How to?- - Market: Bug Report- HikaSerial- - General talk about HikaSerial- - Serial: Bug Report- - Serial: How to?- - Support en Français de HikaSerial (French Support)- - HikaSubscription- HikaAuction- - Auction: Feature requests- - Auction: How to?- - Auction: Bug report Hikashop around the world- Support en Français (French Support)- Russian- - FAQ. Курс выживания с Hikashop. Частые вопросы и о- - Расширения Hikashop- - Наши сайты на Hikashop- 日本語版サポート(Japanese Support)- Thai- German Archives- Bug Report- How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.166 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)

[](#top)
