Does anyone know how I can get a list of products belonging to a specific category from within a view file in Magento?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
I pretty much needed the same. Here is how I have done it:
Hope this helps.
Here is the code to get products from any particular category. You can use this in view file as well.
You should always avoid putting code like this into a view, it's very bad practice. You can also run into issues as views can be cached, leading to unexpected behaviour.
you should override the block you are using, placing code there. you can then call any new methods inside your view files.
for example, you could copy Mage_Catalog_Block_Product_List
from: app/code/core/Catalog/Block/Product/List.php
to: app/code/local/Catalog/Block/Product/List.php
you could then add a new method, possibly using some of the code mentioned in the above posts. your new method would then be available inside your view file (list.phtml or any view using this block)
Here is a code to export all product with it's category into csv