0

we would like to add a variable in the Magento category title (the one you see in Google).

I read this link but the problem is that the category has not been loaded at this point. And this won't work either. If I try to change the page title in the template the header is no longer available (is this correct?).

I was thinking of adding something like {{category_product_count}} or {{CPC}} in the title to end with a title like {{CPC}} shoes online where CPC is replaceed by the category count, resulting in 153 shoes online. We would however add some logic to the number where < 100 we take modulus 5, and < 300 we take modulus 10, and < 100 we take modulus 50, and > 1000 we take modulus 100 - and maybe add a PLUS sign. Resulting in 150+ shoes online

So my question is: what is the best way of adding this functionality? Should we change or maybe add a function to the method? I think it is important that - if we do use it - it is reflected everywhere where the title is requested.

0

You could add this to the viewAction() as suggested in that article you linked to:

$productList = $this->getLayout()->getBlock('product_list');
$this->getLayout()->getBlock('head')->setTitle($this->__('Found %d Products', $productList->getLoadedProductCollection()->count()));

However, this is not recommended as it will load the production collection twice, (once to get the total number, and again to actually build the page.)

You can speed this up and reduce the amount of memory used by only loading the product IDs so that you can count how many there are, like so:

$productList = $this->getLayout()->getBlock('product_list');
$this->getLayout()->getBlock('head')->setTitle($this->__('Found %d Products', count($productList->getLoadedProductCollection()->getAllIds())));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.