2

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.

3 Answers 3

2

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.

1
  • Your Easylife always makes life easier. As you said, I will take it as a starting point. Thank you, Marius. Commented Nov 17, 2015 at 8:22
2

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.

1
  • I think your outline instruction should be enough to make it done. I will try then let you know later. Thank you. Commented Nov 17, 2015 at 8:21
2

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.

1
  • I use category ids to determine some core features of my website, so if a product has multiple category ids, it may lead to unexpected behavior. So I cannot take a risk to do that. By the way, how to show a category outside of the root category without switching store in frontend? Commented Nov 18, 2015 at 1:07

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.