Jump to content

Double execution of ProductController->getProductPageTitle & use of public_group_name (Meta title with attributes)


WisQQ

Recommended Posts

 

Hello,
I found small bug regarding display of attribute group names inside meta title. When changing combination, title is replaced with doubled attribute. This happends because when AjaxRefresh is called on combination change, method getProductPageTitle runs twice.

public function displayAjaxRefresh() //double executed attribute inside title

            'product_title' => $this->getProductPageTitle(
                $this->getTemplateVarPage()['meta'] ?? []
            ),

array['meta'] already has new meta title because $this->getTemplateVarPage() already called $this->getProductPageTitle($page['meta'])

$page['meta']['title'] = $this->getProductPageTitle($page['meta']);

To fix this you should replace 'product_title' inside ajax with this:

public function displayAjaxRefresh() //fixed title

'product_title' => $this->getTemplateVarPage()['meta']['title'],

 

I also found that meta title uses group_name of attributes instead of public_group_name. Both are required on creation of attribute group, so we should use public one to have controll over what is displayed inside meta title.
 

getProductPageTitle(array $meta = null) //old using group_name

        $idProductAttribute = $this->getIdProductAttributeByGroupOrRequestOrDefault();
        if ($idProductAttribute) {
            $attributes = $this->product->getAttributeCombinationsById($idProductAttribute, $this->context->language->id);
            if (is_array($attributes) && count($attributes) > 0) {
                foreach ($attributes as $attribute) {
                    $title .= ' ' . $attribute['group_name'] . ' ' . $attribute['attribute_name'];
                }
            }
        }
getProductPageTitle(array $meta = null) //fixed using public_group_name

        $idProductAttribute = $this->getIdProductAttributeByGroupOrRequestOrDefault();
        if ($idProductAttribute) {
            $attributes = $this->product->getAttributesGroups($this->context->language->id,$idProductAttribute);
            if (is_array($attributes) && count($attributes) > 0) {
                foreach ($attributes as $attribute) {
                    $title .= ' ' . $attribute['public_group_name'] . ' ' . $attribute['attribute_name'];
                }
            }
        }

From what i checked it still the same for version 8.1.
I tested this on 1.7.8.9/10

 

Edited by WisQQ (see edit history)
Link to comment
Share on other sites

  • WisQQ changed the title to Double execution of ProductController->getProductPageTitle & use of public_group_name (Meta title with attributes)

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