×
ecommercecms.org

WatCMS Helpers

No comments

Helpers are a quck functions what you can use anywhere in your theme or module it may be caled like function_name($params). Many of helpers you can find in Laravel Documentations.  There is two tipe of helpers simple methods and OOP hepers 

 

1) app/Helpers/helpers.php

2) app/Helpers/HelperController.php

quickEdit

excerpt

_l

get_shipping_cost

get_link_page

get_shipping_field

product_url

get_random

id_user

get_role

UserRole

get_user_name

get_settings

get_settings_json

return_bulck_settings

update_settings

update_settingsID

resize_crop_image

get_by_curl

minify_html

minify_css

minify_js

get_thumbnail

get_images

get_product_field

get_comments

nr_comments

product_stars

isJSON

get_countrybyid

get_cat_yerahical_option

get_cat_yerahical_checkbox

get_price_full

get_price_number

printw

get_menu

_hooks

_widgets

shortCode

_logo

_favicon

get_sesion

get_cart

get_cart_total

get_applied_cupon

rightTab

 

quickEdit

 Link to quick edit
 url - is the linkt to admin panel
 quickEdit('/admin/page/add-edit/pages/20');
 

excerpt

This method show the first 300 words from text

the limit you can control like bellow 10 words

excerpt('Yur text go here', 10);

excerpt($contetnt='', $limit=300)

_l

this will get the translate

{{_l("Edit")}}

_l($word="")

 

get_shipping_cost

 Get shipping cost
 id - shipping id
 $total - cart total; it will calculate the shipping cost from cart total
 get_shipping_cost($id, $total=0)

 

get_link_page

generate link by page id

$id - page id

get_link_page(10);

 

get_shipping_field

Get shipping cost
 $id- Shipping id
 $field - field; like title or cost

get_shipping_field(20, 'title')

 

product_url

Will return the full product url
  $cpu- product cpu
  $cat - is a product cat json
 
function product_url($cpu="",$cat="")

 

get_random

Will generate a randon string
  $n- length
  $only_letters - only letter not numbers
 
 get_random(20)

id_user

get current user ID if is login

id_user();

 

get_role

Get user role by id role
  id- role id

get_role($id);

 

UserRole

get current user role admin or editor or none
 
UserRole(); return admin;

if curent user role is admin it will return true other cases false

UserRole('admin'); return true or false

 

get_user_name

 Get user name or email by user id

$id - user id

$field - email or name

function get_user_name(20,  "name") // will return the  user name where id is 20

function get_user_name('current',  "email") // will return the current user email

 

get_settings

Return field from table setting by param
 $param - is any param(any word)
 $field - value or value1 or value2
 $field2 - if you want to geth botth like $get->$field ."~". $get->$field2 and after use explode("~", $data)
 
 
 get_settings($param, $field="value", $field2="")

 

get_settings_json

If you keep value in json it will return value1 in json decode : $data['email']
  $param - is any param(any word)
  $field - value or value1 or value2
 
 get_settings_json($param, $field="value1" )

 

return_bulck_settings

Return loop data from table setting by param

$param - any word

return_bulck_settings($param)

 

update_settings

Update or insert if param is not existing
  $param - is the parametr where you can recognise your data
 $value - varchar(255)
 $value1 - text accept big data
 $value2 - varchar(255)

update_settings($param, $value="", $value1="", $value2="")

update_settingsID

Update or insert if id is not existing
 $id - id settings 

 $value - varchar(255)
 $value1 - text accept big data
 $value2 - varchar(255)

update_settings($id, $value="", $value1="", $value2="")

 

resize_crop_image

Crop image easy and eficient

resize_crop_image($max_width, $max_height, $source_file, $dst_dir, $quality = 80, $crop=true)

 

get_by_curl

it will call an external url by curl

$url - any external url

$no_return - leave empty if you don't want to get any response


get_by_curl($url, $no_return = "")

 

minify_html

HTML Minifier

minify_html($input)

 

minify_css

CSS Minifier

minify_css($input)

 

minify_js

  JavaScript Minifier
 minify_js($input)

 

get_thumbnail

Will return the image full path
* $image - it's aimage from options or just image name
* $type - thumb or big (full size)

get_thumbnail($product->optionsdata,  "thumb")

get_images

Get product gallery
 $idp - id Product
 
 get_images($idp)

 

get_product_field

Will get any field from product table
  id - id product
  $field - title or price any field
 
 get_product_field($id="",$field="title")

 

get_comments

Will get all the Comments(Reviews) for the post or product
  $id_post - product id
 
 get_comments($id_post = 0)

 

nr_comments

Will return the number of commnets in array
  for eaxample [5=>10, 4=>2, 3=>1, 2=>7, 1=> 5]
  where array key is stars number and value is the number of comments with key stars
 
 nr_comments(get_comments(20));

 

product_stars

Return the Medium Stars by product id
$id_post- product id

product_stars($id_post=0)

Result will be : *****

 

isJSON

Will return true or false if the string is a json
 $string - any json string or any string
 

isJSON($string);

 

 

get_countrybyid

Get country field by id
 id- id country
 field - any field
 
function get_countrybyid($id, $field)

 

get_cat_yerahical_option

will return the category for select
  $cat - categories array
  $parrent - if you want to be selected

get_cat_yerahical_option($cat=[], $parent="", $nr= 0, $url="", $is_in='')

 

get_cat_yerahical_checkbox

 will return the category in checkbox list
 $cat - categories array
 $parrent - if you want to be checked
 get_cat_yerahical_checkbox($cat=[], $parent="", $nr= 0, $isin=[])

 

get_price_full

get price with currency icon
 $price - normal price
 $sale_price - sale price
 $type - if it's empty than will return the price + incrise what you setup on
  Setting page link: yourwebsite.domain/admin/general-settings/
 if is not empty will return a clear price.
 
 get_price_full($price, $sale_price=0, $type='')

 

get_price_number

 get price only number
 $price - normal price
 $sale_price - sale price
 $price_option - if it's empty than will return the price + incrise what you setup on
 Setting page link: yourwebsite.domain/admin/general-settings/
  if is not empty will return a clear price.
 

function get_price_number($price=0,$sale_price=0, $price_option=0)

 

printw

Print a nice array

 

get_menu

Get menue
  $value2 - top_menu or any what you selected
  get_menu($value2="none")

 

_hooks

Simple hook function

$hook- hook name like header footer

_hooks('header');

in your theme in blade or controller you can add many hooks and from config.php you can add on that part of the page any code you want

 

_widgets

Simple Widgets function

in your theme in blade or controller you can add many widgets and from config.php you can add on that part of the page any code you want

_widgets('left_sidebar')

 

shortCode

This is a short code function if you need to use the short code in page

$content - is page text  or any text where you have some words in square scops like [search]

shortCode($content);

shortCode('[search]');
 

_logo

will return the logo from the settings page

_logo()

return : <a href="'.url("/").'"><img class="logo" src="'.url('/public/img/'.$logo).'"/></a>

 

_favicon

will return the favicon from the settings page

_favicon()

return : <link rel="shortcut icon" type="image/png" href="'.url('/public/img/'.$_favicon_).'"/>
 

 

get_sesion

Will return the tmp_user_id from cookies when user go on the website it automaticle
 generate a unic code what you can identify the user. it use for cart and checkout

@\App\Helpers\HelperController::get_sesion();

 

get_cart

Will return the list of products from current user cart

@\App\Helpers\HelperController::get_cart();

 

get_cart_total

will return the cart total

@\App\Helpers\HelperController::get_cart_total();

 

get_applied_cupon

will return the cupon amount from total of cart

$subtotal- cart total

$nr - yes if you need it in nice array like ['subtotal'=>$subtotal, 'total'=>round($discount, 2), 'cuppon'=>$cuppon->cupon, 'discount'=> $discount_minus]

 

@\App\Helpers\HelperController::get_applied_cupon($subtotal=0, $nr="");

 

rightTab

Will return the tabs content
  $content - content
  $product - product data

@\App\Helpers\HelperController::rightTab($content='', $product='');