Customize data fields in S-Cart
1. Custom data fields in S-Cart
2. Supported data tables
3. Instructions for adding data fields
4. Instructions for getting data
5. Helper
Since version 7.2.5, S-Cart has had updates to better support flexibility in user data.
Normally, to add a field for an object, you must add a new column of data. This causes you to change the data structure and edit the code to handle adding, deleting, and editing data.
Too complicated and difficult for those who don't understand laravel well. Besides, it is also an obstacle when users want to transfer data from other systems to S-Cart when they are different in data fields.
1. What is a custom field in S-Cart?
2. From version 7.2.5, the list of tables that support custom fields includes:
3. Instructions for adding custom fields:
Access to Admin -> SystemConfig -> Setting system -> Custom field data
Note:
The "Default" value column is only for data selections of "Select", "Check box", "Radio". Default value is Json type, for example: {"value1": "Name 1", "value2":"Name 2"}
4. Instructions for getting data
a. Get a list of custom data fields
Example get all custom data fields for customers
5. Helper
Helper functions for custom fields placed in vendor/S-Cart/core/src/Library/Helpers/custom_field.php
See full data relationship in S-Cart here: https://s-cart.org/en/developer/master/data-relations-in-s-cart.html
2. Supported data tables
3. Instructions for adding data fields
4. Instructions for getting data
5. Helper
Since version 7.2.5, S-Cart has had updates to better support flexibility in user data.
Normally, to add a field for an object, you must add a new column of data. This causes you to change the data structure and edit the code to handle adding, deleting, and editing data.
Too complicated and difficult for those who don't understand laravel well. Besides, it is also an obstacle when users want to transfer data from other systems to S-Cart when they are different in data fields.
1. What is a custom field in S-Cart?
We will not directly add new data fields in each table, that will make the data structure bloated, difficult to control, costly to code.
Instead, all new data fields are added unlimitedly in the 2 tables shop_custom_field and shop_custom_field_detail. They are linked to each of the main data tables.
2. From version 7.2.5, the list of tables that support custom fields includes:
+ shop_customer
+ shop_product
+ shop_banner
+ shop_brand
+ shop_supplier
+ shop_category
+ shop_news
+ shop_page
3. Instructions for adding custom fields:
Access to Admin -> SystemConfig -> Setting system -> Custom field data
Note:
The "Default" value column is only for data selections of "Select", "Check box", "Radio". Default value is Json type, for example: {"value1": "Name 1", "value2":"Name 2"}
4. Instructions for getting data
a. Get a list of custom data fields
Example get all custom data fields for customers
b. Get custom data$listCustomFields = (new \SCart\Core\Front\Models\ShopCustomField)->getCustomField($type = 'shop_customer')
$customer = (new \SCart\Core\Front\Models\ShopCustomer)->find($id);
$allDataCustomeField = $customer->getCustomFields(); or $customer->custom_fields;
$dataViaCode = $customer->getCustomField($code);//webding-day
5. Helper
Helper functions for custom fields placed in vendor/S-Cart/core/src/Library/Helpers/custom_field.php
See full data relationship in S-Cart here: https://s-cart.org/en/developer/master/data-relations-in-s-cart.html
Related topics
- Backup & Restore
- S-Cart command line
- Create custom functions
- Configure data validation
- Customize your router
- Customize controller
- Functions helper of S-Cart
- How to customize home page
- Customize admin dashboard page
- Customize helper functions
- Disable ecommerce router
- Convert S-Cart into a news website
- Data relations in S-Cart
- Customize search page
Latest Document
- Upgrade guide 2024-03-24
- Customize search page 2023-08-02
- Discount code (coupon) 2023-05-14
- Upgrade guide 2023-11-23
- Data relations in S-Cart 2023-02-05