0

I think I've kicked the hornets nest. I have a custom db table. I am displaying a list of products in admin similar to the related products tab or the upsell tab.

I want the id's of selected products (those the user has ticked) to go into my database field in the form of a single-dimensional array (1,2,3,4).

Is this insane, possible, sort-of-crazy?

I have the module and the product table but I can't get the data into the database. Any pointers would be helpful, thank you!

1
  • Yes, your architecture is a bit wrong. The correct approach will be to have a relations table instead. Commented Jun 18, 2013 at 8:36

1 Answer 1

1

I'm assuming that you are already displaying the grid and the on a tab of the edit product page.
I'm also assuming you are only looking for a way to save the posted data into your table.
If either assumption is wrong, please rephrase your question.

First, create an observer method that is triggered when a product is saved in the admin. There are many possible events that could be used, but probably catalog_product_save_after in the adminhtml area is a good one.

In your observer method, fetch the posted ID's from the request object:

$ids = Mage::app()->getRequest()->getParam('your_ids', array());

Then, instantiate the model (if your table data is represented by a model) or simply a resource model (if you want to only write to the table without the ORM), and pass the $ids to the corresponding method.

Mage::getResourceModel('your_module/your_class')->saveRelatedProductIds($ids);

Since you already managed to create the grid on the tab, I'll add in a final assumption that you know about models, resource models and event observers. If not, please ask a new question about them.

0

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.