Custom price plugin

  • Posts: 5
  • Thank you received: 0
9 years 4 months ago #208490

-- HikaShop version -- : latest

Hi!

I'm developing a custom plugin, and want to calculate the price using some custom fields with data filled by the user. For that I have created a plugin that catches the onBeforerCalculateProductPriceForQuantity()-trigger in which I get the $product-variable. But I realized I only get the custom fields assigned to the product. I also want the custom fields (and the values) assigned to the item.

How to do that?

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

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
9 years 4 months ago #208499

Hi,

The $product variable given to you in the onBeforerCalculateProductPriceForQuantity contains the custom item fields.
That's because it contains all the columns of the table hikashop_cart_product where you have one column per custom item field.
The only case where the custom item field value would not be in it would be it the column name of the custom item field correspond to the column name of another field (or one of the default column) of the product table as one would overwrite the value of the other during the creation of the $product object

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

  • Posts: 5
  • Thank you received: 0
9 years 4 months ago #208574

Well, maybe I'm using it wrong...

I want to define a custom field that the customer may enter a value in, from the frontend. On submitting the product to the cart I want to recalculate the price depending of the values in the custom fields. If i use a custom field tied to the product-table the customer dont get to set these values, and if I use a custom field tied to the items-table the user can set the field but I cant seem to get these values from the onBeforerCalculateProductPriceForQuantity()-trigger.

How can I accomplish this?

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

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
9 years 4 months ago #208578

Hi,

As I said, these values entered by the user in the custom item fields are in the $product given to that function as first parameter.
So either your code is wrong, or your plugin is not installed or activated.

What I would recommend is to take example on the plugin that we provide in the "How to sell products by Width and Length ?" section of our FAQ:
www.hikashop.com/support/support/documen...on/106-faq.html#cart
It works exactly like you want, by taking the value of two custom item fields in order to calculate the price of the product dynamically once the product is in the cart.

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

  • Posts: 5
  • Thank you received: 0
9 years 4 months ago #208672

I downloaded and installed your plugin, and put a die(print_r($product)); on the first row of the function. Then I can see that the fields are indeed in the products-object, but they dont get the values that the user has entered. Here is the first part of the object:

stdClass Object ( [cart_id] => 10 [user_id] => 0 [session_id] => sa050vt1l8atkd1tqkjbes6lh6 [cart_type] => cart [cart_current] => 0 [cart_share] => nobody [cart_name] => [cart_params] => [cart_product_id] => 18 [product_id] => 1 [cart_product_quantity] => 1 [cart_product_parent_id] => 0 [cart_product_modified] => 1436949412 [cart_product_option_parent_id] => 0 [cart_product_wishlist_id] => 0 [lngd] => [omtag] => [gavelheight] => 32 [aimm] => 23 [bimm] => 123 [cimm] => 13 [color] => 2 [materialfrontend] => [extra] => [fargen] => [product_parent_id] => 0 [product_name] => Fönsterbleck Enkel [product_description] =>

As you can see, some of my fields (like "lngd" and "omtag") is in the object but does not have a value. Some of the fields does have values, but not the values that I've entered from the product-view. Did I setup my fields wrong?

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

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
9 years 4 months ago #208682

Hi,

I don't know how you set them up, and you didn't give a link to the product page.
So I don't know.
If the fields are in the object, it means that they are correctly in the database and if some of them work, then the issue is really with how the others are setup.

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

  • Posts: 5
  • Thank you received: 0
9 years 4 months ago #208744

Hi!

They are all been set up in the same way, but only some of them is in the array. And for those that exists in the array, none of them has the value that the user has submitted. The site is under development and running on my machine locally, so I'm afraid I can't provide you with a link. Screenshots of how the fields are configured are attached, and also a view of the product-view, and of the $product-object. If you can give me an email I could put the site online and give you admin-credentials.

Attachments:

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

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
9 years 4 months ago #208834

Hi,

The settings look fine.
I see that the only two fields without a value are the ones which are not required. Is that linked ? If you change that setting, do you see any change ?
Could it be the product restriction ?
Other than that, could you check the hikashop_cart_product table entries ? Are the values of the fields saved there ?
If not, then the problem is not during the loading of the cart content, but during the saving of the add to cart action that there is something filtering out the value entered.
Did you implement other triggers, or other plugins which could remove these values during the add to cart action ?

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

  • Posts: 5
  • Thank you received: 0
9 years 4 months ago #209442

Hi!

Sorry for the delay.

I cannot see that the required field is linked. As i said, no matter what values i put in the input-boxes, the same values are retrieved in the object (and no, not the values that I've entered).

The values are not stored in the table, but I dont want them to be that either. I just want to use them to calculate the price, not storing data assigned to the product. No other events or triggers are used.

Is there a way that I could pay you for some support, put the site online and let you guys check?

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

  • Posts: 12953
  • Thank you received: 1778
9 years 4 months ago #209448

Hello,

Is there a way that I could pay you for some support, put the site online and let you guys check?

Sure I can do it for you, so if you're interested I just sent you my private email address through a private message so that we can talk about it.

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

Time to create page: 0.091 seconds
Powered by Kunena Forum