PrestaShop – check product category in smarty .tpl

If you need to display some block based on product’s category and you want to check for that category right in the smarty template ( e.g. product.tpl ) you can do so using this code – which as an example uses category 27 as base reference. You can easily find your category ID in admin.

{assign var='cats' value=Product::getProductCategories($product.id)}
{if in_array(27, $cats)}
.. following will only be displayed if this product is in category of ID 27
{/if}

If you for some reason can’t find your category ID, you can look for it by adding following into product.tpl

{assign var='cats' value=Product::getProductCategories($product.id)}
{$cats|@print_r}
Just reload page and you will see in which categories this product is. Alternatively you could use
{debug}
to access all smarty available variables and look in there.

Can’t install Let’s Encrypt certificate through Plesk after update

If you have just updated Plesk and server to latest packages, you might find yourself having issues with Let’s Encrypt. If you get following error while installing certificate from Plesk

Could not obtain directory: cURL error 6: Could not resolve host: acme-v01.api.letsencrypt.org 2; Name or service not known (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

Your openssl has probably been updated as well.

Simply restart of sw-engine and sw-cp-server should do the trick.

systemctl restart sw-engine
systemctl restart sw-cp-server

It’s best to restart php-fpm and nginx as well at this point. But might not be needed.

Allow Facebook to test your Open Graph meta tags ( og debugger ) with htpasswd password

If you are developing new site, you have probably locked it through htpasswd. When you are done with og meta data, you might want to check it with https://developers.facebook.com/tools/debug/sharing/ – but facebook won’t be able to access your content, because you can’t give it your password.

You need to update your htaccess, from

AuthUserFile /.htpasswd
AuthName Disbait
AuthType Basic
Require valid-user
satisfy any
deny from all
allow from 127.0.0.1

to

SetEnvIfNoCase User-Agent "^facebookexternalhit" facebook
SetEnvIfNoCase User-Agent "Facebot" facebook
SetEnvIfNoCase User-Agent "Twitterbot" twitter

AuthUserFile /.htpasswd
AuthName "Restricted Access"
AuthType Basic
Require valid-user
satisfy any
deny from all
allow from 127.0.0.1
allow from env=facebook
allow from env=twitter

Credit coderwall.com/p/8y7t1q/whitelist-facebook-twitter-to-test-your-open-graph-and-twitter-card-implementations