0
votes

This is something that has challenged me for a few days now and I am getting rather frustrated with searching for help/solutions - so trusty StackOverflow it is!

I have made a custom module with a custom database in Magento 1.7 (contains a few things like title, content) for basically a custom static block. I have implemented the product selector available here.

Although - this just does the actual product selecting - no saving functionality!

I am very stuck on how to save the selected magento products - what is the correct/best way?

I thought either comma separated IDs/SKUs for simplicity - or should I create a new entity type? Any knowledge/guidance on the latter would be hugely helpful - specifically saving a product of a new entity type.

Would the code to save the products go in <Module>/controllers/Adminhtml/<Module>Controller.php -> saveAction() or elsewhere?

1

1 Answers

0
votes

in <Module>/controllers/Adminhtml/<Module>Controller.php

public function saveAction()
{
    if ( $this->getRequest()->getPost() ) {
        try {
            $postData = $this->getRequest()->getPost();


            Mage::getModel('productsselector/productsselector')->setId($this->getRequest()->getParam('id'))
                ->setProductSku($postData['product_sku'])
                ...
                ->save();



            Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully saved'));
            Mage::getSingleton('adminhtml/session')->setProductsselectorData(false);

            $this->_redirect('*/*/');
            return;
        } catch (Exception $e) {
            Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
            Mage::getSingleton('adminhtml/session')->setLocalshipData($this->getRequest()->getPost());
            $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
            return;
        }
    }
    $this->_redirect('*/*/');
}

Read more @ Custom Module with Custom Database Table