2nd field on product option?

  • Posts: 137
  • Thank you received: 2
13 years 9 months ago #7487

Hi!

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:

[...]
$time = time();
if (preg_match("/1 year/i", $order->cart->products[$j]->order_product_options)) { 
				$time += ($oneyear); } 
			elseif (preg_match("/6 months/i", $order->cart->products[$j]->order_product_options)) {
				$time += ($oneyear / 2); }
[...]
So I search for dedictated periods but what if I want some special lifetimes like 1 day or 2 years or ... so I think this approach isn't so good, it would be better if i read the lifetime as an int in days, so I'm more flexible. My problem is now: how can I get such a variable in the product option? There is only one field for each option but I need a 2nd field like "order_product_option_code" where I can save the periode in days and not in words. So I can calculate with this value ...

Best regards

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
13 years 9 months ago #7489

Hi,

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.

  • Posts: 137
  • Thank you received: 2
13 years 9 months ago #7493

I tried this (with options instead of drop-down; that shouldn't matter, right?!) but the radio buttons were only displayed in the backend. I want the user to choose the period in the frontend and not to create a own product for every period.

Best regards

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
13 years 9 months ago #7494

If you want to have the custom fields on the product page, you need to create custom fields of the type "item". They are available in the Business edition.

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

  • Posts: 28
  • Thank you received: 0
13 years 9 months ago #8075

Hi!

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.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
13 years 9 months ago #8085

Hi,

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.

  • Posts: 137
  • Thank you received: 2
13 years 9 months ago #8466

Hi!

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:

a:2:{i:8;O:8:"stdClass":6:{s:25:"variant_characteristic_id";s:2:"11";s:18:"variant_product_id";s:2:"29";s:8:"ordering";s:1:"0";s:17:"characteristic_id";s:2:"11";s:24:"characteristic_parent_id";s:1:"8";s:20:"characteristic_value";s:7:"1 month";}s:13:"licenseperiod";s:7:"1 month";}

and not just only the value like 1 month?

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
13 years 9 months ago #8472

Yes. The whole characteristic information is stored.
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.

  • Posts: 137
  • Thank you received: 2
13 years 9 months ago #8665

I'm able to display the whole characteristig information with:

$res_product_options = $database->loadResultArray( 3 );
echo "Lizenz ohne unserialize: ".$res_product_options[0];

But using the "unserialize"-function returns an empty variable:
$res_product_options = $database->loadResultArray( 3 )
$obj = unserialize($res_product_options[0]);
$period = $obj->licenseperiod;
echo "Laufzeit: ".$period;

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
13 years 9 months ago #8666

You're missing a semi column after loadResultArray( 3 ) in your second code.
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.

  • Posts: 137
  • Thank you received: 2
13 years 9 months ago #8667

The missing semi column came from bad copy&paste :)

$res_product_options[0] contains the string I already posted:

a:2:{i:8;O:8:"stdClass":6:{s:25:"variant_characteristic_id";s:2:"12";s:18:"variant_product_id";s:2:"30";s:8:"ordering";s:1:"0";s:17:"characteristic_id";s:2:"12";s:24:"characteristic_parent_id";s:1:"8";s:20:"characteristic_value";s:6:"1 year";}s:13:"licenseperiod";s:6:"1 year";}

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.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
13 years 9 months ago #8669

Actually, it's not an object but an array. You will need to do this:
$period = $obj;

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

  • Posts: 137
  • Thank you received: 2
13 years 9 months ago #8973

Now I developed a Joomla User-Plugin which triggers automatically on "onUserLogin".

I was able to get the Hikashop User-ID with

$user_id =& hikashop::loadUser();
But I would also need the firstname, lastname and the company name. Is it possible to get these variables without a extra database query?

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
13 years 9 months ago #8975

That information isn't in the user table unless you created custom user fields for them but in the address table, so you will have to make a query for that.
Note that your users can have several addresses with several names...

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

Time to create page: 0.090 seconds
Powered by Kunena Forum