テスト中の次の ajax スクリプトがあります。$item->getProduct()->setIsSuperMode(true);を使用するように勧められました。しかし、次のエラーが表示されます: *PHP Fatal error: Call to a member function setIsSuperMode() on a non-object in /var/www/Staging/public_html/ajax_calls/savePrice.php on line 31*. そのため、->getProduct() 部分を削除しましたが、エラーは発生しませんが、カートに追加したときにコードに正しい価格が表示されません。setIsSuperMode を間違って使用しているのか、それともこの ajax 呼び出しを実行するのが早すぎたのかはわかりません。私はモジュール開発が本当に苦手なので、この方法でやろうとしていました。アドバイスしてください、私の頭がぼんやりしています!製品が追加されたときに動的価格がカート ページに正しく反映されないのはなぜですか?
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
}