0

we are using magento marketplace multivendor site.

we gave an option for vendor to update the product details in frontend.

we are using this code for updating the price. its working fine.

Phtml

<input 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 id="price_update_button_<?php echo $products->getId(); ?>" class="update" onclick="updateFieldPrice('<?php echo $products->getId(); ?>'); return false;" >
<span><span style="font-size:12px;"><?php echo $helper->__('Update') ?></span></span>
</button>


<button 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>

JS

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

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

        $product->setPrice($upd_price);
        $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)); 

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

      }

In the same way we need to update the custom attribute "local" .

we are using following code to update local. but its not saving in database.

attribute code ="local" attribute value = "Local"

Phtml

<?php $attribute = $products->getResource()->getAttribute('local');?>
<?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= "price[]" value = "<?php echo $attribute_value; ?>" style = ""/>

<?php endif; ?>

<input type="hidden" name="curr_<?php echo $products->getId(); ?>" id="curr_<?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_update_button_<?php echo $products->getId(); ?>" class="update" onclick="updateFieldLocal('<?php echo $products->getId(); ?>'); return false;" >
<span><span style="font-size:12px;"><?php echo $helper->__('Update') ?></span></span>
</button>


<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>

JS

function updateFieldLocal(product_id) 
{ 
var localId = '#local_'+ product_id; 
var currlocal='#curr_'+ 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}, 
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());
        }

      }
  • if other attribute are saving except the attribute "local" then may be the attribute "local" is not assigned to product's attribute set – Piyush Dec 22 '15 at 10:49
  • @Piyush its assigned to attribute set. Price is working. first time i am trying with custom attribute – Baby in Magento Dec 22 '15 at 10:51
  • Remove "Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);" your controller file and try again – Abdul Dec 22 '15 at 11:21
  • @Abdul i tried, no luck.... – Baby in Magento Dec 22 '15 at 11:22
  • if you are trying save admin side any product with Local attribute value "Test" then working or not – Abdul Dec 22 '15 at 11:31
1

Try this

public function updateFieldLocalAction()
    {
        $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);
            if($product->getId()) {
                $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());
        }
    }
  • no, still same result – Baby in Magento Dec 22 '15 at 12:28
  • if your are debug : $product = Mage::getModel('catalog/product')->load($id); print_r(($product ); die; then get you current product or not – Abdul Dec 22 '15 at 13:08
  • mostly it will come. when i add this code : <?php $product = Mage::getModel('catalog/product')->load($id); print_r(($product ); die; ?> i got "Parse error: syntax error, unexpected ';'" – Baby in Magento Dec 22 '15 at 13:12
  • in the same code file ,i am getting price and quantity values – Baby in Magento Dec 22 '15 at 13:12
  • Pls tried bellow code : public function updateFieldLocalAction() { $product = Mage::getModel('catalog/product')->load(123); try{ $product->setLocal('test'); $product->save(); }catch(Exception $e){ $e->getMessage(); } } – Abdul Dec 22 '15 at 13:17

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.