Calculate price by length of name in custom field.

  • Posts: 10
  • Thank you received: 0
10 years 10 months ago #176980

-- HikaShop version -- : 2.3.4
-- Joomla version -- : 3.3.3
-- PHP version -- : 5.4.16
-- Browser(s) name and version -- : all

Hi,

We have the business edition running.

-1
I have a shop and we can add names of fabrics and clothing.
The length of the name that the customer fills in a custom field must be mutliplied by a price per charachter of the name.
So a name of 3 characters is cheaper as a name of 10 characters.
How can i realise this in the hikashop.

-2
We have a boolean value YES/ NO for the customer that he can use to tell if he wants to have a name on the fabric.
If YES we want to have another field to show up that he vacan use to fill in the name, if NO the name field is hidden (See -1). Is there a way to hide and show fields.

Regards,

Anita

Last edit: 10 years 10 months ago by Babyzooi.

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

  • Posts: 84304
  • Thank you received: 13698
  • MODERATOR
10 years 10 months ago #176985

Hi,

1. You need to develop a small quantity price override plugin.
We have some documentation on that in our developer documentation:
www.hikashop.com/support/support/documen...tation.html#override
And you'll find an example of such price override plugin with the donation plugin:
demo.hikashop.com/index.php?option=com_h...show&cid=214&lang=jp

2. In your second custom field options screen, you can select your first custom field's "yes" value in the option "Display limited to". That way, the second field will only display when the first one is set to "yes".

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

  • Posts: 10
  • Thank you received: 0
10 years 10 months ago #177093

Thank you Nicolas,

Thank you for the quick answer.
I see it working in the donation example, but like to see the code example.
The custom field is easy as item and text with name amount.
Do you have a code example for the price that will depend of the amount of characters in a custom field.
Say each character will cost 1,-.
I'am trying to find my way, but this is new for me.

Regards,

Anita

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

  • Posts: 84304
  • Thank you received: 13698
  • MODERATOR
10 years 10 months ago #177107

Hi,

Suppose that you have a custom field called "amount" with the text entered by the user in it.
The donation plugin file path is plugins/system/custom_price/custom_price.php
There you can just add such line:
$product->amount = strlen($product->amount);

after the line:
if(!empty($product->amount)){

and it should work like you want.

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

  • Posts: 10
  • Thank you received: 0
10 years 10 months ago #177241

Hi Nicolas,

Thank you for your fast and detailed info.
I think i did exactly what you described, but still no results.
I have added 2 screenshots, one with the definition of the custom field and the other one with the result of the product page.
On the product page you see in the attachement shows the custom field 'amount' with value 'John'.
'John' has 4 characters and i like to add 4 times 1,- => 4,- to the base price of 7,95.
The total result should be 11,95, but it stays at the 7,95.
I hope you can help me further with this.

Regards,

Anita

Attachments:

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

  • Posts: 84304
  • Thank you received: 13698
  • MODERATOR
10 years 10 months ago #177252

Hi,

The price will only be changed for the product once it is in the cart with that custom field in the database. It's normal that you don't see the price on the product page to change at that point.

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

  • Posts: 10
  • Thank you received: 0
10 years 10 months ago #177389

Hi Nicolas,

I probably am doing something wrong.
I have created the custom field as ITEM with the name 'amount'.
The field is set to the category where it is shown too.
I have set the extra line $product->amount = strlen($product->amount); in the php file custom_price.php as you have told me behind the line if(!empty($product->amount)){ .
I showed you both definition screens.

No change of my price is seen in the product page were the custom field and the prices are included.
In the cart no change is seen.
When we go on with checking out the price stay the same and no change is noticed.

Regards,

Anita

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

  • Posts: 84304
  • Thank you received: 13698
  • MODERATOR
10 years 10 months ago #177419

Hi,

Then the problem lies with the plugin. Did you install it via the Joomla installer ? Did you activate it via the Joomla plugins manager ?

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

  • Posts: 10
  • Thank you received: 0
10 years 10 months ago #177549

Hi Nicolas,

I installed it by the as a joomla extension and activate it in in the joomla plugin manager.
I do not see the plugin in the menu 'hikashop-system-plugin' under 'new' in the hikashop extension.

What is going wrong?

Ragards,

Anita

Last edit: 10 years 10 months ago by Babyzooi.

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

  • Posts: 26274
  • Thank you received: 4045
  • MODERATOR
10 years 10 months ago #177688

Hi,

The HikaShop plugin interface is just to manage some specific plugins (for the moment, the plugin "user points" and more in the future).
If you want to manage generic plugins, you have to do that in the Joomla plugin manager.

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.

  • Posts: 10
  • Thank you received: 0
10 years 10 months ago #177701

Hi Jerome, Nicolas,

I have enabled the donation plugin now too.
Now i see the price with the amount of money as the length of the name.

Now i want to add this to the normal product price.
The product has a price set in the product definition.
The name to add to the product is extra and must be added upon the product price.
Example the product is 7,95 and the name (JOHN) that must be added has 4 characters.
The total price must be 7,95 + 4 = 11,95.
Now the result is 4,- instead of 11,95.

Hope you can clear this up for me too.

Regards,

Anita

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

  • Posts: 26274
  • Thank you received: 4045
  • MODERATOR
10 years 10 months ago #178210

Hi,

To do so, you first need to create an "custom item field" for the product category you want to affect the name selection by the user.
Then, you will need to duplicate the plugin "system / custom price" also called the "donation plugin".
This plugin force a product price depending an "item custom field" called "amount" ; in your case you want another algorithm for the price calculation, so you will need (or a developer) to write it.
Because it is a specific algorithm, it will result a custom plugin.

The development of such plugin require some PHP/Development knowledge.
The idea of your custom plugin is not to override the product price but to add a determined price to the original product price ; like a dynamic fee depending the value of an item custom field.
And if there is not item custom field for the product (or empty), you can simply exist the function without modifying the product object.

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.

  • Posts: 10
  • Thank you received: 0
10 years 10 months ago #178385

Dear all,
1)
I have changed the php code is the way i have documented in the file attached here.
Is this what you meant?
I created a new variable called $amount that holds the number of chars times 1.
That variable is added to the product price.

Now i have the amount calculated and the name for the ordering too.
That worked well i think.

2)
My second question is that the amount of characters now is multiplied by 1.
Can i enter a price per character say 0,50 cents instead of 1 cent.
I can add it direct in code that works.
However i like to have a field in the product definition were i can add the price per character.
How can i add a field in the procuct definition for the purpose.

3)
Can i use a characteristic as variant to decide to show a custom field or not.
I like to show the custom item field "amount" when the variant is YES and i like to hide when the variant is NO.


Can you check it for me.

Regards,

Ad

Attachments:
Last edit: 10 years 10 months ago by Babyzooi.

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

  • Posts: 26274
  • Thank you received: 4045
  • MODERATOR
10 years 10 months ago #178396

Hi,

More or less yes.
Some parts are good but I see some little "mistakes".
The best will be to just replace the first line you modified by

$my_amount = strlen($product->amount);
And then
foreach($product->prices as $k => $price){
  $product->amount = $product->prices[$k]->price_value + $my_amount;
So for the rest of the price assignations, the product->amount will be used correctly.

You can put a category filtering on the custom item field.
So you can use an hidden HikaShop category to regroup all product affected by the item custom field.

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.
Last edit: 10 years 10 months ago by Jerome.

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

  • Posts: 10
  • Thank you received: 0
10 years 10 months ago #178597

Hi Jerome,

When i make your changes i notice price differences in the webshop.
When i have a name of 4 characters (john) and the base price = 7,95 i see in the end price of the product is 7.95 + 3 euro = 10.95 and the total = 11.95. This is strange because it should be the same price.

The name is not "john" anymore but someting as 10.795.
I need to have the name "john" in the order to have the information so we can add the name to the product.
10.795 is not that what we can use.

My solution likes to work better.

I am puzzeling why your solution is having this effect.
I hope you can explain this for me.
You are the expert.

Can you make chocolate of this..??
I can't.

I like to know were we are going wrong.

Regards,

Anita

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

  • Posts: 26274
  • Thank you received: 4045
  • MODERATOR
10 years 10 months ago #178600

Hi,

Oh yes.. I forgot that point !

Please use instead :

foreach($product->prices as $k => $price){
  $product_amount = $product->prices[$k]->price_value + $my_amount;
And replace the rest of the
$product->amount
into
$product_amount

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.

  • Posts: 10
  • Thank you received: 0
10 years 10 months ago #178737

Hi guys,

I added a image that shows that there is still a lot wrong.

The base price of the product is 7,95
We have added a name with 4 characters that add 4,- to the price.
The price should be 11,95.

The image shows the end price of 11,95 (that is ok).
The product has a price of 10,57? in the image and that should be the same as 11,95.

The VAT (BTW) is 21% and shows 1,38 but is should be 2,22.
Still a lot to do.

I hope you can explain the differences.

Regards,

Anita

Attachments:

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

  • Posts: 26274
  • Thank you received: 4045
  • MODERATOR
10 years 10 months ago #178866

Hi,

At this moment the best is to only modify the product price without taxes and then reprocess the product with tax.
It require some development and even if the plugin "donation" is a good start, it does not provide all required features for your needs.

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.

  • Posts: 10
  • Thank you received: 0
10 years 9 months ago #179357

Hi Jerome,

Were can i find the calculation for the tax.
If i have the php file i can sort things out.
I need to change the calculation so that the option is included too.
I like to calculate the extra taxt caused by the extra price increase by the name option.

Regards,

Anita

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

  • Posts: 84304
  • Thank you received: 13698
  • MODERATOR
10 years 9 months ago #179544

Hi,

The taxes are calculated in the file administrator/components/com_hikashop/classes/currency.php

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

Time to create page: 0.091 seconds
Powered by Kunena Forum