<?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; cookies</title>
	<atom:link href="https://nemops.com/tag/cookies/feed/" rel="self" type="application/rss+xml" />
	<link>https://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 &#8211; Day 4</title>
		<link>https://nemops.com/prestashop-functions-4/</link>
		<comments>https://nemops.com/prestashop-functions-4/#comments</comments>
		<pubDate>Wed, 12 Aug 2015 09:39:09 +0000</pubDate>
		<dc:creator><![CDATA[Nemo]]></dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[category]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[prestashop]]></category>
		<category><![CDATA[products list]]></category>

		<guid isPermaLink="false">http://nemops.com/?p=2504</guid>
		<description><![CDATA[<p>Prestashop has lots of time-saving functions that we can use when developing modules or extensions. Let&#8217;s see how to get various products list and deal with cookies, in this fourth batch. NOTICE: Values with &#8220;=&#8221; in the declaration are optional. Getting products of a Category This is the preferred method to get products from any [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://nemops.com/prestashop-functions-4/">Essential Prestashop Functions &#8211; Day 4</a> appeared first on <a rel="nofollow" href="https://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 see how to get various products list and deal with cookies, in this fourth batch.</p>
<p><span id="more-2504"></span></p>
<p><strong>NOTICE: Values with &#8220;=&#8221; in the declaration are optional. </strong></p>
<h2>Getting products of a Category</h2>
<pre class="brush: php; title: ; notranslate">

Category::getProducts($id_lang, $p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $random = false, $random_number_products = 1, $check_access = true, Context $context = null);

</pre>
<p>This is the preferred method to get products from any category in Prestashop. It&#8217;s used not only in categories pages, but by the homefeatured module, as well as others.</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">

$category = new Category(5);

// Retrieves the first 15 products of a category
$products = $category-&gt;getProducts($this-&gt;context-&gt;language-&gt;id, 1, 15);

// Retrieves the first 15 products of a category, returning the number of total products for that category as well. Ordered by price, lowest to highest
$products = $category-&gt;getProducts($this-&gt;context-&gt;language-&gt;id, 1, 15, 'price', 'asc', true);


// Gets a random number of products, in random order (yes, even if we specified it)
$products = $category-&gt;getProducts($this-&gt;context-&gt;language-&gt;id, 1, 15, 'price', 'asc', false, true);


</pre>
<div class="separator"></div>
<h2>Getting new products</h2>
<pre class="brush: php; title: ; notranslate">

Product::getNewProducts($id_lang, $page_number = 0, $nb_products = 10, $count = false, $order_by = null, $order_way = null, Context $context = null);

</pre>
<p>This method can be used statically, without having to instantiate the product class.</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">

$newProducts = Product::getNewProducts((int) $this-&gt;context-&gt;language-&gt;id, 0, 10);

</pre>
<div class="separator"></div>
<h2>Getting discounted products</h2>
<pre class="brush: php; title: ; notranslate">

Product::getPricesDrop($id_lang, $page_number = 0, $nb_products = 10, $count = false,
		$order_by = null, $order_way = null, $beginning = false, $ending = false, Context $context = null);

</pre>
<p>This method can also be used statically, without having to instantiate the product class.</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">


// get the last 10 prices drop, ordered by position
$price_drops = Product::getPricesDrop((int) $this-&gt;context-&gt;language-&gt;id, 0, 10);

// get the last 10 prices drops, ordered by price, but only where the offer's start date is after july 23, 2015
$price_drops =  Product::getPricesDrop((int) $this-&gt;context-&gt;language-&gt;id, 0, 10, false,
		'price', 'asc', '2015-7-23 10:45:32');

</pre>
<div class="separator"></div>
<h2>Getting Best Sales</h2>
<pre class="brush: php; title: ; notranslate">

ProductSale::getBestSales($id_lang, $page_number = 0, $nb_products = 10, $order_by = null, $order_way = null)

</pre>
<p>This method can also be used statically, without having to instantiate the product class.</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">

// get 10 best selling products, ordered by best selling
$products = ProductSale::getBestSales($this-&gt;context-&gt;language-&gt;id, 0, 10);

</pre>
<div class="separator"></div>
<h2>Getting Best Sales (Light)</h2>
<pre class="brush: php; title: ; notranslate">

ProductSale::getBestSalesLight($id_lang, $page_number = 0, $nb_products = 10, Context $context = null)

</pre>
<p>Lighter and quicker version of the above method, which only retrieves strictly necessary information (not recommended to display products in the product-list template)</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">

// get 5 best selling products, ordered by best selling, called from a hook method
$products = ProductSale::getBestSalesLight((int)$params['cookie']-&gt;id_lang, 0, 5))

</pre>
<div class="separator"></div>
<h2>Adding variables to the cookie object</h2>
<pre class="brush: php; title: ; notranslate">

Cookie::__set($key, $value);

</pre>
<p>Useful to store dynamic information through pages (like user preferences for the current login session)</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">

// you might want to trigger this when a user clicks on the cookie loaw banner (where any), so that you are not prompting him to accept it on every page
$this-&gt;context-&gt;cookie-&gt;__set('cookielawaccepted', 1);

// The value can hold strings as well (arrays can be saved by serializing them)
$this-&gt;context-&gt;cookie-&gt;__set('mycustomoptionmode', 'test');


</pre>
<div class="separator"></div>
<h2>Checking cookie variables</h2>
<pre class="brush: php; title: ; notranslate">

Cookie::__get($key);

</pre>
<p>Gets the given key&#8217;s value from the cookie object.</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">

// Following up the previous example, you can use this to avoid prompting the user again
if(!$this-&gt;context-&gt;cookie-&gt;__get('cookielawaccepted'))
{
	// display the message 
}

</pre>
<div class="separator"></div>
<h2>Clearing a cookie variable</h2>
<pre class="brush: php; title: ; notranslate">

Cookie::__unset($key);

</pre>
<p>Removes the given key from the cookie object.</p>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">

// removes the cookie law entry,
$this-&gt;context-&gt;cookie-&gt;__unset('cookielawaccepted')

</pre>
<div class="separator"></div>
<h2>Logging a user out</h2>
<pre class="brush: php; title: ; notranslate">

Customer::logout();

</pre>
<h3>Example Usage</h3>
<pre class="brush: php; title: ; notranslate">

// Clears all of the current session data for this customer
$this-&gt;context-&gt;customer-&gt;logout();

</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-3/#.Vb9EAPnzrmg" title="Essential Prestashop Functions – Day 3">Essential Prestashop Functions – Day 3</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="https://nemops.com/prestashop-functions-4/">Essential Prestashop Functions &#8211; Day 4</a> appeared first on <a rel="nofollow" href="https://nemops.com">NemoPS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://nemops.com/prestashop-functions-4/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
