Question

we are using the following code to update the QUANTITY. I want to do the same for PRICE also

 <span id="valueqty_<?php echo $products->getId(); ?>"><?php echo (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($products)->getQty(); ?></span>
  <input type = "text" id = "qty_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" "name = "qty" value = "<?php echo (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($products)->getQty(); ?>" style = "display:none"/>


  <!-- aki 2 -->
<span class="label wk_action" id="edit_link_<?php echo $products->getId(); ?>">
        <img onclick="showField('<?php echo $products->getId(); ?>'); return false;" src="<?php echo $this->getSkinUrl('marketplace/images/icon-edit.png'); ?>"/>
    </span>  
<p id="updatedqty_<?php echo $products->getId(); ?>" style = "display:none;color:red;">Updated</p>
    <br/>
    <button id="update_button_<?php echo $products->getId(); ?>" class="button wk_mp_btn1" onclick="updateField('<?php echo $products->getId(); ?>'); return false;" style="display:none" >
        <span><span style="font-size:12px;"><?php echo $helper->__('Update') ?></span></span>
    </button>

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

<script type = "text/javascript" >
        function validateNumbers(e) {
            //var key = '#keyinput_'+ product_id;
            //var e = jQuery(key);

            if (jQuery.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
             // Allow: Ctrl+A, Command+A
            (e.keyCode == 65 && ( e.ctrlKey === true || e.metaKey === true ) ) || 
             // Allow: home, end, left, right, down, up
            (e.keyCode >= 35 && e.keyCode <= 40)) {
                 // let it happen, don't do anything
                 return;
            }
            // Ensure that it is a number and stop the keypress
            if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
                e.preventDefault();
            }
        }
        var $wk_jq = jQuery.noConflict();

        function hideReset(product_id) {
            /*
            var editLink = "#edit_link_"+ product_id;
            var updateButton = "#update_button_"+ product_id;
            var resetButton = "#reset_button"+ product_id;

            $wk_jq(editLink).show();
            $wk_jq(updateButton).hide();
            $wk_jq(resetButton).hide();
            */
            var qtyId='#qty_'+ product_id;
            var editLink="#edit_link_"+ product_id;
            var updateButton="#update_button_"+ product_id;
            var resetButton="#reset_button_"+ product_id;

            $wk_jq(qtyId).hide();
            $wk_jq(editLink).show();
            $wk_jq(updateButton).hide();
            $wk_jq(resetButton).hide();
        }
         function showField(product_id)
        {
            /*
            var qtyId = '#qty_'+ product_id;

            var editLink = "#edit_link_"+ product_id;
            var updateButton = "#update_button_"+ product_id;
            var resetButton = "#reset_button"+ product_id;

            $wk_jq(qtyId).toggle()

            $wk_jq(editLink).hide();
            $wk_jq(updateButton).show();
            $wk_jq(resetButton).show();

            $qty = $wk_jq(qtyId).val();
            */
            var qtyId='#qty_'+ product_id;

            var editLink="#edit_link_"+ product_id;
            var updateButton="#update_button_"+ product_id;
            var resetButton="#reset_button_"+ product_id;

            $wk_jq(qtyId).show();

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

            return false;


        }
        function updateField(product_id)
        {
            var qtyId = '#qty_'+ product_id;
            var valueId = '#valueqty_'+ product_id;
            var updatedqty = '#updatedqty_'+ product_id;


            var editLink = "#edit_link_"+ product_id;
            var updateButton = "#update_button_"+ product_id;
            var resetButton = "#reset_button"+ product_id;
        var url ='<?php echo Mage::getUrl('marketplace/marketplaceaccount/updateField/')?>';

            $wk_jq(qtyId).toggle()

            $wk_jq(editLink).hide();
            $wk_jq(updateButton).show();
            $wk_jq(resetButton).show();

            $qty = $wk_jq(qtyId).val();
            jQuery(valueId).html($qty);
            hideReset(product_id);

            new Ajax.Request(url, {
                method: 'post',
                parameters: {id: product_id, qty: $qty},
                onComplete: function (transport) {
                    //alert(transport.responseText);


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

                    $updateButton.prop('disabled', false);

                    $wk_jq(qtyId).setValue($qty);



                }
            });
        }

controller file

public function updateFieldAction(){
    $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);
    $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($id);
    $stockItem->setData('manage_stock', 1);
    $stockItem->setData('qty', $this->getRequest()->getParam('qty'));

    $stockItem->save();

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

}

what code needs to be changed to work for price....

Was it helpful?

Solution

Price is part of the product object rather than the stock item object. Therefore you need to take a different approach, either loading the products, updating their price values and saving them OR...

... using Mage::getSingleton('catalog/product_action')->updateAttributes($product, array($price stuff)...).

Given this situation you may want to use Magento's import methods to import prices.

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