coneso Posted March 19, 2015 Share Posted March 19, 2015 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: Link to comment Share on other sites More sharing options...
dirtrider118 Posted April 26, 2017 Share Posted April 26, 2017 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 More sharing options...
taniacr Posted May 5, 2017 Share Posted May 5, 2017 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 More sharing options...
activedesign Posted May 5, 2017 Share Posted May 5, 2017 Would you pay 30 euros for such a module? Link to comment Share on other sites More sharing options...
taniacr Posted May 9, 2017 Share Posted May 9, 2017 Hi activedesign Maybe.. but I was hoping I would figure out how to do it myself Link to comment Share on other sites More sharing options...
dirtrider118 Posted May 11, 2017 Share Posted May 11, 2017 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 More sharing options...
taniacr Posted May 11, 2017 Share Posted May 11, 2017 Thank you dirtrider118 But still nothing.. still just Edit: and blank... Link to comment Share on other sites More sharing options...
taniacr Posted May 11, 2017 Share Posted May 11, 2017 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 Link to comment Share on other sites More sharing options...
dirtrider118 Posted May 11, 2017 Share Posted May 11, 2017 Glad I could help. Shame you couldn't display both name and model. If you haven't made any other changes to your file (AdminController.php) other than this edit try replacing your file with mine (attached). As you can see in the image attached I have it working. AdminController.php 1 Link to comment Share on other sites More sharing options...
taniacr Posted May 15, 2017 Share Posted May 15, 2017 Haven't made other changes, but made an override with your file and works perfectly! Thank you so much Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now