1

I created a new column in sales_flat_quote_item named itemcomment. i want to to insert textbox value this column.

my form .....comment.phtml

<form id="orderapproval-item-form" class="orderapproval-hidden" action="<?php echo $this->getUrl('orderapproval/customercart/remarksdecline');?>" method="post">
    <input type="text" name="message" class="orderapproval-disabled" value="<?php echo $this->__('Enter decline reason'); ?>" id="decline" />
    <input type="submit" value="<?php echo $this->__('Decline'); ?>"/>
  </form>

CustomercartController.php

public function remarksdeclineAction()
{

           $message =  $this->getRequest()->getParam('message');
           //echo $message;
           $quoteItem  = Mage::getModel('orderapproval/quoteitem');
          $quoteItem->setItemcomment($message);
         $quoteItem->save();
}

controller is calling with echo

Model/Orderapproval.php

class ZetaPrints_OrderApproval_Model_OrderApproval extends Mage_Core_Model_Abstract

{
    public function _construct() {
        $this->_init('zetaprints_orderapproval/quoteitem','item_id');
    }

}

Model/Resource/Orderapproval.php

class ZetaPrints_OrderApproval_Model_Resource_OrderApproval extends Mage_Core_Model_Resource_Mysql4_Abstract
{
    public function _construct()
    {
        $this->_init('zetaprints_orderapproval/quoteitem','item_id');
    }

}

Model/Resource/Orderapproval/Collection.php

class ZetaPrints_OrderApproval_Model_Resource_OrderApproval_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{
    protected function _construct()
    {
        $this->_init('zetaprints_orderapproval/quoteitem');
    }
}

config.xml

 <models>
      <zetaprints_orderapproval>
        <class>ZetaPrints_OrderApproval_Model</class>
        <resourceModel>zetaprints_orderapproval_resource</resourceModel>
      </zetaprints_orderapproval>
      <zetaprints_orderapproval_resource>
                <class>ZetaPrints_OrderApproval_Model_Resource</class>
                 <entities>
                    <quoteitem>
                        <table>sales_flat_quote_item</table>
                    </quoteitem>
                </entities>
            </zetaprints_orderapproval_resource>
      <sales>
        <rewrite>
          <quote>ZetaPrints_OrderApproval_Model_Quote</quote>
        </rewrite>
      </sales>
    </models>


<resources>
      <orderapproval_setup>
        <setup>
          <module>ZetaPrints_OrderApproval</module>
          <class>Mage_Eav_Model_Entity_Setup</class>
        </setup>
        <connection>
          <use>core_setup</use>
        </connection>
      </orderapproval_setup>

      <orderapproval_write>
        <connection><use>core_write</use></connection>
      </orderapproval_write>

      <orderapproval_read>
        <connection><use>core_read</use></connection>
      </orderapproval_read>
    </resources>

but i am getting Fatal error: Uncaught Error: Call to a member function setItemcomment() on boolean

table name: sales_flate_quote_item column name: itemcomment

Thanks.

1
  • anyone can help me i am very stuck about this query Dec 29, 2016 at 11:19

1 Answer 1

0

You have to call event and a method on that event like :

<events>
    <sales_quote_item_set_product>
        <observers>
        <YOUR_MODULE>
            <class>YOUR_MODULE/observer</class>
            <method>your_method_name</method>
        </YOUR_MODULE>
        </observers>
    </sales_quote_item_set_product>
</events>

Your observer file :

<?php
class ZetaPrints_OrderApproval_Model_Observer
{

    public function your_method_name(Varien_Event_Observer $observer) {

        $item = $observer->getQuoteItem();
        $product = $observer->getProduct();
        $valueToset = $product->getAttributeValue(); // or any value which you want to set
        $item->setCustomField($valueToset); // here your db field name is "custom_field"
        //You can also use $item->setData('field_name',$valueToset);
        return $this;
    }
}
14
  • i did not get you Dec 29, 2016 at 11:40
  • i have added event in config.xml and method in controller Dec 29, 2016 at 11:48
  • 1
    getAttributeValue(); is $message am i right Dec 29, 2016 at 11:49
  • @ErSarveshVTiwari, no, you have to add method in model file like model/observer which class is already mention in event area Dec 29, 2016 at 11:49
  • @ErSarveshVTiwari, you can set any value in $message Dec 29, 2016 at 11:51

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.