1

we have magento 1.9.0 ,multi vendor site, we gave an option for vendor to edit and update product information like Price and custom attributes from frontend. Here Price is working fine, but this custom attribute is not updating and saving in database.

1)Before i gave attribute name as "local", it was updating, than i renamed to "mp_local_shipping_charge". than its not working.
2)in frontend, it showing same value present as in backend. 
3)once we click on update button, its updating values, but once after refresh the page, again it showing old values.

we are using following code for Price

Phtml

<input onFocus="showPriceCancel('<?php echo $products->getId(); ?>');" class="ama1" type = "text" id = "price_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" name= "price[]" value = "<?php echo $products->getPrice(); ?>" style = ""/>

<input type="hidden" name="curr_<?php echo $products->getId(); ?>" id="curr_<?php echo $products->getId(); ?>" value="<?php echo $products->getPrice(); ?>" />

<p id="updatedprice_<?php echo $products->getId(); ?>" style = "display:none;color:red; position:relative; top:16px;">Updated</p>
<br/>


<button style="display:none;" id="price_reset_button_<?php echo $products->getId(); ?>" type="reset" class="cancel" onclick="hideResetPrice('<?php echo $products->getId(); ?>','<?php echo $products->getPrice(); ?>'); return false;">
<span><span><?php echo $helper->__('Cancel') ?></span></span>
</button>

</span>

Javascript

function hideResetPrice(product_id,priceold) { 

var qtyId='#price_'+ product_id; 
var currprice='#curr_'+ product_id; 
var editLink="#price_edit_link_"+ product_id; 
var updateButton="#price_update_button_"+ product_id; 
var valueprice="#valueprice_"+ product_id; 
var resetButton="#price_reset_button_"+ product_id; 

$wk_jq(resetButton).hide(); 
$wk_jq(valueprice).show(); 
$wk_jq(qtyId).val( $wk_jq(currprice).val()); 
$wk_jq(editLink).show(); 

}

function updateFieldPrice(product_id) 
{ 
var priceId = '#price_'+ product_id; 
var currprice='#curr_'+ product_id; 
var updatedqty = '#updatedprice_'+ product_id; 
var url ='<?php echo Mage::getUrl('marketplace/marketplaceaccount/updateFieldPrice/')?>'; 
$price = $wk_jq(priceId).val(); 
$wk_jq(currprice).val($price); 
new Ajax.Request(url, { 
method: 'post', 
parameters: {id: product_id, price: $price}, 
onComplete: function (transport) { 
//alert(transport.responseText); 

jQuery(updatedqty).show().delay(2000).fadeOut(); 

} 
}); 
}

controller.php

 public function updateFieldPriceAction(){
        Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);      
        $id= $this->getRequest()->getParam('id');
        $customerid=Mage::getSingleton('customer/session')->getCustomerId();
        $collection_product = Mage::getModel('marketplace/product')->getCollection()->addFieldToFilter('mageproductid',array('eq'=>$id))->addFieldToFilter('userid',array('eq'=>$customerid));
        //Mage::getSingleton('core/session')->setEditProductId($id);

        try{
        $upd_price = $this->getRequest()->getParam('price');
        $product = Mage::getModel('catalog/product')->load($id);        
        //$product->setData('price', $upd_price);
        $product->setPrice($upd_price);

        //$stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($id);
        //$stockItem->setData('manage_stock', 1);
        //$stockItem->setData('qty', $this->getRequest()->getParam('qty'));
        $product->save();

        echo $price = $product->getPrice();
        echo $name = $product->getName();

        $response['message'] = 'Your Product Is Been Sucessfully Updated';
        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response)); 
        //Mage::getSingleton('core/session')->addSuccess(Mage::helper('marketplace')->__('Your Product Is Been Sucessfully Updated'));


        //endif;
        }catch(Exception $e){
        echo "Not Saving"; exit;    
        Mage::log($e->getMessage());
        }

      }

Following code we are using for custom attribute : "mp_local_shipping_charge"

Phtml

<?php $attribute = $products->getResource()->getAttribute('mp_local_shipping_charge');?>
<?php if($attribute):?>
<?php $attribute_value = $attribute ->getFrontend()->getValue($products); ?>

<input class="ama1" type = "text" id = "local_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" name= "local[]" value = "<?php echo $attribute_value; ?>" style = ""/>
<?php endif; ?>


<input type="hidden" name="localcurr_<?php echo $products->getId(); ?>" id="localcurr_<?php echo $products->getId(); ?>" value="<?php echo $products->getLocal(); ?>" /> 

<p id="updatedlocal_<?php echo $products->getId(); ?>" style = "display:none;color:red; position:relative; top:16px;">Updated</p>
<br/>

<button id="local_reset_button_<?php echo $products->getId(); ?>" type="reset" class="cancel" onclick="hideResetLocal('<?php echo $products->getId(); ?>','<?php echo $products->getPrice(); ?>'); return false;">
<span><span><?php echo $helper->__('Cancel') ?></span></span>
</button>
</span>
</td>       

Javascript

function hideResetLocal(product_id,localold) { 

var qtyId='#local_'+ product_id; 
var currlocal='#localcurr_'+ product_id; 
var editLink="#local_edit_link_"+ product_id; 
var updateButton="#local_update_button_"+ product_id; 
var valuelocal="#valuelocal_"+ product_id; 
var resetButton="#local_reset_button_"+ product_id; 


$wk_jq(valuelocal).show(); 
$wk_jq(qtyId).val( $wk_jq(currlocal).val()); 
$wk_jq(editLink).show(); 

}


function updateFieldLocal(product_id) 
{ 
var localId = '#local_'+ product_id; 
var currlocal='#localcurr_'+ product_id; 
var updatedqty = '#updatedlocal_'+ product_id; 
var url ='<?php echo Mage::getUrl('marketplace/marketplaceaccount/updateFieldLocal/')?>'; 
$local = $wk_jq(localId).val(); 
$wk_jq(currlocal).val($local); 
new Ajax.Request(url, { 
method: 'post', 

parameters: {id: product_id, local: $local}, 
//parameters: {id: product_id, local: $local}, 
onComplete: function (transport) { 
//alert(transport.responseText); 

jQuery(updatedqty).show().delay(2000).fadeOut(); 

} 
}); 
}

controllers.php

public function updateFieldLocalAction(){
        Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);      
        $id= $this->getRequest()->getParam('id');
        $customerid=Mage::getSingleton('customer/session')->getCustomerId();
        $collection_product = Mage::getModel('marketplace/product')->getCollection()->addFieldToFilter('mageproductid',array('eq'=>$id))->addFieldToFilter('userid',array('eq'=>$customerid));

        try{
        $upd_local = $this->getRequest()->getParam('local');
        $product = Mage::getModel('catalog/product')->load($id);        

        $product->setLocal($upd_local);

        $product->save();

        echo $local = $product->getLocal();
        echo $name = $product->getName();

        $response['message'] = 'Your Product Is Been Sucessfully Updated';
        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response)); 

        }catch(Exception $e){
        echo "Not Saving"; exit;    
        Mage::log($e->getMessage());
        }

      }

This is code we are using for saving both price & attribute

public function singlerowupdateAction(){
      if($this->getRequest()->isPost()){
        if(!$this->_validateFormKey()){
             $this->_redirect('marketplace/marketplaceaccount/myproductslist/');
        }
        $id= $this->getRequest()->getParam('id');
        $price= $this->getRequest()->getParam('price');
        $speprice= $this->getRequest()->getParam('speprice');
        $qty = $this->getRequest()->getParam('quantity');
        $mp_local_shipping_charge = $this->getRequest()->getParam('mp_local_shipping_charge');

       $product = Mage::getModel('catalog/product')->load($id);
       $product->setPrice($price);
       $product->setSpecialPrice($price);
       $product->setQty($qty);
       $product->setLocal($mp_local_shipping_charge);
       $product->save();

        Mage::getSingleton('core/session')->addSuccess( Mage::helper('marketplace')->__('Products has been sucessfully saved from your account'));
        $this->_redirect('marketplace/marketplaceaccount/myproductslist/');


    }}

2 Answers 2

1

try that

public function singlerowupdateAction(){
      if($this->getRequest()->isPost()){
        if(!$this->_validateFormKey()){
             $this->_redirect('marketplace/marketplaceaccount/myproductslist/');
        }
        $id= $this->getRequest()->getParam('id');
        $price= $this->getRequest()->getParam('price');
        $speprice= $this->getRequest()->getParam('speprice');
        $qty = $this->getRequest()->getParam('quantity');
        $mp_local_shipping_charge = $this->getRequest()->getParam('local');

       $product = Mage::getModel('catalog/product')->load($id);
       $product->setPrice($price);
       $product->setSpecialPrice($price);
       $product->setQty($qty);
       $product->setMpLocalShippingCharge($mp_local_shipping_charge);
       $product->save();

        Mage::getSingleton('core/session')->addSuccess( Mage::helper('marketplace')->__('Products has been sucessfully saved from your account'));
        $this->_redirect('marketplace/marketplaceaccount/myproductslist/');


    }}
7
  • i tried, after refreshing the page ,its showing old value only.... Commented Feb 16, 2016 at 6:58
  • updated try that and feedback me Commented Feb 16, 2016 at 6:59
  • sorry, still not saving Commented Feb 16, 2016 at 7:01
  • link and crendetial Commented Feb 16, 2016 at 7:06
  • i tested this code and it is working.. Commented Feb 16, 2016 at 15:24
1
$mp_local_shipping_charge = $this->getRequest()->getParam('mp_local_shipping_charge');
$product = Mage::getModel('catalog/product')->load($id);    
$product->setData('mp_local_shipping_charge',$mp_local_shipping_charge);
$product->getResource()->saveAttribute($product,'mp_local_shipping_charge');

Please try the above if it works for your product. You have no attribute code Local so $product->setLocal(); does not mean anything.

2
  • i updated as like this for updateFieldLocalAction() : pastebin.com/UvVETXSw what wrong i did ? Commented Feb 16, 2016 at 7:40
  • once i click on update button and refresh the page, its showing blank value Commented Feb 16, 2016 at 7:43

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.