2013-06-04 84 views
0

我有我測試以下ajax腳本。我真的很喜歡模塊開發,所以試圖這樣做。爲什麼添加產品時動態價格在購物車頁面上沒有正確反映?我記錄了var_dump($ product-> debug());它具有正確的變量定製價格,原始定製價格和isSuperMode(建立數字和真實)。Magento自定義價格不顯示在購物車/結帳

AJAX調用:

<?php 
//error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); 
require_once('/var/www/Staging/public_html/app/Mage.php'); 
umask(0); 
Mage::app(); 

//ensure that the value is legitimate 
if($_POST && is_numeric($_POST['value'])){ 
    $price = $_POST['price']; 
} 

//pass this in your ajax call for the add button 
if($_POST && is_numeric($_POST['product_id'])){ 
    $product_id = $_POST['product_id']; 
} 


$helper = Mage::helper('core'); //for translation 

$block = new Mage_Catalog_Block_Product_View(); // not best practice, but neither are standalones 
$product = Mage::getModel('catalog/product')->load($product_id); // no need to use the _ here, it's not protected/private; 


// Set the custom price 
$product->setCustomPrice($price); 
$product->setOriginalCustomPrice($price); 
// Enable super mode on the product. 
$product->getProduct()->setIsSuperMode(true); 

echo ('Custom Price is ' . $product->getCustomPrice() . '; '); //has correct value 
echo ('Custom Original Price is ' . $product->getOriginalCustomPrice() . '; '); //has correct value 

?> 

這是一個具有Ajax調用的函數。發佈變量是正確的。它無形中在可配置產品頁面上選擇適用的供應商屬性下拉選擇,最後一行將其添加到購物車。

function selectAndAddToCart(value) 
{ 
    var product_id= <?=$product_id ?>; 
    var colorSelected = $j("#attribute92 option:selected").val(); 

    $j('#attribute136 option[value="' + value + '"]').prop('selected',true); 

    $j('#attribute136').removeClass('validation-failed').addClass('validation-passed'); 

    var price = newPriceArray[value][colorSelected]; 
    console.log('The newPriceArray in selectAndAddToCart ' + price); //this is logging correctly 

    //Save price in system 
    $j.ajax({ 
     type: "POST", 
     url: "/ajax_calls/savePrice.php", 
     data: { 'product_id': product_id, 'price': price} 
     }).done(function() { 
       console.log('Prices have been updated in system'); 

       //initiate add to cart function 
       productAddToCartForm.submit(this); 

    });//end inner ajax request 

} 

回答

4

我想保存爲產品保存不在這裏

工作更換

Mage::app(); 

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); 
+0

都能跟得上。仍然不起作用:( – CaitlinHavener

相關問題