Friday, October 21, 2022

Prestashop 1.7 thumbnails of variants in product page

this code will display UNIQUE images of product variants images under main  image product in product page 
ested on ubuntu 20.04 LTS / Prestashop 1.7.8.7 / Php 7.4)

try to change code between 'product_images' and its end of file
YOUR_THEME_SYSTEM_PATH/templates/catalog/_partials/product-cover-thumbnails.tpl


{block name='product_images'}
{if isset($combinationImages)}
<div class="js-qv-mask mask">
<div id="product-images-thumbs" class="product-images js-qv-product-images slick-slider">
{assign 'allIds' []}
{foreach from=$combinationImages item='combination' key='combinationId' name='f_combinationImages'}
{foreach from=$combination item='image' name='f_combinationImage'}
{assign var='thumbImageId' value="{$combinationId}-{$image.id_image|intval}"}
{append var='allIds' value="{$link->getImageLink($product.link_rewrite, $thumbImageId, 'medium_default')}"}
{/foreach}
{/foreach}
{assign 'visitedImgs' []}
{foreach from=$combinationImages item='combination' key='combinationId' name='f_combinationImages'}
{foreach from=$combination item='image' name='f_combinationImage'}
{assign var='thumbImageId' value="{$combinationId}-{$image.id_image|intval}"}
{if in_array({$link->getImageLink($product.link_rewrite, $thumbImageId, 'medium_default')},$allIds)
&& !in_array({$link->getImageLink($product.link_rewrite, $thumbImageId, 'medium_default')},$visitedImgs) }
{append var='visitedImgs' value="{$link->getImageLink($product.link_rewrite, $thumbImageId, 'medium_default')}"}
<div class="thumb-container">
<img
class="thumb js-thumb img-fluid"
data-image-medium-src="{$link->getImageLink($product.link_rewrite, $thumbImageId, 'medium_default')}"
data-image-large-src="{$link->getImageLink($product.link_rewrite, $thumbImageId, 'large_default')}"
src="{$link->getImageLink($product.link_rewrite, $thumbImageId, 'medium_default')}"
alt="{$image.legend}"
title="{$image.legend}"
itemprop="image"
>
</div>
{/if}


{/foreach}
{/foreach}
</div>
</div>

{else}
<div class="js-qv-mask mask">
<div id="product-images-thumbs" class="product-images js-qv-product-images slick-slider">
{foreach from=$product.images item=image name=thumbs}
<div class="thumb-container">
<img
class="thumb js-thumb {if $image.id_image == $product.cover.id_image} selected {/if}img-fluid"
data-image-medium-src="{$image.bySize.medium_default.url}"
data-image-large-src="{$image.large.url}"
src="{$image.bySize.medium_default.url}"
alt="{$image.legend}"
title="{$image.legend}"
width="{$image.bySize.medium_default.width}"
height="{$image.bySize.medium_default.height}"
itemprop="image"
>
</div>
{/foreach}
</div>
</div>
{/if}
{/block}


Credits:
https://www.prestashop.com/forums/topic/963580-showing-thumbnails-for-all-combinations/ (duplicated thumbs are shown)

Monday, July 19, 2021

httpd / svn / ldap authentication Simple and mixed authorizations

i'll not make things hard and long.
Here is an configuration that i use to authenticate users thats use our svn server.


LoadModule dav_svn_module     modules/mod_dav_svn.so
LoadModule authz_svn_module   modules/mod_authz_svn.so

# Add the following to allow a basic authentication and point Apache to where the actual
# repository resides.

        DAV svn
        SVNPath /var/www/html/svn/chartes
        AuthType Basic
        AuthName "My company repo"
	#AuthBasicAuthorative Off
	AuthBasicProvider ldap
	AuthLDAPURL "ldap://AD_IP/DC=DC_1,DC=local?sAMAccountName?sub?(objectClass=*)"
	AuthLDAPBindDN	"LOGIN_OF_AUTHORIZED_USER_TO_SEARCH"
	AuthLDAPBindPassword "PASSWORD_FOR_AUTHORIZED_USER"
	Require valid-user	


Don't specify the port in the server ip
DC items may be more then 2, depending on your AD configuration.
Remark here we use sAMAccountName as research criteria Now imagine we want this scenario:
1-LDAP auth
2-Access rights granted from local file (rw rights)
We can do that by adding a simple directive in our .conf file
AuthzSVNAccessFile
so our new .conf file become:
LoadModule dav_svn_module     modules/mod_dav_svn.so
LoadModule authz_svn_module   modules/mod_authz_svn.so

# Add the following to allow a basic authentication and point Apache to where the actual
# repository resides.

        DAV svn
        SVNPath /var/www/html/svn/chartes
        AuthType Basic
        AuthName "My company repo"
	#AuthBasicAuthorative Off
	AuthBasicProvider ldap
	AuthLDAPURL "ldap://AD_IP/DC=DC_1,DC=local?sAMAccountName?sub?(objectClass=*)"
	AuthLDAPBindDN	"LOGIN_OF_AUTHORIZED_USER_TO_SEARCH"
	AuthLDAPBindPassword "PASSWORD_FOR_AUTHORIZED_USER"
    AuthzSVNAccessFile /etc/svn-repo-chartes.authz
	Require valid-user	

Where /etc/svn-repo-chartes.authzcontent is
[/] * = r

Now no-one has write right on repo here but only read
Let's see that
Sceanrio:
1- Login
2-Checkout
3-Create file
4-Add file to repo
5-commit

Craps!
We have that message :
Accès à '/svn/chartes/!svn/me' interdit' <=> 'Access to .... denied' 

Now you can set authorizations line by line and user by user

Let's continue...
I'll grant to Mr 66456 a write right
Our new authorizations file content become:
[/]
* = r
66456 = rw

Let's commit again...
All right !

Friday, May 14, 2021

Responsive width Facebook Page Plugin

 Facebook plugin can fit into any div by specifying the width attribute 
exemple (here width is set 200px) 


<div class="fb-page" data-href="https://www.facebook.com/facebook" data-tabs="timeline" data-width="200" data-height="" data-small-header="false" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="true"><blockquote cite="https://www.facebook.com/facebook" class="fb-xfbml-parse-ignore"><a href="https://www.facebook.com/facebook">Facebook</a></blockquote></div>

The only constraint is the 180px<=width <=500px

In case when we dont have the exact size of a div until the DOM load, an alternative is to differ the script load after DOM load and pass the correct width at that moment

in this few codes i m  trying to fit the fb feed into a 63.26% of  wrapper

   console.log('running fb script');
    var fb_block = document.getElementById('fb-wrapper');    
    if(fb_block !== null){
        var parent_width = $('.home-social-content').width();        
        var fb_width = parent_width * 63.26 / 100;        
        var rounded_fb_width = Math.round(fb_width);        
        if(fb_width < rounded_fb_width){
            rounded_fb_width -= 1;
        }        
        var inject_html = '<div class="fb-page" data-href="https://www.facebook.com/airbus" data-tabs="timeline" data-width="' + rounded_fb_width +'" data-height="732" data-small-header="true" data-adapt-container-width="true" data-hide-cover="true" data-show-facepile="false"><blockquote cite="https://www.facebook.com/airbus" class="fb-xfbml-parse-ignore"><a href="https://www.facebook.com/airbus">Airbus</a></blockquote></div>';
        inject_html +='<script async defer crossorigin="anonymous" src="https://connect.facebook.net/fr_FR/sdk.js#xfbml=1&version=v10.0&appId=337498777087670&autoLogAppEvents=1" nonce="qjuBX7Rb"></script>';        
        $('#fb-wrapper').html(inject_html); 
        console.log('done...');  


Monday, January 11, 2021

Prestashop 1.6.x - PHP 5.x to PHP 7.x Uncaught Error: Access to undeclared static property:

When upgrading PHP version for prestashop 1.6.x websites from 5.x to 7.x
some errors may occure (Prestashop guys confirm that max allowed version is 5.5)

Typical error is:

Uncaught Error: Access to undeclared static property: CLASS_NAME::PROPERTY/METHOD_NAME in ....
Example:
Uncaught Error: Access to undeclared static property: Validate::$data in ZZZ/classes/ObjectModel.php:1113
So i made change in 2 calsses (up to now) to make the website working :


in classes/controller/AdminController.php (Line 886 ???)
i've changed:
$return = $this->{'process'.Tools::toCamelCase($this->action)}();

to
$return = call_user_func_array(array($this, 'process'.Tools::toCamelCase($this->action)), array());


in classes/ObjectModel: (Line 1135 ???)
if (isset($data['validate']) && !Validate::$data['validate']($value) && (!empty($value) || $data['required']))

to
if (isset($data['validate']) && !call_user_func('Validate::'.$data['validate'],$value) && (!empty($value) || $data['required']))

Notice:
Even your website will reUp, it will be from time to other somme 500erros, in general they are in the same kind of the last indicated php instruction :
related to the call call_user_func that became mondatory

Saturday, November 7, 2020

PHP / MySQL tables optimization

The php code below optimize all tables in MySQL database.


<?php
echo '< html > < body >';
$servername = "*****";
$username = "*****";
$password = "*****";
$database = "****";

// Create connection
$connection = new mysqli($servername, $username, $password, $database);

if ($connection -> connect_errno) {
  echo "Failed to connect to MySQL: " . $connection -> connect_error;
  exit();
}
echo "Connected successfully
"; $sql = "show tables"; if (!$result = $connection->query($sql)) { die ('There was an error running query[' . $connection->error . ']'); } while ($row = $result->fetch_array()) { $table_name = $row[0]; echo 'Optimizing table: '.$table_name.'...... '; $connection->query("OPTIMIZE TABLE '".$tablename."'"); echo ' ....done
'; } $connection->close(); echo 'Disconnected
'; die("End"); echo '< body > < html >'; ?>

Script execution output on Prestashop 1.6 database will be like:

Connected successfully 
Optimizing table: pequi_access...... ....done 
Optimizing table: pequi_accessory...... ....done 
Optimizing table: pequi_address...... ....done 
Optimizing table: pequi_address_format...... ....done ....... 
Optimizing table: temp_attr...... ....done 
Disconnected
End