Custom Field Codes for Coders
S = String
I =Integer
P =Parent
B= Bolean (True)
D = Date
T = Time
M =Image
V =Cart Variant
A =Generic Child Variant
X=Editor
Y=Textarea
For example
<?php if ($field->field_type == S){
My Special String Output
} ?>
Using The Custom Field Type "String" for an extra field.
Warranty Display Example
1st Setup a Custom field type "string" called "warranty" like in the picture below.
Next Go Into a product, and apply the custom field "warranty" to the product.
Fill In the warranty text. 2 years, 3 years etc.
NEXT:: You need to create a position in your product details view for the warranty text.
<div id="warranty-text"><strong>This is the Warranty Div</strong>
<?php if (!empty($this->product->customfieldsSorted['warranty'])) {
$this->position='warranty';
echo $this->loadTemplate('customfields'); } ?></div>
Use the Custom field "IMAGE" to display a NON-cart Variant.
Free Shipping Icon on product page example.
1st Create a Custom field type "image" and name it "shipping icon" like the image below.
Next, upload your free shipping icon in "shop media files"
Go to edit product, and apply the custom field. Choose the image in the dropdown.
Error solution...
Warning: Invalid argument supplied for foreach()
default_customfields
or
default.php
In default.php
This is how the ontop is done
<?php if (!empty($this->product->customfieldsSorted['ontop'])) {
$this->position = 'ontop';
echo $this->loadTemplate('customfields');
} // Product Custom ontop end
?>
When you choose "cart variant" the default position will be in the add to cart form.
THEN,
the ONLY other default positions in the product layout is
"ontop"
THIS CODE IS IN views/productdetails/tmpl/default.php
if (!empty($this->product->customfieldsSorted['ontop'])) { ?>
<div class="product-fields">
<?php
$custom_title = null ;
foreach ($this->product->customfieldsSorted['ontop'] as $field){
if ($field->display) {
?><div class="product-field product-field-type-<?php echo $field->field_type ?>">
<?php if ($field->custom_title != $custom_title) { ?>
<span class="product-fields-title" ><?php echo JText::_($field->custom_title); ?></span>
<?php if ($field->custom_tip) echo JHTML::tooltip($field->custom_tip, JText::_($field->custom_title), 'tooltip.png');
} ?>
<span class="product-field-display"><?php echo $field->display ?></span>
<span class="product-field-desc"><?php echo jText::_($field->custom_field_desc) ?></span>
</div>
<?php
$custom_title = $field->custom_title;
}
} ?>
</div>
<?php } // Product Custom ontop end ?>
YOU can actually set your own positions anywhere. By copying this code, and renaming the "position"
YOU JUST change the 'ontop'
<?php if (!empty($this->product->customfieldsSorted['ontop'])) { ?>
<div class="product-fields">
<?php
$custom_title = null ;
foreach ($this->product->customfieldsSorted['ontop'] as $field){
if ($field->display) {
?><div class="product-field product-field-type-<?php echo $field->field_type ?>">
<?php if ($field->custom_title != $custom_title) { ?>
<span class="product-fields-title" ><?php echo JText::_($field->custom_title); ?></span>
<?php if ($field->custom_tip) echo JHTML::tooltip($field->custom_tip, JText::_($field->custom_title), 'tooltip.png');
} ?>
<span class="product-field-display"><?php echo $field->display ?></span>
<span class="product-field-desc"><?php echo jText::_($field->custom_field_desc) ?></span>
</div>
<?php
$custom_title = $field->custom_title;
}
} ?>
</div>
<?php } // Product Custom ontop end ?>
You can do your own location of custom field.
<?php if (!empty($this->product->customfieldsSorted['my-position'])) {
$this->position='my-position';
echo $this->loadTemplate('customfields');
}
?>
I try to use the below code after the price is displayed but nothing happens... i don't get the custom fields displayed.
<?php if (!empty($this->product->customfieldsSorted['my-position'])) {
$this->position='my-position';
echo $this->loadTemplate('customfields');
}
?>
Change .. my-position
.... to YOUR position
S = String
I =Integer
P =Parent
B= Bolean (True)
D = Date
T = Time
M =Image
V =Cart Variant
A =Generic Child Variant
X=Editor
Y=Textarea
For example
<?php if ($field->field_type == S){
My Special String Output
} ?>
Using The Custom Field Type "String" for an extra field.
Warranty Display Example
1st Setup a Custom field type "string" called "warranty" like in the picture below.
Next Go Into a product, and apply the custom field "warranty" to the product.
Fill In the warranty text. 2 years, 3 years etc.
NEXT:: You need to create a position in your product details view for the warranty text.
<div id="warranty-text"><strong>This is the Warranty Div</strong>
<?php if (!empty($this->product->customfieldsSorted['warranty'])) {
$this->position='warranty';
echo $this->loadTemplate('customfields'); } ?></div>
Use the Custom field "IMAGE" to display a NON-cart Variant.
Free Shipping Icon on product page example.
1st Create a Custom field type "image" and name it "shipping icon" like the image below.
Next, upload your free shipping icon in "shop media files"
Go to edit product, and apply the custom field. Choose the image in the dropdown.
Using a String for external images
Create a Custom field type "string" named "external"
In Edit Product apply the field. Paste the url to the image in the field.
This below is the code for displaying the image.
<div class="product-fields">
<?php
$custom_title = null;
foreach ($this->product->customfieldsSorted[external] as $field) {
if ($field->display) {
?>
<?php if ($field->custom_title != $custom_title) { ?>
<img src="<?php echo $field->display ?>" alt="<?php echo $this->product->product_name ?>" />
<?php } ?>
<?php } ?> <?php } ?>
</div>
Using a String to Link to related articles, installation instructions etc.
Create a Custom field type "string" with the name "Installation Instructions" or whatever you want the anchor text to be.
Assign it to the position "link"
In Edit Product apply the field. Paste the url
This below is the code for displaying the link.
<div class="product-fields">
<?php
$custom_title = null;
foreach ($this->product->customfieldsSorted[link] as $field) {
if ($field->display) {
?>
<?php if ($field->custom_title != $custom_title) { ?>
<a href="<?php echo $field->display ?>" ><?php echo JText::_($field->custom_title); ?></a>
<?php } ?>
<?php } ?> <?php } ?>
</div>
Create a Custom field type "string" named "external"
In Edit Product apply the field. Paste the url to the image in the field.
This below is the code for displaying the image.
<div class="product-fields">
<?php
$custom_title = null;
foreach ($this->product->customfieldsSorted[external] as $field) {
if ($field->display) {
?>
<?php if ($field->custom_title != $custom_title) { ?>
<img src="<?php echo $field->display ?>" alt="<?php echo $this->product->product_name ?>" />
<?php } ?>
<?php } ?> <?php } ?>
</div>
Using a String to Link to related articles, installation instructions etc.
Create a Custom field type "string" with the name "Installation Instructions" or whatever you want the anchor text to be.
Assign it to the position "link"
In Edit Product apply the field. Paste the url
This below is the code for displaying the link.
<div class="product-fields">
<?php
$custom_title = null;
foreach ($this->product->customfieldsSorted[link] as $field) {
if ($field->display) {
?>
<?php if ($field->custom_title != $custom_title) { ?>
<a href="<?php echo $field->display ?>" ><?php echo JText::_($field->custom_title); ?></a>
<?php } ?>
<?php } ?> <?php } ?>
</div>
Error solution...
Warning: Invalid argument supplied for foreach()
default_customfields
or
default.php
In default.php
This is how the ontop is done
<?php if (!empty($this->product->customfieldsSorted['ontop'])) {
$this->position = 'ontop';
echo $this->loadTemplate('customfields');
} // Product Custom ontop end
?>
When you choose "cart variant" the default position will be in the add to cart form.
THEN,
the ONLY other default positions in the product layout is
"ontop"
THIS CODE IS IN views/productdetails/tmpl/default.php
if (!empty($this->product->customfieldsSorted['ontop'])) { ?>
<div class="product-fields">
<?php
$custom_title = null ;
foreach ($this->product->customfieldsSorted['ontop'] as $field){
if ($field->display) {
?><div class="product-field product-field-type-<?php echo $field->field_type ?>">
<?php if ($field->custom_title != $custom_title) { ?>
<span class="product-fields-title" ><?php echo JText::_($field->custom_title); ?></span>
<?php if ($field->custom_tip) echo JHTML::tooltip($field->custom_tip, JText::_($field->custom_title), 'tooltip.png');
} ?>
<span class="product-field-display"><?php echo $field->display ?></span>
<span class="product-field-desc"><?php echo jText::_($field->custom_field_desc) ?></span>
</div>
<?php
$custom_title = $field->custom_title;
}
} ?>
</div>
<?php } // Product Custom ontop end ?>
YOU can actually set your own positions anywhere. By copying this code, and renaming the "position"
YOU JUST change the 'ontop'
<?php if (!empty($this->product->customfieldsSorted['ontop'])) { ?>
<div class="product-fields">
<?php
$custom_title = null ;
foreach ($this->product->customfieldsSorted['ontop'] as $field){
if ($field->display) {
?><div class="product-field product-field-type-<?php echo $field->field_type ?>">
<?php if ($field->custom_title != $custom_title) { ?>
<span class="product-fields-title" ><?php echo JText::_($field->custom_title); ?></span>
<?php if ($field->custom_tip) echo JHTML::tooltip($field->custom_tip, JText::_($field->custom_title), 'tooltip.png');
} ?>
<span class="product-field-display"><?php echo $field->display ?></span>
<span class="product-field-desc"><?php echo jText::_($field->custom_field_desc) ?></span>
</div>
<?php
$custom_title = $field->custom_title;
}
} ?>
</div>
<?php } // Product Custom ontop end ?>
You can do your own location of custom field.
<?php if (!empty($this->product->customfieldsSorted['my-position'])) {
$this->position='my-position';
echo $this->loadTemplate('customfields');
}
?>
I try to use the below code after the price is displayed but nothing happens... i don't get the custom fields displayed.
<?php if (!empty($this->product->customfieldsSorted['my-position'])) {
$this->position='my-position';
echo $this->loadTemplate('customfields');
}
?>
Change .. my-position
.... to YOUR position
No comments:
Post a Comment