2

we are having marketplace [multi vendor] site. so in each seller or vendor account we are displaying name, sku, price .... etc. so that sellers/vendors can edit the product information and save . so it will reflect in backend.... we are using following code to display "Price". in the same way i want to display special Price also. for that what i am trying is in following code a) In Php code I am replacing <?php echo $products->getPrice(); ?> by <?php echo $products->getSpecialPrice(); ?> but

its not saving in backend. please give what changes i need to do in below code to work for special price. This is code for Price.

Php

<span id="valueprice_<?php echo $products->getId(); ?>">
<?php echo $products->getPrice(); ?></span> 



    <input type = "text" id = "price_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" "name = "price" value = "<?php echo $products->getPrice(); ?>" style = "display:none"/>


        <!-- aki 2 -->
    <span class="label wk_action" id="edit_link_<?php echo $products->getId(); ?>">
<img onclick="showFieldPrice('<?php echo $products->getId(); ?>'); return false;" src="<?php echo $this->getSkinUrl('marketplace/images/icon-edit.png'); ?>"/>
</span>  
<p id="updatedprice_<?php echo $products->getId(); ?>" style = "display:none;color:red;">Updated</p>
                <br/>
<button id="price_update_button_<?php echo $products->getId(); ?>" class="button wk_mp_btn1" onclick="updateFieldPrice('<?php echo $products->getId(); ?>'); return false;" style="display:none" >
<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(); ?>'); return false;" style="display:none" >
<span><span><?php echo $helper->__('Cancel') ?></span></span>
        </button>                                                       
    </span>

Javascript

<script>
function showFieldPrice(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='#price_'+ product_id;

            var editLink="#price_edit_link_"+ product_id;
            var updateButton="#price_update_button_"+ product_id;
            var resetButton="#price_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;


        }
        </script>

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));
        //Mage::getSingleton('core/session')->setEditProductId($id);

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

        //$stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($id);
        //$stockItem->setData('manage_stock', 1);
        //$stockItem->setData('qty', $this->getRequest()->getParam('qty'));
        $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)); 
        //Mage::getSingleton('core/session')->addSuccess(Mage::helper('marketplace')->__('Your Product Is Been Sucessfully Updated'));


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

      }
  }

for special price i am using following code :

PHP

<span class="label pro_status">
    <?php //echo $products->getSpecialPrice(); ?>

    <span id="valueprice_<?php echo $products->getId(); ?>">
    <?php echo $products->getSpecialPrice(); ?></span> 



    <input type = "text" id = "price_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" "name = "price" value = "<?php echo $products->getSpecialPrice(); ?>" style = "display:none"/>





    <span class="label wk_action" id="edit_link_<?php echo $products->getId(); ?>">
            <img onclick="showFieldPrice('<?php echo $products->getId(); ?>'); return false;" src="<?php echo $this->getSkinUrl('marketplace/images/icon-edit.png'); ?>"/>
                </span>  
            <p id="updatedprice_<?php echo $products->getId(); ?>" style = "display:none;color:red;">Updated</p>
            <br/>
            <button id="price_update_button_<?php echo $products->getId(); ?>" class="button wk_mp_btn1" onclick="updateFieldSpecialPrice('<?php echo $products->getId(); ?>'); return false;" style="display:none" >
            <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(); ?>'); return false;" style="display:none" >
            <span><span><?php echo $helper->__('Cancel') ?></span></span>
            </button>                                                       
            </span>

JS

<script>
function updateFieldSpecialPrice(product_id)
        {
            var priceId = '#price_'+ product_id;
            var valueId = '#valueprice_'+ product_id;
            var updatedqty = '#updatedprice_'+ product_id;


            var editLink = "#price_edit_link_"+ product_id;
            var updateButton = "#price_update_button_"+ product_id;
            var resetButton = "#price_reset_button"+ product_id;
            var url ='<?php echo Mage::getUrl('marketplace/marketplaceaccount/updateFieldSpecialPrice/')?>';

            $wk_jq(priceId).toggle()

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

            $price = $wk_jq(priceId).val();
            jQuery(valueId).html($price);
            hideReset(product_id);

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

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

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

                    $wk_jq(priceId).setValue($price);



                }
            });
        }

</script>

controllers

public function updateFieldSpecialPriceAction(){
        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));
        //Mage::getSingleton('core/session')->setEditProductId($id);

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

        //$stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($id);
        //$stockItem->setData('manage_stock', 1);
        //$stockItem->setData('qty', $this->getRequest()->getParam('qty'));
        $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)); 
        //Mage::getSingleton('core/session')->addSuccess(Mage::helper('marketplace')->__('Your Product Is Been Sucessfully Updated'));


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

      }
  • replace $product->setPrice($upd_price); with $product->setSpecialPrice($upd_price); in controllers – Qaisar Satti Nov 18 '15 at 6:19
  • please check updated question – Baby in Magento Nov 18 '15 at 6:22
  • please tell me what and all chnages i have to do in php, javascript and contrololers code, because special prices column in frontend is empty. – Baby in Magento Nov 18 '15 at 6:24
  • where you change it i said add in your controller function – Qaisar Satti Nov 18 '15 at 6:26
  • 1
    finalprice is something else so don't change it and it will not show anywhere.. – Qaisar Satti Nov 18 '15 at 7:52
1

replace $product->setPrice($upd_price); with $product->setSpecialPrice($upd_price); in controllers

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.