0

I want to add a new checkbox labeled as "Featured" in create/edit products page in Magento Admin. This determines if a product is a featured product or not.

These are my requirements :

  1. Add "is_featured" column in products table in database
  2. In create/edit products page in General Tab in Admin, add a checkbox with label "Featured"
  3. When saving the product and the "Featured" checkbox is checked, save the value 1 to "is_featured" column in products table, else save the value 0.

On the front-end side, when querying products via magento collection query, i want to sort products and make Featured product as first on the list. Adding is_featured column in db will allow me to sort(descending order) the products easily via is_featured column, sample code :

$_productCollection = Mage::getResourceModel('catalog/product_collection')
                ->setStoreId(0)
                ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id=entity_id', null, 'left')
                ->addAttributeToFilter('category_id', array('in' => $category_ids))
                ->addAttributeToSelect('*')
                ->addAttributeToFilter('visibility', 4) // Only catalog, search visiblity
                ->addAttributeToFilter('status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED))
                ->addAttributeToSort('is_featured', 'DESC')

How do i get started or what's the best way to achieve the requirements mentioned above?

UPDATE :

The purpose of the requirements above is to sort easily the products via is_featured column

Thanks

1 Answer 1

1

Create a product attribute and add the attribute to the attribute set you use. Here is an official guide to do that.

7
  • creating product attribute is not my best option. I want to add is_featured column in db so when i select all products via collection query, i order them in descending order via is_featured such as this code : $_productCollection = Mage::getResourceModel('catalog/product_collection')->->addAttributeToSort('is_featured', 'DESC')
    – Bogz
    Sep 2, 2014 at 16:47
  • By using the attribute/attribute set approach you will be able to do what you want.
    – mbalparda
    Sep 2, 2014 at 16:52
  • i have updated the question above. Please have a look if your suggestion is still the best approach..
    – Bogz
    Sep 2, 2014 at 16:59
  • Yes, it still is.
    – mbalparda
    Sep 2, 2014 at 17:02
  • great to hear. Can you provide a query which will select all products order by featured descending order? im really lost right now since im new to magento.
    – Bogz
    Sep 2, 2014 at 17:06

Your Answer

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

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