<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>NemoPS &#187; functions</title>
	<atom:link href="http://nemops.com/tag/functions/feed/" rel="self" type="application/rss+xml" />
	<link>http://nemops.com</link>
	<description>Prestashop Tutorials, Modules and More!</description>
	<lastBuildDate>Wed, 05 Dec 2018 13:25:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.35</generator>
	<item>
		<title>Essential Prestashop Functions – Day 5</title>
		<link>http://nemops.com/prestashop-functions-5/</link>
		<comments>http://nemops.com/prestashop-functions-5/#comments</comments>
		<pubDate>Tue, 08 Sep 2015 08:40:16 +0000</pubDate>
		<dc:creator><![CDATA[Nemo]]></dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[prestashop]]></category>
		<category><![CDATA[smarty]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://nemops.com/?p=2522</guid>
		<description><![CDATA[<p>Prestashop has lots of time-saving functions that we can use when developing modules or extensions. In today&#8217;s batch, we will examine template level functions. Assigning variables to smarty from PHP Creating translatable strings These are to be used whenever you want to create a translatable string in a template. After adding them, you can reach [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-functions-5/">Essential Prestashop Functions – Day 5</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Prestashop has lots of time-saving functions that we can use when developing modules or extensions. In today&#8217;s batch, we will examine template level functions.</p>
<p><span id="more-2522"></span></p>
<h2>Assigning variables to smarty from PHP</h2>
<pre class="brush: php; title: ; notranslate">

$this-&gt;context-&gt;smarty-&gt;assign('variablenameinsmarty', $myvalue); // you will be able to access this as {$variablenameinsmarty} in the template

// same as above, but in batch
$this-&gt;context-&gt;smarty-&gt;assign(array(
	'variablenameinsmarty' =&gt; $myvalue,
	'anothervariablenameinsmarty' =&gt; $myothervalue,
));

</pre>
<div class="separator"></div>
<h2>Creating translatable strings</h2>
<pre class="brush: php; html-script: true; title: ; notranslate">

{l s='This is my string'} // theme template
{l s='This is my string' mod='modulename'}// module template
{l s='There are %s errors' sprintf=[$account_error|@count]} // theme template with variable replacement
{l s='No file selected' js=1} // supposed to be used in a javascript script, only within addJsDef (see below)
{l s='Billing Address' pdf='true'} // only used within PDF templates
</pre>
<p>These are to be used whenever you want to create a translatable string in a template. After adding them, you can reach out the translations page in the back office and add them into other languages. &#8220;mod&#8221; ones will be found under &#8220;Installed Modules Translations&#8221;; &#8220;pdf&#8221; ones under PDF Translations; theme ones under Front Office Translations, choosing the specific template.</p>
<div class="separator"></div>
<h2>Adding javascript variable definitions</h2>
<pre class="brush: php; html-script: true; title: ; notranslate">

{addJsDef wishlistProductsIds=$wishlist_products}

{addJsDef mySliderCount=7}

{addJsDefL name='youhavelides'}{l s='You save Slides!' js=1}{/addJsDefL}

</pre>
<p>These are needed when you want to pass data from the template to any attached .js file. You will have to make sure to write any script inside a jquery ready statement if you load them in the header, or variables won&#8217;t be readily available. Notice how the first one uses the javascript variable name, while the language one sets it using name=&#8221;.</p>
<h3>Example Usage</h3>
<pre class="brush: jscript; title: ; notranslate">
// will alert &quot;You have slides!&quot; in the current language
if(mySliderCount &gt; 0)
	alert(youhavelides);

</pre>
<div class="separator"></div>
<h2>Displaying a formatted price</h2>
<pre class="brush: php; html-script: true; title: ; notranslate">

{convertPrice price=$price} // display Price in the current currency
{displayPrice price=$price currency=$id_currency} // specify the currency
</pre>
<p>These are used to format the price only. They will not take care of any conversion rate, even if the first one is named that way.</p>
<h3>Example Usage</h3>
<pre class="brush: php; html-script: true; title: ; notranslate">

// default currency is $, id 2 is Euros
{convertPrice price=1} // $1.00
{displayPrice price=1 currency=2} // 1,00 €

</pre>
<div class="separator"></div>
<h2>Displaying a formatted date</h2>
<pre class="brush: php; html-script: true; title: ; notranslate">

{dateFormat date=$date full =1} // display a date formatted like specified in the back office

</pre>
<h3>Example Usage</h3>
<pre class="brush: php; html-script: true; title: ; notranslate">

// chosen date format is dd/mm/yyyy H:i
{dateFormat date=&quot;2015-01-07 22:45:01&quot; } // 07/01/2015
{dateFormat date=&quot;2015-01-07 22:45:01&quot; full=1} // 07/01/2015 22:45

</pre>
<div class="separator"></div>
<h2>Getting a page Link</h2>
<pre class="brush: php; html-script: true; title: ; notranslate">

{$link-&gt;getPageLink('pagename', ssl, id_lang, &quot;GET string or Array&quot;)}

</pre>
<h3>Example Usage</h3>
<pre class="brush: php; html-script: true; title: ; notranslate">

// Gets a link for step 3 of the order process, with ssl
{$link-&gt;getPageLink('order', true, NULL, &quot;step=3&quot;)}

// link to the contact us page
&lt;a href=&quot;{$link-&gt;getPageLink('contact'}&quot; title=&quot;{l s='Contact us'}&quot;&gt;{l s='Contact us'}&lt;/a&gt;

</pre>
<div class="separator"></div>
<h2>Getting a Product Image</h2>
<pre class="brush: php; html-script: true; title: ; notranslate">

{$link-&gt;getImageLink(link_rewrite, id_image, 'image_type')}

</pre>
<h3>Example Usage</h3>
<pre class="brush: php; html-script: true; title: ; notranslate">

// gets the home_default image type, having a product as array
&lt;img src=&quot;{$link-&gt;getImageLink($product.link_rewrite, $product.id_image, 'home_default')}&quot;/&gt;

</pre>
<div class="separator"></div>
<h2>Adding a new hook</h2>
<pre class="brush: php; html-script: true; title: ; notranslate">

{hook h='displaySomething'} // will process any hookDisplaySomething method
{hook h='displaySomething' parameter='my string'} // will pass a variable named &quot;parameter&quot; with value &quot;my string&quot; later available using &quot;params['mystring']&quot; in the hook method

</pre>
<div class="separator"></div>
<h2>Conclusion</h2>
<p>This batch concludes our series on Useful Prestashop Functions. Bear in mind logic should be kept off the templates as much as possible, to preserve the MVC pattern (Prestashop is heading towards it with Prestashop 1.7 removing plenty of modifiers next year). Therefore, whenever possible, try using the PHP counterpart of these functions, preprocessing the output and only using template for displaying data.</p>
<h3>Additional Resources</h3>
<ul>
<li><a href="http://nemops.com/prestashop-functions-1/#.Vb8upPnzrmg" title="Essential Prestashop Functions – Day 1">Essential Prestashop Functions – Day 1</a></li>
<li><a href="http://nemops.com/prestashop-functions-2/#.Vb9Bxvnzrmg" title="Essential Prestashop Functions – Day 2">Essential Prestashop Functions – Day 2</a></li>
<li><a href="http://nemops.com/prestashop-functions-3/#.Vb9EAPnzrmg" title="Essential Prestashop Functions – Day 3">Essential Prestashop Functions – Day 3</a></li>
<li><a href="http://nemops.com/prestashop-functions-4/#.Ve6ZPhHzrmg" title="Essential Prestashop Functions – Day 4">Essential Prestashop Functions – Day 4</a></li>
</ul>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-functions-5/">Essential Prestashop Functions – Day 5</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nemops.com/prestashop-functions-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Essential Prestashop Functions – Day 3</title>
		<link>http://nemops.com/prestashop-functions-3/</link>
		<comments>http://nemops.com/prestashop-functions-3/#comments</comments>
		<pubDate>Mon, 03 Aug 2015 10:34:07 +0000</pubDate>
		<dc:creator><![CDATA[Nemo]]></dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[prestashop]]></category>
		<category><![CDATA[products]]></category>

		<guid isPermaLink="false">http://nemops.com/?p=2495</guid>
		<description><![CDATA[<p>Prestashop has lots of time-saving functions that we can use when developing modules or extensions. The third batch will be focused on product-related methods. NOTICE: Values with &#8220;=&#8221; in the declaration are optional. Getting a Product&#8217;s Price Both methods can be equally used to get a product&#8217;s price. While the first needs to be ran [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-functions-3/">Essential Prestashop Functions – Day 3</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Prestashop has lots of time-saving functions that we can use when developing modules or extensions. The third batch will be focused on product-related methods.</p>
<p><span id="more-2495"></span></p>
<p><strong>NOTICE: Values with &#8220;=&#8221; in the declaration are optional.</strong></p>
<h2>Getting a Product&#8217;s Price</h2>
<pre class="brush: php; title: ; notranslate">

// It needs an instance
Product::getPrice($tax = true, $id_product_attribute = null, $decimals = 6,
		$divisor = null, $only_reduc = false, $usereduc = true, $quantity = 1)

// Static way
Product::getPriceStatic($id_product, $usetax = true, $id_product_attribute = null, $decimals = 6, $divisor = null,
		$only_reduc = false, $usereduc = true, $quantity = 1, $force_associated_tax = false, $id_customer = null, $id_cart = null,
		$id_address = null, &amp;$specific_price_output = null, $with_ecotax = true, $use_group_reduction = true, Context $context = null,
		$use_customer_price = true);

</pre>
<p>Both methods can be equally used to get a product&#8217;s price. While the first needs to be ran by a product instance, the second is static and can be ran from every context, as long as you provide the product id.</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">

// get the product price, after instanciating a new object

$product = new Produc(4); // instanciate a product with id = 4
// get the price, but dynamically check if it needs to apply taxes or not
$product_price = $product-&gt;getPrice(Product::$_taxCalculationMethod == PS_TAX_INC);
// get the price of a specific combination, always with taxes
$product_attribute_price = $product-&gt;getPrice(true, 77);


// get price without instanciating an object
$products = array(
	0 =&gt; array('id_product' =&gt; 2),
	1 =&gt; array('id_product' =&gt; 86),
	2 =&gt; array('id_product' =&gt; 12),
);

foreach($products as $key =&gt; $product)
	$products[$key]['price'] = Product::getPriceStatic($product['id_product']);

</pre>
<div class="separator"></div>
<h2>Getting a Product&#8217;s Name</h2>
<pre class="brush: php; title: ; notranslate">

Product::getProductName($id_product, $id_product_attribute = null, $id_lang = null);

</pre>
<p>Retrieves the given product name in a single language (if not specified, the current one)</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">

// Gets the name in the current language
$name = Product::getProductName(34);

// Gets the combination name in a chosen language
$name = Product::getProductName(34, 6, 2);

</pre>
<div class="separator"></div>
<h2>Getting a Product&#8217;s Quantity</h2>
<pre class="brush: php; title: ; notranslate">


Product::getQuantity($id_product, $id_product_attribute = null, $cache_is_pack = null);

// This will consider a specific warehouse
Product::getRealQuantity($id_product, $id_product_attribute = 0, $id_warehouse = 0, $id_shop = null)

</pre>
<p>They both return the product&#8217;s quantity, but the latter is to be preferred with advanced stock management in mind.</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">

// gets the quantity of all products in the array
$products = array(
	0 =&gt; array('id_product' =&gt; 2),
	1 =&gt; array('id_product' =&gt; 86),
	2 =&gt; array('id_product' =&gt; 12),
);

foreach($products as $key =&gt; $product)
	$products[$key]['qty'] = Product::getQuantity($product['id_product']);


// Gets quantity for a specific combination of a product (product id = 6, combination id = 99)
$quantity = Product::getQuantity(6, 99);


// Gets the quantity in stock for the specific warehouse ID
$quantity = Product::getRealQuantity(6, 0, 1);

</pre>
<div class="separator"></div>
<h2>Getting and displaying Products Cover Image</h2>
<pre class="brush: php; title: ; notranslate">

// Returns an image ID
Product::getCover($id_product, Context $context = null);

// Uses the product rewrite and image id to get the actual image link
Link::getImageLink($name, $ids, $type = null);

</pre>
<p>These can be used in conjunction to display the product&#8217;s cover.</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">

// returns an array like array('id_image' =&gt; 66)
$cover = Product::getCover(5);

if($cover) // if there is an image
{
	// notice 'ipod-nano' is the product link_rewrite field here;
	$img_link = $this-&gt;context-&gt;link-&gt;getImageLink('ipod-nano', $cover['id_image']); // remember the previous is an array
}

</pre>
<div class="separator"></div>
<h2>Getting Product Features for the front office</h2>
<pre class="brush: php; title: ; notranslate">

// Gets features so they can be properly displayed
Product::getFrontFeatures($id_lang);

// The same, but static
Product::getFrontFeaturesStatic($id_lang, $id_product);

</pre>
<p>These methods come in handy when you want to display product features with their names and values.</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">

$product = new Product(10);
$features = $product-&gt;getFrontFeatures($this-&gt;context-&gt;language-&gt;id);


// static way
$features = Product::getFrontFeaturesStatic($this-&gt;context-&gt;language-&gt;id, 10);

</pre>
<div class="separator"></div>
<h2>Getting Product Categories</h2>
<pre class="brush: php; title: ; notranslate">



// Get ids of the categories this product belongs to
Product::getCategories();

// The same, Static
Product::getProductCategories($id_product);

// Get more data about categories, including name and link_rewrite
Product::getProductCategoriesFull($id_product, $id_lang = null);

// Get all parent categories, up to the root, in a single language. It will only consider the default one as starting point
Product::getParentCategories($id_lang = null);

</pre>
<p>They are all used to retrieve data about the product&#8217;s category association.</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">

$product = new Product(10);
// $categories will be ids only
$categories = $product-&gt;getCategories();

// Using the same Object, get all parents
$parent_categories = $product-&gt;getParentCategories();

// Static way, getting more data in the current language
$categories = Product::getProductCategoriesFull(10, $this-&gt;context-&gt;language-&gt;id);


</pre>
<div class="separator"></div>
<h3>Additional Resources</h3>
<ul>
<li><a href="http://nemops.com/prestashop-functions-1/#.Vb8upPnzrmg" title="Essential Prestashop Functions – Day 1">Essential Prestashop Functions – Day 1</a></li>
<li><a href="http://nemops.com/prestashop-functions-2/#.Vb9Bxvnzrmg" title="Essential Prestashop Functions – Day 2">Essential Prestashop Functions – Day 2</a></li>
<li><a href="http://nemops.com/prestashop-functions-4/#.Vc2cffnzrmg" title="Essential Prestashop Functions – Day 4">Essential Prestashop Functions – Day 4</a></li>
<li><a href="http://nemops.com/prestashop-functions-5/#.Ve6fNxHzrmg" title="Essential Prestashop Functions – Day 5">Essential Prestashop Functions – Day 5</a></li>
</ul>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-functions-3/">Essential Prestashop Functions – Day 3</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nemops.com/prestashop-functions-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Essential Prestashop Functions – Day 2</title>
		<link>http://nemops.com/prestashop-functions-2/</link>
		<comments>http://nemops.com/prestashop-functions-2/#comments</comments>
		<pubDate>Tue, 28 Jul 2015 12:19:28 +0000</pubDate>
		<dc:creator><![CDATA[Nemo]]></dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[prestashop]]></category>

		<guid isPermaLink="false">http://nemops.com/?p=2492</guid>
		<description><![CDATA[<p>Prestashop has lots of time-saving functions that we can use when developing modules or extensions. In this second batch we will examine database-related methods. NOTICE: Values with &#8220;=&#8221; in the declaration are optionals. Database-related Functions These methods serve as helpers so that we don&#8217;t have to create a new mysql connection every time we want [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-functions-2/">Essential Prestashop Functions – Day 2</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Prestashop has lots of time-saving functions that we can use when developing modules or extensions. In this second batch we will examine database-related methods.</p>
<p><span id="more-2492"></span></p>
<p><strong>NOTICE: Values with &#8220;=&#8221; in the declaration are optionals.</strong></p>
<h2>Database-related Functions</h2>
<pre class="brush: php; title: ; notranslate">

// Retrieving an array of values from the given table
Db::getInstance()-&gt;executeS($sql, $array = true, $use_cache = true);

// Retrieving a single value
Db::getInstance()-&gt;getValue($sql, $use_cache = true);

// Retrieving a whole row
Db::getInstance()-&gt;getRow($sql, $use_cache = true);

// Executing a generic query, returns true if succeeded, false if failed
Db::getInstance()-&gt;execute($sql, $use_cache = true)

// Inserting a row
Db::getInstance()-&gt;insert($table, $data, $null_values = false, $use_cache = true, $type = Db::INSERT, $add_prefix = true)

// Updating values
Db::getInstance()-&gt;update($table, $data, $where = '', $limit = 0, $null_values = false, $use_cache = true, $add_prefix = true)

// Erase the given entry
Db::getInstance()-&gt;delete($table, $where = '', $limit = 0, $use_cache = true, $add_prefix = true)

// Escape data
Db::getInstance()-&gt;escape($string, $html_ok = false, $bq_sql = false)

// Get the primary key of the last item you added
Db::getInstance()-&gt;Insert_ID()

</pre>
<p>These methods serve as helpers so that we don&#8217;t have to create a new mysql connection every time we want to run a query</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">

// Returns an array with each item correspinding to a single database row
// It should only be used to retrieve values, use execute or the other helpers to insert/update them
$customers = Db::getInstance()-&gt;executeS('SELECT * FROM '._DB_PREFIX_.'customers');

// Returns product data of the ones that belong to the given category only (id = 4)
$products = Db::getInstance()-&gt;executeS('
	SELECT * FROM '._DB_PREFIX_.'product p
	LEFT JOIN '._DB_PREFIX_.'category_product cp ON (cp.id_product = p.id_product)
	WHERE cp.id_category = 4
');


// Retrieving the specific product name for our current language
$product_name = Db::getInstance()-&gt;getValue('SELECT name FROM '._DB_PREFIX_.'product_lang WHERE id_product = 1 AND id_lang = ' . $this-&gt;context-&gt;language-&gt;id);

// Get the whole row for customer id = 1
$customer = Db::getInstance()-&gt;getRow('SELECT * FROM '._DB_PREFIX_.'customer WHERE id_customer = 1');


// Insert some data manually (not recommended, unless you have some really specific SQL to use)
Db::getInstance()-&gt;execute('INSERT INTO '._DB_PREFIX_.'customer (id_customer, email, firstname, lastname) VALUES (9, &quot;nemo@nemops.com&quot;, &quot;Fabio&quot;, &quot;Porta&quot;)');

// Inserting a row
// The $data array must be configured like 
// 		column =&gt; value

$data = array(
	'id_customer' =&gt; 1,
	'email' =&gt; &quot;nemo@nemops.com&quot;,
	'firstname' =&gt; &quot;Fabio&quot;,
	'lastname' =&gt; &quot;Porta&quot;,
);
Db::getInstance()-&gt;insert('customer', $data);

// Updating values, array configured as above
$data = array(
	'id_customer' =&gt; 1,
	'email' =&gt; &quot;nemo@nemops.com&quot;,
	'firstname' =&gt; &quot;Fabio&quot;,
	'lastname' =&gt; &quot;Porta&quot;,
);
Db::getInstance()-&gt;update('customer', $data, 'id_customer = 1');

// Erase customer with id = 1
Db::getInstance()-&gt;delete('customer', 'id_customer = 1');

// Escape data
$sanitized = Db::getInstance()-&gt;escape('&lt;div class=&quot;test&quot;&gt;&lt;div&gt;', true);
// will return &lt;div class=\&quot;test\&quot;&gt;&lt;div&gt;

// Get the primary key of the last item you added

$data = array(
	'email' =&gt; &quot;nemo@nemops.com&quot;,
	'firstname' =&gt; &quot;Fabio&quot;,
	'lastname' =&gt; &quot;Porta&quot;,
);
Db::getInstance()-&gt;insert('customer', $data);
$last_id = Db::getInstance()-&gt;Insert_ID()
// $last_id will be the id_customer of the entry we just added


</pre>
<div class="separator"></div>
<h2>The Query object in Prestashop</h2>
<pre class="brush: php; title: ; notranslate">

DbQuery::select($fields)
DbQuery::from($table, $alias = null)
DbQuery::join($fields)
DbQuery::leftJoin($table, $alias = null, $on = null)
DbQuery::where($restriction)
DbQuery::having($restriction)
DbQUery::orderBy($fields)
DbQUery::groupBy($fields)
DbQuery::limit($limit, $offset = 0)

</pre>
<p>All these functions are used to streamline a query creation. Inspect the <strong>DbQuery</strong> class to have a complete list.</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">

	// get all products with id &gt; 3, with relative language data

	$query = new DbQuery();
	$query-&gt;select('p.*, pl.*')
		-&gt;from('product', 'p')
		-&gt;leftJoin('product_lang', 'pl', 'p.id_product = pl.id_product')
		-&gt;where('p.id_product &gt; 34')
		-&gt;where('pl.id_lang = ' . $this-&gt;context-&gt;language-&gt;id)
		-&gt;groupBy('p.id_product')
		-&gt;limit(5)

	$result = Db::getInstance()-&gt;getValue($query);

</pre>
<div class="separator"></div>
<h2>Quick escape in a SQL query</h2>
<pre class="brush: php; title: ; notranslate">

pSQL($string, $htmlOK = false)

</pre>
<p>Sanitize data which will be injected into SQL query</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">

	$search = '2&quot; clamps';
	// get aliases for the given search word, as you can see the above requires douple quotes to be escaped
	$aliases = Db::getInstance()-&gt;executeS('
	SELECT a.alias
	FROM `'._DB_PREFIX_.'alias` a
	WHERE `search` = \''.pSQL($search).'\'');

</pre>
<h2>Wrapping it up</h2>
<p>All of the methods we examined today are a huge time saver when dealing with the Database in Prestashop. I rarely use the query object, I admit, as I prefer relying on the other methods. However, since it&#8217;s getting more and more built into the standard workflow of core modules and methods, it&#8217;s good practice to start using that as well, and integrate it into your own Prestashop Module/Extension.</p>
<div class="separator"></div>
<h3>Additional Resources</h3>
<ul>
<li><a href="http://nemops.com/prestashop-functions-1/#.Vb8upPnzrmg" title="Essential Prestashop Functions – Day 1">Essential Prestashop Functions – Day 1</a></li>
<li><a href="http://nemops.com/prestashop-functions-3/#.Vb9EAPnzrmg" title="Essential Prestashop Functions – Day 3">Essential Prestashop Functions – Day 3</a></li>
<li><a href="http://nemops.com/prestashop-functions-4/#.Vc2cffnzrmg" title="Essential Prestashop Functions – Day 4">Essential Prestashop Functions – Day 4</a></li>
<li><a href="http://nemops.com/prestashop-functions-5/#.Ve6fNxHzrmg" title="Essential Prestashop Functions – Day 5">Essential Prestashop Functions – Day 5</a></li>
</ul>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-functions-2/">Essential Prestashop Functions – Day 2</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nemops.com/prestashop-functions-2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Essential Prestashop Functions &#8211; Day 1</title>
		<link>http://nemops.com/prestashop-functions-1/</link>
		<comments>http://nemops.com/prestashop-functions-1/#comments</comments>
		<pubDate>Tue, 21 Jul 2015 10:03:01 +0000</pubDate>
		<dc:creator><![CDATA[Nemo]]></dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[prestashop]]></category>

		<guid isPermaLink="false">http://nemops.com/?p=2486</guid>
		<description><![CDATA[<p>Prestashop has lots of time-saving functions that we can use when developing modules or extensions. Let&#8217;s have a look at the first batch of Prestashop Functions, and in which context they might come in use. If you want to dive into Prestashop development, these are likely the first methods you&#8217;ll be needing. NOTICE: Values with [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-functions-1/">Essential Prestashop Functions &#8211; Day 1</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Prestashop has lots of time-saving functions that we can use when developing modules or extensions. Let&#8217;s have a look at the first batch of Prestashop Functions, and in which context they might come in use.</p>
<p><span id="more-2486"></span></p>
<p>If you want to dive into Prestashop development, these are likely the first methods you&#8217;ll be needing.</p>
<p><strong>NOTICE: Values with &#8220;=&#8221; in the declaration are optionals.</strong></p>
<h2>Managing Configuration values in Prestashop</h2>
<pre class="brush: php; title: ; notranslate">

// Updating a single/multiple value/s
Configuration::updateValue($key, $values, $html = false, $id_shop_group = null, $id_shop = null);

// Getting a single value
Configuration::get($key, $id_lang = null, $id_shop_group = null, $id_shop = null)

// Getting Multiple Values
Configuration::getMultiple($keys, $id_lang = null, $id_shop_group = null, $id_shop = null)

// Getting the same key in all languages
Configuration::getInt($key, $id_shop_group = null, $id_shop = null)

// Erase the given entry
Configuration::deleteByName($key)

</pre>
<p>These methods are used to interact with the *prefix_*configuration table. It&#8217;s the quickest way to store simple data in Prestashop.</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">
// Saving a normal string
$my_text = 'This is some text';
Configuration::updateValue('MY_CONFIG_PARAMETER', $my_text);

// Saving an html string
$my_text = '&lt;p&gt;This is some text&lt;/p&gt;';
Configuration::updateValue('MY_CONFIG_PARAMETER', $my_text, true);

// Saving multiple values, KEYS represend ID_LANG
$my_texts = array(
	1 =&gt; 'This is some text',
	2 =&gt; 'This is some text in another language'
	);
Configuration::updateValue('MY_CONFIG_PARAMETER_MULTILANG', $my_text);


// Getting a single value
$my_text = Configuration::get('MY_CONFIG_PARAMETER');

// Getting a single value for the current language only
$my_text = Configuration::get('MY_CONFIG_PARAMETER', $this-&gt;context-&gt;language-&gt;id);

// Getting Multiple Values
$keys_to_get = array('MY_CONFIG_PARAMETER', 'OTHER_CONFIG_PARAMETER');
Configuration::getMultiple($keys_to_get);

// Delete the given key
Configuration::deleteByName('MY_CONFIG_PARAMETER');
</pre>
<div class="separator"></div>
<h2>Getting POST and GET in Prestashop</h2>
<pre class="brush: php; title: ; notranslate">
Tools::getValue($key, $default_value = false)

</pre>
<p>Retrieves the current POST or GET variable with the given key</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">
// Getting either POST or GET with the key 'myvalue', the second parameter is what to assign then nothing is found.
$value = Tools::getValue('myvalue', 4);
// If no 'myvalue' POST or GET variable is set, $value will be 4.
</pre>
<div class="separator"></div>
<h2>Checking for submitted data in Prestashop</h2>
<pre class="brush: php; title: ; notranslate">
Tools::isSubmit($key);
</pre>
<p>Check whether or not the given key has been submitted to the current page.</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">
if(Tools::isSubmit('myvalue'))
{
	// do something
}
</pre>
<div class="separator"></div>
<h2>Displaying Errors in Prestashop</h2>
<pre class="brush: php; title: ; notranslate">
Tools::displayError($string = 'Fatal error', $htmlentities = true, Context $context = null)
</pre>
<p>Displays an error with proper formatting.</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">
if($myvalue != 1)
{
	// will need to be displayed later on
	$error_string = Tools::displayError('It is different from 1');
}
</pre>
<div class="separator"></div>
<h2>Displaying Confirmations in Prestashop Modules</h2>
<pre class="brush: php; title: ; notranslate">
$this-&gt;displayConfirmation($string);
</pre>
<p>Displays a properly formatted confirmation message. $this refers to a module, it is therefore only available in module contexts only. Refer to the proper variable elsewhere.</p>
<pre class="brush: php; title: ; notranslate">

// this is inside a module's method
if($myvalue == 1)
{
	// will need to be displayed later on
	$conf_string = $this-&gt;displayConfirmation('Updated!');
}

</pre>
<div class="separator"></div>
<h2>Adding CSS in Prestashop</h2>
<pre class="brush: php; title: ; notranslate">
ControllerCore::addCSS($css_uri, $css_media_type = 'all', $offset = null, $check_path = true)
</pre>
<p>Appends the given CSS file/s to the page</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">

// this is inside a module's method
$this-&gt;context-&gt;controller-&gt;addCSS($this-&gt;_path.'css/myfile.css', 'all');

// this is inside a controller's method
$this-&gt;addCSS(_THEME_CSS_DIR_.'product.css');

// adding multiple files
$files = array(
	_THEME_CSS_DIR_.'product.css' =&gt; 'all',
	_THEME_CSS_DIR_.'other_css.css' =&gt; 'all'
);
$this-&gt;addCSS($files);

</pre>
<div class="separator"></div>
<h2>Adding Javascript in Prestashop</h2>
<pre class="brush: php; title: ; notranslate">
ControllerCore::addJS($js_uri, $check_path = true);
</pre>
<p>Appends the given JS file/s to the page</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">

// this is inside a module's method
$this-&gt;context-&gt;controller-&gt;addCSS($this-&gt;_path.'css/myfile.css', 'all');

// this is inside a controller's method
$this-&gt;addCSS(_THEME_CSS_DIR_.'product.css');

</pre>
<div class="separator"></div>
<h2>Adding jQuery Plugins in Prestashop</h2>
<pre class="brush: php; title: ; notranslate">
ControllerCore::addJqueryPlugin($name, $folder = null, $css = true)
</pre>
<p>Appends the given jQuery Plugin/s to the page</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">

// this is inside a module's method, multiple files
$this-&gt;context-&gt;controller-&gt;addjqueryPlugin('fancybox');

// this is inside a controller's method
$this-&gt;addjqueryPlugin('fancybox');

// this is inside a controller's method, multiple values
$this-&gt;addjQueryPlugin(array('scrollTo', 'alerts', 'chosen', 'autosize', 'fancybox' ));

// this is inside a controller's method, without loading the plugin's CSS
$this-&gt;addjQueryPlugin('growl', null, false);

</pre>
<div class="separator"></div>
<h2>Adding jQuery UI Components in Prestashop</h2>
<pre class="brush: php; title: ; notranslate">
ControllerCore::addJqueryUI($component, $theme = 'base', $check_dependencies = true);
</pre>
<p>Appends the given jQuery UI component/s to the page</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">

// this is inside a module's method, single file
$this-&gt;context-&gt;controller-&gt;addjQueryUI(ui.datepicker');

// this is inside a controller's method, multiple files
$this-&gt;addJqueryUI(array('ui.slider', 'ui.datepicker'));

</pre>
<div class="separator"></div>
<h2>Wrapping it up</h2>
<p>We saw quite a number of useful PrestaShop Functions today, which are enough to start coding your own, simple module. Apart from trying to remember them all, I suggest creating code snippets with some text expander, so you can quickly drop them in, without having to remember the exact syntax.</p>
<div class="separator"></div>
<h3>Additional Resources</h3>
<ul>
<li><a href="http://nemops.com/prestashop-functions-2/#.Vb9Bxvnzrmg" title="Essential Prestashop Functions – Day 2">Essential Prestashop Functions – Day 2</a></li>
<li><a href="http://nemops.com/prestashop-functions-3/#.Vb9EAPnzrmg" title="Essential Prestashop Functions – Day 3">Essential Prestashop Functions – Day 3</a></li>
<li><a href="http://nemops.com/prestashop-functions-4/#.Vc2cffnzrmg" title="Essential Prestashop Functions – Day 4">Essential Prestashop Functions – Day 4</a></li>
<li><a href="http://nemops.com/prestashop-functions-5/#.Ve6fNxHzrmg" title="Essential Prestashop Functions – Day 5">Essential Prestashop Functions – Day 5</a></li>
</ul>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-functions-1/">Essential Prestashop Functions &#8211; Day 1</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nemops.com/prestashop-functions-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
