Prestashop snippets tools for 1.6 and 1.7 versions.<br>
This extension will help you faster to make common using snippets.
PHP snippets to help you be more productive when developing in PHP
Support tab to previous/next slug.
Snippets PHP
- p:ajaxMethod => Ajax Call Your Method
- p:ajaxAdminController => Ajax Call Your Admin Controller Code
- p:ajaxFrontController => Ajax Call Your Front Controller Code
- p:dump => dump('');
- p:vdump => var_dump('');
- p:printr => print_r('');
- p:getIsset => Checks if a key exists either in $_POST or $_GET Tools::getIsset('');
- p:getval => Tools::getValue('');
- p:getAllValues => Get all values from $_POST/$_GET. Tools::getAllValues();
- p:redirectAdmin => Redirect user to another page (using header Location) Tools::redirectAdmin($url);
- p:redirectLink => Redirect URLs already containing PS_BASE_URI Tools::redirectLink($url);
- p:redirect => Redirect user to another page Tools::redirect($url);
- p:token => Give a admin token Tools::getAdminTokenLite('<admin_controller_name>');
- p:clean => Allows to display the text without HTML tags and slashes
- p:userBrowser => Get user browser
- p:userPlatform => Get user platform
- p:boolVal => Bool Value
- p:phpVer => Identify the version of php
- p:camelCaseToKebabCase => Converts SomethingLikeThis to something-like-this
- p:toUnderscoreCase => Converts SomethingLikeThis to something-like-this
- p:toCamelCase => Translates a string with underscores into camel case (e.g. first_name -> firstName)
- p:simplexml_load_file => Function simplexml_load_file()
- p:class => Create a Prestashop object model sample !
- p:module => Create a Prestashop Module sample !
- p:assign => Give a $this->context->smarty->assign(array());
- p:mail_send => Give a complete Mail::send() call
Functions with PHPStorm
- As you can see, I add new functions , references by PHPStorm.
Shortcut |
Function |
_c |
build construct method |
eco |
echo |
fore |
foreach |
forek |
foreach with key |
inc |
include |
inco |
include_once |
prif |
build private method |
prisf |
build private static method |
prof |
build protected method |
prosf |
build protected static method |
pubf |
build public method |
pubsf |
build public static method |
rqr |
require |
rqro |
require_once |
thr |
throw new... |
php snippets
Shortcut |
Output |
|
|
|
|
|
|
|
$_ |
$_COOKIE['...'] |
|
|
|
|
|
|
|
$_ |
$_ENV['...'] |
|
|
|
|
|
|
|
$_ |
$_FILES['...'] |
|
|
|
|
|
|
|
$_ |
$_GET['...'] |
|
|
|
|
|
|
|
$_ |
$_POST['...'] |
|
|
|
|
|
|
|
$_ |
$_REQUEST['...'] |
|
|
|
|
|
|
|
$_ |
$_SERVER['...'] |
|
|
|
|
|
|
|
$_ |
$_SESSION['...'] |
|
|
|
|
|
|
|
r |
return; |
|
|
|
|
|
|
|
dd |
dd(...) |
|
|
|
|
|
|
|
trt |
trait ... { |
|
|
|
|
|
|
|
?= |
<?= ... ?> |
|
|
|
|
|
|
|
c |
class ... { |
|
|
|
|
|
|
|
cc |
class ... { w/ constructor |
|
|
|
|
|
|
|
As much as possible I try and make the ... be where your cursor ends up.
Magic constants
Shortcut |
Constant |
_l |
__LINE__ |
_f |
__FILE__ |
_d |
__DIR__ |
_fun |
__FUNCTION__ |
_cl |
__CLASS__ |
_t |
__TRAIT__ |
_m |
__METHOD__ |
_n |
__NAMESPACE__ |
_cn |
ClassName::class |
Snippets SQL in PHP
- p:sqlDb => $db = Db::getInstance();
- p:sqlDb1 => $db = Db::getInstance(PS_USE_SQL_SLAVE);
- p:prefix => Get Data base prefix DB_PREFIX
- p:prefix1 => Get Data base prefix Db::getInstance->getPrefix();
- p:sqlQuery => Show an instance of DBQuery
- p:sqlExecute => Prestashop DB execute function
- p:sqlExecuteS => Prestashop DB executeS function
- p:sqlRow => Give a Db::getInstance()->getRow($sql);
- p:sqlVal => Give a Db::getInstance()->getValue($sql);
- p:sqlInsert => SQL prestashop insert into
- p:sqlInsert1 => SQL insert into 1
- p:sqlInsert2 => SQL insert into 2
- p:sqlUpdate => SQL update
- p:sqlDelete => SQL prestashop delete
- p:sqlDelete1 => SQL delete
- p:sqlGetLastId => SQL returns the ID created during the latest INSERT query
- p:sqlAffectedRows => SQL returns the number of lines impacted by the latest UPDATE or DELETE query
- p:sqlGetMsgError => SQL returns the latest error message, if the query has failed
- p:sqlGetNumberError => SQL returns the latest error number, if the query has failed
- p:sqlEscape => SQL Sanitize data which will be injected into SQL query
- p:sqlNumRows => SQL Get the number of rows in a result
Configuration storage service
Store configuration data
Check if a configuration data set exists
Update configuration data
Retrieve configuration data
Delete configuration
Snippets Smarty
- p:l => {l s='' mod='' d='Shop.Theme.Action'}
- p:l => {l s='' sprintf=[$var|intval] mod='<module_name>' d='Shop.Theme.Action'}
- p:dump => {$var|dump}
- p:vdump => {$var|var_dump}
- p:printr => {$var|print_r}
- p:hook => {hook h='<hook_name>' mod='<hook_name>'}
- p:widget => {widget name='<module_name>' hook='<hook_name>'}
- p:token => {Tools::getAdminTokenLite('<admin_controller_name>')}
- p:s.get => {$smarty.get.<get_parammetr>}
display value of page from URL ($_GET) http://www.example.com/index.php?page=foo
- p:s.post => {$smarty.post.<post_parammetr>}
display the variable "page" from a form ($_POST['page'])
- p:s.cookie => {$smarty.cookies.username}
display the value of the cookie "username" ($_COOKIE['username'])
- p:s.server_name => {$smarty.server.SERVER_NAME}
display the server variable "SERVER_NAME" ($_SERVER['SERVER_NAME'])
- p:s.path => {$smarty.env.PATH}
display the system environment variable "PATH"
- p:s.session.id => {$smarty.session.id}
display the php session variable "id" ($_SESSION['id'])
- p:s.request.username => {$smarty.request.username}
display the variable "username" from merged get/post/cookies/server/env
Link to admin controller
- p:link-admin-controller => {$link->getAdminLink('<admin_controller_name>')}
Link to page (new-products, specials, my-account etc.)
- p:link-page-1.6 => {$link->getPageLink()}
- p:link-page-1.7 => {url entity='my-account' params=['edited' => 1, 'id' => $id]}
Link to category
- p:link-category-1.6 => {$link->getCategoryLink()}
- p:link-category-1.7 => {url entity='category' id=<id_category> id_lang=<id_lang>}
Link to product
- p:link-product-1.6 => {$link->getProductLink()}
- p:link-product-1.7 => {url entity='product' id=<id_product>}
Link to module
- p:link-module-1.6 => {$link->getModuleLink('<module_name>','<controller_name>','<array_of_params>')}
- p:link-module-1.7 => {url entity='module' name='myModule' controller='myController' params = ['paramKey1' => $paramValue1, 'paramKey2' => $paramValue2]}
Link to image
p:link-image-1.6 => {$link->getCatImageLink()}
p:link-image-1.7 => {url entity='categoryImage' id=$id_category name='imageType'}
imageType
cart_default (125px x 125px)
small_default (98px x 98px)
medium_default (452px x 452px)
home_default (250px x 250px)
large_default (800px x 800px)
category_default (141px x 180px)
stores_default (170px x 115px)
Snippets SCSS, SASS, LESS, CSS
Generate media queries for these devices
p:media_phone => Generate Media Query Phone
@media screen and (max-width: 767px) {
}
p:media_tablet => Generate Media Query Tablet
@media screen and (min-width: 768px) and (max-width: 991px) {
}
p:media_desktop => Generate Media Query Desktop
@media screen and (min-width: 992px) {
}
p:flex-center => Display Flex Center attributes
display: flex;
justify-content: center;
align-items: center;
Snippets Vanila JS, jQuery
Vanila JS
jQuery
p:eachBasic => Basic jQuery.each()
$('element').each(function(index, value){"
console.log(this.text());
"});
p:eachArray => Array jQuery.each()
$.each(array, function(index, value){
console.log(`${index}: ${value}`);
});
p:eachJSON => JSON jQuery.each()
const colors = [
{ 'red': '#f00' },
{ 'green': '#0f0' },
{ 'blue': '#00f' }
];
$.each(colors, function() {
$.each(this, function(name, value) {
console.log(`${name} = ${value}`);
});
});
p:eachCLASS => CLASS jQuery.each()
$.each($('.link'), function(index, value) {
console.log(index + ':' + $(value).text());
});
p:ajaxFrontController => jQuery Ajax Call Your Front Controller
p:ajaxAdminController => jQuery Ajax Call Your Admin Controller
Extension Dependencies
Smarty language pack & PHP Symbols & PHP DocBlocker & HTML $ CSS!
Author : Roman Matviy
Site : https://matviy.pp.ua
Source : https://marketplace.visualstudio.com/items?itemName=apartner-top.prestashop-snippets
Donate
Buy me a coffee :)
QR Code
Or PayPall
Thank You!
Our partners
Note
If you have a snippet that you use a lot submit a pull-request!
An issue would also be an easy way to suggest a snippet to be added.
Just add the code that you'd want to be turned in to a snippet and I'll see if I can't get it added.
Known issues
I've not found a way to start a snippet with the leading less than symbol (<... ). VS Code also seems to use the opening PHP tag to define it's context insead of the selector in the bottom right of the window (or the extension). So far I've not been able to add a snippet that would twig out an entire script yet.
Enjoy!
| |