フロントエンドのページを更新した後に特別価格が表示されています

magento.stackexchange https://magento.stackexchange.com//questions/91495

  •  13-12-2019
  •  | 
  •  

質問

フロントエンドのページを更新した後に特別価格が表示されています。価格は大丈夫です、特別価格は問題を与えています。

テキストフィールド価格と特別価格

を編集するための次のコードを使用しています。

価格のPHPコード

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

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



<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>
</td>
.

特殊価格のPHPコード

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


<span id="valueprice_<?php echo $products->getId(); ?>"><?php echo $products->getSpecialPrice(); ?></span>
<input type = "text" id = "specialprice_<?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="showFieldSpecialPrice('<?php echo $products->getId(); ?>'); return false;" src="<?php echo $this->getSkinUrl('marketplace/images/icon-edit.png'); ?>"/>
    </span>  
<p id="updatedspecialprice_<?php echo $products->getId(); ?>" style = "display:none;color:red;">Updated</p>
<br/>
<button id="specialprice_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="spe

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

価格

のJSとAjaxコード
public function updateFieldPrice(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/updateFieldPrice/')?>';

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



                }
            });
.

特別価格のJSとAjaxコード

function updateFieldSpecialPrice(product_id)
        {
            var priceId = '#specialprice_'+ product_id;
            var valueId = '#valuespecialprice_'+ product_id;
            var updatedqty = '#updatedspecialprice_'+ product_id;


            var editLink = "#specialprice_edit_link_"+ product_id;
            var updateButton = "#specialprice_update_button_"+ product_id;
            var resetButton = "#specialprice_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);



                }
            });
        }
.

価格のためのコントローラ

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

      }
.

特殊価格のコントローラファイル

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

      }
.

役に立ちましたか?

解決

これを試してください。Ajaxの両方を以下のように更新する

onComplete: function (transport) {
            .......
            jQuery(priceId).val($price);
            // $wk_jq(priceId).setValue($price);
           ......

}
.

ライセンス: CC-BY-SA帰属
所属していません magento.stackexchange
scroll top