Split Up Custom Items in default.php

  • Posts: 20
  • Thank you received: 0
11 years 4 months ago #108394

Hi,
I've spent a couple days on this now and all I can do is duplicate the entire block of custom items with as little as 2 lines of code my default.php Product Page.

I want to move only one specific field to the right part of the default.php. Although I did find some discussion about displaying custom items, there is not enough detail to get the right syntax for just the one row.

My custom field name is "includemyreturnaddress", it's id is 63 and it's a yes or no, with a "no" default. It might be just the way I am constructing the span id or the echo ... but i'm getting bupkas.

an example would be most appreciated and I'm sure I'll be able to apply the same method to the other fields as I don't want this field to repeat in the main part ...

Thanks in advance

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

  • Posts: 13201
  • Thank you received: 2322
11 years 4 months ago #108411

Hi,

You can unpublish the custom field in the frontend, then edit the view displaying the product, generally "product / show_default" and add a code like:

<input id="includemyreturnaddress_yes" type="radio" onclick="hikashopToggleFields(this.value,'includemyreturnaddress','item',0);" value="yes" name="data[item][includemyreturnaddress]"></input>
<label for="includemyreturnaddress_yes">yes</label>
<input id="includemyreturnaddress_no" type="radio" onclick="hikashopToggleFields(this.value,'includemyreturnaddress','item',0);" value="no" name="data[item][includemyreturnaddress]"></input>
<label for="includemyreturnaddress_no">no</label>

The following user(s) said Thank You: LenaK

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

  • Posts: 20
  • Thank you received: 0
11 years 4 months ago #108510

Oh Thank You !
I cannot express a greater gratitude.

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

  • Posts: 20
  • Thank you received: 0
11 years 4 months ago #108965

This works well for displaying the custom items before they get added to cart. My trouble is that the custom items don't get added to the cart view in step one. I've tried to make modifications to the checkout / custom_fields.php file so that the data entered is displayed in the cart, but to no avail. Since all published custom fields display no problem i tried changing the custom_fields.php file to include the unpublished fields, but that doesn't display these custom fields in the checkout or my syntax had no errors.

I also don't seem to get any validation happening either for "required" content, so I'm wondering if i have to use form tags in my code. In that's the case, there doesn't appear to be a form for the checkout in my views tab and i don't know what form i would be posting.

Sure would appreciate some hints. Thank you.

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

  • Posts: 13201
  • Thank you received: 2322
11 years 4 months ago #109029

Hi,

Sorry, you have to let it published, add the code in the view and add some css to hide the default custom field.
You can use the css property:

.hikashop_product_custom_item_value_64{display:none;}

Where 64 has to be replaced with the id of the custom field.

The following user(s) said Thank You: LenaK

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

  • Posts: 20
  • Thank you received: 0
11 years 4 months ago #109151

Ok, that works better for some fields. It started off with just one field and has expanded to the whole set.

If a textarea is required, my cart goes through a continuous loop and doesn't recognize the data that is entered by the user using the following code in my default.php. Hopefully you can spot the problem.

Additionally with textareas, I thought I might get the characters remaining to display using the following code, however that didn't pan out for me either, but I was just guessing based on the "onclick" syntax.

<textarea name="data[item][recipient]" id="recipient" rows="4" cols="45" onclick="hikashopToggleFields(this.value,'recipient','item',0);" onblur="hikashopTextCounter(this.value,'recipient_count','item',0);" onkeyup="hikashopTextCounter(this.value,'recipient_count','item',0);" ></textarea>

If i'm using a date field, the calendar does not become active whether i use the following code or if i change the type to "date" or "item" instead of text. It looks nice.

<label>Mail Later</label>
<input id="maillater" type="text" onchange="maillater_checkDate(1);" value="<?php echo date('Y-m-d'); ?>" name="data[item][maillater]" >
<img id="maillater_img" class="calendar" alt="Calendar" src="/media/system/images/calendar.png">

I would appreciate your suggestions. Thank you.

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

  • Posts: 82758
  • Thank you received: 13346
  • MODERATOR
11 years 4 months ago #109281

What you want to do won't work with the method explained by Xavier.
The date field as well as the textarea field require js code that is only added when you call the display function of the field class with the correct parameters.
If you add the HTML on your end, you won't have the JS linked to it and thus it won't work.
The problem is the same for the check for required fields as the system won't find your HTML field and will deny the submission.

What you will need to do is to use the PHP code to generate your fields manually and completely remove the normal call to the custom fields display block in your default.php file.

Here is an example of code for your radio button:

<?php
$oneExtraField =& $this->itemFields['includemyreturnaddress'];
$itemData = JRequest :: getString('item_data_includemyreturnaddress', $this->element->includemyreturnaddress);
					$onWhat='onchange';
					if($oneExtraField->field_type=='radio')
						$onWhat='onclick';
					$oneExtraField->product_id = $this->element->product_id;
					echo $this->fieldsClass->display($oneExtraField,$itemData,'data[item][includemyreturnaddress]',false,' '.$onWhat.'="hikashopToggleFields(this.value,\'includemyreturnaddress\',\'item\',0);"'); 
?>

The following user(s) said Thank You: LenaK

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

  • Posts: 20
  • Thank you received: 0
11 years 4 months ago #109283

You all rock.

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

  • Posts: 20
  • Thank you received: 0
11 years 4 months ago #109353

Oh man! I have all my custom item fields displaying EXACTLY as I want them now. The final code that worked for me was this:

<?php
$oneExtraField =& $this->itemFields;
$itemData = JRequest :: getString('item_data_includemyreturnaddress', $this->element->includemyreturnaddress);
?>
<td class="key">
<span id="hikashop_product_custom_item_name_includemyreturnaddress" class="hikashop_product_custom_item_name">
<?php echo $this->fieldsClass->getFieldName($oneExtraField);?>
</span>
</td>
<td>
<span id="hikashop_product_custom_item_value_includemyreturnaddress" class="hikashop_product_custom_item_value">
<?php
$onWhat='onchange';
if($oneExtraField->field_type=='radio')
$onWhat='onclick';
$oneExtraField->product_id = $this->element->product_id;
echo $this->fieldsClass->display($oneExtraField,$itemData,'data[item]',false,' '.$onWhat.'="hikashopToggleFields(this.value,\''.$fieldName.'\',\'item\',0);"');
?></span>
</td>

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

Time to create page: 0.086 seconds
Powered by Kunena Forum