- Posts: 137
- Thank you received: 2
2nd field on product option?
- emergentec
-
Topic Author
- Offline
I encountered the next problem in establashing my shop: I wrote a costum plugin (onAfterOrderCreate) to send some order information via SOAP to another server. This works but I have different product options which I need to catch, in this case the lifetime of a license.
My first approach was to create a product option where the user can choose the periode (e.g. 1 month, 6 months, 1 year) and in the plugin I wrote something like this:
Best regards
Please Log in or Create an account to join the conversation.
When you create a custom field of the type multiple dropdown or single dropdown, you have two columns for the values of the dropdown: Value and Title. The title is what will be displayed to the user, the Value is what will be stored in the database. That way, you could set the titles "1 year" and "3 days" with the values being 365 and 3.
Please Log in or Create an account to join the conversation.
- emergentec
-
Topic Author
- Offline
- Posts: 137
- Thank you received: 2
Best regards
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
We (I'm employee at emergentec) have already bought the business edtion
I just made this item custom field, it is displayed in the frontend, so far so good but I have some further questions about this:
1.) Every single option is displayed on every single product. That's not what I want, I want to choose on which product which option is displayed. Where/How to configure that?
2.) How can I adjust the price depending on the option chosen by the customer?
3.) Where is the option value stored in the checkout process? I need to read it in my plugin (onAfterOrderCreate)?
thanks and best regards!
Please Log in or Create an account to join the conversation.
1/ There is no such option at the moment.
2/ Price cannot be changed based on custom fields.
In such cases, you should use characteristics like you did in your first approach. The values of the characteristics can be displayed differently with a one or two lines modification in the file administrator/components/com_hikashop/types/characteristic.php but limiting custom item fields on some products and/or changing the price based on them will require a lot of changes.
3/ in :
foreach($order->cart->products as $product){
echo $product->custom_item_field_column_name;
}
Please Log in or Create an account to join the conversation.
- emergentec
-
Topic Author
- Offline
- Posts: 137
- Thank you received: 2
3) I found the content of the option field in the database in the field order_product_options. But when I have 3 different values like 1 day, 1 month, 1 year, why is it stored this way in the database:
and not just only the value like 1 month?
Please Log in or Create an account to join the conversation.
You can use the function unserialize on that data in order to get a php object that you will be able to use.
like this:
$obj = unserialize($data);
$period = $obj->licenseperiod;
Please Log in or Create an account to join the conversation.
- emergentec
-
Topic Author
- Offline
- Posts: 137
- Thank you received: 2
But using the "unserialize"-function returns an empty variable:
Please Log in or Create an account to join the conversation.
The unserialize function will transformed a serialized string into a php variable as long as the string is valid serialized data. So if you get an empty $obj it means that $res_product_options[0] does not contain the serialized string. It's a standard php function:
fr2.php.net/manual/en/function.unserialize.php
Please Log in or Create an account to join the conversation.
- emergentec
-
Topic Author
- Offline
- Posts: 137
- Thank you received: 2
$res_product_options[0] contains the string I already posted:
I tried to get the period with $period = $obj->characteristic_value; and $period = $obj->licenseperiod;
Please Log in or Create an account to join the conversation.
$period = $obj;
Please Log in or Create an account to join the conversation.
- emergentec
-
Topic Author
- Offline
- Posts: 137
- Thank you received: 2
I was able to get the Hikashop User-ID with
Please Log in or Create an account to join the conversation.
Note that your users can have several addresses with several names...
Please Log in or Create an account to join the conversation.