php - Magento 自定义价格未显示在购物车/结账上

标签 php javascript magento

我正在测试以下ajax脚本。我真的不擅长模块开发,所以尝试这样做。添加产品后,为什么动态价格没有正确反射(reflect)在购物车页面上?我已记录 var_dump($product->debug()); 并且它具有正确的变量自定义价格、原始自定义价格和 isSuperMode(已建立的数字和 true)。

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 调用的函数。后置变量是正确的。它在可配置产品页面上无形地选择 vendor 属性的适用下拉选项,最后一行将其添加到购物车。

    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

}

最佳答案

我认为保存是产品保存在这里不起作用

替换

Mage::app(); 

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

关于php - Magento 自定义价格未显示在购物车/结账上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16908449/

相关文章:

客户导入时的 Magento 电子邮件验证

magento - 显示购物车规则和与每个规则关联的产品类别的集合

php - 数组上奇怪的 PHP 魔法 setter/getter

PHP 上传表单不会上传超过 16 个文件

javascript - 功能 - 显示与执行 console.log

javascript - 根据 Jquery 父级多选列表中选择的值构建子菜单

c# - 在 C# 中为 Magento 动态创建端点

php - 如何在 php sdk 3.1.1 中将权限参数添加到 getLoginUrl()

php - 简化 PHP 中的长 IF 语句

php - 在 onClick 函数中传递 php 变量