I am new to Shopware, developing plugin to get the article count of a particular category and display in the listing/category page beside the category name in side bar, I have written the below code in Bootstrap.php of my plugin but I am getting only the parent ID of category.
Firstly thank you very much for replying to my question, I have applied your solution to my template and I am getting the following outpu, please check the below screen shot.
Please reply to my query, your help will be very much thankful.
this is because the variable sNumberArticles contains the number of the current category, which is „Mountain air & adventure“ in your case. If you want to add the right count for each category, you have to extend the sCategories variable. Which means you have to change the result of the \sCategories::sGetCategories() method.
Thank you for the valuable reply, I understood the answer for it, but the extending should be be done in template level or plugin ?? this question may be awkward but I am new to Shopware so please helpme out with your detailed reply.
in your own template, which is extending from on of the default themes (Bare, Responsive), you should only do, yeah, template stuff Also see the dev docs
A plugin extends the functionality of shopware. So this is the right place for your extension. Read Developing plugins for further information.
Thank you for the reply, I have got two clues from your suggestions, I am mentionaing it below:
* sCategories::sGetCategoryIdByArticleId function use now the s_articles_categories table.
* We have to extend the sCategories variable. Which means you have to change the result of the sCategories::sGetCategories() method.
Can you please help me to implement it, I don’t need complete code, just need to know how to extend sCategories class in my plugin or template. I can see sCategories class returns $category array which has all info about category but not article count. Please reply me with a hint.
In your case you need an after hook on the sCategories::sGetCategories() method, to extend the array which the method returns. Unfortunately there is no event, you can use. After you added the new value, you can use it in the themes/Frontend/Bare/frontend/index/sidebar-categories.tpl template file.
I have went through the links you provided, not found any appropiate solution to my problem, can you please help me with some more in depth hint, I need an example how to extend the sCategories::sGetCategories().
What I am trying to do is, I will get the ID of each category through my plugin and count products in s_srticles_categories and display in the TPL which you mentioned in previous reply.
Thank you for the hint, but my target is to get ID of the category from the TPL to my plugin, so that I can fetch the count, as per your answer sCategories array is sent to TPL , looping there and pritining the ID or other fields, I am unable to access ID of individual category in my plugin.