Functions helper of S-Cart
List of supported S-Cart functions:
Location: https://github.com/s-cart/core/tree/master/src/Library/Helpers(Customize helper functions HERE)
#Validation
sc_check_view | sc_clean |
#System
#Currency
sc_send_mail | sc_process_send_mail |
#Event
sc_event_order_success | sc_event_order_created | sc_event_customer_created |
sc_event_order_update_status |
#File #Langauge
sc_language_all | sc_languages | sc_language_replace |
sc_language_render | sc_language_quickly | sc_get_locale |
sc_lang_switch |
#Plugin
sc_get_all_plugin | sc_get_plugin_installed | sc_get_all_plugin_actived |
sc_get_class_plugin_controller | sc_get_class_plugin_config | sc_get_plugin_namespace |
#Store
#Captcha
sc_captcha_method | sc_captcha_page | sc_get_plugin_captcha_installed |
#Cache
sc_clear_cache | sc_set_cache |
#Order
sc_order_process_after_success (>7.1) | sc_order_mapping_validate (>7.1) |
#Product
sc_product_admin_select_list (>7.1) |
#Customer
sc_customer_sendmail_reset_notification (>7.1) | sc_customer_sendmail_verify (> 7.1) | sc_customer_sendmail_welcome (> 7.1) |
sc_customer_address_mapping (>7.1) | sc_customer_data_insert_mapping (> 7.1) | sc_customer_data_edit_mapping (> 7.1) |
sc_customer_created_by_client (>7.1) | sc_customer_created_by_admin (> 7.1) |
#Other
#Validation
#sc_check_view
This function checks if the view file exists. If not, will output a message to the screen and stop processing the display of the website. It will also call the sc_report function to alert the administrator.
Syntax:
#sc_cleansc_check_view('path-to-view')
This function cleans data from a string or array of values. The returned result is a cleaned string or array.
Syntax:
Inside:sc_clean($data = null, $exclude = [], $level_hight = null)
$data is a string or array of data
$exclude is the array will ignore
$level_hight is the processing level
#System
#sc_admin_can_config
Check if the user has permission to change the value in the admin_config table
Syntax:
#sc_configsc_admin_can_config()
Returns the value of the "value" column in the admin_config table corresponding to the "key" column.
Syntax:
Inside:sc_config($key = null, $storeId = null, $default = null)
$key is the name of the key (string), or a single array
$storeId is the ID of the store
$default is the default value returned if the key is not found in the admin_config table
Processing logic:
- If $key is null, the result is an array of all config values corresponding to store
- If $storeId is null, the value config('app.storeId') is used
- If $key is not found with store_id = $storeId, the result will be returned with store_id = 0
(*) You can use sc_config([$key => $value], $storeId) to update key value
#sc_config_admin
Is function sc_config, with storeId = session('adminStoreId')
Syntax:
#sc_config_globalsc_config_admin($key = null, $default = null)
Is function sc_config, with storeId = 0
Syntax:
#sc_config_groupsc_config_global($key = null, $default = null)
Returns array of config values based on group
Syntax:
#sc_storesc_config_group($group = null, $suffix = null)
Return store information
Syntax:
Inside:sc_store($key = null, $store_id = null, $default = null)
$key is the name of the key (string), or a single array
$storeId is the ID of the store
$default is the default value returned if the key is not found in the admin_store table
Processing logic:
- If $key is null, the result is an array of all store information in the admin_store table
- If $storeId is null, the value config('app.storeId') is used
- If $key is not found, the value $default is returned
(*) You can use sc_store([$key => $value], $storeId) to update key value
#sc_store_active
Trả về thông tin của cửa hàng đang hoạt động
Cú pháp:
Processing logic:sc_store_active($field = null)
- Nếu $field = 'code', kết quả trả về là mảng giá trị "code" của các cửa hàng
- Nếu $field = 'domain', kết quả trả về là mảng giá trị "domain" của các cửa hàng
- Nếu $field không phải là "code", "domain", giá trị trả về sẽ là thông tin đầy đủ của các cửa hàng đang hoạt động
#sc_store_block
Returns the collection of blocks in the shop_store_block table.
Syntax:
(*) The result returned depends on the template the store is usingsc_store_block()
#sc_store_css
Returns the css information of the template in use.
Syntax:
#sc_linksc_store_css()
Returns a links of associations grouped by the "group" of stores.
Syntax:
#sc_link_collection ( >=7.2)sc_link()
Returns links and collection of associations grouped by the "group" of stores.
Syntax:
#sc_get_all_templatesc_link_collection()
Returns an array of templates in the "views/templates" directory.
Syntax:
#sc_routesc_get_all_template()
Route handler function
Syntax:
#sc_route_adminsc_route($name, $param = [])
The route handler function in admin
Syntax:
#Currencysc_route_admin($name, $param = [])
#sc_tax_price
The function returns the selling price of the product including tax
Syntax:
Inside:sc_tax_price($price, $tax)
$price is the product price
$tax is a percentage of tax
#sc_render_option_price
Render html product attributes
Syntax:
#sc_currency_rendersc_render_option_price($arrtribute, $currency = null, $rate = null)
Returns the converted value, including associated formats.
Syntax:
#sc_currency_render_symbolsc_currency_render(float $money, $currency = null, $rate = null, $space_between_symbol = false, $useSymbol = true)
Only add symbols to the currency format
Syntax:
#sc_currency_valuesc_currency_render_symbol(float $money, $currency = null, $space_between_symbol = false, $include_symbol = true)
Returns the value after currency conversion
Syntax:
#sc_currency_codesc_currency_value(float $money, float $rate = null)
Returns the code of the currency being used
Syntax:
#sc_currency_ratesc_currency_code()
Returns the rate of the currency in use against the Bits of the S-Cart
Syntax:
#sc_currency_formatsc_currency_rate()
Returns the format in currency, excluding symbol
Syntax:
#sc_currency_infosc_currency_format(float $money)
Returns the information array of the currency in use.
Syntax:
#sc_currency_allsc_currency_info()
Returns a collection of all active currencies.
Syntax:
#sc_currency_all_activesc_currency_all()
Returns the network code value and name of the active currency.
Syntax:
sc_currency_all_active()
#sc_send_mail
The send function handles sending mail. Depending on configuration, mail will be sent directly or through a queue.
Syntax:
Inside:sc_send_mail($view, array $dataView = [], array $emailConfig = [], array $attach = [])
$view is the path to the view file
$dataView is the array of values sent to the email, rendered in the view
$emailConfig is an array of configuration information when sending an email: to, cc, bcc, replyTo, subject
$attach is an array of information about attachments
#sc_process_send_mail
Handle sending emails directly without going through the queue.
#Event
#sc_event_order_success
Call event when order is successful
Syntax:
sc_event_order_success(ShopOrder $order)
#sc_event_order_created
Call event when order is created
Syntax:
#sc_event_customer_createdsc_event_order_created(ShopOrder $order)
Call event when customer account is created
Syntax:
#sc_event_order_update_statussc_event_order_update_status(ShopOrder $order)
Call event when order status change
Syntax:
#Filesc_event_customer_created(ShopCustomer $customer)
#sc_image_upload
Image upload function, returns an array of image information after successful upload.
Syntax:
#sc_file_uploadsc_image_upload($fileContent, $disk = 'public', $path = null, $name = null, $options = ['unique_name' => true, 'thumb' => false, 'watermark' => false])
File upload function, returns an array of file information after successful upload.
Syntax:
#sc_remove_filesc_file_upload($fileContent, $disk = 'public', $path = null, $name = null)
File delete function
Syntax:
#sc_image_insert_watermarksc_remove_file($pathFile, $disk = null)
Function to add watermark to images
Syntax:
#sc_image_generate_thumbsc_image_insert_watermark($pathFile, $pathWatermark = null)
Thumb constructor
Syntax:
#sc_image_rendersc_image_generate_thumb($pathFile, $widthThumb = null, $heightThumb = null, $disk = 'public')
Image render function
Syntax:
#sc_image_get_pathsc_image_render($path, $width = null, $height = null, $alt = null, $title = null, $urlDefault= null, $options = '')
The function returns the string as the image path
Syntax:
#sc_image_get_path_thumbsc_image_get_path($path, $urlDefault = null)
The function returns the string of the image's thumb path
Syntax:
sc_image_get_path_thumb($pathFile)#sc_zip
File compression function
Syntax:
#sc_unzipsc_zip(string $pathToSource, string $pathSaveTo)
Zip file decompression function
Syntax:
#sc_filesc_unzip(string $pathToSource, string $pathSaveTo)
Returns the asset path of the file
Syntax:
#sc_path_download_renderfunction sc_file(string $pathFile = null, bool $security = null)
Returns the path of the downloaded file.
Syntax:
sc_path_download_render(string $string)
#Language
#sc_language_all
Returns a collection of all active languages
Syntax:
#sc_languagessc_language_all()
Returns an array of all the "code" and "text" of the language
Syntax:
(*)Attention:sc_languages($locale)
This function (including all calls to it) must not be used in _construct, mildware because the language may not work correctly.
#sc_language_replace
The function replaces conventional strings in the language into a complete string.
Syntax:
#sc_language_rendersc_language_replace(string $line, array $replace)
Returns the processed language value
Syntax:
(*)Attention:sc_language_render($string, array $replace = [], $locale = null)
This function (including all calls to it) must not be used in _construct, mildware because the language may not work correctly.
Processing logic:
- S-Cart will check the language information in the database first (table sc_languages). Otherwise, the search will follow the default Laravel logic.
#sc_language_quickly
A function that quickly returns the value of the language. If not, the default value is returned.
Syntax:
#sc_get_localesc_language_quickly($string, $default = null)
The function returns the current locale
Syntax:
#sc_lang_switchsc_get_locale()
Function to convert the current locale, by changing the value of locale
Syntax:
#Pluginsc_lang_switch($lang = null)
#sc_get_all_plugin
Returns information for all plugins in the "app/Plugins" directory
Syntax:
#sc_get_plugin_installedsc_get_all_plugin(string $code)
Returns information about installed Plugins
Syntax:
#sc_get_all_plugin_activedsc_get_plugin_installed($code = null, $onlyActive = true)
Returns information about active plugins.
Syntax:
Ex: sc_get_all_plugin_actived('Payment'), sc_get_all_plugin_actived('Shipping')sc_get_all_plugin_actived($code)
#sc_get_class_plugin_controller
Returns the namespace of the controller
Syntax:
#sc_get_class_plugin_configsc_get_class_plugin_controller(string $code, string $key = null)
Returns the namespace of the config . class
Syntax:
#sc_get_plugin_namespacesc_get_class_plugin_config(string $code, string $key)
Returns the main namespace of the plugin
Syntax:
#Storesc_get_plugin_namespace(string $code, string $key)
#sc_get_list_code_store
Returns the code array of the stores
Syntax:
#sc_get_domain_from_codesc_get_list_code_store()
Return the store's domain via code
Syntax:
#sc_get_domain_rootsc_get_domain_from_code(string $code)
Return domain root
Syntax:
#sc_store_is_partnersc_get_domain_root()
Check if the store is a partner through id.
Syntax:
#sc_store_is_rootsc_store_is_partner(int $storeId)
Check if the store is root or not, via id
Syntax:
#sc_get_list_store_of_product_detailsc_store_is_root(int $storeId)
Returns an array of ids of stores selling products
Syntax:
#sc_get_list_store_of_discount_detailsc_get_list_store_of_product_detail($pId)
Returns an array of ids of stores using discount codes
Syntax:
#sc_get_list_store_of_brandsc_get_list_store_of_discount_detail($dId)
Returns an array of store ids grouped by brand_id
Syntax:
#sc_get_list_store_of_brand_detailsc_get_list_store_of_brand(array $arrBrandId)
Returns an array of ids of stores containing brand_id
Syntax:
#sc_get_list_store_of_bannersc_get_list_store_of_brand_detail($cId)
Returns an array of store ids grouped by banner_id
Syntax:
#sc_get_list_store_of_banner_detailsc_get_list_store_of_banner(array $arrBannerId)
Returns the id array of stores containing banner_id
Syntax:
#sc_get_list_store_of_newssc_get_list_store_of_banner_detail($bId)
Returns an array of store ids grouped by news_id
Syntax:
#sc_get_list_store_of_news_detailsc_get_list_store_of_news(array $arrNewsId)
Returns an array of ids of stores containing news_id
Syntax:
#sc_get_list_store_of_pagesc_get_list_store_of_news_detail($nId)
Returns an array of store ids grouped by page_id
Syntax:
#sc_get_list_store_of_page_detailsc_get_list_store_of_page(array $arrPageId)
Returns array of ids of stores containing page_id
Syntax:
#sc_get_list_store_of_ordersc_get_list_store_of_page_detail($pId)
Returns an array of store ids grouped by order_id
Syntax:
#sc_get_list_store_of_categorysc_get_list_store_of_order(array $arrOrderId)
Returns an array of store ids grouped by category_id
Syntax:
#sc_get_list_store_of_category_detailsc_get_list_store_of_category(array $arrCategoryId)
Returns an array of ids of stores containing category_id
Syntax:
#Captchasc_get_list_store_of_category_detail($cId)
#sc_captcha_method
Returns the currently used captcha method
Syntax:
#sc_captcha_pagesc_captcha_method()
Returns an array of pages using captcha
Syntax:
#sc_get_plugin_captcha_installedsc_captcha_page()
Returns an array of installed captcha plugins
Syntax:
#Cachesc_get_plugin_captcha_installed($onlyActive = true)
#sc_clear_cache
Cache clearing function
Syntax:
#sc_set_cachesc_clear_cache($typeCache = 'cache_all', $storeId = null)
Function set value for cache
Syntax:
#Ordersc_set_cache($cacheIndex, $value, $time = null)
#sc_order_process_after_success (from SC 7.1)
Processing after the order is completed.
For example, sending mail, information is returned on the order completion screen.
Syntax:
sc_order_process_after_success(string $orderID)
#sc_order_mapping_validate (from SC 7.1)
Perform mapping of validation data for order-related information. The returned result is an array.
Syntax:
sc_order_mapping_validate()
#Product
sc_product_admin_select_list (from SC 7.1)
Process the list of products used in select on the admin page. The return result is an array
Syntax:
sc_product_admin_select_list(array $dataFilter = [], $storeId = null)
#Customer
#sc_customer_sendmail_reset_notification (from SC 7.1)
Handling email reset password.
Syntax:
sc_customer_sendmail_reset_notification(string $token, string $emailReset)#sc_customer_sendmail_verify (from SC 7.1)
Handling sending verification email.
Syntax:
sc_customer_sendmail_verify()#sc_customer_sendmail_welcome (from SC 7.1)
Handles sending welcome emails.
Syntax:
sc_customer_sendmail_welcome(array $data)#sc_customer_address_mapping (from SC 7.1)
Handles sending welcome emails.
Syntax:
sc_customer_address_mapping(array $dataRaw)#sc_customer_data_insert_mapping (from SC 7.1)
Xử lý gửi mapping dữ liệu khách hàng trước khi insert.
Syntax:
sc_customer_data_insert_mapping(array $dataRaw)#sc_customer_data_edit_mapping (from SC 7.1)
Process to send mapping customer data before inserting.
Syntax:
sc_customer_data_edit_mapping(array $dataRaw)#sc_customer_created_by_client (from SC 7.1)
Processing after the customer account is created.
Syntax:
sc_customer_created_by_client(ShopCustomer $user, array $dataMap)#sc_customer_created_by_admin
Processing after the customer account is created by admin.
Syntax:
sc_customer_created_by_admin (ShopCustomer $user, array $dataMap)
#Other
#sc_word_format_url
Process string to url format.
Syntax:
#sc_url_rendersc_word_format_url(string $str)
Return the complete url
Syntax:
#sc_html_rendersc_url_render(string $string)
Function to render HMTL.
Syntax:
#sc_word_format_classsc_html_render(string $string)
Function to format words by class name
Syntax:
#sc_word_limitsc_word_format_class(string $word)
String slicing function
Syntax:
Inside:sc_word_limit(string $word, int $limit = 20, string $arg = '')
$arg is the string to be appended after the trimmed string.
#sc_token
Function that generates random code with specified length
Syntax:
#sc_reportsc_token(int $length = 32)
Functions to handle error messages, including logging and sending notifications to Slack
Syntax:
Inside:sc_report(string $msg, array $ext = [])
- $ext is the array of actions to ignore
By default, dynamic logging to the file will always be performed.
#sc_process_domain_store
String handling function, returning domain name
Syntax:
#sc_push_include_viewsc_process_domain_store(string $domain)
Add a view to the config value, which will be used to render in the respective locations
Syntax:
#sc_push_include_scriptsc_push_include_view(string $position, string $pathView)
Add a script to the config value, which will be used to render in the respective locations
Syntax:
#sc_datetime_to_datesc_push_include_script($position, $pathScript)
Convert data type for time
Syntax:
#adminsc_datetime_to_date($datetime, $format = 'Y-m-d')
Returns admin account information currently logged in
Syntax:
#sc_sync_cartadmin()
The function that synchronously handles the user's order, is called after the user login event.
Syntax:
#sc_requestsc_sync_cart($userId)
Returns string or array depending on whether $type is string or array
Syntax:
sc_request($key, $default,$type)
Related topics
- Backup & Restore
- S-Cart command line
- Create custom functions
- Configure data validation
- Customize your router
- Customize controller
- How to customize home page
- Customize admin dashboard page
- Customize helper functions
- Disable ecommerce router
- Convert S-Cart into a news website
- Customize data fields in S-Cart
- 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