Jump to content

Adding product reference (SKU) to admin page header title


Recommended Posts

Hi, after looking for a solution for a long time by myself i decided to ask for help here. I need to customize my Prestashop admin - I want to add the product reference (sku) in the title of the admin page header when the product is edited (There is label "Edit: (product name)). Tried looking in tpl's and controller files but without any success. For detailed info, here is a screenshot with this area marked:

post-946629-0-68098700-1426777532_thumb.png

Link to comment
Share on other sites

  • 2 years later...

Hello,

 

This is how I got it to work on prestashop 1.6.1.1. Edit file AdminController.php and find below if statement around line 1470.

 

Find:

if (Validate::isLoadedObject($obj) && isset($obj->{$this->identifier_name}) && !empty($obj->{$this->identifier_name})) {
                    array_pop($this->toolbar_title);
                    array_pop($this->meta_title);
                    $this->toolbar_title[] = is_array($obj->{$this->identifier_name}) ? $obj->{$this->identifier_name}[$this->context->employee->id_lang] : $obj->{$this->identifier_name};
                    $this->addMetaTitle($this->toolbar_title[count($this->toolbar_title) - 1]);
                }
                break;
            case 'edit':
                $obj = $this->loadObject(true);
                if (Validate::isLoadedObject($obj) && isset($obj->{$this->identifier_name}) && !empty($obj->{$this->identifier_name})) {
                    array_pop($this->toolbar_title);
                    array_pop($this->meta_title);
                    $this->toolbar_title[] = sprintf($this->l('Edit: %s'), (is_array($obj->{$this->identifier_name}) && isset($obj->{$this->identifier_name}[$this->context->employee->id_lang])) ? $obj->{$this->identifier_name}[$this->context->employee->id_lang] : $obj->{$this->identifier_name});
                    $this->addMetaTitle($this->toolbar_title[count($this->toolbar_title) - 1]);
                }

 

Replace with:

if (Validate::isLoadedObject($obj) && isset($obj->{$this->identifier_name}) && !empty($obj->{$this->identifier_name})) {
                    array_pop($this->toolbar_title);
                    array_pop($this->meta_title);
                    
                    // Get product name
                    $nameArray = (is_array($obj->{$this->identifier_name}) && isset($obj->{$this->identifier_name}[$this->context->employee->id_lang])) ? $obj->{$this->identifier_name}[$this->context->employee->id_lang] : $obj->{$this->identifier_name};
                    // Get product model
                    $modelArray = (is_array($obj->{$this->identifier_model}) && isset($obj->{$this->identifier_model}[$this->context->employee->id_lang])) ? $obj->{$this->identifier_model}[$this->context->employee->id_lang] : $obj->{$this->identifier_model};
                    
                    // Strip long product names    and add dots                
                    $maxLength = 52;

                    if (strlen($nameArray) > $maxLength) {
                        $stringCut = substr($nameArray, 0, $maxLength);
                        $nameArray = substr($stringCut, 0, strrpos($stringCut, ' '));
                        $nameArray = $nameArray . '...';
                    }
                    
                    // Title Value    
                    $this->toolbar_title[] = sprintf($this->l('Edit: %s'), $nameArray . "\n" . "(" . $modelArray . ")" );
                    
                    $this->addMetaTitle($this->toolbar_title[count($this->toolbar_title) - 1]);
                }

 

Hope this helps!

Link to comment
Share on other sites

  • 2 weeks later...

Hello,

 

This is how I got it to work on prestashop 1.6.1.1. Edit file AdminController.php and find below if statement around line 1470.

 

Find:

if (Validate::isLoadedObject($obj) && isset($obj->{$this->identifier_name}) && !empty($obj->{$this->identifier_name})) {

                    array_pop($this->toolbar_title);

                    array_pop($this->meta_title);

                    $this->toolbar_title[] = is_array($obj->{$this->identifier_name}) ? $obj->{$this->identifier_name}[$this->context->employee->id_lang] : $obj->{$this->identifier_name};

                    $this->addMetaTitle($this->toolbar_title[count($this->toolbar_title) - 1]);

                }

                break;

            case 'edit':

                $obj = $this->loadObject(true);

                if (Validate::isLoadedObject($obj) && isset($obj->{$this->identifier_name}) && !empty($obj->{$this->identifier_name})) {

                    array_pop($this->toolbar_title);

                    array_pop($this->meta_title);

                    $this->toolbar_title[] = sprintf($this->l('Edit: %s'), (is_array($obj->{$this->identifier_name}) && isset($obj->{$this->identifier_name}[$this->context->employee->id_lang])) ? $obj->{$this->identifier_name}[$this->context->employee->id_lang] : $obj->{$this->identifier_name});

                    $this->addMetaTitle($this->toolbar_title[count($this->toolbar_title) - 1]);

                }

 

Replace with:

if (Validate::isLoadedObject($obj) && isset($obj->{$this->identifier_name}) && !empty($obj->{$this->identifier_name})) {

                    array_pop($this->toolbar_title);

                    array_pop($this->meta_title);

                    

                    // Get product name

                    $nameArray = (is_array($obj->{$this->identifier_name}) && isset($obj->{$this->identifier_name}[$this->context->employee->id_lang])) ? $obj->{$this->identifier_name}[$this->context->employee->id_lang] : $obj->{$this->identifier_name};

                    // Get product model

                    $modelArray = (is_array($obj->{$this->identifier_model}) && isset($obj->{$this->identifier_model}[$this->context->employee->id_lang])) ? $obj->{$this->identifier_model}[$this->context->employee->id_lang] : $obj->{$this->identifier_model};

                    

                    // Strip long product names    and add dots                

                    $maxLength = 52;

 

                    if (strlen($nameArray) > $maxLength) {

                        $stringCut = substr($nameArray, 0, $maxLength);

                        $nameArray = substr($stringCut, 0, strrpos($stringCut, ' '));

                        $nameArray = $nameArray . '...';

                    }

                    

                    // Title Value    

                    $this->toolbar_title[] = sprintf($this->l('Edit: %s'), $nameArray . "\n" . "(" . $modelArray . ")" );

                    

                    $this->addMetaTitle($this->toolbar_title[count($this->toolbar_title) - 1]);

                }

 

Hope this helps!

 

Thank you dirtrider118

 

Tried your solution but now only appears "Edit:" and blank....

Maybe i'm missing something.. using. 1.6.1.13

Link to comment
Share on other sites

Thank you dirtrider118

 

Tried your solution but now only appears "Edit:" and blank....

Maybe i'm missing something.. using. 1.6.1.13

 

Hi taniacr,

 

Sorry i missed some code. In AdminController.php around line 80 find:

 

/** @var string */

    protected $identifier_name = 'name';

 

and add this right below:

 

protected $identifier_model = 'reference';

 

 

Let me know how it goes!

Link to comment
Share on other sites

With your help made a workaround,

 

After adding:

 

protected $identifier_model = 'reference';

 

Replaced identifier_name with identifier_model so my code looks like:

if (Validate::isLoadedObject($obj) && isset($obj->{$this->identifier_model}) && !empty($obj->{$this->identifier_model})) {
                    array_pop($this->toolbar_title);
                    array_pop($this->meta_title);
                    $this->toolbar_title[] = is_array($obj->{$this->identifier_model}) ? $obj->{$this->identifier_model}[$this->context->employee->id_lang] : $obj->{$this->identifier_model};
                    $this->addMetaTitle($this->toolbar_title[count($this->toolbar_title) - 1]);
                }
                break;
            case 'edit':
                $obj = $this->loadObject(true);
                if (Validate::isLoadedObject($obj) && isset($obj->{$this->identifier_model}) && !empty($obj->{$this->identifier_model})) {
                    array_pop($this->toolbar_title);
                    array_pop($this->meta_title);
                    $this->toolbar_title[] = sprintf($this->l('Edit: %s'), (is_array($obj->{$this->identifier_model}) && isset($obj->{$this->identifier_model}[$this->context->employee->id_lang])) ? $obj->{$this->identifier_name}[$this->context->employee->id_lang] : $obj->{$this->identifier_model});
                    $this->addMetaTitle($this->toolbar_title[count($this->toolbar_title) - 1]);
					
                }

Only displays the product reference.. but that's what the customer wanted so it works :P

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...