2

I am using the block rewrite below to add two fields to module Amasty_Shopby.

<?php

class Etre_Amshopby_Block_Rewrite_Shopby_Adminhtml_Filter_Edit_Tab_General extends Amasty_Shopby_Block_Adminhtml_Filter_Edit_Tab_General
{

protected function _prepareRegularForm()
{

    $fldSet3 = $this->_form->addFieldset('etre_amshopby_extra', array('legend'=> $this->__('Bonus Options by Etre')));
    $fldSet3->addField('labelOnFrontend', 'select', array(
        'label'     => $this->__('Show Label on Frontend'),
        'name'      => 'displayLabelFrontEnd',
        'values'    => $this->yesno,
        'required' => true
    ));
    $fldSet3->addField('labelInDropdown', 'select', array(
        'label'     => $this->__('Show Label in Dropdown'),
        'name'      => 'displayLabelInDropdown',
        'values'    => $this->yesno,
        'required' => true
    ));
    parent::_prepareRegularForm();
}
}

The fields show up but they do not save. I'm not sure what the most appropriate way to handle this is.

My guess is part of what needs to be done is each of these fields needs to be added to the Amasty filter table in the DB but I have setup few SQL install scripts within Magento modules so I am unsure as to how I should proceed.

The save action for the filter form is below. My fields are displayed when Zend_Debug::dump($data) is called within this action.

public function saveAction()
{
    $id     = $this->getRequest()->getParam('id');
    $model  = Mage::getModel('amshopby/filter');
    $data = $this->getRequest()->getPost();
    if ($data) {
        $model->setData($data);
        $model->setId($id);

        if ($model->getData('display_type') == Amasty_Shopby_Model_Catalog_Layer_Filter_Price::DT_FROMTO) {
            $model->setData('from_to_widget', true);
        }

        try {
            $model->save();
            Mage::getSingleton('adminhtml/session')->setFormData(false);

            $msg = Mage::helper('amshopby')->__('Filter properties have been successfully saved');
            Mage::getSingleton('adminhtml/session')->addSuccess($msg);
            if ($this->getRequest()->getParam('continue')){
                $this->_redirect('*/*/edit', array('id' => $model->getId()));
            }
            else {
                $this->_redirect('*/*');
            }

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

        $this->invalidateCache();
        return;
    }
    Mage::getSingleton('adminhtml/session')->addError(Mage::helper('amshopby')->__('Unable to find a filter to save'));
    $this->_redirect('*/*/');
}
2

Yes, if you are going to modify Improved Layered Navigation module by Amasty, you need to

1. Increment the module version
2. Put the update SQL script in the folder `app\code\local\Amasty\Shopby\sql\amshopby_setup\mysql4-upgrade-2.8.0-2.8.1.php`

where 2.8.0 is your current module version and 2.8.1 is your new version.
Then clear the cache to apply the changes.

Alternatively, you can just add 2 fields directly in the database table.

1
  • I'd considered taking this route but was unsure if it was the only one available. In the spirit of extending, not modifying, I was hoping I could accomplish the same through my extension. Plausible? – TylersSN Jul 27 '15 at 12:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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