0

we are using marketplace multivendor site, so we gave an option for seller to update the product attributes from frontend. now if we update attribute values from backend , its working fine in frontend. but if we try saving in frontend,its not saving in backend.

In frontend, its saving, but after refreshing the page, it show old values..

we are using following code to save values in database :

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>

JS

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 showFieldLocal(product_id)
        {

            var qtyId='#local_'+ product_id;

            var editLink="#local_edit_link_"+ product_id;
            var valuelocal="#valuelocal_"+ product_id;
            var updateButton="#local_update_button_"+ product_id;
            var resetButton="#local_reset_button_"+ product_id;

            $wk_jq(qtyId).show();
            $wk_jq(valuelocal).hide();

            $wk_jq(editLink).hide();
            $wk_jq(updateButton).show();
            $wk_jq(updateButton).prop('disabled', false);//just in case
            $wk_jq(resetButton).show();

            return false;


        }




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(); 

} 
}); 
}

Controller.php

 public function updateFieldLocalAction(){
 //   Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); 

     Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
     $product = Mage::getModel('catalog/product')->load($id);
     $product->setStoreId(Mage::app()->getStore()->getStoreId())->setMpLocalShippingCharge($upd_local)->save();

    $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');
     Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
    $product = Mage::getModel('catalog/product')->load($id);
    $product->setStoreId(Mage::app()->getStore()->getStoreId())->setMpLocalShippingCharge($upd_local)->save();


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

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

    }    

  }
6
  • what is type of this attribute? Feb 12 '16 at 5:19
  • it is at textfield Feb 12 '16 at 5:23
  • try this $product->setData('local',$upd_local); Feb 12 '16 at 5:27
  • i added your code below this line : $product->setLocal($upd_local); , but it didt worked Feb 12 '16 at 5:32
  • replace with this line ... Feb 12 '16 at 5:42
1

try this one

 $product->setData('mp_local_shipping_charge', $upd_local)
            ->getResource()
            ->saveAttribute($product, 'local');

    $product->save();

or try that

try{
    $upd_local = $this->getRequest()->getParam('local');
     Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
    $product = Mage::getModel('catalog/product')->load($id);
    $product->setStoreId(Mage::app()->getStore()->getStoreId())->setMpLocalShippingCharge($upd_local)->save();


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

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

    }    
10
  • sorry, not saving, may i reindex once more ? Feb 12 '16 at 5:51
  • i reindexed, but still same issue Feb 12 '16 at 6:06
  • remove this codeMage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); add new code try that.. Feb 12 '16 at 6:10
  • i tried but it didt worked.... Feb 12 '16 at 6:19
  • have you tried second suggestion? Feb 12 '16 at 6:20

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.