How To Add Dynamic Product Option

Hello



How can I add dynamic option for a product.

I mean I want to add an extra option to the product in the product page based on a DB field value.



That is my plan for doing this:

1- Add a new hook 'get_product_options_post'.

2- In the function of this hook I will check the DB for some values.

3- Depending on the previous check I will show that extra option or not.



So, as you can see steps 1 and 2 are clear to me I'm just asking about step 3.

How can I do this?

And take into account that this extra option will also have a price modifier and its value is different depending on that DB check.



Waiting for your replies

hi Elsherif,



not clear why you need it, but cs-cart allows to create global options (menu Products → Options).

such options can be added to product in 2 ways: linked or unlinked. The linked way means that if you update global option (e.g. change any variant), it will be updated for all products to which the options is linked.



best regards,

WSA team

Why can't you just assign your dynamic option to the '$options' from the get_product_options_post hook?

[quote name=‘Damir (WSA-team)’ timestamp=‘1437411113’ post=‘223645’]

hi Elsherif,



not clear why you need it, but cs-cart allows to create global options (menu Products → Options).

such options can be added to product in 2 ways: linked or unlinked. The linked way means that if you update global option (e.g. change any variant), it will be updated for all products to which the options is linked.



best regards,

WSA team

[/quote]

I can’t use this because I want to add the option only in the one case I described (depending on a DB field value that can be changed by my addon) so if the admin changes this field and I’m using your solution the option won’t be dynamically deleted.

I hope it is clear to you and thanks for your reply :-)

[quote name='tbirnseth' timestamp='1437424947' post='223667']

Why can't you just assign your dynamic option to the '$options' from the get_product_options_post hook?

[/quote]

That will be my last solution … but as I said the option will have a price modifier so I want to benefit from the automatic price update function when option is checked and that one depends on the option id to work.

That would be my first choice and adding it there will be done before any of the cart calculation occurs so any price modifier will be included.

[quote name=‘tbirnseth’ timestamp=‘1437514061’ post=‘223832’]

That would be my first choice and adding it there will be done before any of the cart calculation occurs so any price modifier will be included.

[/quote]

You are right … but my option will not be stored in the DB and so it doesn’t have an ID and the automatic update function depends on option ID to apply the modifier.

Anyway I’m trying this now I hope it goes well ;-)

I have products to which can be added other products at their respective prices. For example, I offer gift baskets to which when you choose a design you are given the option to add flowers at $20.00, balloons at $7.00 and a plush toy (teddy bear, etc) at $10.00. These options apply to all of the gift basket designs. My problem isthat I want to change the price of each but don't know how to so that it makes the change for all at one time rather than my having to do it individually for each. Your help will be appreciated.

"hi Elsherif,

not clear why you need it, but cs-cart allows to create global options (menu Products -> Options).
such options can be added to product in 2 ways: linked or unlinked. The linked way means that if you update global option (e.g. change any variant), it will be updated for all products to which the options is linked"

I can't find any linking option in the global options selection for add new products or for linking exisitng products either?