0

we are using following code to update custom attribute values .attribute code : "mp_local_shipping_price [ Text field ]" , attribute label : Local. its working fine

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>

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->setData('mp_local_shipping_charge',$upd_local);
        $product->getResource()->saveAttribute($product,'mp_local_shipping_charge');       

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

      }

we are using following code to update custom attribute values .attribute code : "cod_available [ Drop Down ]" , attribute label : Cod . its not updating.

Phtml

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

<select id = "cod_<?php echo $products->getId(); ?>" name= "cod[]" "> 

<option value="0" <?php if($pro->getCod()==0) { echo "selected";} ?>>No</option> 
<option value="1"<?php if($pro->getCod()==1) { echo "selected";} ?>>Yes</option> 

</select> 

<?php endif; ?>

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

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

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

Script

function hideResetCod(product_id,codold) { 

var qtyId='#cod_'+ product_id; 
var currcod='#codcurr_'+ product_id; 
var editLink="#cod_edit_link_"+ product_id; 
var updateButton="#cod_update_button_"+ product_id; 
var valuecod="#valuecod_"+ product_id; 
var resetButton="#cod_reset_button_"+ product_id; 


$wk_jq(valuecod).show(); 
$wk_jq(qtyId).val( $wk_jq(currcod).val()); 
$wk_jq(editLink).show(); 

}




function updateFieldCod(product_id) 
{ 
var codId = '#cod_'+ product_id; 
var currcod='#codcurr_'+ product_id; 
var updatedqty = '#updatedcod_'+ product_id; 
var url ='<?php echo Mage::getUrl('marketplace/marketplaceaccount/updateFieldCod/')?>'; 
$cod = $wk_jq(codId).val(); 
$currcod = $wk_jq(codId).val(); 
if($cod!=$currcod) {
$wk_jq(currcod).val($cod); 
new Ajax.Request(url, { 
method: 'post', 

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

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

} 
}); 
}
}

Controller.php

public function updateFieldCodAction(){
        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_cod = $this->getRequest()->getParam('cod');
        $product = Mage::getModel('catalog/product')->load($id);        
        $product->setData('cod_available',$upd_cod);
        $product->getResource()->saveAttribute($product,'cod_available');  
     //   $product->setCod($upd_cod);

        $product->save();

        echo $cod = $product->getCod();
        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());
        }

      }

we are using following code to update both custom attributes. Local [textfield] attribute is working & Cod [dropdown] attribute is not working.

code to update one product

Phtml

<button id="update_button_<?php echo $products->getId(); ?>" class="button wk_mp_btn1" onclick="updateAllFields('<?php echo $products->getId(); ?>'); return false;"  >
<span><span style="font-size:12px;"><?php echo $helper->__('Update') ?></span></span>
</button>

script

<script>

function updateAllFields(product_id) {
        jQuery('#price_reset_button_'+product_id).css('display','none');
        if(jQuery("#price_"+product_id).val() != jQuery("#curr_"+product_id).val())
              updateFieldPrice(product_id);

        if(jQuery("#specialprice_"+product_id).val() != jQuery("#specialcurr_"+product_id).val())
            updateFieldSpecialPrice(product_id);
            updateField(product_id);
        if(jQuery("#local_"+product_id).val() != jQuery("#localcurr_"+product_id).val())
            updateFieldLocal(product_id);
        if(jQuery("#regional_"+product_id).val() != jQuery("#regionalcurr_"+product_id).val())
            updateFieldRegional(product_id);
        if(jQuery("#state_"+product_id).val() != jQuery("#statecurr_"+product_id).val())
            updateFieldState(product_id); 
        if(jQuery("#cod_"+product_id).val() != jQuery("#codcurr_"+product_id).val())
            updateFieldCod(product_id); 
        if(jQuery("#qty_"+product_id).val() != jQuery("#currqty_"+product_id).val())
            updateFieldqty(product_id);

</script>

controller.php

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');
        $cod_available = $this->getRequest()->getParam('cod_available');
       $product = Mage::getModel('catalog/product')->load($id);
       $product->setPrice($price);
       $product->setSpecialPrice($price);
       $product->setQty($qty);
       $product->setLocal($mp_local_shipping_charge);
       $product->setCod($cod_available);
       $product->save();

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


    }}

code to update multiple products code to update all products attributes by clicking on single update button

public function massupdatesellerproAction(){
      if($this->getRequest()->isPost()){
        if(!$this->_validateFormKey()){
             $this->_redirect('marketplace/marketplaceaccount/myproductslist/');
        }
        $ids= $this->getRequest()->getParam('product_mass_update');
        $price= $this->getRequest()->getParam('price');
        $special= $this->getRequest()->getParam('specialprice');

        $local= $this->getRequest()->getParam('local');
        $regional= $this->getRequest()->getParam('regional');
        $state= $this->getRequest()->getParam('state');
        $cod= $this->getRequest()->getParam('cod');

        foreach ($ids as $key => $value) {
    $product = Mage::getModel('catalog/product')->load($value);
    $product->setPrice($price[$key]);
    $product->setSpecialPrice($special[$key]);
    $product->setMpLocalShippingCharge($local[$key]);
    $product->setMpRegionalShippingCharge($regional[$key]);
    $product->setMpStateShippingCharge($state[$key]);
    $product->setCod($cod[$key]);

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


    }}

1 Answer 1

1

you param is cod not cod_available check your jquery here parameters: {id: product_id, cod: $cod},

just change in controller it will start working

$cod_available = $this->getRequest()->getParam('cod');

and update that too $product->setCod($cod[$key]); to $product->setCodAvailable($cod[$key]);

11
  • sorry, did't worked for me Commented Feb 22, 2016 at 12:03
  • where is problem single update or multiple multiple? Commented Feb 22, 2016 at 12:05
  • both are giving me problem Commented Feb 22, 2016 at 12:06
  • seems by default, it showing "NO" for all products in frontend Commented Feb 22, 2016 at 12:07
  • did you check this attribute Used in Product Listing is yes in admin side Commented Feb 22, 2016 at 12:10

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.