Bottle deposit and base price information

  • Posts: 30
  • Thank you received: 3
  • Hikashop Business
2 months 5 days ago #365624

Hi!

We're looking for an e-commerce solution based on Joomla. Since HikaShop is well know in the last years, I would give it a try. But there are two things I'm not sure about.

#1 Bottle deposit

I want to create an online shop for a "Drinks Market". This market is based in Germany. Here you have to handle with "bottle deposit". This is an additional price per product, that have to be displayed on the product listings, product details page, shopping cart, order mail and invoice.

As far as I know, HikaShop does not offer such an extension.

But maybe it can be realized with HikaShop. Would it be possible to use custom fields (for products) for deposit values? These deposit values have to be displayed _and_ calculated as SUMMARIZED deposit value in the shopping cart (and order mail, invoice).

One example:
Let's say, we have two products in the shopping cart...

product price 1 = 10,00 €
deposit price 1 = 3,00 €
product price 2 = 5,00 €
deposit price 2 = 1,00 €

The shopping cart shows the product prices (single and summarized, as per default) and adds another line "deposit", that shows the sum of all deposit prices (in the example: 4,00 €). So the final result is the summarized price of 19,00 €.

#2 Base price information

Here in germany exists a regulation for price information ("Preisangabenverordnung" -> "Price Indication Ordinance" or "base price").
It means, that if we sell packages or goods by weight/volume/quantitiy/bulk we have to display the base price per unit.

One example:
A product - let's say a water bottle - contains 0,5 l. The price is 0,90 €. On the product listing page and the product details page the following has to be displayed:

Price: 0,90 € (as usually)
Content: 0,5 Litre (1,80 € / 1 Litre)

Now I try to describe the need..

For the configuration (in the backend) I would need two fields:

[UNIT_VALUE] - in my example "0,5"
[UNIT_BASE_VALUE] - in my example "1"

Now we need a little calculation for the base price per unit: [BASE_PRICE] = [ARTICLE_PRICE] / [UNIT_VALUE]
Now we need to display the result in the frontend - on following pages: ARTICLE_LISTINGS and ARTICLE_DETAIL_PAGE - like this:

Content: [UNIT_VALUE] [UNIT] ([BASE_PRICE] € / [UNIT_BASE_VALUE] [UNIT])
... and now with values:
Content: 0.5 Litre (1,80 € * / 1 Liter)

In the frontend: This information has to be displayed directly near the price information (in the html code: mainly directly after the price - with it's own css class for styling).

What do you think? Can HikaShop achive these jobs? ;)


Cheers
Rusty

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

  • Posts: 83599
  • Thank you received: 13531
  • MODERATOR
2 months 5 days ago #365625

Hi,

1.
You can do that with a custom product field ( www.hikashop.com/support/documentation/4...shop-field-form.html ) and the cart fee plugin ( www.hikashop.com/marketplace/product/279-cart-fee.html ).
With the custom field, you can fill in a fee in each product, and have it displayed on the listing / product page with the display settings of the custom field.
And with the cart fee plugin, you can have a formula to automatically calculate the sum of the fee of each product in the cart and add it as an extra line between the subtotal and the total.
So no need for a specific extension to do that since you can easily set this up with these more general features / plugin.

2. The HikaShop configuration has a setting "Display the cost per weight unit":
www.hikashop.com/support/documentation/5...html#display_product
If you activate it, the system will automatically display the cost per weight unit. For example, with it, you can configure a price of 12€ and a weight of 2KG. Then, HikaShop will automatically display "6€ per KG" on the product details page after the price with an extra span HTML element with the class hikashop_product_price_per_weight_unit
This is done in the view file product / listing_price which you can edit via the menu Display>Views if you need to extend it to support listings, use custom product fields instead of the weight / weight unit, etc.
It should be relatively easy, even if you have no PHP knowledge.
For example, if you want to use a custom product field instead of the weight of the product, you can just change the several instances of "product_weight" in that view file to use the column name of your custom field.
And if you want to add it to the listings too, you can just change the line:

if(!empty($this->element->product_id) && isset($this->row->product_weight) && bccomp(sprintf('%F',$this->row->product_weight), 0, 3)) {
to:
if(isset($this->row->product_weight) && bccomp(sprintf('%F',$this->row->product_weight), 0, 3)) {

The following user(s) said Thank You: Rusty

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

  • Posts: 30
  • Thank you received: 3
  • Hikashop Business
2 months 5 days ago #365628

@nicolas Thank you for your fast reply! I will check it out!

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

  • Posts: 30
  • Thank you received: 3
  • Hikashop Business
2 days 1 hour ago #366649

nicolas wrote: And with the cart fee plugin, you can have a formula to automatically calculate the sum of the fee of each product in the cart and add it as an extra line between the subtotal and the total.

Okay ... I bought the plugin. But I struggle with the use.
I have to set a condition and a formula. But not sure how exactly to do.

I created a custom field "pfand" as text. And filled it with a value (a price, maybe: 3.00).

Then I went to the fee plugin.
I think my condition must be something like "{product.pfand}==1" or so ... because the fee should only be calculated if the custom field is filled.
The value of my field (pfand) is displayed in the cart - but only as single value. If I raise the amount of the product, it remains by its single price.

I have to calculate the value * amount of product - for each product. The sum of the value (pfand) must be displayed in a separate line in the cart.
For the formula I need help, please! :-)
I tried this: abs({product.pfand})*{product.price} ... but doesn't work. The value of "pfand" is not multiplied by the amount of the product. And the line "sum of pfand" is missing too. Need help!

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

  • Posts: 83599
  • Thank you received: 13531
  • MODERATOR
1 day 13 hours ago #366652

Hi,

If you enter a condition like "{product.pfand}==1" then the formula will only be taken into account if the value of pfand is "1" exactly.
So if you have "3" for it in the product in the cart, then the formula will be ignored.

If you leave the condition setting empty, then the formula will be taken into account. So I think you want to leave it empty in your case.

Your formula looks good if you want the fee to be equal to the sum of the product prices times the pfand value.

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

  • Posts: 30
  • Thank you received: 3
  • Hikashop Business
1 day 11 hours ago #366659

nicolas wrote: If you enter a condition like "{product.pfand}==1" then the formula will only be taken into account if the value of pfand is "1" exactly.
So if you have "3" for it in the product in the cart, then the formula will be ignored.


Ah okay, missunderstood the principles. I thought the boolean means "1" is true. Wasn't aware that it checks the exact value.

nicolas wrote: If you leave the condition setting empty, then the formula will be taken into account. So I think you want to leave it empty in your case.

Your formula looks good if you want the fee to be equal to the sum of the product prices times the pfand value.


Hm ... if I leave the condition empty and use only the formula which is - as you said - good, then the whole website is broken. When I press F5, I get the following error:
0
Unsupported operand types: string + float

Go Home

What to do? :-)

P.S. I read the plugin info text again. And now I'm confused a little bit. You suggested to leave the conditions empty. But the info text says:
"... if you leave the condition empty, the formula will be ignored." Hm ...

Last edit: 1 day 10 hours ago by Rusty.

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

  • Posts: 83599
  • Thank you received: 13531
  • MODERATOR
1 day 8 hours ago #366665

Hi,

First, you need to activate the "debug" setting of the Joomla backend configuration page in order to get the full error message.
The abbreviated message you provided doesn't provide enough information to be able to say what the problem is.

Also, please provide a screenshot of the settings of your custom field and of the settings of the cart fees plugin please.

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

  • Posts: 30
  • Thank you received: 3
  • Hikashop Business
1 day 7 hours ago #366668

@nicolas
I just realised something. Could it be a problem that the custom field is type "text"? If so, what field type should I use instead? Something like "integer" is not supported.

Here the debug info:

ERROR 0 - Unsupported operand types: string + float in /var/www/path_to_website/plugins/hikashop/fees/fees.php:117
Call Stack
#	Function	Location
1	()	JROOT/plugins/hikashop/fees/fees.php:117
2	plgHikashopFees->_replaceProductTags()	JROOT/plugins/hikashop/fees/fees.php:75
3	plgHikashopFees->onAfterCartShippingLoad()	JROOT/libraries/src/Plugin/CMSPlugin.php:289
4	Joomla\CMS\Plugin\CMSPlugin->{closure:Joomla\CMS\Plugin\CMSPlugin::registerLegacyListener():273}()	JROOT/libraries/vendor/joomla/event/src/Dispatcher.php:454
5	Joomla\Event\Dispatcher->dispatch()	JROOT/libraries/src/Application/EventAware.php:111
6	Joomla\CMS\Application\WebApplication->triggerEvent()	JROOT/administrator/components/com_hikashop/classes/cart.php:1448
7	hikashopCartClass->getFullCart()	JROOT/components/com_hikashop/views/product/view.html.php:2522
8	ProductViewProduct->cart()	JROOT/components/com_hikashop/views/product/view.html.php:29
9	ProductViewProduct->display()	JROOT/administrator/components/com_hikashop/helpers/helper.php:937
10	hikashop_getLayout()	JROOT/modules/mod_hikashop_cart/mod_hikashop_cart.php:73
11	include()	JROOT/libraries/src/Dispatcher/ModuleDispatcher.php:52
12	Joomla\CMS\Dispatcher\ModuleDispatcher::{closure:Joomla\CMS\Dispatcher\ModuleDispatcher::dispatch():43}()	JROOT/libraries/src/Dispatcher/ModuleDispatcher.php:55
13	Joomla\CMS\Dispatcher\ModuleDispatcher->dispatch()	JROOT/libraries/src/Helper/ModuleHelper.php:289
14	Joomla\CMS\Helper\ModuleHelper::renderRawModule()	JROOT/libraries/src/Helper/ModuleHelper.php:160
15	Joomla\CMS\Helper\ModuleHelper::renderModule()	JROOT/libraries/src/Document/Renderer/Html/ModuleRenderer.php:99
16	Joomla\CMS\Document\Renderer\Html\ModuleRenderer->render()	JROOT/libraries/astroid/framework/library/astroid/Document.php:650
17	Astroid\Document->_moduleId()	JROOT/libraries/astroid/framework/library/astroid/Document.php:617
18	Astroid\Document->loadModule()	JROOT/libraries/astroid/framework/elements/module_position/module_position.php:22
19	include()	JROOT/libraries/src/Layout/FileLayout.php:128
20	Joomla\CMS\Layout\FileLayout->render()	JROOT/libraries/astroid/framework/library/astroid/Element/Element.php:62
21	Astroid\Element\Element->_content()	JROOT/libraries/astroid/framework/library/astroid/Element/Element.php:51
22	Astroid\Element\Element->render()	JROOT/libraries/astroid/framework/library/astroid/Element/Column.php:46
23	Astroid\Element\Column->render()	JROOT/libraries/astroid/framework/library/astroid/Element/Row.php:46
24	Astroid\Element\Row->render()	JROOT/libraries/astroid/framework/library/astroid/Element/Section.php:27
25	Astroid\Element\Section->render()	JROOT/libraries/astroid/framework/library/astroid/Element/Layout.php:37
26	Astroid\Element\Layout::render()	JROOT/libraries/astroid/framework/frontend/document/body.php:93
27	include()	JROOT/libraries/src/Layout/FileLayout.php:128
28	Joomla\CMS\Layout\FileLayout->render()	JROOT/libraries/astroid/framework/library/astroid/Document.php:130
29	Astroid\Document->include()	JROOT/templates/astroid_template_two/index.php:35
30	require()	JROOT/libraries/src/Document/HtmlDocument.php:731
31	Joomla\CMS\Document\HtmlDocument->_loadTemplate()	JROOT/libraries/src/Document/HtmlDocument.php:785
32	Joomla\CMS\Document\HtmlDocument->_fetchTemplate()	JROOT/libraries/src/Document/HtmlDocument.php:622
33	Joomla\CMS\Document\HtmlDocument->parse()	JROOT/libraries/src/Application/CMSApplication.php:1106
34	Joomla\CMS\Application\CMSApplication->render()	JROOT/libraries/src/Application/SiteApplication.php:761
35	Joomla\CMS\Application\SiteApplication->render()	JROOT/libraries/src/Application/CMSApplication.php:311
36	Joomla\CMS\Application\CMSApplication->execute()	JROOT/includes/app.php:58
37	require_once()	JROOT/index.php:32

Attachments:
Last edit: 1 day 7 hours ago by Rusty.

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

  • Posts: 83599
  • Thank you received: 13531
  • MODERATOR
1 day 5 hours ago #366671

Hi,

No, the problem is not that the type of the custom field is "text".
It's actually a bug with the cart fees plugin and the use of the {product.price} tag.
I've made a patch for it.
Download again the install package of the plugin on our website and install it on yours and you should not have that error anymore.

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

  • Posts: 30
  • Thank you received: 3
  • Hikashop Business
1 day 1 hour ago #366679

nicolas wrote: It's actually a bug with the cart fees plugin and the use of the {product.price} tag.
I've made a patch for it.
Download again the install package of the plugin on our website and install it on yours and you should not have that error anymore.

I guess it's not fixed. :-(
0
abs(): Argument #1 ($num) must be of type int|float, string given

Go Home
ERROR 0 - abs(): Argument #1 ($num) must be of type int|float, string given in /var/www/path_to_website/administrator/components/com_hikashop/inc/expression.php:348
Call Stack
#	Function	Location
1	()	JROOT/administrator/components/com_hikashop/inc/expression.php:348
2	abs()	JROOT/administrator/components/com_hikashop/inc/expression.php:348
3	HikashopExpressionInc->pfx()	JROOT/administrator/components/com_hikashop/inc/expression.php:80
4	HikashopExpressionInc->evaluate()	JROOT/plugins/hikashop/fees/fees.php:276
5	plgHikashopFees->_evaluate()	JROOT/plugins/hikashop/fees/fees.php:77
6	plgHikashopFees->onAfterCartShippingLoad()	JROOT/libraries/src/Plugin/CMSPlugin.php:289
7	Joomla\CMS\Plugin\CMSPlugin->{closure:Joomla\CMS\Plugin\CMSPlugin::registerLegacyListener():273}()	JROOT/libraries/vendor/joomla/event/src/Dispatcher.php:454
8	Joomla\Event\Dispatcher->dispatch()	JROOT/libraries/src/Application/EventAware.php:111
9	Joomla\CMS\Application\WebApplication->triggerEvent()	JROOT/administrator/components/com_hikashop/classes/cart.php:1448
10	hikashopCartClass->getFullCart()	JROOT/components/com_hikashop/views/product/view.html.php:2522
11	ProductViewProduct->cart()	JROOT/components/com_hikashop/views/product/view.html.php:29
12	ProductViewProduct->display()	JROOT/administrator/components/com_hikashop/helpers/helper.php:937
13	hikashop_getLayout()	JROOT/modules/mod_hikashop_cart/mod_hikashop_cart.php:73
14	include()	JROOT/libraries/src/Dispatcher/ModuleDispatcher.php:52
15	Joomla\CMS\Dispatcher\ModuleDispatcher::{closure:Joomla\CMS\Dispatcher\ModuleDispatcher::dispatch():43}()	JROOT/libraries/src/Dispatcher/ModuleDispatcher.php:55
16	Joomla\CMS\Dispatcher\ModuleDispatcher->dispatch()	JROOT/libraries/src/Helper/ModuleHelper.php:289
17	Joomla\CMS\Helper\ModuleHelper::renderRawModule()	JROOT/libraries/src/Helper/ModuleHelper.php:160
18	Joomla\CMS\Helper\ModuleHelper::renderModule()	JROOT/libraries/src/Document/Renderer/Html/ModuleRenderer.php:99
19	Joomla\CMS\Document\Renderer\Html\ModuleRenderer->render()	JROOT/libraries/astroid/framework/library/astroid/Document.php:650
20	Astroid\Document->_moduleId()	JROOT/libraries/astroid/framework/library/astroid/Document.php:617
21	Astroid\Document->loadModule()	JROOT/libraries/astroid/framework/elements/module_position/module_position.php:22
22	include()	JROOT/libraries/src/Layout/FileLayout.php:128
23	Joomla\CMS\Layout\FileLayout->render()	JROOT/libraries/astroid/framework/library/astroid/Element/Element.php:62
24	Astroid\Element\Element->_content()	JROOT/libraries/astroid/framework/library/astroid/Element/Element.php:51
25	Astroid\Element\Element->render()	JROOT/libraries/astroid/framework/library/astroid/Element/Column.php:46
26	Astroid\Element\Column->render()	JROOT/libraries/astroid/framework/library/astroid/Element/Row.php:46
27	Astroid\Element\Row->render()	JROOT/libraries/astroid/framework/library/astroid/Element/Section.php:27
28	Astroid\Element\Section->render()	JROOT/libraries/astroid/framework/library/astroid/Element/Layout.php:37
29	Astroid\Element\Layout::render()	JROOT/libraries/astroid/framework/frontend/document/body.php:93
30	include()	JROOT/libraries/src/Layout/FileLayout.php:128
31	Joomla\CMS\Layout\FileLayout->render()	JROOT/libraries/astroid/framework/library/astroid/Document.php:130
32	Astroid\Document->include()	JROOT/templates/astroid_template_two/index.php:35
33	require()	JROOT/libraries/src/Document/HtmlDocument.php:731
34	Joomla\CMS\Document\HtmlDocument->_loadTemplate()	JROOT/libraries/src/Document/HtmlDocument.php:785
35	Joomla\CMS\Document\HtmlDocument->_fetchTemplate()	JROOT/libraries/src/Document/HtmlDocument.php:622
36	Joomla\CMS\Document\HtmlDocument->parse()	JROOT/libraries/src/Application/CMSApplication.php:1106
37	Joomla\CMS\Application\CMSApplication->render()	JROOT/libraries/src/Application/SiteApplication.php:761
38	Joomla\CMS\Application\SiteApplication->render()	JROOT/libraries/src/Application/CMSApplication.php:311
39	Joomla\CMS\Application\CMSApplication->execute()	JROOT/includes/app.php:58
40	require_once()	JROOT/index.php:32

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

  • Posts: 83599
  • Thank you received: 13531
  • MODERATOR
13 hours 48 minutes ago #366681

Hi,

That's not the same error. The previous error has been fixed by my patch. Unfortunately, I can't fix errors I didn't see yet :)
Now, the new error says that you apparently have something which is not a number in the pfand custom field in one of the products.

Change the formula to :

abs(decimal({product.pfand}))*{product.price}
and it should prevent the error from happening as it will force the conversion of the string to a number.
Now, that also means that you might not get the result you expect for the calculation because converting a string to a number can lead to strange results based on what you have in the string. So you might have to check what you have in the custom field of the products to make sure you don't have spaces at the beginning or the end for example, only numbers.

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

  • Posts: 30
  • Thank you received: 3
  • Hikashop Business
12 hours 40 minutes ago #366685

nicolas wrote: Unfortunately, I can't fix errors I didn't see yet :)


Sorry, not meant to be a reproach!

nicolas wrote: Now, the new error says that you apparently have something which is not a number in the pfand custom field in one of the products.


I found the problem: I typed in "3,75" instead of "3.75".
This problem comes to account because I changed the decimal system in the currencies configuration. I have replaced "," by "." and vice versa. But the new custom field doesn't "know" this. I think I need to change the formula to convert the "." to "," so that the formula could calculate correctly.

Here I need help (if I think the right way). How to change to formula so that it can convert the custom field decimal system?

Next: The formula works ... more or less as expected. Currently the value of the custom field is multiplied by the product price. I replaced "product.price" with "order.price" for testing reasons. I think I have to multiply the custom field value with the product quantitiy. But I could not find the correct variable. I tried "product.quantity" but this doesn't work.

What do I want to achive?
Let's talk about the cart view ...

Each product line has [custom field] and [quantity] and [price]
-> for each line I have to calculate: [custom field sum] = [custom field] * [quantity]

The summary line of the cart already contains a "sum field" for the custom field. That is great. But it works not as needed.
Here I need: SUM("all product lines [custom field sum]

example of a cart:
IMG -- PRODUCT NAME -- CUSTOM FIELD -- SINLGE PRICE -- QUANTITY -- TOTAL PRICE
------------------------------------------------------------------------------
img  -- product 1   -- 3,75         -- 8,80         -- 2        -- 17,60
img  -- product 2   -- 2,00         -- 8,80         -- 1        --  8,80
------------------------------------------------------------------------------
Subtotal                                                           26,40
Sum of Custom fields                                                9,50
TAX 19%                                                             4,22
------------------------------------------------------------------------------
Total                                                              32,15

How to achive this?

And here comes another important thing: How to apply the tax configuration to the custom field?
"Technical - financial" correct would it be if the custom field's tax is linked to the tax configuration of its product. How to achive this?

In this case we would calculate: ( ( [SUBTOTAL] + [SUM OF CUSTOM FIELDS] ) * TAX ) / 100 * TAX
In the example cart above, the correct TAX would be: 5,73

Last edit: 12 hours 26 minutes ago by Rusty.

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

  • Posts: 83599
  • Thank you received: 13531
  • MODERATOR
7 hours 38 minutes ago #366690

Hi,

1. If you use the "decimal" function, as I have proposed in my previous message, it should properly take into account the comma.

2. If you want the fee to be the sum of the value in the custom field times the quantity of the product in the cart, you want to use this:

abs(decimal({product.pfand}))*{product.cart_product_quantity}

3. The tax amount cannot, at the moment, take into account the fee added by the plugin. This would require adding an extra option to the plugin to be able to select the tax category, and then some code modifications to process the taxes on the fee when it is added to the cart.
What you could do instead for now would be to add a second formula:
abs(decimal({product.pfand}))*{product.cart_product_quantity}*0.19
with the label "TAX 19% on pfand fee" or something like that.
That way you would have rows like this:
subtotal
pfand fee
pfand fee tax
rest of the tax
total

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

  • Posts: 30
  • Thank you received: 3
  • Hikashop Business
6 hours 45 minutes ago #366699

nicolas wrote: 1. If you use the "decimal" function, as I have proposed in my previous message, it should properly take into account the comma.

2. If you want the fee to be the sum of the value in the custom field times the quantity of the product in the cart, you want to use this:

abs(decimal({product.pfand}))*{product.cart_product_quantity}


Great! Works as expected! Thank you! :)

nicolas wrote: 3. The tax amount cannot, at the moment, take into account the fee added by the plugin. This would require adding an extra option to the plugin to be able to select the tax category, and then some code modifications to process the taxes on the fee when it is added to the cart.
What you could do instead for now would be to add a second formula:

abs(decimal({product.pfand}))*{product.cart_product_quantity}*0.19
with the label "TAX 19% on pfand fee" or something like that.
That way you would have rows like this:
subtotal
pfand fee
pfand fee tax
rest of the tax
total


Hm ... but what if several products have different tax? Let's say we have "Beer" (tax is 19%). Then we have "Milk" (tax is 7%). The tax of the custom field fee must match the tax of the based product. Thing is, I have only these two taxes. Is there any way to create a formula that checks what tax the product has and then use either the 19%-formula or the 7%-formula?

Last edit: 6 hours 45 minutes ago by Rusty.

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

  • Posts: 83599
  • Thank you received: 13531
  • MODERATOR
3 hours 28 minutes ago #366701

Sure. Create another custom product field where you provide the tax rate in each product, 0.19 or 0.07
Then, instead of 0.19 in the formula, you can use the tag of that custom product field:

abs(decimal({product.pfand}))*{product.cart_product_quantity}*{product.xxx}
where xxx is the column name of that new custom product field.

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

Time to create page: 0.130 seconds
Powered by Kunena Forum