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
sc_admin_can_config sc_config sc_config_admin
sc_config_global sc_config_group sc_store
sc_store_active sc_store_block sc_store_css
sc_link sc_get_all_template sc_route
sc_route_admin sc_store_block sc_store_css
sc_link_collection (>=7.2)
 
#Currency
sc_tax_price sc_render_option_price sc_currency_render
sc_currency_render_symbol sc_currency_value sc_currency_code
sc_currency_rate sc_currency_format sc_currency_info
sc_currency_all sc_currency_all_active
 
#Email
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
sc_image_upload sc_file_upload sc_remove_file
sc_image_insert_watermark sc_image_generate_thumb sc_image_render
sc_image_get_path sc_image_get_path_thumb sc_zip
sc_unzip sc_file  sc_path_download_render
#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
sc_get_list_code_store sc_get_domain_from_code sc_get_domain_root
sc_store_is_partner sc_store_is_root sc_get_list_store_of_product_detail
sc_get_list_store_of_discount_detail sc_get_list_store_of_brand sc_get_list_store_of_brand_detail
sc_get_list_store_of_banner sc_get_list_store_of_banner_detail sc_get_list_store_of_news
sc_get_list_store_of_news_detail sc_get_list_store_of_page sc_get_list_store_of_page_detail
sc_get_list_store_of_order sc_get_list_store_of_category sc_get_list_store_of_category_detail
sc_process_domain_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
sc_word_format_url sc_url_render sc_html_render
sc_word_format_class sc_word_limit sc_token
sc_report sc_sync_cart sc_datetime_to_date
admin sc_push_include_view sc_push_include_script
sc_request (>=7.2)
 

#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_check_view('path-to-view')

#sc_clean
This function cleans data from a string or array of values. The returned result is a cleaned string or array.
Syntax:

sc_clean($data = null, $exclude = [], $level_hight = null)

Inside:
$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_admin_can_config()

#sc_config
Returns the value of the "value" column in the admin_config table corresponding to the "key" column.
Syntax:

sc_config($key = null, $storeId = null, $default = null)

Inside:
$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_admin($key = null, $default = null)

#sc_config_global
Is function sc_config, with storeId = 0
Syntax:

sc_config_global($key = null, $default = null)

#sc_config_group
Returns array of config values based on group
Syntax:

sc_config_group($group = null, $suffix = null)

#sc_store
Return store information
Syntax:

sc_store($key = null, $store_id = null, $default = null)

Inside:
$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:

sc_store_active($field = null)

Processing logic:
- 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:

sc_store_block()

(*) The result returned depends on the template the store is using
#sc_store_css
Returns the css information of the template in use.
Syntax:

sc_store_css()

#sc_link
Returns a links of associations grouped by the "group" of stores.
Syntax:

sc_link()

#sc_link_collection ( >=7.2)
Returns links and collection of associations grouped by the "group" of stores.
Syntax:

sc_link_collection()

#sc_get_all_template
Returns an array of templates in the "views/templates" directory.
Syntax:

sc_get_all_template()

#sc_route
Route handler function
Syntax:

sc_route($name, $param = [])

#sc_route_admin
The route handler function in admin
Syntax:

sc_route_admin($name, $param = [])

#Currency
#sc_tax_price
The function returns the selling price of the product including tax
Syntax:

sc_tax_price($price, $tax)

Inside:
$price is the product price
$tax is a percentage of tax
#sc_render_option_price
Render html product attributes
Syntax:

sc_render_option_price($arrtribute, $currency = null, $rate = null)

#sc_currency_render
Returns the converted value, including associated formats.
Syntax:

sc_currency_render(float $money, $currency = null, $rate = null, $space_between_symbol = false, $useSymbol = true)

#sc_currency_render_symbol
Only add symbols to the currency format
Syntax:

sc_currency_render_symbol(float $money, $currency = null, $space_between_symbol = false, $include_symbol = true)

#sc_currency_value
Returns the value after currency conversion
Syntax:

sc_currency_value(float $money, float $rate = null)

#sc_currency_code
Returns the code of the currency being used
Syntax:

sc_currency_code()

#sc_currency_rate
Returns the rate of the currency in use against the Bits of the S-Cart
Syntax:

sc_currency_rate()

#sc_currency_format
Returns the format in currency, excluding symbol
Syntax:

sc_currency_format(float $money)

#sc_currency_info
Returns the information array of the currency in use.
Syntax:

sc_currency_info()

#sc_currency_all
Returns a collection of all active currencies.
Syntax:

sc_currency_all()

#sc_currency_all_active
Returns the network code value and name of the active currency.
Syntax:​​​​​​

sc_currency_all_active()

#Email
#sc_send_mail
The send function handles sending mail. Depending on configuration, mail will be sent directly or through a queue.
Syntax:

sc_send_mail($view, array $dataView = [], array $emailConfig = [], array $attach = [])

Inside:
$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_order_created(ShopOrder $order)

#sc_event_customer_created
Call event when customer account is created
Syntax:

sc_event_order_update_status(ShopOrder $order)

#sc_event_order_update_status
Call event when order status change
Syntax:

sc_event_customer_created(ShopCustomer $customer)

#File
#sc_image_upload
Image upload function, returns an array of image information after successful upload.
Syntax:

sc_image_upload($fileContent, $disk = 'public', $path = null, $name = null, $options = ['unique_name' => true, 'thumb' => false, 'watermark' => false])

#sc_file_upload
File upload function, returns an array of file information after successful upload.
Syntax:

sc_file_upload($fileContent, $disk = 'public', $path = null, $name = null)

#sc_remove_file
File delete function
Syntax:

sc_remove_file($pathFile, $disk = null)

#sc_image_insert_watermark
Function to add watermark to images
Syntax:

sc_image_insert_watermark($pathFile, $pathWatermark = null)

#sc_image_generate_thumb
Thumb constructor
Syntax:

sc_image_generate_thumb($pathFile, $widthThumb = null, $heightThumb = null, $disk = 'public')

#sc_image_render
Image render function
Syntax:

sc_image_render($path, $width = null, $height = null, $alt = null, $title = null, $urlDefault= null, $options = '')

#sc_image_get_path
The function returns the string as the image path
Syntax:

sc_image_get_path($path, $urlDefault = null)

#sc_image_get_path_thumb
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_zip(string $pathToSource, string $pathSaveTo)

#sc_unzip
Zip file decompression function
Syntax:

sc_unzip(string $pathToSource, string $pathSaveTo)

#sc_file
Returns the asset path of the file
Syntax:

function sc_file(string $pathFile = null, bool $security = null)

#sc_path_download_render
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_language_all()

#sc_languages
Returns an array of all the "code" and "text" of the language
Syntax:

sc_languages($locale)

(*)Attention:
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_replace(string $line, array $replace)

#sc_language_render
Returns the processed language value
Syntax:

sc_language_render($string, array $replace = [], $locale = null)

(*)Attention:
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_language_quickly($string, $default = null)

#sc_get_locale
The function returns the current locale
Syntax:

sc_get_locale()

#sc_lang_switch
Function to convert the current locale, by changing the value of locale
Syntax:

sc_lang_switch($lang = null)

#Plugin
#sc_get_all_plugin
Returns information for all plugins in the "app/Plugins" directory
Syntax:

sc_get_all_plugin(string $code)

#sc_get_plugin_installed
Returns information about installed Plugins
Syntax:

sc_get_plugin_installed($code = null, $onlyActive = true)

#sc_get_all_plugin_actived
Returns information about active plugins.
Syntax:

sc_get_all_plugin_actived($code)

Ex: sc_get_all_plugin_actived('Payment'), sc_get_all_plugin_actived('Shipping')
#sc_get_class_plugin_controller
Returns the namespace of the controller
Syntax:

sc_get_class_plugin_controller(string $code, string $key = null)

#sc_get_class_plugin_config
Returns the namespace of the config . class
Syntax:

sc_get_class_plugin_config(string $code, string $key)

#sc_get_plugin_namespace
Returns the main namespace of the plugin
Syntax:

sc_get_plugin_namespace(string $code, string $key)

#Store
#sc_get_list_code_store
Returns the code array of the stores
Syntax:

sc_get_list_code_store()

#sc_get_domain_from_code
Return the store's domain via code
Syntax:

sc_get_domain_from_code(string $code)

#sc_get_domain_root
Return domain root
Syntax:

sc_get_domain_root()

#sc_store_is_partner
Check if the store is a partner through id.
Syntax:

sc_store_is_partner(int $storeId)

#sc_store_is_root
Check if the store is root or not, via id
Syntax:

sc_store_is_root(int $storeId)

#sc_get_list_store_of_product_detail
Returns an array of ids of stores selling products
Syntax:

sc_get_list_store_of_product_detail($pId)

#sc_get_list_store_of_discount_detail
Returns an array of ids of stores using discount codes
Syntax:

sc_get_list_store_of_discount_detail($dId)

#sc_get_list_store_of_brand
Returns an array of store ids grouped by brand_id
Syntax:

sc_get_list_store_of_brand(array $arrBrandId)

#sc_get_list_store_of_brand_detail
Returns an array of ids of stores containing brand_id
Syntax:

sc_get_list_store_of_brand_detail($cId)

#sc_get_list_store_of_banner
Returns an array of store ids grouped by banner_id
Syntax:

sc_get_list_store_of_banner(array $arrBannerId)

#sc_get_list_store_of_banner_detail
Returns the id array of stores containing banner_id
Syntax:

sc_get_list_store_of_banner_detail($bId)

#sc_get_list_store_of_news
Returns an array of store ids grouped by news_id
Syntax:

sc_get_list_store_of_news(array $arrNewsId)

#sc_get_list_store_of_news_detail
Returns an array of ids of stores containing news_id
Syntax:

sc_get_list_store_of_news_detail($nId)

#sc_get_list_store_of_page
Returns an array of store ids grouped by page_id
Syntax:

sc_get_list_store_of_page(array $arrPageId)

#sc_get_list_store_of_page_detail
Returns array of ids of stores containing page_id
Syntax:

sc_get_list_store_of_page_detail($pId)

#sc_get_list_store_of_order
Returns an array of store ids grouped by order_id
Syntax:

sc_get_list_store_of_order(array $arrOrderId)

#sc_get_list_store_of_category
Returns an array of store ids grouped by category_id
Syntax:

sc_get_list_store_of_category(array $arrCategoryId)

#sc_get_list_store_of_category_detail
Returns an array of ids of stores containing category_id
Syntax:

sc_get_list_store_of_category_detail($cId)

#Captcha
#sc_captcha_method
Returns the currently used captcha method
Syntax:

sc_captcha_method()

#sc_captcha_page
Returns an array of pages using captcha
Syntax:

sc_captcha_page()

#sc_get_plugin_captcha_installed
Returns an array of installed captcha plugins
Syntax:

sc_get_plugin_captcha_installed($onlyActive = true)

#Cache
#sc_clear_cache
Cache clearing function
Syntax:

sc_clear_cache($typeCache = 'cache_all', $storeId = null)

#sc_set_cache
Function set value for cache
Syntax:

sc_set_cache($cacheIndex, $value, $time = null)

#Order
#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_word_format_url(string $str)

#sc_url_render
Return the complete url
Syntax:

sc_url_render(string $string)

#sc_html_render
Function to render HMTL.
Syntax:

sc_html_render(string $string)

#sc_word_format_class
Function to format words by class name
Syntax:

sc_word_format_class(string $word)

#sc_word_limit
String slicing function
Syntax:

sc_word_limit(string $word, int $limit = 20, string $arg = '')

Inside:
$arg is the string to be appended after the trimmed string.
#sc_token
Function that generates random code with specified length
Syntax:

sc_token(int $length = 32)

#sc_report
Functions to handle error messages, including logging and sending notifications to Slack
Syntax:

sc_report(string $msg, array $ext = [])

Inside:
- $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_process_domain_store(string $domain)

#sc_push_include_view
Add a view to the config value, which will be used to render in the respective locations
Syntax:

sc_push_include_view(string $position, string $pathView)

#sc_push_include_script
Add a script to the config value, which will be used to render in the respective locations
Syntax:

sc_push_include_script($position, $pathScript)

#sc_datetime_to_date
Convert data type for time
Syntax:

sc_datetime_to_date($datetime, $format = 'Y-m-d')

#admin
Returns admin account information currently logged in
Syntax:

admin()

#sc_sync_cart
The function that synchronously handles the user's order, is called after the user login event.
Syntax:

sc_sync_cart($userId)

#sc_request
Returns string or array depending on whether $type is string or array
Syntax:

sc_request($key, $default,$type)

Related topics

Latest Document