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.

asked Sep 19, 2016 at 17:38

1 Answer 1

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())));
answered Sep 19, 2016 at 21:31

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.