0

I need to write an extension that whenever a user view products grid, of any category, the extension will push additional 4 items to the products grid based on some backend magic.

I've done several magento turorials, read about the architecture and observers and all, and still uncertain how to start. do I need to listen to some event that is called when products are presented? to I need to write something to layouts that add my custom products? do I need to change phtml files?

this should be an extension that other sites will be able to download and use later, so it must be things that can be packed up nicely without changing any core etc.

thanks!

2 Answers 2

1

I think you can start by overriding the list.phtml file in your theme and then create a module with a helper, a block and a model to have there your backend magic.

By overriding the list.phtml file you will be able to add a conditional and call the block class to retrieve your products. Technically this is a clean way without touching core files. You can also use an observer and listen to a layout update event or a controller pre dispatch but for this case in particular I think I the easiest way is to handle this in the phtml file.

1
  • thanks, asking the same question I asked wittyvishwas - in this case, do I need to worry about messing up other extensions that also override the list.phtml? I prefer a solution that append the customized block to page rather then replacing something existing, so any site can install it without worries. thanks :)
    – Ronen Ness
    Oct 13, 2015 at 11:13
1

You can get that product collection (Backend magic) into the the List.phtml of your theme that would be in app/design/frontend/CUSTOM-THEME/template/catalog/product/list.phtml. You can append those four product their using your second collection .

6
  • thank you, and another question - in this case, do I need to worry about messing up other extensions that might override the list.phtml? I prefer a solution that append the customized block to page rather then replacing something existing. thanks :)
    – Ronen Ness
    Oct 13, 2015 at 11:08
  • 1
    i don't think it will be messing up anything as long as you are using a separate product collection to add those products Oct 13, 2015 at 11:16
  • thanks, I'll look into it (I'm still pretty new to magento) and if it works I'll pick this as the accepted answer
    – Ronen Ness
    Oct 13, 2015 at 11:22
  • sorry to bother you again, but it looks like this solution requires the site owner to choose my theme and completely replace his previous theme. is that correct or I misunderstood you? thanks again :)
    – Ronen Ness
    Oct 14, 2015 at 9:05
  • Yes i completely missed the fact that you are writing an extension sorry , Use this link for your extension local.xml , stackoverflow.com/questions/30982465/… and use phtml file insted of CMS blocks Oct 14, 2015 at 9:15

Your Answer

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

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