【问题标题】:Magento Custom Variable issueMagento 自定义变量问题
【发布时间】:2014-06-09 11:37:24
【问题描述】:

我正在编写一个自定义模块,用户可以输入每个产品的运费。

我为我的所有产品添加了一个名为“initial_shipping_charge”的自定义变量。在我的“获取运费”功能中,我试图遍历我的购物篮中的产品并获取变量(这些将被添加到总体总数中)。

var_dump($shipping_price_initial);行返回 NULL 而不是它包含的变量 - 知道为什么这不起作用吗?

提前致谢。

protected function _getStandardShippingRate()
{
    $rate = Mage::getModel('shipping/rate_result_method');
    /* @var $rate Mage_Shipping_Model_Rate_Result_Method */

    $rate->setCarrier($this->_code);
    /**
     * getConfigData(config_key) returns the configuration value for the
     * carriers/[carrier_code]/[config_key]
     */


     $shipping_price_value = rand(10 , 50);

     //Create a basket session object
     $session = Mage::getSingleton('checkout/session');

    foreach ($session->getQuote()->getAllItems() as $item) {

        $item_id = $item->getId();
        $_basketProduct = Mage::getModel('catalog/product')->load($item_id);

        $shipping_price_initial = $_basketProduct->getAttribute('initial_shipping_charge');

        var_dump($shipping_price_initial);
    }

    $rate->setCarrierTitle($this->getConfigData('title'));

    $rate->setMethod('standand');
    $rate->setMethodTitle('Standard');

    $rate->setPrice($shipping_price_value);
    $rate->setCost(0);

    return $rate;
}

【问题讨论】:

  • 如果您在加载产品(并且显然启用了系统日志)后执行Mage::log($_basketProduct->getData()),您能看到正确的值吗?

标签: php magento magento-1.8


【解决方案1】:
$_basketProduct->getAttribute('initial_shipping_charge');

应该是

$_basketProduct->getData('initial_shipping_charge');

$_basketProduct->getInitialShippingCharge();

但我猜您甚至没有产品,因为您获取报价项目 ID 并尝试使用该 ID 加载产品....您需要:

$item->getProduct()

附注:

产品->报价->订单

有一个转换过程,寻找“报价到订单转换”或“产品到报价项目转换”

【讨论】:

  • @mishcha :哎呀,有一个拼写错误。我想你打算$_basketProduct->getInitialShippingCharge();
  • 恐怕不高兴 - 不过感谢您的建议 :)
  • 在使用 $item->getProduct() 后得到了这个工作 - 非常感谢您的帮助 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-18
  • 1970-01-01
相关资源
最近更新 更多