Question

I want to build a custom module (called My_Collection) that works almost same as Catalog. It means:

  1. In admin

    • Able to create new Collection and its data (name, url key, meta data,...).
    • Able to select products belong to the Collection and set position for each product.
  2. In frontend

    • Listing products of Collection, the url is from Collection's url key.

I am familiar with creating modules and extending core codes. So, I need an outline instruction.

What are hints to do that?

Thank you all.

Notes:

  • A Collection may have products what are from varied Categories.
  • A product may belong to many Collections.
  • Should not alter Categories and Products data.
Was it helpful?

Solution

I can recommend you this free extension.
It does almost everything you need except one thing.
It allows you to create different product collections based on rules.
The rules are similar to the catalog discount rules.
This includes creating collections by skus.
It has support for url keys and it allows you to include the collection link to the main menu.
the only thing that it doesn't is allow you to set a sort order for the products.
If the extension does not do everything you need, you can use it a starting point at least.

OTHER TIPS

I'll try for this.

First, you will need to decide whether a flat model will be suffucient for the situation or you are going to need one EAV. With EAV model, you'll have the flexibility of adding extra attributes to your collection in future without any ALTER table statements but it will be a little more complex than Flat model to implement.

Now your data (name, url key, meta data etc) will become the properties of your model. They will be columns in case of a flat model and attributes in case of an EAV model.

Upto this part, nothing should be tricky to implement with some basic knowledge of Magento. After that, to hold the relationship between your collection and products, you'll need a separate table. You can show the products grid in same way as it's done with individual categories and with the help of some JS, you can easily POST the selected products with your collection object data for processing.

This way, you can achieve what you are looking for without modifying anything in the products or categories themselves. To get a better idea about implementing relationship between collection and products, you can take a look at catalog_category_product table in your Magento database.

Also, in order to have the working model of URL key, you will need to hook into controller_front_init_routers event for targeting the request to your controller. You can do it in any other way, I just thought it to be a little cleaner.

I'd always try to reuse as much as possible from the Magento core and avoid building overly complex solutions.

You need product collections almost the same as categories? Why not use actual categories? You can create category trees outside of the store root category for whatever you need.

You described what features of categories you need, obviously you can achieve this with categories. You did not explain what's the difference to categories. But try to approach your problem this way: use categories and see what additional behavior you need to implement. Maybe a category attribute to flag your special categories and some additional frontend templates is all you need.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top