我正在编写一个自定义模块,用户可以输入每件产品的运输成本。Magento自定义变量问题
我已将一个自定义变量添加到所有名为'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())'加载产品后(并明显启用系统日志),你能看到正确的值吗? –