1

I have an online e-commerce project which focuses on selling paintings from different artists. These products have been assigned to sub-categories of the artists name.

Category structure:

Root Category
        |-----Gallery
                |-----artist_1
                       |-----painting_001
                       |-----painting_012
                       |-----painting_024
                |-----artist_2
                       |-----painting_003
                       |-----painting_004
                |-----artist_3
                       |-----painting_005
                       |-----painting_007
                ...
                |-----artist_64
                       |-----painting_045

If I were to build a plugin where the client is able to limit the products shown per the artist's name, e.g only show 2 paintings of artist_1 on the 1st products page, only show 1 painting of artist_32, only show 4 paintings of artist_13 etc etc.(no limit to the rest of the pages) Which way would I have to go to be able to accomplish this particular function? I know that you can manually do this by manually entering the position of each product within a category.

Here is a mockup of how the plugin might look like: Product Arranger Screenshot

0

This is a too too broad question. Effectively you are asking for an extension which are going to use custom tables. So take this answer as a generalized answer.

As I said before, you need to create a new table that will use to store artist_reference, category_reference, filter_type, size_limit. You need to then use this table in both admin and frontend. Let me call this table as artist_category_reference.

> SELECT * FROM `artist_category_reference` LIMIT 1;
 _________________________________________________________________________________
|  id  |  artist_reference  |  category_reference  |  filter_type  |  size_limit  |
 _________________________________________________________________________________
|  1   |       3            |          5           |    created    |      4       |
 _________________________________________________________________________________

artist_reference   : id of artist. Other than category if you have a table to refer for an artist, then you can use this for referring to that entity. Otherwise, you can store category_id here. In that case  3 column is not required.
category_reference : category id correspond to artist
filter_type        : use to store ASC or  DESC and filter type.
size_limit         : what should be the page size of artist category

You can now observe to an event controller_action_layout_generate_blocks_after and set new page size limit to the category toolbar block. For this, your observer somewhat look like this.

<?php
class Namespace_Module_Model_Observer
{

    public function setPageSizeForCategory(Varien_Event_Observer $observer)
    {
        $currentCategory = Mage::registry('current_category');

        //check whether current page is a category page
        if ($currentCategory instanceof Mage_Catalog_Model_Category) {

            //eventhough this is a collection, this collection should hold
            //only one artist reference item. ie in your table, for a particular
            //category reference, there should be only one entry.
            $ArtistReference = Mage::getModel('namespace_module/reference')
                ->getCollection()
                ->addFieldToFilter('category_reference', $currentCategory->getId())
                ->load();

            //set page size
            foreach ($ArtistReference as $artist) {
                if (isset($artist->getId())) {
                    //check whether toolbar block exist or not
                    $toolbar =  $observer->getLayout()->getBlock('product_list_toolbar');
                    if ($toolbar) {
                        //sets page size to corresponding mode
                        $listMode = $toolbar->getCurrentMode();
                        $toolbar = $toolbar->addPagerLimit($listMode , $artist->getSizeLimit());
                    }
                }
                exit();
            }
        }

        return $this;
    }
}

This is just a blueprint of how your observer should look like. Here what I have done is, if the page that is requested is a category page and is an artist category, then grab the size_limit from artist_category_reference table and then set the toolbar page size to that value.

So this is just a blue print, in the similar way you should apply your custom filter too. I hope this will give you a general idea.

|improve this answer|||||

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