Jump to content

I want to add another column in the product page in the back office in prestashop 1.7.8.8


Recommended Posts

  • 3 weeks later...

yes , i found a way that lets you display the manufacturer name , but i want to display another table and can't find a way to display the data , i added the column by overriding the twig but it stays empty no matter what i did 

Link to comment
Share on other sites

    <td class="text-center column-img-reduction">

      {% if reduction is defined %}

        <a href="{{ reduction }}"  target="_blank" > {{ reduction }}{{ reduction|default('') }}</a>

      {% else %}

       <h1> "reduction"</h1>

      {% endif %}

    </td>

this is the collumn i added in list.html.twig  

  <th scope="col">

        {{ ps.sortable_column_header("reduction"|trans({}, 'Admin.Global'), 'reduct', orderBy, sortOrder) }}

      </th> 

and this is the collumn header 

i changed the query in AdminProductsController with a left join to retrieve the data from the specific table but it does not show anything  and the collumn is empty

Link to comment
Share on other sites

I am actually trying to display a String called link from a table that i added , not a original Prestashop table and im using a join but the collumn is always empty 

<?php
// ...

public function hookActionAdminProductsListingFieldsModifier(array $params)
{
    if ($this->isPrestaShop16) {
        if (isset($params['select'])) {
            $params['select'] .= ', a.id_product, cp.produit_lien AS produit_lien';
        }

        if (isset($params['join'])) {
            $params['join'] .= ' LEFT JOIN ' . _DB_PREFIX_ . 'produit AS cp ON (a.id_product = cp.id_produit)';
        }

        $params['fields']['produit_lien'] = [
            'title' => $this->l('Link'),
            'align' => 'text-center',
            'class' => 'fixed-width-xs',
            'filter_key' => 'cp!produit_lien',
            'order_key' => 'cp!produit_lien',
        ];

        if (Configuration::get(static::CONFIGURATION_KEY_SHOW_LOGO)) {
            $params['fields']['produit_lien']['icon'] = true;
            $params['fields']['produit_lien']['class'] .= ' column-img-produit_lien';
        }
    } else {
        $params['sql_select']['id_product'] = [
            'table' => 'p',
            'field' => 'id_product',
            'filtering' => ' %s ',
        ];

        $params['sql_select']['produit_lien'] = [
            'table' => 'cp',
            'field' => 'produit_lien',
            'filtering' => 'LIKE \'%%%s%%\'',
        ];

        $params['sql_table']['cp'] = [
            'table' => 'produit',
            'join' => 'LEFT JOIN',
            'on' => 'p.`id_product` = cp.`id_produit`',
        ];

        
        $produit_filter = Tools::getValue('filter_column_produit');
        if (!empty($produit_filter) && Validate::isCatalogName($produit_filter)) {
            $params['sql_where'][] .= sprintf('cp.produit_lien LIKE "%%%s%%"', pSQL($produit_filter));
        }
    }
}

public function hookActionAdminProductsListingResultsModifier(array $params)
{
    if (!Configuration::get(static::CONFIGURATION_KEY_SHOW_LOGO)) {
        return;
    }

    if ($this->isPrestaShop16 && !empty($params['list'])) {
        foreach ($params['list'] as $key => $fields) {
            if (isset($fields['id_product'], $fields['produit_lien'])) {
                $params['list'][$key]['produit_lien'] = [
                    'src' => '../m/' . (int)$fields['produit_lien'],
                    'alt' => Tools::safeOutput($fields['produit_lien']),
                ];
            }
        }
    } else {
        foreach ($params['products'] as $key => $product) {
            if ($product['id_product']) {
                $params['products'][$key]['produit_lien'] = $this->context->link->getMediaLink(_THEME_MANU_DIR_ . $product['produit_lien']);
            }
        }
    }
}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...