Question

1)Initially this is the attribute code : "mp_local_shipping_region" ,

2)than i renamed attribute code to "local" , than i implemented feature of saving attribute from frontend. everything as fine. But some other problems happened after renamed the attribute code.

3)so i decided to revert to original attribute code "mp_local_shipping_region", but now attribute is not saving from frontend. once we click on "update" button it shows saved values, once we refresh the page, again it shows old values.

I want to know, in following code, is there anywhere i need to rename the attribute code from "local" to "mp_local_shipping_charge"

This is code i used to save attributes from frontend.

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

      }
Was it helpful?

Solution

thats actually bad debugging practice, but if you don't know xdebug it's a way to get this information you maybe need. You could try to do the following in your controller to see if you get the params right from the ajax call.

in your controller, before the $product-save();, you could insert the following code:

Zend_Debug::dump($id);
Zend_Debug::dump($upd_local);
die();

Then in your browser, you can track this ajax call.

In Chrome you can open the developer console by pressing F12 and then go to the Network tab. Then, before you click on the node that executes the call, you clean up the history there with the clear button (second row, second from the left for my Chrome version). When you then execute your ajax call there is only one or maybe a few requests.

You have to target the right request for your ajax call and then you should see the debug output you created in the controller in the response or preview tab on the right

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top