skip to Main Content

Improving the extra field handling in X-Cart 4

Improving The Extra Field Handling In X-Cart 4

One of the first changes I perform to the X-Cart 4 core code as a theme developer is to improve the way Extra Fields are held on the product page.

Extra Fields are a great way to add custom fields to a product that can be used on the product page. So for example a store owner would ask me to add an option in the backend at product level which will allow them to show a ‘Made in the UK’ flag at product level. The store owner would like to control each product individually and also be able to use the mass modify option too.

The main problem for the developer is that the extra fields array is held in an array that is not indexed efficiently. So you would need to loop each array element of extra fields and then test if it is populated and active.

The problem with this is that it is a processing overhead (not massive) but also makes your code untidy in the smart template.

The extra field array would look like this

If you edit the file modules\Extra_Fields\extra_fields.php


and add the following after it
Then reupload the file. You will now have an additional array available called $extra_fields_idx in smarty and it will be structured as follows
So now in the customer/main/product.tpl and customer/main/product.tpl files you can refer directly to the extra fields as follows
Back To Top